Original Post
I am experimenting with GLSL shaders. What I wanted to do is just create a simple shader that replicates the openGL lighting model and I can't seem to do it. I'm sure that this is a very noob question with a simple answer but I can't figure it out.
Here is what the opengl render looks like:
http://i713.photobucket.com/albums/ww140/ogre722/nonshader.png?t=1276329120
And this is what the GLSL render looks like:
http://i713.photobucket.com/albums/ww140/ogre722/shader.png?t=1276329172
Based on this code:
[Vertex Shader]
varying vec4 diffuse;
void main()
{
gl_Position = ftransform();
vec3 normal = gl_Normal;
vec3 lightVector = vec3(0,0,5);
lightVector = gl_LightSource[0].position.xyz - gl_Vertex.xyz;
lightVector = normalize(lightVector);
float nxDir = max(0.0, dot(normal, -lightVector));
diffuse = gl_LightSource[0].diffuse * nxDir;
}
[Fragment Shader]
varying vec4 diffuse;
void main()
{
gl_FragColor = gl_LightSource[0].ambient + diffuse;
}
Here is what the opengl render looks like:
http://i713.photobucket.com/albums/ww140/ogre722/nonshader.png?t=1276329120
And this is what the GLSL render looks like:
http://i713.photobucket.com/albums/ww140/ogre722/shader.png?t=1276329172
Based on this code:
[Vertex Shader]
varying vec4 diffuse;
void main()
{
gl_Position = ftransform();
vec3 normal = gl_Normal;
vec3 lightVector = vec3(0,0,5);
lightVector = gl_LightSource[0].position.xyz - gl_Vertex.xyz;
lightVector = normalize(lightVector);
float nxDir = max(0.0, dot(normal, -lightVector));
diffuse = gl_LightSource[0].diffuse * nxDir;
}
[Fragment Shader]
varying vec4 diffuse;
void main()
{
gl_FragColor = gl_LightSource[0].ambient + diffuse;
}