Commit c9a09c1e authored by Jan Möbius's avatar Jan Möbius

Updated phong shader

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5501 383ad7c9-94d9-4d36-a494-682f7c89f535
parent e5293dcf
varying vec4 diffuse_color;
varying vec3 normal;
varying vec4 vertexPosition;
varying vec4 diffuse,ambient;
varying vec3 normal,lightDir,halfVector;
vec4 phong_direct(int lightSource) {
vec3 light_pos = vec3(gl_LightSource[lightSource].position);
vec3 eye_pos = vec3(vertexPosition / vertexPosition.w);
vec3 lightVector = vec3(light_pos - eye_pos);
float lightDistance = length(lightVector);
lightVector /= lightDistance;
void main()
{
vec3 n,halfV,viewV,ldir;
float NdotL,NdotHV;
vec4 color = ambient;
/* a fragment shader can't write a verying variable, hence we need
a new variable to store the normalized interpolated normal */
n = normalize(normal);
/* compute the dot product between normal and ldir */
NdotL = max(dot(n,lightDir),0.0);
vec4 color = vec4(0.0);
vec3 n;
float NdotL, NdotHV;
n = normalize(normal);
NdotL = dot(n, lightVector);
float LdotD = dot(lightVector, gl_LightSource[lightSource].spotDirection);
if (NdotL > 0.0) {
halfV = normalize(halfVector);
NdotHV = max(dot(n,halfV),0.0);
color += gl_FrontMaterial.specular * gl_LightSource[0].specular * pow(NdotHV,gl_FrontMaterial.shininess);
color += diffuse * NdotL;
}
if (NdotL > 0.0 && LdotD < 0.0) {
color = gl_LightSource[lightSource].diffuse * -LdotD * NdotL;
}
// Use Alpha Value from original color
color[3] = diffuse_color[3];
return color;
gl_FragColor = color;
}
void main() {
gl_FragColor = phong_direct(0);
}
varying vec4 diffuse_color;
varying vec3 normal;
varying vec4 vertexPosition;
varying vec4 diffuse,ambient;
varying vec3 normal,lightDir,halfVector;
void main()
{
normal = normalize(gl_NormalMatrix * gl_Normal);
vertexPosition = gl_ModelViewMatrix * gl_Vertex;
gl_Position = gl_ProjectionMatrix * vertexPosition;
diffuse_color = gl_FrontMaterial.diffuse;
}
{
/* first transform the normal into eye space and
normalize the result */
normal = normalize(gl_NormalMatrix * gl_Normal);
/* now normalize the light's direction. Note that
according to the OpenGL specification, the light
is stored in eye space. Also since we're talking about
a directional light, the position field is actually direction */
lightDir = normalize(vec3(gl_LightSource[0].position));
/* Normalize the halfVector to pass it to the fragment shader */
halfVector = normalize(gl_LightSource[0].halfVector.xyz);
/* Compute the diffuse, ambient and globalAmbient terms */
diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
ambient += gl_LightModel.ambient * gl_FrontMaterial.ambient;
gl_Position = ftransform();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment