mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
working on the lighting
This commit is contained in:
parent
3e9e13ce01
commit
471da3935d
2 changed files with 19 additions and 24 deletions
|
@ -92,5 +92,4 @@ vec3 evalLightmappedColor(float shadowAttenuation, vec3 normal, vec3 diffuse, ve
|
|||
return diffuse * (ambientLight + diffuseLight);
|
||||
}
|
||||
|
||||
|
||||
<@endif@>
|
||||
|
|
|
@ -23,6 +23,8 @@ uniform float radius;
|
|||
|
||||
uniform mat4 invViewMat;
|
||||
|
||||
|
||||
|
||||
void main(void) {
|
||||
// get the depth and exit early if it doesn't pass the test
|
||||
vec2 texCoord = gl_TexCoord[0].st / gl_TexCoord[0].q;
|
||||
|
@ -37,7 +39,6 @@ void main(void) {
|
|||
vec4 wPos;
|
||||
wPos = invViewMat * frag.position;
|
||||
Light light = getLight();
|
||||
gl_FragColor = vec4(frag.normal, 0.0);
|
||||
|
||||
vec3 lightVector = getLightPosition(light) - wPos.xyz;
|
||||
if (dot(lightVector, lightVector) > getLightSquareRadius(light)) {
|
||||
|
@ -45,29 +46,24 @@ void main(void) {
|
|||
}
|
||||
|
||||
float lightDistance = length(lightVector);
|
||||
lightVector = lightVector / lightDistance;
|
||||
vec3 lightDir = lightVector / lightDistance;
|
||||
|
||||
float lightAttenuation = evalLightAttenuation(light, lightDistance);
|
||||
gl_FragColor.xyz *= lightAttenuation;
|
||||
/*
|
||||
float diffuse = dot(frag.normal, lightVector);
|
||||
|
||||
|
||||
float diffuse = dot(normalizedNormal, lightVector);
|
||||
float facingLight = step(0.0, diffuse);
|
||||
vec4 baseColor = texture2D(diffuseMap, texCoord) * (gl_FrontLightProduct[1].ambient +
|
||||
gl_FrontLightProduct[1].diffuse * (diffuse * facingLight));
|
||||
|
||||
// compute attenuation based on distance, etc.
|
||||
float attenuation = step(lightDistance, radius) / dot(vec3(gl_LightSource[1].constantAttenuation,
|
||||
gl_LightSource[1].linearAttenuation, gl_LightSource[1].quadraticAttenuation),
|
||||
vec3(1.0, lightDistance, lightDistance * lightDistance));
|
||||
|
||||
// add base to specular, modulate by attenuation
|
||||
float specular = facingLight * max(0.0, dot(normalize(lightVector - normalize(vec4(position.xyz, 0.0))),
|
||||
normalizedNormal));
|
||||
vec4 specularColor = texture2D(specularMap, texCoord);
|
||||
gl_FragColor = vec4((baseColor.rgb + pow(specular, specularColor.a * 128.0) * specularColor.rgb) * attenuation, 0.0);
|
||||
*/
|
||||
// gl_FragColor = vec4(frag.normal, 0.0);
|
||||
vec4 wNor = invViewMat * vec4(frag.normal, 0.0);
|
||||
vec4 wEyeVector = invViewMat * vec4(-frag.position.xyz, 0.0);
|
||||
vec3 eyeDir = normalize(wEyeVector.xyz);
|
||||
vec3 wHalfDir = normalize(eyeDir + lightDir);
|
||||
// Diffuse Lighting
|
||||
float diffuseDot = dot(wNor.xyz, lightDir);
|
||||
float facingLight = step(0.0, diffuseDot);
|
||||
vec3 diffuseColor = frag.diffuse * diffuseDot * facingLight;
|
||||
|
||||
// compute the specular multiplier (sans exponent)
|
||||
float specularPower = facingLight * max(0.0,
|
||||
dot(eyeDir, wHalfDir));
|
||||
vec3 specularColor = pow(specularPower, frag.gloss * 128.0) * frag.specular;
|
||||
|
||||
// add specular contribution
|
||||
gl_FragColor = vec4((diffuseColor + specularColor) * lightAttenuation * getLightColor(light) * getLightIntensity(light), 0.0);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue