Search Unity

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

Discussion in 'High Definition Render Pipeline' started by nasos_333, Sep 14, 2019.

  1. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,363
    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
     
  2. b1gry4n

    b1gry4n

    Joined:
    Sep 11, 2013
    Posts:
    146
    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

    Code (CSharp):
    1. float3 atmosColor;
    2. float3 atmosOpacity;
    3. EvaluateAtmosphericScattering(posInput, viewDirection, atmosColor, atmosOpacity);
    4. outColor = float4(saturate(outColor + atmosColor), 1);
     
    Last edited: Sep 15, 2020
    nasos_333 likes this.