Last active
August 29, 2015 14:11
-
-
Save Zarkonnen/cf6eb01937e40d71e4ed to your computer and use it in GitHub Desktop.
bump.glsl
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
uniform sampler2D tex; | |
uniform sampler2D lightFromLeft; | |
uniform sampler2D lightFromTop; | |
uniform sampler2D lightFromRight; | |
uniform sampler2D lightFromBottom; | |
uniform sampler2D bump; | |
uniform vec4 tint; | |
uniform float strength; | |
uniform vec2 lightSize; | |
uniform float screenHeight; | |
uniform int flipped; | |
uniform float angle; | |
void main(void) { | |
vec4 bumpLookup = texture2D(bump, floor(gl_TexCoord[0].st) / 1024.0); | |
float topM = max(bumpLookup.x - 0.3, 0.0) * 2.0 * bumpLookup.z * strength; | |
float bottomM = max(0.7 - bumpLookup.x, 0.0) * 2.0 * bumpLookup.z * strength; | |
float leftM = max(bumpLookup.y - 0.3, 0.0) * 2.0 * bumpLookup.z * strength; | |
float rightM = max(0.7 - bumpLookup.y, 0.0) * 2.0 * bumpLookup.z * strength; | |
float m0 = max(0, cos(angle)); | |
float m1 = max(0, cos(angle + 0.785398163)); | |
float m2 = max(0, cos(angle + 1.570796327)); | |
float m3 = max(0, cos(angle + 2.35619449)); | |
vec4 lightTop = texture2D(lightFromTop, vec2(gl_FragCoord.x, screenHeight - gl_FragCoord.y) / lightSize / 8.0); | |
vec4 lightBottom = texture2D(lightFromBottom, vec2(gl_FragCoord.x, screenHeight - gl_FragCoord.y) / lightSize / 8.0); | |
vec4 lightLeft = texture2D(lightFromLeft, vec2(gl_FragCoord.x, screenHeight - gl_FragCoord.y) / lightSize / 8.0); | |
vec4 lightRight = texture2D(lightFromRight, vec2(gl_FragCoord.x, screenHeight - gl_FragCoord.y) / lightSize / 8.0); | |
if (flipped == 1) { | |
vec4 totalLight = | |
topM * (lightTop * m0 + lightRight * m1 + lightBottom * m2 + lightLeft * m3) + // top | |
leftM * (lightTop * m3 + lightRight * m0 + lightBottom * m1 + lightLeft * m2) + // left | |
bottomM * (lightTop * m2 + lightRight * m3 + lightBottom * m0 + lightLeft * m1) + // bottom | |
rightM * (lightTop * m1 + lightRight * m2 + lightBottom * m3 + lightLeft * m0); // right | |
gl_FragColor = texture2D(tex, floor(gl_TexCoord[0].st) / 1024.0) * tint + vec4(totalLight.x, totalLight.y, totalLight.z, 0); | |
} else { | |
vec4 totalLight = | |
topM * (lightTop * m0 + lightRight * m1 + lightBottom * m2 + lightLeft * m3) + // top | |
rightM * (lightTop * m3 + lightRight * m0 + lightBottom * m1 + lightLeft * m2) + // left | |
bottomM * (lightTop * m2 + lightRight * m3 + lightBottom * m0 + lightLeft * m1) + // bottom | |
leftM * (lightTop * m1 + lightRight * m2 + lightBottom * m3 + lightLeft * m0); // right | |
gl_FragColor = texture2D(tex, floor(gl_TexCoord[0].st) / 1024.0) * tint + vec4(totalLight.x, totalLight.y, totalLight.z, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment