How to access directional ambient light in HDRP shader code

I’m trying to implement a custom fullscreen pass in HDRP for volumetric fog, as part of the algorithm I need to be able to sample the intensity of ambient lighting (from the sky and sun) coming in from a given direction.

The algorithm is way too complicated to convert into shadergraph, so I’m writing HLSL shader code in classic .shader and .cginc files, but I can’t find much information about this specific for HDRP.

I did find a lot of topics related to spherical harmonics, but not how to physically get that information in a frag function.

Hey, you can use this super simple snippet to get ambient probe intensity for L0.
This is basic but you can use luminance instead of the simple addition for example.

SphericalHarmonicsL2 ambiantProbe = RenderSettings.ambientProbe;
float R = sh[0, 0];
float G = sh[0, 1];
float B = sh[0, 2];

ambientLightingIntensityL0 = R + G + B;

Using the documentation you can also get L1/L2 for more precision / directionality.

ok, so I should just pass this info into the shader and evaluate there? I’m still looking how to evaluate L2 exactly, something like c0 + x * c1 + y * c2 + z * c3 + x * y * c4 etc

1 Like