Hello guys,
I have some problem when calculating the attenuation through shadow map.
My goal is to implement light scattering (volumetric light) through calculating light attenuation in the ray marching step, and here’s the final snapshot in the built-in render system.
And then I write some code in shader to calculate light attenuation only, and the result looks like this :
And this is how I access shadow map in built-in render system.
float4 cascadeWeights = GetCascadeWeights_SplitSpheres(wpos);
bool inside = dot(cascadeWeights, float4(1, 1, 1, 1)) < 4;
float4 samplePos = GetCascadeShadowCoord(float4(wpos, 1), cascadeWeights);
atten = inside ? UNITY_SAMPLE_SHADOW(_CascadeShadowMapTexture, samplePos.xyz) : 1.0f;
atten = _LightShadowData.r + atten * (1 - _LightShadowData.r);
But I got a quite different result in URP, and I used another way to access shadow map. I’m pretty sure those two scenes (transform of scene objects, camera transforms, FOV …etc) are in same condition.
And this is how I access shadow map in URP, and this shader executed as a Blit material.
half cascadeIndex = ComputeCascadeIndex(wpos);
float4 coords = mul(_MainLightWorldToShadow[cascadeIndex], float4(wpos, 1.0));
ShadowSamplingData shadowSamplingData = GetMainLightShadowSamplingData();
half4 shadowParams = GetMainLightShadowParams();
atten = inside ? SampleShadowmap(TEXTURE2D_ARGS(_MainLightShadowmapTexture, sampler_MainLightShadowmapTexture), coords, shadowSamplingData, shadowParams, false) : 1.0f;
atten = shadowParams.r + atten * (1 - shadowParams.r);
The main camera is set in perspective mode (and I know the _MainLightShadowmapTexture built in orthogonal mode), and the shader is from Here.
Is there anything wrong during these steps ? any advice would be appreciated.
[Edit] I just want to know how to sample shadow map in URP and the equivalent way with the built-in method.
Have a nice day !