x


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!

more ▼

asked Feb 07 '12 at 08:03 PM

Jacktang gravatar image

Jacktang
63 5 10 13

I don't understand why you'd need a fixed function blending operation. If you have two textures, add them in the shader.

Feb 07 '12 at 08:08 PM Jessy

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.

Feb 07 '12 at 08:36 PM Jacktang

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.

Feb 07 '12 at 08:50 PM Jessy

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.

Feb 07 '12 at 09:21 PM Jacktang
(comments are locked)
10|3000 characters needed characters left

1 answer: sort oldest

I figured out that I can use Material.SetTexture to make them available in the shader

more ▼

answered Feb 24 '12 at 04:34 PM

Jacktang gravatar image

Jacktang
63 5 10 13

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1649
x191
x11

asked: Feb 07 '12 at 08:03 PM

Seen: 991 times

Last Updated: Feb 24 '12 at 04:34 PM