Skip to content

Fog light projectors#106395

Draft
TheMagnat wants to merge 2 commits into
godotengine:masterfrom
TheMagnat:fog-light-projectors
Draft

Fog light projectors#106395
TheMagnat wants to merge 2 commits into
godotengine:masterfrom
TheMagnat:fog-light-projectors

Conversation

@TheMagnat
Copy link
Copy Markdown

@TheMagnat TheMagnat commented May 14, 2025

This is a WIP branch which is based on my precedent branch to add directional light projectors.

Its goal is to responds to this discussion : godotengine/godot-proposals#11987 and make the volumetric fog affected lights projectors

Done in this PR :

  • Added atlas texture srgb and projector sampler in the fog shaders
  • Added computation of the projector in the fog

To do :

  • Add control over the impact of the projector in the fog ? (Don't know if needed in addition to the light_volumetric_fog_energy parameter)
  • Verify if we want to use mipmaps

My main concerns are :

  • Is my approach to add the samplers available in the volumetric_fog_update method the good one ? (Adding it as a parameter)
  • What is the performance impact of adding a condition and sampling a texture in it in the fog shader, since, unlike the scene shaders, It seems like the fog shader don't have shader specialization constants yet

Little preview :
godotRays
OmniLights
otherRays
party

20250514-1008-34.7902792.mp4

@BlueCube3310 BlueCube3310 added this to the 4.x milestone May 14, 2025
@TheMagnat TheMagnat force-pushed the fog-light-projectors branch from b9a09e4 to ef283ac Compare May 14, 2025 17:24
@TheMagnat TheMagnat force-pushed the fog-light-projectors branch 2 times, most recently from bb104cd to 483f245 Compare May 15, 2025 19:40
@jcostello
Copy link
Copy Markdown
Contributor

Impresive. Can you implement this (projectors) for lightmap baking?

- Added projector scale / offset in directional light
- Added directional light matrix, scale and offset in forward shaders
- Added computation logic of the projection in the forward and forward mobile shaders
- Computing projector matrix in the update_light_buffers and pushing it to the gpu
- Adapted light models to have projector scale and offset stored (even in gles3 for the future inclusion of projectors)
- Added a sub group for the directional light projector properties
- Added directional projector pipeline specialization constant for mobile and forward rendering
- Edited the way decals store texture to now repeat in the border instead of storing black color
- Added projector warning for DirectionalLight3D in compatibility mode (Moved the projector warning to Light3D level since all can use projector now)
Copy link
Copy Markdown
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, it works as expected. Code looks good to me.

image image image

Some feedback:

  • Is my approach to add the samplers available in the volumetric_fog_update method the good one ? (Adding it as a parameter)

During all my testing with various projector textures (going as low as 16×16) and volumetric fog energy increased to 100, I couldn't spot a difference between the various filter modes on all light types, even after restarting the editor and using maximum precision fog settings (512 size/512 depth/temporal reprojection disabled). With more realistic settings, it's even less likely to make a visible difference.

I think you can remove the parameter and always sample the projector texture within the volumetric fog as linear (no mipmaps).

  • Add control over the impact of the projector in the fog ? (Don't know if needed in addition to the light_volumetric_fog_energy parameter)

I wouldn't add a parameter now, the effect is quite subtle in practice with the default fog volume size/depth. If you increase both of these, then it starts becoming more noticeable, but values above 128 have a heavy performance cost anyway.

With the default fog volume settings (64 size/64 depth), it is possible to see noise in the volumetric fog when moving the camera with very high scale on cloud textures in DirectionalLight3D, but only with temporal reprojection disabled. Even then, with a more realistic texture scale, it basically never happens.

  • Verify if we want to use mipmaps

I don't think it's needed when temporal reprojection is enabled. When temporal reprojection is disabled though, it could help reduce noise when the camera moves, but this can be left for a future PR as temporal reprojection is typically left enabled.


// Higher values will make light in volumetric fog fade out sooner when it's occluded by shadow.
const float INV_FOG_FADE = 10.0;
const float INV_FOG_FADE = 300.0; //TODO: We should change this constant to a user setting
Copy link
Copy Markdown
Member

@Calinou Calinou Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was originally configurable with Fog Fade, but that property was removed during 4.0 development to make space for Volumetric Fog Energy.

However, if we find a way to reintroduce this property without increasing the size of the push constant, it's welcome. This is main difficulty about reintroducing it. Packing two half float values inside a single float could help here, although it would limit the effective range of both values. (The default Fog Fade was 0.1 rather than 10.0, since it was expressed as the inverse.)

Added computation of the projector in the fog
Added volumetric fade parameter in the environment and send it to the process fog shader in the params uniform buffer
@TheMagnat
Copy link
Copy Markdown
Author

@Calinou I don't think the process shader of the fog is using push constants, actually it only have an uniform buffer containing the parameters, so I added the fade in it. If we don't want to make it configurable we can just revert these changes but with the projectors affecting the fog, it can get really noticeable when the fade value is too high (like the old default 0.1) and fog can get through small structures.

I updated this PR to be up to date with the directional light projector PR and will keep doing this until the first one get merge to then rebase on master directly

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fog not being affected by light projector

4 participants