Last active
December 25, 2015 20:19
-
-
Save joshuajnoble/7033768 to your computer and use it in GitHub Desktop.
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 src_tex_unit0; | |
uniform vec4 globalColor = vec4(1.0); | |
in vec2 texCoordVarying; | |
in vec4 colorVarying; | |
out vec4 fragColor; | |
uniform vec3 lightCenter; | |
uniform float lightRadius; | |
uniform vec3 lightColor; | |
uniform float lightCutoff; | |
uniform sampler2D tex; | |
vec3 directIllumination(vec3 position, vec3 normal, vec3 center, float rad, vec3 color, float cutoff) | |
{ | |
// calculate normalized light vector and distance to sphere light surface | |
float r = rad; | |
vec3 L = center - position; | |
float distance = length(L); | |
float d = max(distance - r, 0.); | |
L /= distance; | |
// calculate basic attenuation | |
float denom = d/r + 1.; | |
float attenuation = 1. / (denom*denom); | |
// scale and bias attenuation such that: | |
// attenuation == 0 at extent of max influence | |
// attenuation == 1 when d == 0 | |
attenuation = (attenuation - cutoff) / (1. - cutoff); | |
attenuation = max(attenuation, 0.); | |
float dot = max(dot(L, normal), 0.); | |
return color * dot * attenuation; | |
} | |
void main() | |
{ | |
// if you need a texture, otherwise | |
gl_FragColor = vec4(directIllumination(pp, nn, lightCenter, lightRadius, lightColor, lightCutoff).xyz, 1.0) + texture(src_tex_unit0, texCoordVarying); | |
// if you need a color | |
//gl_FragColor = vec4(directIllumination(pp, nn, lightCenter, lightRadius, lightColor, lightCutoff).xyz, 1.0) + colorVarying; | |
// no texturing | |
// gl_FragColor = vec4(directIllumination(pp, nn, lightCenter, lightRadius, lightColor, lightCutoff).xyz, 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
uniform mat4 projectionMatrix; | |
uniform mat4 modelViewMatrix; | |
uniform mat4 textureMatrix; | |
uniform mat4 modelViewProjectionMatrix; | |
in vec4 position; | |
in vec4 color; | |
in vec2 texcoord; | |
out vec2 texCoordVarying; | |
out vec4 colorVarying; | |
void main() | |
{ | |
texCoordVarying = texcoord; | |
colorVarying = color; | |
gl_Position = modelViewProjectionMatrix * position; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment