views:

422

answers:

3

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 return 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) .

A: 

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.

Chris Peredun
A: 

Here is my vertex shader (my keyboard just broke so no return 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.

David
@David - Have you tried removing the `lowp` from your fragment shader? GLSL doesn't (or didn't?) do auto-casting, so it being defined as normal precision in vertex and low precision in the fragment might be causing it to hiccup somehow.
Chris Peredun
A: 

I've tried removing the precision qualifier, and then I get a compile error:

Shader compile log: ERROR: 0:9: '4-component vector of float' : declaration must include a precision qualifier for type

I've tried adding the highp qualifier to both fragment and vertex shaders declarations of the colorVarying variable but I still have no visible "scanline" effect. (it compiles fine though).

Is this definitely supported by the iPad simulator? I'm testing with a core-duo 1.8Ghz Mac-mini running snow leopard.

David