diff options
Diffstat (limited to 'example/fragmentshadowshader.glsl')
-rw-r--r-- | example/fragmentshadowshader.glsl | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/example/fragmentshadowshader.glsl b/example/fragmentshadowshader.glsl new file mode 100644 index 0000000..4e551c4 --- /dev/null +++ b/example/fragmentshadowshader.glsl @@ -0,0 +1,49 @@ +#version 130 +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 +varying vec4 fragpos; +varying vec4 fragnormal; +varying vec2 fragtexcoord; +void main() +{ + vec4 elevpix = texture(elev, fragtexcoord); + //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; + } else { + } + vec3 camnormal = normalize(campos - refpos); + 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 dist = abs(length(difpos - lightpos)) / lightattrib.a; + if (dist > 1.0) { + dist = 1.0; + } + dist = 1 - pow(dist, 4.0); + float lightr = (elevpix.b) * 0.5 * lightattrib.r * reflect + elevpix.a * 0.5 * dist * diffuse; + float lightg = (elevpix.b) * 1.0 * lightattrib.g * reflect + elevpix.a * 1.0 * dist * diffuse; + float lightb = (elevpix.b) * 0.5 * lightattrib.b * reflect + elevpix.a * 0.5 * dist * diffuse; + vec4 texpix = texture(tex, fragtexcoord); + //this should be the vertex in camera space without the w value + //outpix = gl_FragCoord; + 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); +} |