70081

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

Answer1:

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.

Recommend

  • No uniform with name in shader
  • GLSL : accessing framebuffer to get RGB and change it
  • GLSL fragment shader syntax error
  • Visual Basic Vending Machine
  • mod-rewrite rule for sitemap.xml
  • WebGL: Access buffer from shader
  • Is need install mysql on AWS EC2 if i am using AWS rds as database instance?
  • Oracle SQL - Generate and update a column with different random number in every row
  • C# fibonacci function returning errors
  • NUnit 3.0 TestCase const custom object arguments
  • android google indoor map
  • How to get current document uri in XSLT?
  • Convert Type Decimal to Hex (string) in .NET 3.5
  • What is the purpose of TaskExecutor in spring?
  • Calling Worksheet functions from vba in foreign language versions of Excel
  • Groovy: Unexpected token “:”
  • Read text file and split every line in MSBuild
  • Date difference with leap year
  • output of program is not same as passed argument
  • Akka Routing: Reply's send to router ends up as dead letters
  • SVN: Merging two branches together
  • Hibernate gives error error as “Access to DialectResolutionInfo cannot be null when 'hibernate.
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Java static initializers and reflection
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • Change div Background jquery
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • Qt: Run a script BEFORE make
  • Bitwise OR returns boolean when one of operands is nil
  • unknown Exception android
  • EntityFramework adding new object to nested object collection
  • Is there any way to bind data to data.frame by some index?
  • Checking variable from a different class in C#
  • Django query for large number of relationships
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • failed to connect to specific WiFi in android programmatically
  • Converting MP3 duration time
  • How to push additional view controllers onto NavigationController but keep the TabBar?
  • How can I use threading to 'tick' a timer to be accessed by other threads?