I have the following vertex shader
Code: Select all
// bring in data
uniform vec3 lightPos;
// send to fragment shader
out vec3 Position;
out vec3 Normal;
out vec4 Color;
void main()
{
// compute the normal
Normal = normalize( gl_NormalMatrix * gl_Normal );
// compute the position
Position = (gl_ModelViewMatrix * gl_Vertex).xyz;
// get the color
Color = gl_Color;
// gl_FrontColor = gl_Color;
// calculate the position
// transform the vertex
// gl_Position = ftransform();
gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;
}
Code: Select all
// uniform sampler2D reflMap;
uniform vec3 lightPos;
in vec3 Position;
in vec3 Normal;
in vec4 Color;
// write the ads function
vec3 ads()
{
vec3 n = normalize( Normal );
vec3 s = normalize( lightPos - Position.xyz );
vec3 v = normalize( vec3(-Position) );
vec3 r = reflect( -s, n );
// get the ambient
// vec3 ambient = gl_LightSource[0].ambient.xyz * gl_FrontMaterial.ambient.xyz;
//ambient
// get the diffuse
/*vec3 diffuse = gl_LightSource[0].diffuse.xyz * gl_FrontMaterial.diffuse.xyz *
max( dot( s, n ), 0.0 );*/
vec3 diffuse = Color.xyz * max( dot( s, n ), 0.0 );
// get the specular
/*vec3 specular = gl_LightSource[0].specular.xyz * gl_FrontMaterial.specular.xyz *
pow( max( dot(r,v), 0.0 ), gl_FrontMaterial.shininess );*/
vec3 specular = vec3(1.0,1.0,1.0)*pow( max( dot(r,v), 0.0 ), 10 );
// get the light intensity
// return (ambient + diffuse + specular)*gl_Color.xyz;
return diffuse + specular;
}
void main()
{
gl_FragColor = vec4(ads(),1.0);
}