PDA

View Full Version : glMaterial parameters when texturing



Swoop
12-03-2008, 07:53 PM
Are the glMaterial parameters generally used with shaders and texturing, or are they ignored? are they combined with the values pulled from the active textures? or are they more of a relic from the untextured days.
Or another way of putting it, looking at the red book section on "The Mathematics of Lighting" where do textures fit into the equation? does a "texture" essentially replace material ambient/diffuse/specular/emissive/shininess or modulate these parameters in some way.

arekkusu
12-04-2008, 12:29 AM
In the old, fixed function world:
Materials are for per-vertex lighting. The results of the lit vertex color are then fed into the fragment stage. What happens with the texturing depends on the TexEnv settings. By default, texture values are modulated with the vertex color (and the specular lighting component optionally added afterwards, in the color sum stage.)

In the new, shader world:
You do whatever you want in the vertex shader, and then you do whatever you want in the fragment shader. You can access the builtin material state if you really want to, but it's probably better to just roll your own lighting completely.

Dark Photon
12-05-2008, 06:37 AM
Are the glMaterial parameters generally used with shaders and texturing, or are they ignored? are they combined with the values pulled from the active textures? or are they more of a relic from the untextured days.

arekkusu's got you covered. Pop in a vertex shader and "poof" all the default vertex shader behavior is gone, including lighting and use of materials. You can reimplement this in your custom vertex shader, or do whatever you want.


Or another way of putting it, looking at the red book section on "The Mathematics of Lighting" where do textures fit into the equation? does a "texture" essentially replace material ambient/diffuse/specular/emissive/shininess or modulate these parameters in some way.

Texture sampling and application is a fragment shader thing. Pop in just a vertex shader, and the fixed-function (default) fragment shader is still there and working as normal. Whether it REPLACEs, MODULATEs, or does something else with the color generated by the vertex shader (which may or may not be the result of having done a lighting calculation) is determined by such things as the TEXTURE_ENV_MODE, which are your directions for how OpenGL should build that fragment shader. And of course again, pop in your own custom fragment shader to get rid of this behavior and do whatever you want.