Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fog aerial perspective does not blend seamlessly into the sky #97803

Open
ttencate opened this issue Oct 4, 2024 · 5 comments · May be fixed by #89995
Open

Fog aerial perspective does not blend seamlessly into the sky #97803

ttencate opened this issue Oct 4, 2024 · 5 comments · May be fixed by #89995

Comments

@ttencate
Copy link
Contributor

ttencate commented Oct 4, 2024

Tested versions

v4.3.stable.mono.official [77dcf97], also on v4.3.stable.arch_linux.

System information

Godot v4.3.stable.mono - Arch Linux #1 SMP PREEMPT_DYNAMIC Wed, 04 Sep 2024 15:16:37 +0000 - X11 - Vulkan (Forward+) - dedicated AMD Radeon RX 6600 (amdgpu) - 13th Gen Intel(R) Core(TM) i7-13700K (24 Threads)

Issue description

The documentation for Environment::fog_aerial_perspective says:

If set above 0.0 (exclusive), blends between the fog's color and the color of the background Sky.

So if this is set to 1.0, I would expect the fog to be the same colour as the sky. In places where fog density approaches 100%, I would expect to see the sky colour, as if the object has become transparent.

However, that's not what is happening:

2024-10-04T11:03:29_1152x648

This screenshot was made with a PanoramaSky consisting of blue at the top and red at the bottom. Fog density is set to 0.3, and aerial perspective is set to 1.0. The spheres have a green albedo. However, in the distance, the spheres do not become red/blue, but rather an intermediate magenta colour.

From a cursory glance at the code, it seems that the shader is reading from the radiance cube map to do its thing. Could it be that it's reading from the wrong mip level, causing too much blending between the colours? That's just a wild guess though.

Steps to reproduce

Just open the attached MRP, which consists of the above scene.

Minimal reproduction project (MRP)

AerialPerspectiveTest.zip

@mrjustaguy
Copy link
Contributor

More likely the Radiance map isn't large enough, and is also filtered, so blue and red mix instead of picking one or the other, which due to an insufficiently large Radiance map size is very obvious in this case, whereas a larger radiance map would just turn magenta on a line on said spheres instead, with the upper and lower parts actually going their read and blue respective ways.

@ttencate
Copy link
Contributor Author

ttencate commented Oct 4, 2024

Hmm, could be, but then the effective resolution after filtering is extremely low. Here's the same scene with a tall white plane added behind the spheres:

2024-10-04T11:34:22_1152x648

Even at 135° vertical FOV, the plane still doesn't reach the right colours at its endpoints:

2024-10-04T11:37:46_1152x648

(I turned off ambient lighting on its material to make sure that the very soft gradient does not come from global illumination. In fact, without fog, the plane is black because the sun illuminates it from behind.)

Adding a fully reflective sphere (metallic = 1.0, roughness = 0.0) shows that the radiance cube map has plenty of resolution to give a sharp line:

2024-10-04T11:39:14_1152x648

@clayjohn
Copy link
Member

clayjohn commented Oct 4, 2024

Aerial perspective chooses a mipmap level based on the distance from the camera. So pixels on the far plan will read from the highest resolution mipmap and pixels on the near plane will read from the blurriest mip level. This is done to emulate atmospheric scattering (which is what Aerial perspective is).

I think the documentation should be clearer about this

@Calinou
Copy link
Member

Calinou commented Oct 4, 2024

You probably want something like #89995, although it'll have to be a new option to avoid breaking compatibility.

@ttencate
Copy link
Contributor Author

ttencate commented Oct 5, 2024

Thanks for your responses! @clayjohn is of course right that aerial perspective != blending with sky. The documentation should be clearer about this.

Maybe, rather than having a boolean that just forces the highest resolution mipmap, it could be a slider like "mip bias":

  • -1: Always use lowest mip level (0), i.e. highest resolution. Best approximation of what the docs currently say. Might be suitable for fading out distant geometry, even if imperfect.
  • 0: Current implementation.
  • 1: Always use highest mip level, i.e. a single pixel, the average sky colour. Might be a reasonable approximation of isotropic inscattering.

This is not more difficult to implement, and gives the user even more control over the effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants