[URP] Adaptive Probe Volume Compute Shader Init Fix
Solution
Unity 2022.2.x - Unity 6.3.x
Published Sat, Mar 14
An uninitialized variable error specifically bakeDiffuseLighting occurs within a compute shader when attempting to utilize EvaluateAdaptiveProbeVolume to sample scene lighting. This issue arises because the Adaptive Probe Volume (APV) runtime resources, including necessary volume textures and structured buffers, are not explicitly bound to your compute shader kernel prior to dispatch.
The bakeDiffuseLighting uninitialized variable error in your compute shader indicates that the Adaptive Probe Volume runtime resources are not bound to the GPU context. To resolve this, you must ensure that your compute shader has access to the APV data structures.
- Access the
ProbeReferenceVolume.instancewhich manages the lifecycle of probe data. - Invoke
ProbeReferenceVolume.instance.BindAPVRuntimeResources(commandBuffer, computeShader, kernelIndex)within your render loop or scriptable render pass to bind the necessary textures and buffers. - Call
ProbeReferenceVolume.instance.UpdateShaderVariablesProbeVolumes(commandBuffer)to sync the global probe volume parameters used by theEvaluateAdaptiveProbeVolumemacro. - Ensure your shader is compiled with the
PROBE_VOLUMES_L1orPROBE_VOLUMES_L2keywords if your logic depends on specific spherical harmonics orders.
Additional Tips
- Verify that bakeDiffuseLighting is not being optimized out by the compiler; you can check the “Keep Constant Buffer” settings in the
Shaderinspector. - Ensure the
UniversalRenderPipelineAssethas Adaptive Probe Volumes enabled under the Lighting settings. - If sampling APV data in a custom
ScriptableRenderPass, ensure you are calling the bind methods within theExecutemethod using the providedCommandBuffer.
TL;DR
Address bakeDiffuseLighting uninitialized variable errors in compute shaders by ensuring APV runtime resources are bound via ProbeReferenceVolume.instance.BindAPVRuntimeResources and updating shader globals before dispatch.
Related Posts Haven't quite found a solution to your problem? We think these posts might help you.
Content inspired by a Unity discussion post.