How do I use the new volumetric shader graph?

I currently don't see how I should use the new volumetric material in unity.
Are there any samples available?

2 Likes

Here: https://github.com/keijiro/VolumetricMaterialTest

4 Likes

Hello,

We are currently building volumetric material samples to help get started with the feature and the documentation is in review.
In the meantime, I can share some details with you:

Volumetric materials are a new way to customize the fog in Local Volumetric Fog using the ShaderGraph. Instead of authoring your shader for a 2D surface used on meshes, you'll author it for a volume evaluated in 3D. This mainly means that the input of your graph will be a 3D position instead of 2D UV.

In the ShaderGraph you can use the UV node or the position node to get the 3D position and start creating your effect (UV has a 3rd dimension for this material type).
8289920--1086623--upload_2022-7-18_19-14-0.jpg

The Material asset can be used in a Local Volumetric Fog when you select the Mask Mode "Material"
8289920--1086626--upload_2022-7-18_19-15-9.jpg

Here's an example of a graph that applies a noise on a single axis of the fog:
8289920--1086656--upload_2022-7-18_19-37-8.jpg

Creating complex volumetric materials can quickly become expansive on the GPU, to ensure that your shader is running correctly here are some advice:

  • Try to keep the calculation in your Shader Graph to the minimum, it can quickly become a limiting factor regarding the parallelization of your shader on the GPU
  • Keep in mind that your shader is going to be executed for every voxel in the local volumetric fog, resulting in a lot of pixel shader invocation (similar to the case of transparent overdraw).
  • Use mipmaps when sampling textures, this helps the texture fetcher in the shader since the resolution of the volumetric buffer is usually a lot lower than the screen.
  • Keep the screen space size of the volume to the minimum, you can use the debug mode “LocalVolumetricFogOverdraw” located under Window > Rendering Debugger > Rendering > Fullscreen Debug Mode.
  • Prefer using medium-sized volumes over a lot of small ones. Each volume has a fixed overhead that can become big if using a lot of volumes.
  • In the GPU profiler, look for the “Fog Volume Mesh Voxelization” marker. Usually, the voxelization step is faster than the “Volumetric Lighting”, if it’s not the case, you can try reducing the number of volumes in your scene or lowering the quality of the volumetric fog.
13 Likes

The end goal for me would be to so something similar to what is happening with fluidninja over on Unreal engine. Is this feature a good fit for that behaviour? It can cover quite a large volume at times judging by the fluidninja samples.

Here is one such example:

https://www.youtube.com/watch?v=q-qKuU0SQfM


The ability to bake and inject seems profoundly useful for Realtime 3D.

3 Likes

This post was really helpful.:)

Although some more information about properly settings up and optimising volumetric fog setting would be really helpful.
Right now it's hard to increase the fog distance more than 100units, otherwise we can quite easily see the lights flickering as we move closer to them.

For the sample could you include scenarios where we might want volumetric fog in a distance(sun shaft from clouds) but still it should look good enough when close to camera (sun shafts from object shadows etc).

That would be really helpful.:)

2 Likes

Hi Anthony, Is it possible to use a mesh as a volumetric fog shape? So can we sample a mesh/skinned mesh for this? Or do we need to take an SDF-like approach here? (where we have spheres and cubes to make shapes etc)

[quote=“hippocoder”, post:4, topic: 887777]
The end goal for me would be to so something similar to what is happening with fluidninja over on Unreal engine. Is this feature a good fit for that behaviour? It can cover quite a large volume at times judging by the fluidninja samples.
[/quote]

We’ll not go that far, but plugins/assets can use this system to build effects like that. Though the volumetric fog is not really fit for that kind of effect. In the video showcasing Fluid Ninja on clouds, it uses the volumetric clouds of UE which is different from the volumetric fog (the biggest difference is that volumetric clouds can cast and receive shadows while volumetric fog can only receive them).

I guess for that kind of effect it would be better to use the HDRP Volumetric Clouds in Manual mode and provide cloud textures from a 2D fluid simulation instead of doing it in 3D with volumetric fog.

1 Like


I see, but this feature is still going to be good for local effects. Sounds like some kind of LOD on the processing of it might come in handy, skip calculations and so on.

1 Like

[quote=“Ruchir”, post:5, topic: 887777]
Although some more information about properly settings up and optimising volumetric fog setting would be really helpful.
[/quote]

Yes, we’re aware that the current fog settings are pretty hard to configure and the quality isn’t good enough compared to the cost of the system and we’re actually working on improving this.

The first thing to do when configuring the fog is to enable the “Show Additional Properties” toggle, it makes visible a lot of useful properties
8293238--1087130--upload_2022-7-19_17-7-42.png

Keep in mind that the setup is highly dependent on the content of your scene and it’s not possible to have something that works for all cases.

Now regarding the settings in the fog component:

Volumetric Fog Distance: try to minimize the distance as smaller distances will increase the quality of the fog (fog slices will be denser), though you can tweak the other settings to have pretty good results with big distances like 500m or 1km.
The point here is to have the max distance kind of match the “Distance Fade Start” and “Distance Fade End” settings in the Local Volumetric Fog so that when you reach the max distance of the volumetric fog, the volumes already started to fade out, this helps a lot reducing the flickering of lights.

Denoising Mode: This one is important, if your fog has sharp features or hard corners, then either use the Reprojection mode or disable it, Gaussian mode will blur the fog so it’s ideal for blurry fogs with no hard shapes defined. Keep in mind that the reprojection can cause some ghosting depending on the case.

Slice Distribution Uniformity: This setting can help you reduce the flickering by changing how the slices are distributed, a higher value will increase the precision near the camera and lower values will use a more uniform distribution meaning that the slices’ artifacts will be the same near and far away from the camera. Generally, a good value for this is between 0.5 and 0.9 but it depends on your scene.

Quality and Fog Control Mode: Here I prefer to use Custom and Manual respectively as it provides precise control over the quality and the budget

Screen Resolution Percentage: This value represents how the fog will be precise, depending on your content, try to lower this value as much as possible. For example, if you’re making really diffuse fog you can put a really low value which saves a lot of memory and computation that you can spend elsewhere. I advise you to never go above 30% as the memory cost becomes insane after that.

Volume Slice Count: This setting is the most important if you want to avoid flickering, as usual, try to minimize this value to reduce the memory cost but if you want to have a fog over long distances, then you’ll need to have a lot of slices. It’s interesting to tweak this with the slice uniformity distribution as these two settings are related to each other, for example, if you increase a lot the slice count, you may be able to decrease a bit the slice distribution uniformity to put more slices at the back and decrease flickering.

In the Local Volumetric Fog - Blend Distance and Falloff Mode: Be sure to always have a blend distance above 0, it greatly helps reduce the “slice” artifacts on the border of the volume, also generally the falloff mode “Exponential” generally produces visually a better result for the blend interpolation.

For more information on the fog settings, please refer to the documentation page: https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@15.0/manual/Override-Fog.html

4 Likes

[quote=“merpheus”, post:6, topic: 887777]
Is it possible to use a mesh as a volumetric fog shape? So can we sample a mesh/skinned mesh for this? Or do we need to take an SDF-like approach here? (where we have spheres and cubes to make shapes etc)
[/quote]

Right now you need to bake an SDF and sample it in the ShaderGraph if you want to make that. We’re working on the second part of this feature that will hopefully allow doing that (it’s a VFX graph output for the fog in HDRP)

1 Like


So right now we can't have skinned meshes moving around, for things like ghosts etc. But VDB support and vfxgraph-fog output will land later on, is that correct?

I can't say for VDB files because there is no plan on supporting them in Unity right now but for the VFX fog output yes it will land later.


Cool, last question, will it be possible to have skinned meshes with this feature? (As I mentioned, from games perspective, having an animated fog character can be useful. For things like ghosts etc.)

We discarded the possibility to have meshes directly voxelized into the fog as it was too expansive to execute in real-time. The recommended approach for this will be to sample the skinned mesh from the VFX graph and output fog

5 Likes

@antoinel_unity are their any plans to support this feature for existing volumetric clouds system in unity???

[quote=“hippocoder”, post:2, topic: 887777]
Here: https://github.com/keijiro/VolumetricMaterialTest
[/quote]
Thanks, these simple samples are always very helpful. Just need to make sure you have fog enabled everywhere when you put it in your own project :smile:
However, I don’t see the fog in the scene view in this sample or in my project. Do you have to enable this separately somehow?

[quote]
@antoinel_unity are their any plans to support this feature for existing volumetric clouds system in unity???
[/quote]
Not currently, volumetric clouds are using a separate volumetric system which is not compatible with this kind of customization.

1 Like

Could it be that there is a problem with fog since this change?
I use two machines on which one the Fog is rendered and one where it isnt.
Before i made the update it was visible on both machines.

I tried to regenerate shader includes. Could that be the Problem?

[quote=“MaxWitsch”, post:18, topic: 887777]
Could it be that there is a problem with fog since this change?
[/quote]
There are 2 known issues currently: on some GPUs, the fog doesn’t display and the fog is not displayed correctly in VR.
These have been fixed and the fix will be published when it lands

2 Likes


Thank you :) Besides that, fog materials are friggin Awesome!

Here is a small application scenario of what you can do with it.

https://www.youtube.com/watch?v=SjSRspqObFw

16 Likes