[osg-users] Phong and Gouraud Shader question

Dominic Stalder dominic.stalder at bluewin.ch
Fri Nov 13 09:57:28 PST 2009


Hi Paulo

thanks for your feedback, I will try the shader.

Regards
Dominic

Paulo Silva schrieb:
> Hi,
>
> GL by default uses either GL_SMOOTH
> http://www.opengl.org/sdk/docs/man/xhtml/glShadeModel.xml
> Probably osg also uses the default value.
> GL_SMOOTH calculates the light at each vertex and interpolates the value in the primitive, also called Gouraud shading
> http://en.wikipedia.org/wiki/Gouraud_shading
> While the Phong shading interpolates not the color but the normals in the primitive
> http://en.wikipedia.org/wiki/Phong_reflection_model
>
> I do happen to have a phong shader lying around, but only for one light.
> But you can find it anywhere, both books and web...
> (vert)
> varying vec3 v_V;
> varying vec3 v_N;
>
> void main() {
> 	gl_Position = ftransform();
> 	v_V = (gl_ModelViewMatrix * gl_Vertex).xyz;
> 	v_N = gl_NormalMatrix * gl_Normal;
> }
>
>
> (frag)
> varying vec3 v_V;
> varying vec3 v_N;
>
> void main() {
> 	vec3 N = normalize(v_N);
> 	vec3 V = normalize(v_V);
> 	vec3 R = reflect(V, N);
> 	vec3 L = normalize(vec3(gl_LightSource[0].position));
>
> 	vec4 ambient = gl_FrontMaterial.ambient;
> 	vec4 diffuse = gl_FrontMaterial.diffuse * max(dot(L, N), 0.0);
> 	vec4 specular = gl_FrontMaterial.specular
> 		* pow(max(dot(R, L), 0.0), gl_FrontMaterial.shininess);
>
> 	gl_FragColor = ambient + diffuse + specular;
> }
>
> Cheers,
> Paulo
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=19598#19598
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>   



More information about the osg-users mailing list