How can I modify the shader in the iPhone OpenGL ES template to produce this effect?
I'm trying to modify the fragment shader which is part of the standard iPhone/XCode OpenGL ES template. I want to make it so that every other row of pixels is transparent. I have this code so far:
varying lowp vec4 colorVarying;
void main()
{
gl_FragColor = vec4(colorVarying.x, colorVarying.y, colorVarying.z, floor(mod(gl_FragCoord.y, 2.0)));
}
But when I compile and run I still get the same square moving up and down with no other effects.
Here is my vertex shader (my keyboard just broke so no ret开发者_如何学Gourn key! DOH!)
attribute vec4 position;
attribute vec4 color;
varying vec4 colorVarying;
uniform float translate;
void main()
{
gl_Position = position;
gl_Position.y += sin(translate) / 2.0;
colorVarying = color;
}
Using this vertex shader and fragment shader above, I get no 'scanline effect' which I was hoping for. I'm testing using the iPad simulator and also the 3.1.3 iPhone simulator.
What am I doing wrong here? I'm a complete n00b at Glsl - I'm trying to teach myself the very basics (starting with this tutorial) .
Can you post your vertex shader as well? Assuming that it's passing over the vec4 colorVarying
there's no reason it shouldn't work when squashed into a single line as opposed to the two-line code in the sample (posted below)
float odd = floor(mod(gl_FragCoord.y, 2.0));
gl_FragColor = vec4(colorVarying.x, colorVarying.y, colorVarying.z, odd);
The only other difference I see is that you specified lowp
- try it without that.
精彩评论