Ricardo Sanchez-Saez
Ricardo Sanchez-Saez

Reputation: 9566

How to apply post processing shader to part of a scene

I have the following rendering pipeline:

[Input texture that changes every frame] -> [3D content rendered on top of changing texture] -> [Post processing shader] -> [Composited texture with post processing applied to input texture + 3D content].

I want to achieve this pipeline:

[Input texture that changes every frame] -> [3D content rendered on top of changing texture]+[Post processing shader applied to 3D content] -> [Composited texture with post processing only applied to 3D content].

What's the best way of achieving this?

I was thinking about rendering the 3D content to an offscreen texture (with transparent non-rendered parts), then applying the post processing shader to this texture, and then rendering the post processed texture with transparency on top of the background texture.

Is there any better way of doing this? If there isn't, how would one go about rendering on a texture with alpha and then compositing it over a previous texture?

Upvotes: 2

Views: 269

Answers (1)

Yakov Galka
Yakov Galka

Reputation: 72479

If your post-processing is something simple like white-balancing or HDR, then you can first render the 3D content, apply the post-processing, and then render your background texture with depth-test enabled and at an appropriate maximum depth.

If your post-processing is more complicated, like a blur or something similar, then I'm afraid that rendering to a second texture is the only solution. Rendering into an RGBA texture is straightforward, just like into an RGB one. Just make sure that you use pre-multiplied alpha throughout your pipeline, as otherwise you won't be able to compose the textures correctly. Before rendering clear your texture with a (0,0,0,0) color.

Upvotes: 2

Related Questions