summaryrefslogtreecommitdiff
path: root/example/fragmentshader.glsl
diff options
context:
space:
mode:
authorknolax <1339802534.kk@gmail.com>2017-02-22 20:43:47 -0500
committerknolax <1339802534.kk@gmail.com>2017-02-22 20:43:47 -0500
commitc7bdd6fcae58e09597071405c1449df64e084c51 (patch)
treec9ca26278a7a86725aa2e5af7e1a330c89265137 /example/fragmentshader.glsl
parentd137bf2485050b54bb0ac65ef543ba24f18fabbe (diff)
implemented phoung shading and surrounding infrastructure, gen.cpp compiles a simple program that creates raw vertex data from vertexes in a way that surppassess the limitations of opengl's native elements[] protocol. next step is to allow for z distance based override and multi draw;
Diffstat (limited to 'example/fragmentshader.glsl')
-rw-r--r--example/fragmentshader.glsl21
1 files changed, 20 insertions, 1 deletions
diff --git a/example/fragmentshader.glsl b/example/fragmentshader.glsl
index d15860a..70c55b5 100644
--- a/example/fragmentshader.glsl
+++ b/example/fragmentshader.glsl
@@ -1,6 +1,25 @@
#version 130
out vec4 outpix;
+uniform vec3 campos;
+uniform vec3 lightpos;
+//varing blends them it is transformed to world space
+varying vec4 fragpos;
+varying vec4 fragnormal;
void main()
{
- outpix = vec4(1.0, 0.0, 0.0, 0.5);
+ vec3 lightnormal = normalize((lightpos - vec3(fragpos.x, fragpos.y, fragpos.z)));
+ float diffuse = dot(lightnormal, vec3(fragnormal.x, fragnormal.y, fragnormal.z));
+ if (diffuse < 0.0) {
+ diffuse = 0.0;
+ }
+ vec3 camnormal = normalize(campos - vec3(fragpos.x, fragpos.y, fragpos.z));
+ float reflect = dot(camnormal, fragnormal.xyz);
+ diffuse = pow(diffuse, 2.0);
+ reflect = pow(reflect, 2.0);
+ float light = .4 * reflect + .6 * diffuse;
+ //this should be the vertex in camera space without the w value
+ //outpix = gl_FragCoord;
+ outpix = vec4(light * 1.0,light * 1.0,light * 1.0, 1.0);
+ //outpix = vec4(fragpos.x ,fragpos.y ,fragpos.z, 0.5);
+ //outpix = vec4(fragnormal.x, fragnormal.y, fragnormal.z, 0.5);
}