Jump to content
  • Advertisement
Sign in to follow this  

Diffuse Color + Texture problems...

This topic is 5468 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well, what can I say... I've been at this for hours and I can't nail it down. Here is my Vertex Format #define D3DFVF_TERRAIN (D3DFVF_DIFFUSE|D3DFVF_NORMAL|D3DFVF_TEX1|D3DFVF_XYZ) struct TERRAINVERT { D3DXVECTOR3 vPosition; // position D3DXVECTOR3 vNormal; // normal D3DCOLOR Diffuse; // diffuse color float tu, tv; // texture coordinates }; My texture is just greyscale... I would like it to blend it with the diffuse colors of the vertices. I am mainly confused about the render states... As it stands now, if the r, g, or b values of the Diffuse color are greater than 0, they act as if they are 100 percent. Example: 0x00ff0000 == 0x00010000 (as it appears on the screen) I think I just need to set my render states properly to blend diffuse vertex colors with the texture. Thanks very much for the help.

Share this post

Link to post
Share on other sites
To blend the texture and the vertices diffuse color, all you need to do is set the texturestagestate operation to modulate between the two.

SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE );
SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TEXTURE );

Share this post

Link to post
Share on other sites
Hmm.. I implemented those render states... and I thought that would fix my problem.. but it didn't make any difference.


When I set the diffuse colors of my terrain vertices to:

pVertList[(short) counter].Diffuse = 0x00ff0001;

The result is my greyscale texture blended with a VERY PINKISH-PURPLE color ... But we know it should be a VERY RED color instead.


0x00ff0000; results in a Solid red blend


0x00010000; results in exactly the same solid red blend (very dark)

It seems like my colors are all or nothing... It seems that I can either have 100 percent redness, or none at all... and that goes for green & blue as well.

Thanks for the help... I'm so confused.

Share this post

Link to post
Share on other sites
By the way, if this is of any help to anybody...

I have 1 light (2 if you count the ambient light)

VOID SetupLighting()

// Setup Light
ZeroMemory( &light, sizeof(D3DLIGHT9) );
light.Type = D3DLIGHT_POINT;
light.Diffuse.r = 1.0f;
light.Diffuse.g = 1.0f;
light.Diffuse.b = 1.0f;
light.Attenuation0 = 0.0f;
light.Attenuation1 = 0.0f;
light.Attenuation2 = 0.0f;
light.Direction = D3DXVECTOR3(0,-1,0);
light.Range = 2000.0f;
light.Position = D3DXVECTOR3(0, 500, 0);

g_pd3dDevice->SetLight( 0, &light );
g_pd3dDevice->LightEnable(0, TRUE);

//Turn on lighting
g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE);

//Set ambient light level
g_pd3dDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(32, 32, 32));

g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE );
g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TEXTURE );



Share this post

Link to post
Share on other sites
You know... It's funny that I just posted that lighting business... I went back in and started playing with my lights again.

I discovered a fix to my problem.

IT is a GOOD thing to have greater-than-0 attenuation on your lights!

I had 0 attenuation on my lights and it was causing very little diffuse color to become a LOT of diffuse color.

Sorry for the trouble, thanks again.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!