Skip to content

Instantly share code, notes, and snippets.

@danielpunkass
Created September 27, 2013 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielpunkass/ae8c554015de0af8dfdc to your computer and use it in GitHub Desktop.
Save danielpunkass/ae8c554015de0af8dfdc to your computer and use it in GitHub Desktop.
Example of using OpenGL ES shaders to simulate static TV-noise style animation.
//
// Shader.fsh
// ExampleGL
//
// Created by Daniel Jalkut on 1/6/12.
// Copyright (c) 2012 Red Sweater Software. All rights reserved.
//
// The idea for this GL-based noise shader was inspired by Mike Ash when I was chatting with him about
// how I could more efficiently generate the random noise updates to a UIView.
// Comes from the vertex shader
varying highp vec4 positionInput;
// Come from the client app
uniform highp float randomInput;
highp float rand(highp vec2 co)
{
// I got this technique online ... don't know if there is anything magical about the constants
// or if it's just thrown in junk...
highp float returnVal = fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
return returnVal;
}
void main()
{
highp float grayComponent = rand(vec2(positionInput.x + randomInput, positionInput.y + randomInput));
gl_FragColor = vec4(grayComponent, grayComponent, grayComponent, 1.0);
}
//
// Shader.vsh
// ExampleGL
//
// Created by Daniel Jalkut on 1/6/12.
// Copyright (c) 2012 Red Sweater Software. All rights reserved.
//
attribute vec4 position;
varying highp vec4 positionInput;
void main()
{
positionInput = position;
gl_Position = position;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment