Forward+
Zilk opened this issue · 3 comments
Adding support for forward+ would be awesome. It flickers now if forward+ is activated. Also would be neat if the point/spot lights listened to the ramp texture instead of creating bands.
Have got Forward+ on my list, just need to find some time to try it out. I'm planning to implement Cookies & Light Layers first.
I likely won't change the additional lights in the Toon example to use a ramp texture. It's mostly just meant to be an example anyway. If sampling inside the loop that also wouldn't be great for performance, though might be possible to combine the distance attenuations then apply the ramp outside the loop. It's up to you if you want to try implementing that.
If anyone is interested in Forward+ right now, the UniversalFragmentBlinnPhong function in the URP Lighting.hlsl should provide a good example of how to set it up, though may vary in different versions (this is master branch, so may be too up-to-date)
https://github.com/Unity-Technologies/Graphics/blob/2784a76e620f9c63d8ff04c4d75604113b55d6a7/Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl#L358
#if defined(_ADDITIONAL_LIGHTS)
uint pixelLightCount = GetAdditionalLightsCount();
#if USE_FORWARD_PLUS
for (uint lightIndex = 0; lightIndex < min(URP_FP_DIRECTIONAL_LIGHTS_COUNT, MAX_VISIBLE_LIGHTS); lightIndex++)
{
FORWARD_PLUS_SUBTRACTIVE_LIGHT_CHECK
Light light = GetAdditionalLight(lightIndex, inputData, shadowMask, aoFactor);
#ifdef _LIGHT_LAYERS
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
#endif
{
lightingData.additionalLightsColor += CalculateBlinnPhong(light, inputData, surfaceData);
}
}
#endif
LIGHT_LOOP_BEGIN(pixelLightCount)
Light light = GetAdditionalLight(lightIndex, inputData, shadowMask, aoFactor);
#ifdef _LIGHT_LAYERS
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
#endif
{
lightingData.additionalLightsColor += CalculateBlinnPhong(light, inputData, surfaceData);
}
LIGHT_LOOP_END
#endif
Would need a boolean keyword for USE_FORWARD_PLUS
Nice! This helps a long way, really cool!
One thing I noticed now that I got it working properly is that the point lights have no attenuation? Meaning they light all faces of the mesh equally even if they point away from the point light?
Have you considered having the point lights react to the same texture ramp instead of hardcoded banding?