Lux URP Blend Lighting.hlsl 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef URP_BLENDLIGHTING_INCLUDED
  2. #define URP_BLENDLIGHTING_INCLUDED
  3. half4 LuxFragmentBlendPBR(InputData inputData, half3 albedo, half metallic, half3 specular,
  4. half smoothness, half occlusion, half3 emission, half alpha, float3 shadowShift)
  5. {
  6. BRDFData brdfData;
  7. InitializeBRDFData(albedo, metallic, specular, smoothness, alpha, brdfData);
  8. // ShadowMask: To ensure backward compatibility we have to avoid using shadowMask input, as it is not present in older shaders
  9. #if defined(SHADOWS_SHADOWMASK) && defined(LIGHTMAP_ON)
  10. half4 shadowMask = inputData.shadowMask;
  11. #elif !defined (LIGHTMAP_ON)
  12. half4 shadowMask = unity_ProbesOcclusion;
  13. #else
  14. half4 shadowMask = half4(1, 1, 1, 1);
  15. #endif
  16. Light mainLight = GetMainLight(inputData.shadowCoord, inputData.positionWS, shadowMask);
  17. //Light mainLight = GetMainLight(inputData.shadowCoord);
  18. // SSAO
  19. #if defined(_SCREEN_SPACE_OCCLUSION)
  20. AmbientOcclusionFactor aoFactor = GetScreenSpaceAmbientOcclusion(inputData.normalizedScreenSpaceUV);
  21. mainLight.color *= aoFactor.directAmbientOcclusion;
  22. occlusion = min(occlusion, aoFactor.indirectAmbientOcclusion);
  23. #endif
  24. MixRealtimeAndBakedGI(mainLight, inputData.normalWS, inputData.bakedGI, half4(0, 0, 0, 0));
  25. half3 color = GlobalIllumination(brdfData, inputData.bakedGI, occlusion, inputData.normalWS, inputData.viewDirectionWS);
  26. color += LightingPhysicallyBased(brdfData, mainLight, inputData.normalWS, inputData.viewDirectionWS);
  27. #ifdef _ADDITIONAL_LIGHTS
  28. uint pixelLightCount = GetAdditionalLightsCount();
  29. for (uint lightIndex = 0u; lightIndex < pixelLightCount; ++lightIndex)
  30. {
  31. // shadowShift is > 0 only for pixels around or below the intersection. So using inputData.positionWS + shadowShift should be ok.
  32. //Light light = GetAdditionalLight(lightIndex, inputData.positionWS + shadowShift);
  33. // URP 10: We have to use the new GetAdditionalLight function
  34. Light light = GetAdditionalLight(lightIndex, inputData.positionWS + shadowShift, shadowMask);
  35. #if defined(_SCREEN_SPACE_OCCLUSION)
  36. light.color *= aoFactor.directAmbientOcclusion;
  37. #endif
  38. color += LightingPhysicallyBased(brdfData, light, inputData.normalWS, inputData.viewDirectionWS);
  39. }
  40. #endif
  41. #ifdef _ADDITIONAL_LIGHTS_VERTEX
  42. color += inputData.vertexLighting * brdfData.diffuse;
  43. #endif
  44. color += emission;
  45. return half4(color, alpha);
  46. }
  47. #endif