views:

73

answers:

1

I noticed old code has GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR etc. inputs with glMaterialfv. How are those replaced in modern GLSL code?

e.g. Assuming a library importing models (Assimp) gives direct values to such color categories , can they be still used directly (on core Context)?

+1  A: 

Yes, at least sort of (though, of course, in modern code, you handle most of that computation in shaders).

One typical possibility is to use uniforms for your ambient color(s), light position(s), eye position, etc. Then set up a couple of varyings that will be used to pass a diffuse color and specular color from your vertex shader to your fragment shader. Your vertex shader computes values for those varyings based on the uniform inputs.

The fragment shader then receives (for example) a texture and the varyings mentioned above, and combines them together (along with any other inputs you might want) to produce a final color for the fragment (which it assigns to gl_FragColor).

Jerry Coffin
Varying is deprecated lately.
Lela Dax
@Lela Dax: true, but it does not change the validity of the method. It's trivial to change varying to in/out pair.
Bahbar