开发者

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 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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜