-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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