I am trying to render some transparent objects to a render texture, but they end up being tinted by the cameras background color (even if alpha is set to 0).
This is just an example, Iām going to be using this for something a bit more complicated.
Iām trying to be as clear as possible. I donāt want the cubes to be affected by any background color at all.
Regardless of the cubeās color or the background.
Yes, I already tried that. No matter what the background color is, the transparent object will always be tinted that color. When the color is black, the objects will be darker than they should be.
They are transparent, right? Black means the color is not changed. It might look āmore blackā than the alternatives, but the new background should make the impact.
Does it look very different when you do a black background vs loading the objects directly in the other camera?
If so, can you provide screenshots?
It is not for you to understand why. Like I said before, I am using this for something much more complicated in another project. All I need is the answer to the question I originally asked.
Also I donāt have an answer or any need to do this at the moment, I wonder why itās happening.
It seems like itās a common thing. I remember 3dsmax had the same issue.
It looks like rgb components are rendered using alpha blending and then alpha channel is added on top of that.
Yeah, itās weird. The especially strange thing is that it doesnāt seem to be blending the rgb normally. I looked up the standard equation to try and āundoā the blending with a post-processing shader, but Unity seems to use a different equation.
If you set the background to black then divide rgb by the alpha value it should look okay.
Look up āunpremultiply colorsā.
You could also render them opaque and then somehow pass the alpha values to the alpha channel (although overlapping transparencies would be completely broken then).
I actually tried that already but was having some weird issues. It works fine with the cube example, but not what I need it for in the other project.
I set the camera to black like you said and made a new cube that uses a custom material.
Itās basically just a transparent unlit material with a texture and color (code on the left). I also made a post-effect shader to fix the colors by dividing by the alpha (code on the right).
I then set the background camera to the same color as the cube to emphasize the issue:
For some reason thereās a white rim where the alpha blends to zero. Do you have any idea why this might be happening or how to fix it?