Modern OpenGL colors
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)?
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 uniform
s for your ambient color(s), light position(s), eye position, etc. Then set up a couple of varying
s 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 varying
s based on the uniform
inputs.
The fragment shader then receives (for example) a texture and the varying
s 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
).
精彩评论