• Advertisement
Sign in to follow this  

Can you mimic GL_SEPARATE_SPECULAR_COLOR in GLSL?

This topic is 3199 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to mimic: glLightModeli(GL12.GL_LIGHT_MODEL_COLOR_CONTROL,GL12.GL_SEPARATE_SPECULAR_COLOR); in a GLSL shader. I can't seem to figure out the code to do it though. I like having the specular separated because I'm using some black textures (that without the separation, don't reflect back any of the specular light). Anyone have any experience with this or some sample code I could look at? Here's my current fragment shader code for the non-separated specular: final_color = (gl_FrontLightModelProduct.sceneColor * gl_FrontMaterial.ambient) + (gl_LightSource[0].ambient * gl_FrontMaterial.ambient); vec3 N = normalize(normal); vec3 L = normalize(lightDir); float lambertTerm = dot(N,L); if(lambertTerm > 0.0) { final_color += gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse * lambertTerm; vec3 E = normalize(eyeVec); vec3 R = reflect(-L, N); float specular = pow( max(dot(R, E), 0.0), gl_FrontMaterial.shininess ); final_color += gl_LightSource[0].specular * gl_FrontMaterial.specular * specular; }

Share this post


Link to post
Share on other sites
Advertisement
Yes, just add the specular color to the final color as the last operation after the lighting and texture mapping has been applied.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement