Jump to content
  • Advertisement
Sign in to follow this  
derek_of_bodom@hotmail.com

Diffuse color?

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

With XNA, you have BasicEffect which has the "Diffuse" property. I haven't messed with HLSL in a while, but I'm wondering how to write the code to add color to a texture. For example: I have a texture, and I want to draw it with it blended red. What would I do if I had float4 blendColor and float4 texColor (where texColor is the color of the pixel for that pass)?

Share this post


Link to post
Share on other sites
Advertisement
Then you can just go like this in your pixel shader (in pseudocode):

outputcolor = (texColor + blendColor) * 0.5;

Or you can blend it more or less strongly like this:

outputcolor = lerp(texColor, blendColor, t);

If t = 0, the output color will just be texColor, if t = 1 then it will be blendColor. Values in between give various blend levels. t = 0.5 corresponds to the blend before.

Share this post


Link to post
Share on other sites

Then you can just go like this in your pixel shader (in pseudocode):

outputcolor = (texColor + blendColor) * 0.5;

Or you can blend it more or less strongly like this:

outputcolor = lerp(texColor, blendColor, t);

If t = 0, the output color will just be texColor, if t = 1 then it will be blendColor. Values in between give various blend levels. t = 0.5 corresponds to the blend before.

I actually figured it out myself. I tried the code you provided, and it didn't do what I wanted. It did some weird blending. texColor * blendColor does exactly what I want.

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.

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!