1
0
Fork 0

clamp lighting values and support transparency material animation

The transparency animation support is a hack, but should get the job done
for a bit.


Author: Tim Moore <timoore@redhat.com>
This commit is contained in:
timoore 2009-11-17 21:57:07 +00:00
parent ca82d06aef
commit 56fc0f9076
3 changed files with 27 additions and 11 deletions

View file

@ -13,7 +13,8 @@ void main()
vec4 color = ambient + gl_FrontMaterial.emission;
vec4 texel;
vec4 fragColor;
vec4 specular = vec4(0.0);
n = normalize(normal);
NdotL = max(dot(n, lightDir), 0.0);
if (NdotL > 0.0) {
@ -21,12 +22,17 @@ void main()
halfV = normalize(halfVector);
NdotHV = max(dot(n, halfV), 0.0);
if (gl_FrontMaterial.shininess > 0.0)
color += gl_FrontMaterial.specular * gl_LightSource[0].specular
* pow(NdotHV, gl_FrontMaterial.shininess);
specular.rgb = (gl_FrontMaterial.specular.rgb
* gl_LightSource[0].specular.rgb
* pow(NdotHV, gl_FrontMaterial.shininess));
}
color.a = alpha;
// This shouldn't be necessary, but our lighting becomes very
// saturated. Clamping the color before modulating by the texture
// is closer to what the OpenGL fixed function pipeline does.
color = clamp(color, 0.0, 1.0);
texel = texture2D(texture, gl_TexCoord[0].st);
fragColor = color * texel;
fragColor = color * texel + specular;
fogFactor = exp(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord);
gl_FragColor = mix(gl_Fog.color, fragColor, fogFactor);
}

View file

@ -13,7 +13,7 @@ void main()
vec4 color = constantColor;
vec4 texel;
vec4 fragColor;
vec4 specular = vec4(0.0);
n = normalize(normal);
NdotL = max(dot(n, lightDir), 0.0);
if (NdotL > 0.0) {
@ -21,12 +21,17 @@ void main()
halfV = normalize(halfVector);
NdotHV = max(dot(n, halfV), 0.0);
if (gl_FrontMaterial.shininess > 0.0)
color += gl_FrontMaterial.specular * gl_LightSource[0].specular
* pow(NdotHV, gl_FrontMaterial.shininess);
specular.rgb = (gl_FrontMaterial.specular.rgb
* gl_LightSource[0].specular.rgb
* pow(NdotHV, gl_FrontMaterial.shininess));
}
color.a = alpha;
// This shouldn't be necessary, but our lighting becomes very
// saturated. Clamping the color before modulating by the texture
// is closer to what the OpenGL fixed function pipeline does.
color = clamp(color, 0.0, 1.0);
texel = texture2D(texture, gl_TexCoord[0].st);
fragColor = color * texel;
fragColor = color * texel + specular;
fogFactor = exp(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord);
gl_FragColor = mix(gl_Fog.color, fragColor, fogFactor);
}

View file

@ -5,8 +5,8 @@
// The only light used is gl_LightSource[0], which is assumed to be
// directional.
//
// Diffuse and ambient colors come from the gl_Color. This is
// equivalent to osg::Material::AMBIENT_AND_DIFFUSE.
// Diffuse colors come from the gl_Color, ambient from the material. This is
// equivalent to osg::Material::DIFFUSE.
varying vec4 diffuse, constantColor;
varying vec3 normal, lightDir, halfVector;
@ -22,7 +22,12 @@ void main()
lightDir = normalize(vec3(gl_LightSource[0].position));
halfVector = normalize(gl_LightSource[0].halfVector.xyz);
diffuse = gl_Color * gl_LightSource[0].diffuse;
alpha = gl_Color.a;
// Super hack: if diffuse material alpha is less than 1, assume a
// transparency animation is at work
if (gl_FrontMaterial.diffuse.a < 1.0)
alpha = gl_FrontMaterial.diffuse.a;
else
alpha = gl_Color.a;
constantColor = gl_FrontLightModelProduct.sceneColor
+ gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
fogCoord = abs(ecPosition3.z);