How to sample volumetric fog density - color at a point in shader

Hi,

I need to know the volumetric fog density in my custom shader, is this possible in HDRP using the Atmospheric scattering library ?

I try to include the EvaluateAtmosphericScattering function in

#include “Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl”

but it gives me various errors of missing variables declarations.

I tried add more libs to solve, but finally get some strange error of an undeclared #define variable, which though is defined in one of the libs and now sure how to solve

I add those

#include “AutoLight.cginc”

#include “Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl”
#include “Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl”
#include “Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesFunctions.hlsl”
#include “Packages/com.unity.render-pipelines.high-definition/Runtime/Material/Material.hlsl”
#include “Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/ShaderVariablesAtmosphericScattering.cs.hlsl”

and i get the following errors

Shader error in ‘SkyMaster/ShaderVolumeClouds-Desktop-SM3.0 v3.4.3’: ‘GetWorldToObjectMatrix’: function must return a value at /Unity/VolumeShaderCloudsHDRP/Library/PackageCache/com.unity.render-pipelines.core@4.10.0-preview/ShaderLibrary/SpaceTransforms.hlsl(12) (on d3d11)
Compiling Vertex program with DIRECTIONAL
Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_LIGHTMAP_FULL_HDR

Shader error in ‘SkyMaster/ShaderVolumeClouds-Desktop-SM3.0 v3.4.3’: undeclared identifier ‘UNITY_MATRIX_I_M’ at /Unity/VolumeShaderCloudsHDRP/Library/PackageCache/com.unity.render-pipelines.core@4.10.0-preview/ShaderLibrary/SpaceTransforms.hlsl(12) (on d3d11)
Compiling Vertex program with DIRECTIONAL
Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_LIGHTMAP_FULL_HDR

What is the way to properly include this library and sample the volume density for custom HDRP shader ?

Note that UNITY_MATRIX_I_M is defined in ShaderVariables.hlsl which i include, but for some reason is not found.

Thanks for any insight in this

1 Like

A year later…posting this for anyone that stumbles on to this page since its one of the only posts I could find. I recently was able to achieve this in a custom render pass for HDRP injected at “Before post processing”. Not quite sure what OP was running into, but that was also a while ago so a lot has probably changed since then.

Youre looking for EvaluateAtmosphericScattering located in AtmosphericScattering.hlsl

float3 atmosColor;
float3 atmosOpacity;
EvaluateAtmosphericScattering(posInput, viewDirection, atmosColor, atmosOpacity);
outColor = float4(saturate(outColor + atmosColor), 1);

2 Likes