summaryrefslogtreecommitdiff
path: root/example/fragmentshader.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'example/fragmentshader.glsl')
-rw-r--r--example/fragmentshader.glsl17
1 files changed, 11 insertions, 6 deletions
diff --git a/example/fragmentshader.glsl b/example/fragmentshader.glsl
index 6e8c4c5..631ea69 100644
--- a/example/fragmentshader.glsl
+++ b/example/fragmentshader.glsl
@@ -11,20 +11,25 @@ varying vec2 fragtexcoord;
void main()
{
vec4 elevpix = texture(elev, fragtexcoord);
- vec3 lightnormal = normalize((lightpos - vec3(fragpos.x, fragpos.y, fragpos.z)));
- float diffuse = dot(lightnormal, vec3(fragnormal.x, fragnormal.y, fragnormal.z));
+ //the format is diffuse reflect and percent
+ vec3 difpos = vec3(fragpos.xyz) + ((elevpix.r - .5) * 2 * fragnormal.xyz);
+ vec3 refpos = vec3(fragpos.xyz) + ((elevpix.g - .5) * 2 * fragnormal.xyz);
+ vec3 lightnormal = normalize((lightpos - difpos));
+ float diffuse = dot(lightnormal, fragnormal.xyz);
if (diffuse < 0.0) {
diffuse = 0.0;
}
- vec3 camnormal = normalize(campos - vec3(fragpos.x, fragpos.y, fragpos.z));
- float reflect = dot(camnormal, fragnormal.xyz);
+ vec3 camnormal = normalize(campos - refpos);
+ lightnormal = -normalize((lightpos - refpos)); // this time it is an incoming vector
+ vec3 refnormal = lightnormal - (2 * dot(lightnormal, fragnormal.xyz) * fragnormal.xyz);
+ float reflect = dot(camnormal, refnormal);
diffuse = pow(diffuse, 2.0);
reflect = pow(reflect, 2.0);
- float light = .4 * reflect + .6 * diffuse;
+ float light = (elevpix.b) * reflect + elevpix.a * diffuse;
vec4 texpix = texture(tex, fragtexcoord);
//this should be the vertex in camera space without the w value
//outpix = gl_FragCoord;
- outpix = texpix;
+ outpix = light * texpix;
//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);