UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

graphics

[URP] Adaptive Probe Volume Compute Shader Init Fix

Solution

lightinggraphicsshaders

Unity 2022.2.x - Unity 6.3.x

Published Sat, Mar 14

Issue

 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.

Explanation

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.

  1. Access the ProbeReferenceVolume.instance which manages the lifecycle of probe data.
  2. Invoke ProbeReferenceVolume.instance.BindAPVRuntimeResources(commandBuffer, computeShader, kernelIndex) within your render loop or scriptable render pass to bind the necessary textures and buffers.
  3. Call ProbeReferenceVolume.instance.UpdateShaderVariablesProbeVolumes(commandBuffer) to sync the global probe volume parameters used by the EvaluateAdaptiveProbeVolume macro.
  4. Ensure your shader is compiled with the PROBE_VOLUMES_L1 or PROBE_VOLUMES_L2 keywords 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 Shader inspector.
  • Ensure the UniversalRenderPipelineAsset has Adaptive Probe Volumes enabled under the Lighting settings.
  • If sampling APV data in a custom ScriptableRenderPass, ensure you are calling the bind methods within the Execute method using the provided CommandBuffer.

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.