Skip to content

Commit

Permalink
Section: Illuminating the Text with a Light
Browse files Browse the repository at this point in the history
  • Loading branch information
enobayram committed Nov 14, 2015
1 parent b96a7bd commit 64921d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Binary file modified plump.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 16 additions & 1 deletion text_and_shaders.ini
Expand Up @@ -28,7 +28,7 @@ String = HELLO WORLD!!
Font = plump

[TextShader]
ParamList = texture # BorderColor ; We've added a new parameter
ParamList = texture # BorderColor # LightPos # LightColor; We've added a new parameter
Code = "
void main() {
// Get the texture value for the current pixel
Expand All @@ -37,9 +37,24 @@ void main() {
// Here's the fun; We blend in the border color based on R channel
gl_FragColor.rgb = mix(vec3(1.0), BorderColor, tex.r) * gl_Color.rgb;
// Let's derive the surface normal from the green and blue channels
vec3 normal = normalize(vec3(tex.g-0.5, tex.b-0.5, 0.5));
// Let's find the unit vector pointing from this pixel towards the light
vec3 light_dir = normalize(LightPos-gl_FragCoord.xyz);
// The illumination of a Lambertian surface is the dot product
// of the surface normal and the unit vector towards the light
float illumination = max(0.0, dot(normal, light_dir));
// Let's apply the light color and the illumination
gl_FragColor.rgb *= LightColor * illumination;
// Set the pixel alpha to the texture's alpha multiplied by the object's
gl_FragColor.a = tex.a * gl_Color.a;
}"
BorderColor = (0,0,255) ; Let's make the border blue, just for fun.
LightPos = (200,150,100) ;
LightColor = (1,0.7,0.7) ;

@plump.ini@

0 comments on commit 64921d0

Please sign in to comment.