Hello,

I have a quick question ;)

At the moment I am playing a little bit with lighting and material and 
therefore I tried to use a shader. I set up a simple shapeDrawable 
(sphere) and a vertex and fragment program. The code for the shaders I 
found in a tutorial. It is posted bellow. I also enabled lighting und 
light0 and set up values for these. What I get is really not phong. Just 
some real white and black. Could there be a problem with the normals?

Greetings,
Marcus

VERT

varying vec3 normal;
varying vec3 v;
varying vec3 lightvec;
void main(void)
{
  normal          = normalize(gl_NormalMatrix * gl_Normal);
  v               = vec3(gl_ModelViewMatrix * gl_Vertex);
  lightvec        = normalize(gl_LightSource[0].position.xyz - v);
  gl_Position     = gl_ModelViewProjectionMatrix * gl_Vertex;
}

FRAG

varying vec3 normal;
varying vec3 v;
varying vec3 lightvec;
 
void main(void)
{
 vec3 Eye             = normalize(-v);
 
 vec3 Reflected       = normalize( reflect( -lightvec, normal ));
 //hat den selben effekt wie
 //vec3 Reflected       = normalize( 2.0 * dot(normal, lightvec) *  
normal - lightvec);
 
 vec4 IAmbient        = gl_LightSource[0].ambient;
 vec4 IDiffuse        = gl_LightSource[0].diffuse * max(dot(normal, 
lightvec), 0.0);
 vec4 ISpecular       = gl_LightSource[0].specular * 
pow(max(dot(Reflected, Eye), 0.0), gl_FrontMaterial.shininess);
 gl_FragColor         = gl_FrontLightModelProduct.sceneColor + IAmbient 
+ IDiffuse + ISpecular;
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to