1
0
Fork 0
fgdata/Compositor/Shaders/ALS/model-transparent.frag

51 lines
1.4 KiB
C++

// -*-C++-*-
// Ambient term comes in gl_Color.rgb.
#version 120
varying vec4 diffuse_term;
varying vec3 normal;
varying float flogz;
uniform float fg_Fcoef;
uniform sampler2D texture;
void main()
{
vec3 n;
float NdotL, NdotHV;
vec4 color = gl_Color;
vec3 lightDir = gl_LightSource[0].position.xyz;
vec3 halfVector = gl_LightSource[0].halfVector.xyz;
vec4 texel;
vec4 fragColor;
vec4 specular = vec4(0.0);
// If gl_Color.a == 0, this is a back-facing polygon and the
// normal should be reversed.
n = (2.0 * gl_Color.a - 1.0) * normal;
n = normalize(n);
NdotL = dot(n, lightDir);
if (NdotL > 0.0) {
color += diffuse_term * NdotL;
NdotHV = max(dot(n, halfVector), 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 = diffuse_term.a;
// 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;
gl_FragColor = fragColor;
// logarithmic depth
gl_FragDepth = log2(flogz) * fg_Fcoef * 0.5;
}