1
0
Fork 0

light two-sided polygons

Also, remove model-default.frag; for the moment one fragment shader works for
both terrain and models.


Author: Tim Moore <timoore@redhat.com>
This commit is contained in:
timoore 2009-11-19 16:20:51 +00:00
parent 42832d3e79
commit 971b6c3ef2
4 changed files with 13 additions and 44 deletions

View file

@ -62,7 +62,7 @@
</texture-unit> </texture-unit>
<program> <program>
<vertex-shader>Shaders/model-default.vert</vertex-shader> <vertex-shader>Shaders/model-default.vert</vertex-shader>
<fragment-shader>Shaders/model-default.frag</fragment-shader> <fragment-shader>Shaders/default.frag</fragment-shader>
</program> </program>
<uniform> <uniform>
<name>texture</name> <name>texture</name>

View file

@ -1,21 +1,27 @@
// -*-C++-*- // -*-C++-*-
varying vec4 diffuse, ambient; varying vec4 diffuse, constantColor;
varying vec3 normal, lightDir, halfVector; varying vec3 normal, lightDir, halfVector;
varying float fogCoord, alpha; varying float fogCoord, alpha;
uniform sampler2D texture; uniform sampler2D texture;
float luminance(vec3 color)
{
return dot(vec3(0.212671, 0.715160, 0.072169), color);
}
void main() void main()
{ {
vec3 n, halfV; vec3 n, halfV;
float NdotL, NdotHV, fogFactor; float NdotL, NdotHV, fogFactor;
vec4 color = ambient + gl_FrontMaterial.emission; vec4 color = constantColor;
vec4 texel; vec4 texel;
vec4 fragColor; vec4 fragColor;
vec4 specular = vec4(0.0); vec4 specular = vec4(0.0);
n = normalize(normal); n = normalize(normal);
if (!gl_FrontFacing)
n = -n;
NdotL = max(dot(n, lightDir), 0.0); NdotL = max(dot(n, lightDir), 0.0);
if (NdotL > 0.0) { if (NdotL > 0.0) {
color += diffuse * NdotL; color += diffuse * NdotL;

View file

@ -8,7 +8,7 @@
// Diffuse and ambient colors come from the gl_Color. This is // Diffuse and ambient colors come from the gl_Color. This is
// equivalent to osg::Material::AMBIENT_AND_DIFFUSE. // equivalent to osg::Material::AMBIENT_AND_DIFFUSE.
varying vec4 diffuse, ambient; varying vec4 diffuse, constantColor;
varying vec3 normal, lightDir, halfVector; varying vec3 normal, lightDir, halfVector;
varying float fogCoord, alpha; varying float fogCoord, alpha;
@ -22,7 +22,7 @@ void main()
halfVector = normalize(gl_LightSource[0].halfVector.xyz); halfVector = normalize(gl_LightSource[0].halfVector.xyz);
diffuse = gl_Color * gl_LightSource[0].diffuse; diffuse = gl_Color * gl_LightSource[0].diffuse;
alpha = gl_Color.a; alpha = gl_Color.a;
ambient = gl_Color * gl_LightSource[0].ambient; constantColor = gl_FrontLightModelProduct.sceneColor
ambient += gl_Color * gl_LightModel.ambient; + gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
fogCoord = abs(ecPosition.z); fogCoord = abs(ecPosition.z);
} }

View file

@ -1,37 +0,0 @@
// -*-C++-*-
varying vec4 diffuse, constantColor;
varying vec3 normal, lightDir, halfVector;
varying float alpha, fogCoord;
uniform sampler2D texture;
void main()
{
vec3 n, halfV;
float NdotL, NdotHV, fogFactor;
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) {
color += diffuse * NdotL;
halfV = normalize(halfVector);
NdotHV = max(dot(n, halfV), 0.0);
if (gl_FrontMaterial.shininess > 0.0)
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 + specular;
fogFactor = exp(-gl_Fog.density * gl_Fog.density * fogCoord * fogCoord);
gl_FragColor = mix(gl_Fog.color, fragColor, fogFactor);
}