godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.7k stars 20.12k forks source link

OpenGL: Environment fog does not affect sky rendering #66456

Closed Calinou closed 2 weeks ago

Calinou commented 1 year ago

Godot version

4.0.beta (53d2a9acd)

System information

Fedora 36, GeForce GTX 1080 (NVIDIA 515.65.01)

Issue description

Unlike in Vulkan, environment fog does not affect sky rendering when using the OpenGL renderer. Fog Sky Affect's value is ignored.

Fog disabled

2022-09-26_20 01 30

Fog enabled

2022-09-26_20 01 26

Steps to reproduce

Minimal reproduction project

test_opengl_fog_sky_affect.zip

ParsleighScumble commented 1 year ago

I've been looking into fixing up some of the GLES fog issues because of the fog_sky_affect issue. There are some uniforms in the sky shader but they ain't exactly hooked up to the rendering backend properly. I wanted to pick your brain @Calinou and @clayjohn about what approach the Godot team would like here. Should we pack those guys in a UBO SkySceneData (name in shader) with a struct SkySceneState (mirrored storage on host) to make it more like the Vulkan renderer? Then we would update values in the UBO from RendererEnvironmentStorage in void RasterizerSceneGLES3::_setup_sky. Or should we stick to setting individual uniforms and avoid making a new UBO?

clayjohn commented 1 year ago

@ParsleighScumble Either approach is fine. Initially I went with the individual uniforms for small things that change frequently, but once you have more than one or two uniforms, it becomes just as fast to pack everything into a UBO that you update every frame.

ParsleighScumble commented 1 year ago

Let's go with a UBO, then. I should have fog sky affect working in GLES pretty soon.

Calinou commented 8 months ago

I can still reproduce this on 4.3.dev 13a0d6e9b.

@ParsleighScumble Did you get it working in the end? If so, please open a pull request :slightly_smiling_face: If not, let us know and someone can continue this work.

ParsleighScumble commented 8 months ago

I did get it working but it's a bit of a mess and I didn't get tonemapping working for all background modes. I can post what I have though.

Calinou commented 8 months ago

I can post what I have though.

Please do :slightly_smiling_face:

Calinou commented 2 months ago

I see in https://github.com/godotengine/godot/issues/92019 that fog stops sky affects to be changed, is this the main issue here?

Yes, fog should affect sky rendering to the extent set by the Environment Fog Sky Affect property. That property defaults to 1.0, which means the sky color should match the fog color according to the Camera3D's Z far property (the sky is assumed to be at the same depth as Z far).