- Home /
Graphics.Blit with an additive shader
Hey, I'm trying to implement the ability to paint on a texture with a particle effect. What I've done is I've set up a camera that renders my particle effect to a renderTexture. What I want to do is copy the contents of that RenderTexture to a secondary texture, without clearing what has been rendered in previous frames from that secondary texture, so in effect, wherever I paint with my particle is permanently baked into my secondary texture.
I've tried setting my cameras clear flags to "Don't clear", but that doesn't seem to work for some reason. I may need to revisit that option down the road. But the other option I'm more interested in is using Graphics.Blit with a custom shader for an additive post processing effect. I'm not sure if this option will function the way I want it to though. When using Graphics.Blit, is it possible for me to combine the source texture and the dest texture using an additive shader?
Thanks!
I don't understand why you'd need a fixed function blending operation. If you have two textures, add them in the shader.
I confess I know very very little about shaders, so forgive my ignorance on these things. I guess I was ultimately asking how to go about doing what you suggest. I've tried digging into some shader operations a bit, and I've discovered that it seems to be quite easy to add two textures together, but I don't know how to gain a reference to the source and dest textures that I pass into the Graphics.Blit function, and then store the results in the destination texture. Am I going about this in the wrong way? I ultimately need to use the destination texture as an alpha mask.
Sounds like you're on the right track. I only have experience running post process effects on the entire screen, though, so can't offer up any code, presently. For fullscreen effects, it's basically as simple as using the + operator.
I'm just not entirely sure what I stick that + operator between. I create a brand new shader, but I don't know how to get a reference to my two textures into the shader so that I can add them together.
Answer by Jacktang · Feb 24, 2012 at 04:34 PM
I figured out that I can use Material.SetTexture to make them available in the shader
Your answer
Follow this Question
Related Questions
dynamic hole in layer / texture / camera 0 Answers
Blit isn't writing to render texture 1 Answer
Multiple Blit problem 2 Answers
Blit shader to RenderTexture results in solid black 0 Answers
Prevent Render Texture clearing 1 Answer