Modulated texture and lighting

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

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

Thanks Wizzo,

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

Thanks

Originally posted by wizzo:
[b]
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[/b]
In 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.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.