Last active
August 29, 2015 14:06
-
-
Save AtkinsSJ/6045f0cf018f19fbd32d to your computer and use it in GitHub Desktop.
Basic shader that makes things dark and blueish. The Vertex shader is just a generic one. The fragment shader gets the lightness of the pixel at the right place on the texture, darkens it, and gives it a blue tint.
This file contains hidden or 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
float lightDistance = 100.0; | |
void main(void) | |
{ | |
vec2 uv = gl_FragCoord.xy / iResolution.xy; | |
uv.y = iResolution.y - uv.y; | |
vec4 tex = texture2D(iChannel0, uv); | |
// How far are we from the mouse? | |
float mouseDist = distance(gl_FragCoord.xy, iMouse.xy); | |
if (mouseDist > lightDistance) { | |
// How "light" is this pixel? | |
float lightness = (tex.r + tex.g + tex.b) / 3.0; | |
// Make everything dark and blue-ish | |
gl_FragColor = vec4(lightness/5.0, lightness/5.0, lightness/3.0, 1.0); | |
} else { | |
gl_FragColor = tex; | |
} | |
} |
This file contains hidden or 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
#ifdef GL_ES | |
precision mediump float; | |
#endif | |
varying vec4 v_color; | |
varying vec2 v_texCoords; | |
uniform sampler2D u_texture; | |
void main() | |
{ | |
vec4 tex = v_color * texture2D(u_texture, v_texCoords); | |
float lightness = (tex.r + tex.g + tex.b) / 3.0; | |
// Make things dark and blueish | |
gl_FragColor = vec4(lightness/5.0, lightness/5.0, lightness/3.0, tex.a); | |
} |
This file contains hidden or 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
attribute vec4 a_position; | |
attribute vec4 a_color; | |
attribute vec2 a_texCoord0; | |
uniform mat4 u_projTrans; | |
varying vec4 v_color; | |
varying vec2 v_texCoords; | |
void main() | |
{ | |
v_color = a_color; | |
v_texCoords = a_texCoord0; | |
gl_Position = u_projTrans * a_position; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment