Light probes not working properly with instanced meshes

Hello, friends.
From a while, I have been toying with the fascinating world of baked lighting, and light probes. Everything worked fine, but there’s an issue that is bugging me.
See, in one of my scenes, I use mesh instancing. As far as I have read, GPU Instancing works fine with Light probes, but my scene is showing a strange behaviour.
This is the scene, from above (unlit):


All the persons you see here are instanced quads. The gizmo in the picture shows the position of the spawner object.

What’s the issue? See if I turn on the lights:


See that the signaled instanced meshes don’t receive any green light?

And this is what happens when I move the pivot point towards the light:

TL;DR : Light probes are only evaluating the position of the spawner object, and not each mesh position, causing all the meshes to have the same lighting.

I use:

 Graphics.DrawMeshInstancedIndirect(_mesh[type], i, _material[type], _bounds, _argsBuffer[type], 0, _materialPropertyBlock[type], _shadowMode, _receiveShadows, 0, null, UnityEngine.Rendering.LightProbeUsage.BlendProbes);

And I have tried also the following example:

My first impression was that I was missing a step or that I should send the data manually to the GPU, but everything I have read about this matter is that “It’s supported and it should work”. Besides, all iterations I have done (changing the type of LighProbeUsage to LPPV and CustomProvided, using the Unity example of mesh instancing, etc) have the same problem: they use only the spawner position to evaluate lighting.

What I am missing?

Hey @carcasanchez ,

The light probes structure lives entirely on the CPU side and for each object that uses light probes that structure is queried to provide an interpolated value.
That means that Graphics.DrawMeshInstancedIndirect doesn’t work well with it, as all the per instance data needed for interpolation queries lives on the GPU side (and not on the CPU side).

The best approach is to make sure that the light probe data is on the GPU as well, and that you can do by using LPPVs. I see that you wrote that you tried that, however let me just provide the details of the needed steps, so that we’re on the same page.

The Graphics.DrawMeshInstancedIndirect docs specify that the last two parameters are

Rendering.LightProbeUsage lightProbeUsage = LightProbeUsage.BlendProbes,
LightProbeProxyVolume lightProbeProxyVolume = null

Please use Rendering.LightProbeUsage.UseProxyVolume and specify which volume to use by providing a reference to it.
See the “Global Illumination and GPU Instancing” section in GPU instancing docs.

This LightProbeProxyVolume can live on any GameObject. However in your case the size and position of that LPPV can’t be inferred automatically (as that automated logic needs a MeshRenderer). Thankfully you can use a custom bounding box that will encompass your instanced meshes.
See the “Bounding Box Mode” section in Light Probe Proxy Volume component docs.

The above will make sure that the data is interpolated on the CPU for all the vertices of the LPPV, passed to the GPU and in there it will be interpolated per pixel for each of your instanced meshes.

Hope this helps!
Kuba

1 Like

Thank you for your reply, but I have tried and is the same result (note the same lighting in all instanced meshes:


I have some concerns, though. If I remember well, the first time I used LPPV there was a number of probe gizmos forming a grid inside de volume, which now don’t appear. I checked online, and it seems like that.
Besides, I have found this bug report that makes me wonder if there’s a relationship.
Moreover: it is supposed that LPPV needs an existing light probe group in scene? There’s a warning saying that I should add a Ligh Probe Group component.

Maybe I am mistaken and my memories are betraying me, but I would swear that there was a time when LPPV worked as intended. I don’t know what’s different now, but the gizmos not showing are bugging me a lot.

Ok, new update. For a reason I cannot discern (maybe reflection probes in scene were giving conflicts?), the gizmos appeared. And they affect the instanced meshes properly.
BUT.

Now, the baked light in the probes is not right!


The white middle probes make no sense, and there’s no sign of the red light from the spot line.

Besides, this is what happens when I turn off the stage lights and leave only the red ones:

Why?

Ok, solved! Is was just that the LPPV needs a probe group active in scene, and I had only the stage one.
Just by putting another group in the crowd and baking solves the issue.

1 Like

I mean… they don’t work properly with any meshes lmao