summaryrefslogtreecommitdiff
path: root/example/fragmentshader.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'example/fragmentshader.glsl')
-rw-r--r--example/fragmentshader.glsl19
1 files changed, 16 insertions, 3 deletions
diff --git a/example/fragmentshader.glsl b/example/fragmentshader.glsl
index 631ea69..fc7b4c8 100644
--- a/example/fragmentshader.glsl
+++ b/example/fragmentshader.glsl
@@ -2,6 +2,7 @@
out vec4 outpix;
uniform vec3 campos;
uniform vec3 lightpos;
+uniform vec4 lightattrib;
uniform sampler2D tex;
uniform sampler2D elev;
//varing blends them it is transformed to world space
@@ -18,18 +19,30 @@ void main()
float diffuse = dot(lightnormal, fragnormal.xyz);
if (diffuse < 0.0) {
diffuse = 0.0;
+ } else {
}
vec3 camnormal = normalize(campos - refpos);
- lightnormal = -normalize((lightpos - refpos)); // this time it is an incoming vector
+ lightnormal = normalize((refpos - lightpos)); // this time it is an incoming vector
vec3 refnormal = lightnormal - (2 * dot(lightnormal, fragnormal.xyz) * fragnormal.xyz);
float reflect = dot(camnormal, refnormal);
+ if (reflect < 0.0) {
+ reflect = 0.0;
+ } else {
+ }
diffuse = pow(diffuse, 2.0);
reflect = pow(reflect, 2.0);
- float light = (elevpix.b) * reflect + elevpix.a * diffuse;
+ float dist = abs(length(difpos - lightpos)) / lightattrib.a;
+ if (dist > 1.0) {
+ dist = 1.0;
+ }
+ dist = 1 - pow(dist, 4.0);
+ float lightr = (elevpix.b) * 1.0 * lightattrib.r * reflect + elevpix.a * 1.0 * dist * diffuse;
+ float lightg = (elevpix.b) * 1.0 * lightattrib.g * reflect + elevpix.a * 1.0 * dist * diffuse;
+ float lightb = (elevpix.b) * 1.0 * lightattrib.b * reflect + elevpix.a * 1.0 * dist * diffuse;
vec4 texpix = texture(tex, fragtexcoord);
//this should be the vertex in camera space without the w value
//outpix = gl_FragCoord;
- outpix = light * texpix;
+ outpix = vec4(lightr * texpix.r, lightg * texpix.g, lightb * texpix.b, texpix.a);
//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);