Skip to content

Commit 14723e4

Browse files
yvain-raeymaekersEvergreen
authored andcommitted
[GFXLIGHT-1755] Make LightBaker use standard radiometric units for its inputs/outputs
1 parent c2696ab commit 14723e4

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

Packages/com.unity.render-pipelines.core/Editor/PathTracing/BakeInputToWorldConversion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ internal static void ConvertInstancesAndMeshes(
389389
sceneBounds = new Bounds();
390390

391391
// Extract meshes
392-
meshes = new Mesh[bakeInput.meshData.Length];
392+
meshes = new Mesh[bakeInput.meshData.Length + bakeInput.terrainData.Length];
393393
int meshIndex = 0;
394394
for (int i = 0; i < bakeInput.meshData.Length; i++)
395395
{

Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/GlobalIlluminationUtils.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,6 @@ public static bool LightDataGIExtract(Light light, ref LightDataGI lightDataGI)
7979
lightDataGI.shadow = (byte)(light.shadows != LightShadows.None ? 1 : 0);
8080

8181
LightType lightType = add.legacyLight.type;
82-
if (!lightType.IsArea())
83-
{
84-
// For HDRP we need to divide the analytic light color by PI (HDRP do explicit PI division for Lambert, but built in Unity and the GI don't for punctual lights)
85-
// We apply it on both direct and indirect are they are separated, seems that direct is no used if we used mixed mode with indirect or shadowmask bake.
86-
lightDataGI.color.intensity /= Mathf.PI;
87-
lightDataGI.indirectColor.intensity /= Mathf.PI;
88-
directColor.intensity /= Mathf.PI;
89-
indirectColor.intensity /= Mathf.PI;
90-
}
91-
9282
switch (lightType)
9383
{
9484
case LightType.Directional:

Packages/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineCore.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ public static void InitializeShaderGlobalKeywords()
10961096
ShaderGlobalKeywords._ENABLE_ALPHA_OUTPUT = GlobalKeyword.Create(ShaderKeywordStrings._ENABLE_ALPHA_OUTPUT);
10971097
ShaderGlobalKeywords.ForwardPlus = GlobalKeyword.Create(ShaderKeywordStrings.ForwardPlus); // Backward compatibility. Deprecated in 6.1.
10981098
#if (UNITY_META_QUEST)
1099-
ShaderGlobalKeywords.META_QUEST_ORTHO_PROJ = GlobalKeyword.Create(ShaderKeywordStrings.META_QUEST_ORTHO_PROJ);
1099+
ShaderGlobalKeywords.META_QUEST_ORTHO_PROJ = GlobalKeyword.Create(ShaderKeywordStrings.META_QUEST_ORTHO_PROJ);
11001100
ShaderGlobalKeywords.META_QUEST_LIGHTUNROLL = GlobalKeyword.Create(ShaderKeywordStrings.META_QUEST_LIGHTUNROLL);
11011101
#endif
11021102

@@ -1434,7 +1434,7 @@ public static class ShaderKeywordStrings
14341434

14351435
#if (UNITY_META_QUEST)
14361436
/// <summary> Used to statically branch when checking for projection type on Meta Quest device . </summary>
1437-
internal const string META_QUEST_ORTHO_PROJ = "META_QUEST_ORTHO_PROJ";
1437+
internal const string META_QUEST_ORTHO_PROJ = "META_QUEST_ORTHO_PROJ";
14381438

14391439
/// <summary> Unroll light loop if there is only one additional light on Meta Quest device . </summary>
14401440
internal const string META_QUEST_LIGHTUNROLL = "META_QUEST_LIGHTUNROLL";
@@ -1607,6 +1607,12 @@ internal static RenderTextureDescriptor CreateRenderTextureDescriptor(Camera cam
16071607
private static Lightmapping.RequestLightsDelegate lightsDelegate = (Light[] requests, NativeArray<LightDataGI> lightsOutput) =>
16081608
{
16091609
LightDataGI lightData = new LightDataGI();
1610+
1611+
// URP uses a game like lambertian response for punctual lights, they are off by a factor PI.
1612+
// Since LightBaker expects its punctual lights to be expressed in standard radiometric units, the intensity is pre-multiplied by PI here to counteract this.
1613+
// This ensures that the baked punctual light intensity matches realtime intensity. (See GFXLIGHT-1755)
1614+
const float piCorrection = Mathf.PI;
1615+
16101616
#if UNITY_EDITOR
16111617
// Always extract lights in the Editor.
16121618
for (int i = 0; i < requests.Length; i++)
@@ -1621,6 +1627,8 @@ internal static RenderTextureDescriptor CreateRenderTextureDescriptor(Camera cam
16211627
case LightType.Directional:
16221628
DirectionalLight directionalLight = new DirectionalLight();
16231629
LightmapperUtils.Extract(light, ref directionalLight);
1630+
directionalLight.color.intensity *= piCorrection;
1631+
directionalLight.indirectColor.intensity *= piCorrection;
16241632

16251633
if (light.cookie != null)
16261634
{
@@ -1642,11 +1650,15 @@ internal static RenderTextureDescriptor CreateRenderTextureDescriptor(Camera cam
16421650
case LightType.Point:
16431651
PointLight pointLight = new PointLight();
16441652
LightmapperUtils.Extract(light, ref pointLight);
1653+
pointLight.color.intensity *= piCorrection;
1654+
pointLight.indirectColor.intensity *= piCorrection;
16451655
lightData.Init(ref pointLight, ref cookie);
16461656
break;
16471657
case LightType.Spot:
16481658
SpotLight spotLight = new SpotLight();
16491659
LightmapperUtils.Extract(light, ref spotLight);
1660+
spotLight.color.intensity *= piCorrection;
1661+
spotLight.indirectColor.intensity *= piCorrection;
16501662
spotLight.innerConeAngle = light.innerSpotAngle * Mathf.Deg2Rad;
16511663
spotLight.angularFalloff = AngularFalloffType.AnalyticAndInnerAngle;
16521664
lightData.Init(ref spotLight, ref cookie);
@@ -1692,16 +1704,22 @@ internal static RenderTextureDescriptor CreateRenderTextureDescriptor(Camera cam
16921704
case LightType.Directional:
16931705
DirectionalLight directionalLight = new DirectionalLight();
16941706
LightmapperUtils.Extract(light, ref directionalLight);
1707+
directionalLight.color.intensity *= piCorrection;
1708+
directionalLight.indirectColor.intensity *= piCorrection;
16951709
lightData.Init(ref directionalLight);
16961710
break;
16971711
case LightType.Point:
16981712
PointLight pointLight = new PointLight();
16991713
LightmapperUtils.Extract(light, ref pointLight);
1714+
pointLight.color.intensity *= piCorrection;
1715+
pointLight.indirectColor.intensity *= piCorrection;
17001716
lightData.Init(ref pointLight);
17011717
break;
17021718
case LightType.Spot:
17031719
SpotLight spotLight = new SpotLight();
17041720
LightmapperUtils.Extract(light, ref spotLight);
1721+
spotLight.color.intensity *= piCorrection;
1722+
spotLight.indirectColor.intensity *= piCorrection;
17051723
spotLight.innerConeAngle = light.innerSpotAngle * Mathf.Deg2Rad;
17061724
spotLight.angularFalloff = AngularFalloffType.AnalyticAndInnerAngle;
17071725
lightData.Init(ref spotLight);

0 commit comments

Comments
 (0)