godotengine / godotengine/godot
`SubViewport` transparent background makes whole viewport transparent when using physical lighting
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
- Found in 4.2.2.stable.official
### System information
Godot v4.2.2.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 970 (NVIDIA; 32.0.15.5585) - Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz (8 Threads)
### Issue description
I'm trying to render a 3D object in a `SubViewport` to have that object overlaid on the screen with another 3D scene behind it. However when I enable physical lighting units, set the subviewport's `transparent_bg` to true, and use a `CameraAttributesPhysical`, everything in the subviewport is rendered transparent, not just the background. When using `CameraAttributesPractical`, or when having no camera attributes set at all, it works as intended with the subviewport scene being rendered to the parent `SubViewportContainer` and overlaid on the scene. However, when setting camera attributes to an instance of `CameraAttributesPhysical`, whether it's in a `WorldEnvironment` node, the subviewport's world 3D override, or the camera attributes, the whole subviewport becomes transparent when `transparent_bg` is enabled and is not rendered.
### Steps to reproduce
1. Observe when running the example scene or viewing the `SubViewport`'s inspector in the editor that the sphere is not rendered.
2. Clear the camera attributes in the `WorldEnvironment` node or replace them with an instance of `CameraAttributesPractical`
3. Run the scene or view the inspector for the `SubViewport` and observe that the sphere is rendered
### Minimal reproduction project (MRP)
Example scene:
```
[gd_scene load_steps=4 format=3 uid="uid://djjdj454opky6"]
[sub_resource type="Environment" id="Environment_dldea"]
[sub_resource type="CameraAttributesPhysical" id="CameraAttributesPhysical_ukoa2"]
[sub_resource type="SphereMesh" id="SphereMesh_xfy0c"]
[node name="Main" type="Node3D"]
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_dldea")
camera_attributes = SubResource("CameraAttributesPhysical_ukoa2")
[node name="SubViewportContainer" type="SubViewportContainer" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
stretch = true
[node name="SubViewport" type="SubViewport" parent="SubViewportContainer"]
transparent_bg = true
size = Vector2i(1152, 648)
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="SubViewportContainer/SubViewport"]
transform = Transform3D(0.851086, 0.379608, -0.362698, 0, 0.690819, 0.723028, 0.525026, -0.615359, 0.587947, 0, 0, 0)
light_temperature = 5800.0
light_angular_distance = 1.0
shadow_enabled = true
sky_mode = 1
[node name="Camera3D" type="Camera3D" parent="SubViewportContainer/SubViewport"]
fov = 37.8493
[node name="MeshInstance3D" type="MeshInstance3D" parent="SubViewportContainer/SubViewport"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -2)
mesh = SubResource("SphereMesh_xfy0c")
```
Contributor guide
Research direction
Start with the supplied minimal reproduction project and run it with CameraAttributesPhysical, then compare it with CameraAttributesPractical or no camera attributes. Investigate the interaction between SubViewport.transparent_bg and physical camera attributes; done means the sphere renders while the SubViewport background remains transparent.
Written by the indexing model from the issue text.
Assessment
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100