Jump to content
  • Advertisement
Sign in to follow this  
Chris Reynolds

Fade between two colors in shader

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

Hey forum, I have a quick question -

I have a texture that recursively colors itself. It is initially cleared to all blue, then dots are drawn on it in black each frame. I want the dots to slowly fade out to blue over time, so that old dots eventually fade out.

How can I do this in a shader?

Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Two possibilities I can think of:

1) Every frame just do a blend operation to add a tiny fraction of blue to each pixel each frame.

or

2) When you add a new dot, store some kind of 'timestamp' value either in the alpha channel or in a separate render target. Lerp between black and blue based on the time that has elapsed since the pixel was stamped. Once the time reaches a threshold just clear the timestamp and reset the pixel to blue.

Share this post


Link to post
Share on other sites
On your first thought, what would this equation look like? This seems the most reasonable to me, and what I've been trying to do, but I can't figure out what the actual equation would be.

Share this post


Link to post
Share on other sites
You could render the dots to a separate texture. And each frame lower the alpha of each pixel a little. Then draw that texture to your blue one.

Share this post


Link to post
Share on other sites
Hello,

You can do it without using a shader. You can draw your black dots. And on the next frame instead of clearing the color buffer, you render a full-screen transparent blue quad. The alpha value of this quad controls the fading speed.

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!