PDA

View Full Version : Modulated texture and lighting



yossi
06-09-2005, 02:23 AM
I am trying to render a 3D model
1) With textures (GL_MODULATE attribute)
+
2) Lighted
+
3) modulated with different colors (defined by glColor3f) according to different distances from the viewer.

From what I see, it is impossible to do so because the texture is already modulated with the material colors used for lighting.
I can do either modulation with current RGB with no lighting OR render the model with lighting but without modulating with current RGB, but not both.
Is my assumption correct?

Many thanks

wizzo
06-09-2005, 06:56 AM
whatever lighting-related settings you made with fixed functionality aren't taken into account in the fragment shader.
if you have a fragment shader, you can/have to redefine every lighting equation you want to perform.

In your case, it'll be something such as:
gl_fragColor = texture2d(textureId, texCoord1) * texture2d(illuminationTexture, texCoord2) * color;

If you set your color with glColor3f, it will be available in your vertex shader (and only in your vertex shader i think), so you'll have to pass it to your frag shader through a varying vec3

hope i didn't misunderstood your question,
wizzo

yossi
06-13-2005, 08:34 PM
Thanks Wizzo,

I wonder if there is a solution using only the fixed pipeline functionality.

Thanks

V-man
06-14-2005, 02:10 AM
Originally posted by wizzo:

In your case, it'll be something such as:
gl_fragColor = texture2d(textureId, texCoord1) * texture2d(illuminationTexture, texCoord2) * color;

If you set your color with glColor3f, it will be available in your vertex shader (and only in your vertex shader i think), so you'll have to pass it to your frag shader through a varying vec3

hope i didn't misunderstood your question,
wizzoIn the vertex shader, you can assign color with

gl_FrontColor = gl_Color;
gl_BackColor = gl_Color;

The pipeline will choose the front or back color depending on your GL state.
In the fragment shader, you read gl_Color

so do something like texel * gl_Color.

Most likely, you don't need the back color at all.