How can I modify the shader in the iPhone OpenGL ES template to produce this effect?

大兔子大兔子 提交于 2019-12-12 20:04:44

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/2965941/how-can-i-modify-the-shader-in-the-iphone-opengl-es-template-to-produce-this-eff

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!