diff options
author | knolax <1339802534.kk@gmail.com> | 2017-03-01 10:51:50 -0500 |
---|---|---|
committer | knolax <1339802534.kk@gmail.com> | 2017-03-01 10:51:50 -0500 |
commit | 50462167289384ba8c546331a71d8d8558f06c80 (patch) | |
tree | 655c34c43889c47e86a8d9f5159af8850158c08c /example/fragmentshader.glsl | |
parent | cf3f284a5f24bd02006e9ff929cc29d10c428a3e (diff) |
changed the elevation texture and switched the diffuse/reflect value positions
Diffstat (limited to 'example/fragmentshader.glsl')
-rw-r--r-- | example/fragmentshader.glsl | 17 |
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); |