I’m trying to use EvaluateAdaptiveProbeVolume in a compute shader to estimate how bright an object is (similar to how LightProbes.GetInterpolatedProbe works). I’m encountering an error related to the bakeDiffuseLighting variable.
Here’s my compute shader code:
I’m getting the following error:
variable ‘bakeDiffuseLighting’ used without having been completely initialized at kernel CSMain (ProbeVolume.hlsl:762)
How can I resolve this?
Before you include ProbeVolume.hlsl, you need to define either PROBE_VOLUMES_L1 or PROBE_VOLUMES_L2. Usually done via keyword like so:
#pragma multi_compile_local _ PROBE_VOLUMES_L1 PROBE_VOLUMES_L2
Then you can set the relevant keyword with Unity - Scripting API: ComputeShader.EnableKeyword
Alternatively you can just #define PROBE_VOLUMES_L1
or #define PROBE_VOLUMES_L2
before including ProbeVolume.hlsl if you know you’ll be using L1 or L2 probes.
1 Like
Thanks, this solved the previous issue (used #define PROBE_VOLUMES_L2
as I intend to only use those).
However, now I’m getting “Property (_APVResL0_L1Rx) at kernel index (0) is not set” when I’m trying to dispatch the compute shader. Not sure I’m using it as intended since I’m not too familiar with compute shaders. Any advice?
The GPU data used by APV hasn’t been bound. You can use ProbeReferenceVolume.instance.BindAPVRuntimeResources() to bind it. It assumes you have a CommandBuffer, so if you want to use it, you’ll have to use CommandBuffer.DispatchCompute instead of ComputeShader.Dispatch etc. Alternatively you can look at the body of that function and copy the relevant code, but change CommandBuffer.SetGlobalTexture calls to Shader.SetGlobalTexture. You may also need to call ProbeReferenceVolume.instance.UpdateShaderVariablesProbeVolumes() - don’t quite remember.
We should probably have an example of all this in the docs. I’ll look into at some point.
1 Like
Thank you for the help!
For future reference, I was able to get the result with the following code:
However, had to switch SH bands to L1 since I was getting Property (_APVResL2_L0) at kernel index (0) is not set
.
You need to have the L2 enabled in your SRP asset to use the L2 band. I believe it is set to L1 by default