Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Colored light to recolor a texture?

This topic is 6095 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

I need the ability to recolor a sprite in my 2D engine (using D3D). I can tint it (somewhat) by changing the diffuse color of the vertices of the polygons I''m drawing, but what I need is the ability specify a color and effectively convert the texture to greyscale and then recolor it to the specified color. It''s for highlighting things... I figured a colored light source may do the trick, but I''m having a hard time even getting one to work. I want to use a directional light source since it won''t have any falloff or attenuation like point and spotlights do. I tried setting one up but it doesn''t affect the sprite at all. It shouldn''t be too tricky to get a light to affect a sprite in a 2D engine... I''d hope... I used this code after creating the light to enable it: g_pd3dDevice->SetLight(0, &light); g_pd3dDevice->LightEnable(0, TRUE); g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE); I tried searching the forums for colored lighting articles, but it returned no results after a long delay (broken search engine?). Any help would be great! -- Dan (flaXen)

Share this post

Link to post
Share on other sites
Instead of a light, which affects everything in the scene, consider using a material for the object you want to tint:

You can also use the diffuse in the vertices, if you want to specify it per vertex:

Then blend the diffuse value with the texture value. Something like (maybe you want a different op than add):

d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
d3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
d3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_ADD);

Share this post

Link to post
Share on other sites
Actually, i just tried it on my computer, and add really sucks. I get better results with D3DTOP_MULTIPLYADD (it tends to desaturate and brighten if I use white light and white material, or tint with a colored light ot colored material).

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!