So the usual way of looping over lightsources now longer works with Forward+.
In this file
int GetAdditionalLightsCount()
{
#if USE_FORWARD_PLUS
// Counting the number of lights in clustered requires traversing the bit list, and is not needed up front.
return 0;
#else
// TODO: we need to expose in SRP api an ability for the pipeline cap the amount of lights
// in the culling. This way we could do the loop branch with an uniform
// This would be helpful to support baking exceeding lights in SH as well
return int(min(_AdditionalLightsCount.x, unity_LightData.y));
#endif
}
The functions for getting additional lights are changed to get light-structs from the structured buffer, so in my example, i can use GetAdditionalLight(0, d.positionWorldSpace) and it returns a lightstruct.
How do i know how many there are?
Or: How to i traverse the list in a better way?
Here in line 27+
there a cluster iterator loop defined. That works, with a little “but”.
Light mainLight = GetMainLight(d.shadowCoord, d.positionWorldSpace, 1);
float3 color = CustomLightHandling(d, mainLight);
uint lightsCount = GetAdditionalLightsCount();
LIGHT_LOOP_BEGIN(lightsCount)
Light light = GetAdditionalLight(lightIndex, d.positionWorldSpace);
float lightColor = light.color * light.distanceAttenuation;
color += light.color; // this line crashes the editor
LIGHT_LOOP_END
This crashes unity with a D3D11 error saying GPU timeout.
Sources:
Functions and definitions:
URP shaders do use that way of looping additional lights: