-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
FogVolumes, FogShaders, FogMaterial, and overhaul of VolumetricFog #53353
Conversation
Hope I'm not providing feedback a little too early, given this is still a draft. I'm quite excited to see this PR.
Edit: I was testing on this branch merged with the latest master. Seems it's not an issue on your branch, unmodified. Silly me, but also somewhat suspicious. |
@briansemrau That is very odd. I am not sure what would have caused that. At any rate, testing is very welcome, I will be pushing docs and some QOL changes and taking this out of draft within the hour! :) |
42ad8b7
to
ff9bbca
Compare
73e00be
to
1f1f8b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor things I noticed while testing.
1f1f8b3
to
dcaa8e7
Compare
5a24a21
to
e7cacfc
Compare
b5bafe0
to
56b235f
Compare
I've done some testing and it seems that when shadows are enabled for an OmniLight3D or SpotLight3D, its volumetric fog will always appear to have the same size and will be very faint. When you adjust the light's range, the volumetric fog will keep the same size. This problem goes away if you disable shadows for the light and reload the current scene. Also, would it be possible to add a "albedo multiplies density" option to WorldEnvironment's volumetric fog? This would allow for purely additive volumetric fog without a constant emission component (since you can't adjust the emission's alpha value). |
56b235f
to
81526e3
Compare
…metricFog Co-authored-by: Brian Semrau <brian.semrau@gmail.com>
73fcbde
to
1b2cd9f
Compare
@akien-mga done! :) |
Thanks! |
The shader compilation fails on macOS, IIRC Metal (and MoltenVK) do not support atomic operations on most types of images.
|
@bruvzg do you know if there are any extensions to enable atomic operations? This technique really relies on atomics in order to be viable. edit: is the issue that the images are unsigned? If so, we could probably work around it and use signed integers on Apple devices |
No, it's the same if I change it to Relevant MoltenVK issues - KhronosGroup/MoltenVK#345, KhronosGroup/SPIRV-Cross#835 |
I guess we should create a fallback for macOS that disables fog volumes. Ideally, support for global volumetric fog should be kept. It's not very important to support volumetric fog on macOS yet anyway, since I expect only the most powerful Macs to handle volumetric fog smoothly right now (M1 Max with 24 or 32 GPU cores). |
Hmmm, I wonder if it would work if we used a storagebuffers on Mac instead. I imagine performance would take a hit and our code would be slightly more complex, but it could be worthwhile. edit: it looks like atomic operations can be used on buffers in "device" space (I believe this is equivalent to Vulkan's storage buffers). https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf. The trick is going to be how to get MoltenVK to adequately translate a StorageBuffer containing an array of |
Changing it to the storage buffers seems to work. I have not compared it to the original, but performance seems to be OK - #55281 |
Hey, how does one get a fog volume from an image?? |
|
Wow, it does indeed work! Thanks, I really appreciate it. I wonder if it's possible to also animate it. Like convert this fog material to a shader and perhaps use TIME to animate the uvs or something... |
To animate an arbitrary 3D texture over time, you'd need to have a 4D texture (which is not supported by GPUs to my knowledge). Instead, using a noise function to warp the 3D texture over time is a better idea. If you only need an extruded 2D texture, then a 3D texture can be used to animate this texture over time using a custom shader. |
I was thinking noise, but since i'm using a 2d image imported as a 3d texture, I should probably animate using a shader. If only I knew how to do that...:) |
Implements: godotengine/godot-proposals#2261
FogVolumes
FogVolumes are entities that can be rendered into the VolumetricFog's Froxel buffer. They can have 3 different shapes: ellipsoid, box, or world. As the name suggests world shape FogVolumes are not culled and are rendered for every froxel in the froxel buffer. They are very useful for world-space effects like global height fog. However, because they write to every froxel, they have a more significant impact on performance than the other shapes, use them sparingly.
FogVolumes using ellipsoid or box shapes can set their extents with the
extents
parameter.Screenshot showing ellipsoid, box, and world volumes, as well as a subtractive volume
When temporal reprojection is enabled, moving volumes can result in "ghosting" artifacts. It is best to keep movement or animation of fog quite slow.
FogMaterial
The FogMaterial contains a short FogShader that sets
density
,albedo
, andemission
and allows scaling the density by theSDF
of the shape and a 3D density texture.FogShaders
FogShaders are attached to Fog Volumes. Internally they are compute shaders that run for each froxel within the Froxel-Aligned-Bounding-Box of the FogVolume (calculated just before rendering). The real beauty in FogShaders is that they use Atomic operations so that multiple volumes can be rendered at the same time.
Radeon GPU profiler showing the GPU barely working while simultaneously rendering 96 simple FogVolumes
FogShaders can output
DENSITY
,ALBEDO
, andEMISSION
. They must write toDENSITY
and may write toALBEDO
, andEMISSION
. If you do not write to eitherALBEDO
orEMISSION
the shader will skip adding them and save on a few instructions.By default. all parameters are additive. However, you can set
DENSITY
to a negative value to reduce density locally, whenDENSITY
is negative, neitherALBEDO
norEMISSION
are written.ALBEDO
is converted to scattering internally (which is additive)VolumetricFog
Volumetric fog has been modified to use a PBR material model (internally, scattering, absorption, emission) exposed to the user as Density, Albedo, Emission. It also takes material anisotropy into account. Anisotropy refers to the direction that light is scattered in through a volume. Fog tends to scatter light forward, while smoke tends to scatter light equally in all directions. The default
0.2
makes the fog slightly brighter when facing towards a light source.I have also changed the integration to integrate lighting over the depth of the froxel (as described here: https://www.ea.com/frostbite/news/physically-based-unified-volumetric-rendering-in-frostbite) which results in significantly more plausible lighting and a smoother integration.
Future work:
I have not added icons for FogMaterial or FogVolume, I would appreciate a hand with those if someone is interested in making some iconsconsider adding Sky as a light source