- Home /
Understanding Render Targets and Render Textures.
Hello. I'm currently trying to understand the following article to implement weighted order independent transparency. http://casual-effects.blogspot.com.au/2014/03/weighted-blended-order-independent.html
The technique described uses a shader that outputs to two render targets. I've been trying to understand how it is achieved in unity, and at what cost.
I understand unity pro has Render Textures, where a shader can essentially output to a texture which can then be used for multiple purposes. Is this the same thing as what a render target is? Can one shader output to two render textures?
The technique also mentions that using multiple passes can achieve the same results for older cards. This makes me wonder about cost. Do render textures essentially have the same cost as a shader pass?
Also, if want to use render textures/targets to achieve this order-independent transparency, can I 'prevent' the main camera from drawing transparent objects?
I'm a bit unsure how it all fits together. Any help would be appreciated.
Thanks.
Here is the relevant extract from the article:
During transparent surface rendering, shade surfaces as usual but output to two render targets. The first render target must have at least RGBA16F precision and the second must have at least R8 precision. Clear the first render target to vec4(0) and the second render target to 1 (using a pixel shader or glClearBuffer + glClear).
Then, render the surfaces in any order to these render targets, adding the following to the bottom of the pixel shader and using the specified blending modes: (code available in article)
Finally, after all surfaces have been rendered, composite the result onto the screen using a full-screen pass.
See the paper for full details and fallback paths for GPUs or APIs that do not support multiple render targets or per-render target blending functions.
Did you find a solution to this that worked? I am trying to do the same thing
Answer by MakeCodeNow · Jan 20, 2015 at 06:48 AM
In Unity, RenderTarget and RenderTexture are very close to the same thing. Technically, a RenderTarget can use a RenderTexture or RenderBuffer.
You can do MRT in Unity. See Graphics.SetRenderTarget and Google if you need examples.
You can put all transparent objects on a layer and then use the main camera culling mask to skip that layer.
Note that order independent transparency is often impractically expensive. I can't think of any commercial games that use it.
I have tried using Camera.SetTargetBuffers(...) API before rendering (RenderPipeline OnBeginCameraRender event) and it doesn't seem to work on my side. If I use any of the RenderTargets directly on the camera.targetTexture it does write to it, just not the $$anonymous$$RT way. Is it confirmed that $$anonymous$$RTs work with cameras as is out of the box?
Your answer
![](https://koobas.hobune.stream/wayback/20220613180837im_/https://answers.unity.com/themes/thub/images/avi.jpg)