Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


Diffuse color?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Nyxenon   Members   -  Reputation: 104

Like
0Likes
Like

Posted 21 April 2012 - 02:14 PM

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)?

Sponsor:

#2 Bacterius   Crossbones+   -  Reputation: 9065

Like
0Likes
Like

Posted 21 April 2012 - 03:25 PM

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.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#3 Nyxenon   Members   -  Reputation: 104

Like
1Likes
Like

Posted 21 April 2012 - 03:54 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS