Bug or missunderstanding (Viewport render to texture)?
I'm trying out custom post processing and rendering to textures.
Not sure if I stumbled over a bug in 3.1 Beta or just don't grasp the concept yet.
I have the following scene:
Inside the first viewport is just a camera and 2 identical meshes with an alpha faded texture.
Mesh1 is on culling layer 1
Mesh2 on culling layer 2
The main Camera sees only culling layer 1
then I have another Viewports without shader and a transparent background
It has another camera that only sees culling layer 2
My goal was to only process one of the 2 meshes with a post processing shader
Since the ViewportContainer for camera2 has no shader yet, I would expect to see 2 identical meshes.
But it seems the viewport messes up the alpha blending somehow as the mesh on culling layer 2 darkens the background.
Do I just missunderstand the concept or is this a bug?
Best Answer
-
comboy Posts: 5
It seems to be a known issue
https://github.com/godotengine/godot/issues/17574Due to non pre multiplied alpha.
I managed to nearly fix it by manually doing the pre multiplication in the shader code of the object and the ViewportContainer.
That only leaves a small artifact.A premultiplied alpha option is on the roadmap for 3.2 as I understand. So until then one has to be carefull with transparent objects in viewports.
Answers
On your Viewport, do you have
transparent_bg
enabled?Looking at the sphere on the left, it looks like it is blending with a darker color, which is especially noticeable at the bottom. It could be that it is not using a transparent background, and in Godot when a Viewport does not have a transparent background it renders what would be transparent black.
Another potential issue I could see is that the Viewport is in its own world, and so it is not blending the background/sky simply because it does not exist in the Viewport. If you disable
own_world
then it should make it where it uses the same World resource as the main scene, which should make it use the same background/sky.If
transparent_bg
is enabled andown_world
is disabled on the Viewport, then I have no idea as it should be rendering both spheres exactly the same.If neither fix works I would suggest opening a issue on the GitHub repository.
It seems to be a known issue
https://github.com/godotengine/godot/issues/17574
Due to non pre multiplied alpha.
I managed to nearly fix it by manually doing the pre multiplication in the shader code of the object and the ViewportContainer.
That only leaves a small artifact.
A premultiplied alpha option is on the roadmap for 3.2 as I understand. So until then one has to be carefull with transparent objects in viewports.