Skip to content

Commit cb7e9ad

Browse files
EvgeniiGsebastienlagarde
authored andcommitted
Add light layer on indirect lighting controller #777
1 parent 2a79682 commit cb7e9ad

File tree

15 files changed

+135
-23
lines changed

15 files changed

+135
-23
lines changed

com.unity.render-pipelines.high-definition/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111
- Added support for AxF measurements importing into texture resources tilings.
1212
- Added Layer parameter on Area Light to modify Layer of generated Emissive Mesh
1313
- Added support for multiple mapping modes in AxF.
14+
- Add support of lightlayers on indirect lighting controller
1415

1516
### Fixed
1617
- Fixed issue with reflection probes in realtime time mode with OnEnable baking having wrong lighting with sky set to dynamic (case 1238047).

com.unity.render-pipelines.high-definition/Documentation~/Override-Indirect-Lighting-Controller.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ The **Indirect Lighting Controller** uses the [Volume](Volumes.html) framework,
1717

1818
| Property | Description |
1919
| ------------------------------- | ------------------------------------------------------------ |
20-
| **Indirect Diffuse Intensity** | A multiplier for baked and realtime Global Illumination lightmaps and Light Probes. HDRP multiplies the lightmap and Light Probe data by this value. |
21-
| **Indirect Specular Intensity** | A multiplier for baked, realtime, and custom Reflection Probes. HDRP multiplies the Reflection Probe data by this value. |
22-
23-
20+
| **Indirect Diffuse Lighting Multiplier** | A multiplier for lightmaps, Light Probes, Light Probe Volumes, Screen-Space Global Illumination, and [Ray-Traced Global Illumination](Ray-Traced-Global-Illumination.md). HDRP multiplies the light data from all of these by this value. |
21+
| **Indirect Diffuse Lighting Layers** | Specifies the [Light Layers](Light-Layers.md) for indirect diffuse lighting. If you enable Light Layers, you can use them to decouple Meshes in your Scene from the above multiplier. |
22+
| **Reflection Lighting Multiplier** | A multiplier for baked, realtime, custom [Reflection Probes](Reflection-Probe.md) and [Planar Probes](Planar-Reflection-Probe.md), [Screen-Space Reflection](Override-Screen-Space-Reflection.md), [Ray-Traced Reflection](Ray-Traced-Reflections.md), and Sky Reflection. HDRP multiplies the light data from all of these by this value. |
23+
| **Reflection Lighting Layers** | LSpecifies the [Light Layers](Light-Layers.md) for reflection lighting. If you enable Light Layers, you can use them to decouple Meshes in your Scene from the above multiplier. |
24+
| **Reflection Probe Intensity Multiplier** | A multiplier for baked, realtime, and custom [Reflection Probes](Reflection-Probe.md) and [Planar Probes](Planar-Reflection-Probe.md). HDRP multiplies the Reflection Probe data by this value. |
2425

2526
## Details
2627

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,47 @@
1+
using UnityEngine;
12
using UnityEngine.Rendering.HighDefinition;
3+
using UnityEngine.Rendering;
24

35
namespace UnityEditor.Rendering.HighDefinition
46
{
57
[CanEditMultipleObjects]
68
[VolumeComponentEditor(typeof(IndirectLightingController))]
79
class IndirectLightingControllerEditor : VolumeComponentEditor
810
{
9-
SerializedDataParameter m_IndirectDiffuseIntensity;
10-
SerializedDataParameter m_IndirectSpecularIntensity;
11+
SerializedDataParameter m_IndirectDiffuseLightingMultiplier;
12+
SerializedDataParameter m_IndirectDiffuseLightingLayers;
13+
14+
SerializedDataParameter m_ReflectionLightingMultiplier;
15+
SerializedDataParameter m_ReflectionLightingLayers;
16+
17+
SerializedDataParameter m_ReflectionProbeIntensityMultiplier;
1118

1219
public override void OnEnable()
1320
{
1421
var o = new PropertyFetcher<IndirectLightingController>(serializedObject);
1522

16-
m_IndirectSpecularIntensity = Unpack(o.Find(x => x.indirectSpecularIntensity));
17-
m_IndirectDiffuseIntensity = Unpack(o.Find(x => x.indirectDiffuseIntensity));
23+
m_IndirectDiffuseLightingMultiplier = Unpack(o.Find(x => x.indirectDiffuseLightingMultiplier));
24+
m_IndirectDiffuseLightingLayers = Unpack(o.Find(x => x.indirectDiffuseLightingLayers));
25+
26+
m_ReflectionLightingMultiplier = Unpack(o.Find(x => x.reflectionLightingMultiplier));
27+
m_ReflectionLightingLayers = Unpack(o.Find(x => x.reflectionLightingLayers));
28+
29+
m_ReflectionProbeIntensityMultiplier = Unpack(o.Find(x => x.reflectionProbeIntensityMultiplier));
1830
}
1931

2032
public override void OnInspectorGUI()
2133
{
22-
PropertyField(m_IndirectDiffuseIntensity, EditorGUIUtility.TrTextContent("Indirect Diffuse Intensity", "Sets the multiplier for baked diffuse lighting."));
23-
PropertyField(m_IndirectSpecularIntensity, EditorGUIUtility.TrTextContent("Indirect Specular Intensity", "Sets the multiplier for reflected specular lighting."));
34+
PropertyField(m_IndirectDiffuseLightingMultiplier, EditorGUIUtility.TrTextContent("Indirect Diffuse Lighting Multiplier", "Sets the multiplier for indirect diffuse lighting.\nIt affect Ambient Probe, Light Probes, Lightmaps, Light Probe Volumes, Screen Space Global Illumination, Raytrace Global Illumination."));
35+
GUI.enabled = HDUtils.hdrpSettings.supportLightLayers;
36+
PropertyField(m_IndirectDiffuseLightingLayers, EditorGUIUtility.TrTextContent("Indirect Diffuse Lighting Layers", "Sets the light layer mask for indirect diffuse lighting. Only matching RenderingLayers on Mesh will get affected by the multiplier."));
37+
GUI.enabled = true;
38+
39+
PropertyField(m_ReflectionLightingMultiplier, EditorGUIUtility.TrTextContent("Reflection Lighting Multiplier", "Sets the multiplier for reflected specular lighting.\nIt affect Sky Reflection, Reflection Probes, Planar Probes, Screen Space Reflection, Raytrace Reflection."));
40+
GUI.enabled = HDUtils.hdrpSettings.supportLightLayers;
41+
PropertyField(m_ReflectionLightingLayers, EditorGUIUtility.TrTextContent("Reflection Lighting Layers", "Sets the light layer mask for reflected specular lighting. Only matching RenderingLayers on Mesh will get affected by the multiplier."));
42+
GUI.enabled = true;
43+
44+
PropertyField(m_ReflectionProbeIntensityMultiplier, EditorGUIUtility.TrTextContent("Reflection/Planar Probe Intensity Multiplier", "Sets the intensity multiplier for Reflection/Planar Probes."));
2445
}
2546
}
2647
}

com.unity.render-pipelines.high-definition/Editor/Wizard.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23

34
namespace UnityEngine.Rendering.HighDefinition
45
{
@@ -8,9 +9,54 @@ namespace UnityEngine.Rendering.HighDefinition
89
[Serializable, VolumeComponentMenu("Lighting/Indirect Lighting Controller")]
910
public class IndirectLightingController : VolumeComponent
1011
{
11-
/// <summary>Indirect specular intensity multiplier, between 0 and 1</summary>
12-
public MinFloatParameter indirectSpecularIntensity = new MinFloatParameter(1.0f, 0.0f);
13-
/// <summary>Indirect diffuse intensity multiplier, between 0 and 1</summary>
14-
public MinFloatParameter indirectDiffuseIntensity = new MinFloatParameter(1.0f, 0.0f);
12+
[UnityEngine.Serialization.FormerlySerializedAs("indirectDiffuseIntensity")]
13+
/// <summary>Indirect diffuse lighting multiplier, between 0 and 1</summary>
14+
public MinFloatParameter indirectDiffuseLightingMultiplier = new MinFloatParameter(1.0f, 0.0f);
15+
/// Controls which layer will be affected by the indirect diffuse lighting multiplier
16+
public LightLayerEnumParameter indirectDiffuseLightingLayers = new LightLayerEnumParameter(LightLayerEnum.LightLayerDefault);
17+
18+
/// <summary>Reflection lighting multiplier, between 0 and 1</summary>
19+
public MinFloatParameter reflectionLightingMultiplier = new MinFloatParameter(1.0f, 0.0f);
20+
/// Controls which layer will be affected by the reflection lighting multiplier
21+
public LightLayerEnumParameter reflectionLightingLayers = new LightLayerEnumParameter(LightLayerEnum.LightLayerDefault);
22+
23+
[UnityEngine.Serialization.FormerlySerializedAs("indirectSpecularIntensity")]
24+
/// <summary>Reflection probe intensity multiplier, between 0 and 1</summary>
25+
public MinFloatParameter reflectionProbeIntensityMultiplier = new MinFloatParameter(1.0f, 0.0f);
26+
27+
/// <summary>
28+
/// Returns a mask of reflection lighting layers as uint and handle the case of Everything as being 0xFF and not -1
29+
/// </summary>
30+
/// <returns></returns>
31+
public uint GetReflectionLightingLayers()
32+
{
33+
int value = (int)reflectionLightingLayers.GetValue<LightLayerEnum>();
34+
return value < 0 ? (uint)LightLayerEnum.Everything : (uint)value;
35+
}
36+
37+
/// <summary>
38+
/// Returns a mask of indirect diffuse lighting layers as uint and handle the case of Everything as being 0xFF and not -1
39+
/// </summary>
40+
/// <returns></returns>
41+
public uint GetIndirectDiffuseLightingLayers()
42+
{
43+
int value = (int)indirectDiffuseLightingLayers.GetValue<LightLayerEnum>();
44+
return value < 0 ? (uint)LightLayerEnum.Everything : (uint)value;
45+
}
46+
47+
/// <summary>
48+
/// Sky Ambient Mode volume parameter.
49+
/// </summary>
50+
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
51+
public sealed class LightLayerEnumParameter : VolumeParameter<LightLayerEnum>
52+
{
53+
/// <summary>
54+
/// Light Layer Enum parameterconstructor.
55+
/// </summary>
56+
/// <param name="value">Light Layer Enum parameter.</param>
57+
/// <param name="overrideState">Initial override value.</param>
58+
public LightLayerEnumParameter(LightLayerEnum value, bool overrideState = false)
59+
: base(value, overrideState) { }
60+
}
1561
}
1662
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ internal bool GetEnvLightData(CommandBuffer cmd, HDCamera hdCamera, in Processed
18161816
envLightData.lightLayers = hdCamera.frameSettings.IsEnabled(FrameSettingsField.LightLayers) ? probe.lightLayersAsUInt : uint.MaxValue;
18171817
envLightData.influenceShapeType = influence.envShape;
18181818
envLightData.weight = processedProbe.weight;
1819-
envLightData.multiplier = probe.multiplier * m_indirectLightingController.indirectSpecularIntensity.value;
1819+
envLightData.multiplier = probe.multiplier * m_indirectLightingController.reflectionProbeIntensityMultiplier.value;
18201820
envLightData.rangeCompressionFactorCompensation = Mathf.Max(probe.rangeCompressionFactor, 1e-6f);
18211821
envLightData.influenceExtents = influence.extents;
18221822
switch (influence.envShape)

com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.hlsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,10 @@ void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BS
466466

467467
ApplyDebugToLighting(context, builtinData, aggregateLighting);
468468

469+
// Note: We can't apply the IndirectDiffuseMultiplier here as with GBuffer, Emissive is part of the bakeDiffuseLighting.
470+
// so IndirectDiffuseMultiplier is apply in PostInitBuiltinData or related location (like for probe volume)
471+
aggregateLighting.indirect.specularReflected *= GetIndirectSpecularMultiplier(builtinData.renderingLayers);
472+
469473
// Also Apply indiret diffuse (GI)
470474
// PostEvaluateBSDF will perform any operation wanted by the material and sum everything into diffuseLighting and specularLighting
471475
PostEvaluateBSDF( context, V, posInput, preLightData, bsdfData, builtinData, aggregateLighting,

com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ShaderVariablesScreenSpaceLighting.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ struct ShaderVariablesScreenSpaceLighting
1212
// Ambient occlusion
1313
public Vector4 _AmbientOcclusionParam; // xyz occlusion color, w directLightStrenght
1414

15-
public Vector4 _IndirectLightingMultiplier; // .x indirect diffuse multiplier (use with indirect lighting volume controler)
15+
public float _IndirectDiffuseLightingMultiplier;
16+
public uint _IndirectDiffuseLightingLayers;
17+
public float _ReflectionLightingMultiplier;
18+
public uint _ReflectionLightingLayers;
1619

1720
// Screen space refraction
1821
public float _SSRefractionInvScreenWeightDistance; // Distance for screen space smoothstep with fallback

com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/ShaderVariablesScreenSpaceLighting.cs.hlsl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
float4 _DepthPyramidScale;
1212
float4 _CameraMotionVectorsScale;
1313
float4 _AmbientOcclusionParam;
14-
float4 _IndirectLightingMultiplier;
14+
float _IndirectDiffuseLightingMultiplier;
15+
uint _IndirectDiffuseLightingLayers;
16+
float _ReflectionLightingMultiplier;
17+
uint _ReflectionLightingLayers;
1518
float _SSRefractionInvScreenWeightDistance;
1619

1720

com.unity.render-pipelines.high-definition/Runtime/Material/BuiltinUtilities.hlsl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ void PostInitBuiltinData( float3 V, PositionInputs posInput, SurfaceData surfa
105105
{
106106
// Apply control from the indirect lighting volume settings - This is apply here so we don't affect emissive
107107
// color in case of lit deferred for example and avoid material to have to deal with it
108-
builtinData.bakeDiffuseLighting *= _IndirectLightingMultiplier.x;
109-
builtinData.backBakeDiffuseLighting *= _IndirectLightingMultiplier.x;
108+
float multiplier = GetIndirectDiffuseMultiplier(builtinData.renderingLayers);
109+
builtinData.bakeDiffuseLighting *= multiplier;
110+
builtinData.backBakeDiffuseLighting *= multiplier;
110111

111112
#ifdef MODIFY_BAKED_DIFFUSE_LIGHTING
112113

0 commit comments

Comments
 (0)