Skip to content

Add light layer on indirect lighting controller #777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added support to combine RTSSS and RTGI (1248733).
- Added IES Profile support for Point, Spot and Rectangular-Area lights
- Added support for multiple mapping modes in AxF.
- Add support of lightlayers on indirect lighting controller

### Fixed
- Fix when rescale probe all direction below zero (1219246)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ The **Indirect Lighting Controller** uses the [Volume](Volumes.html) framework,

| Property | Description |
| ------------------------------- | ------------------------------------------------------------ |
| **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. |
| **Indirect Specular Intensity** | A multiplier for baked, realtime, and custom Reflection Probes. HDRP multiplies the Reflection Probe data by this value. |


| **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. |
| **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. |
| **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. |
| **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. |
| **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. |

## Details

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.Rendering;

namespace UnityEditor.Rendering.HighDefinition
{
[CanEditMultipleObjects]
[VolumeComponentEditor(typeof(IndirectLightingController))]
class IndirectLightingControllerEditor : VolumeComponentEditor
{
SerializedDataParameter m_IndirectDiffuseIntensity;
SerializedDataParameter m_IndirectSpecularIntensity;
SerializedDataParameter m_IndirectDiffuseLightingMultiplier;
SerializedDataParameter m_IndirectDiffuseLightingLayers;

SerializedDataParameter m_ReflectionLightingMultiplier;
SerializedDataParameter m_ReflectionLightingLayers;

SerializedDataParameter m_ReflectionProbeIntensityMultiplier;

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

m_IndirectSpecularIntensity = Unpack(o.Find(x => x.indirectSpecularIntensity));
m_IndirectDiffuseIntensity = Unpack(o.Find(x => x.indirectDiffuseIntensity));
m_IndirectDiffuseLightingMultiplier = Unpack(o.Find(x => x.indirectDiffuseLightingMultiplier));
m_IndirectDiffuseLightingLayers = Unpack(o.Find(x => x.indirectDiffuseLightingLayers));

m_ReflectionLightingMultiplier = Unpack(o.Find(x => x.reflectionLightingMultiplier));
m_ReflectionLightingLayers = Unpack(o.Find(x => x.reflectionLightingLayers));

m_ReflectionProbeIntensityMultiplier = Unpack(o.Find(x => x.reflectionProbeIntensityMultiplier));
}

public override void OnInspectorGUI()
{
PropertyField(m_IndirectDiffuseIntensity, EditorGUIUtility.TrTextContent("Indirect Diffuse Intensity", "Sets the multiplier for baked diffuse lighting."));
PropertyField(m_IndirectSpecularIntensity, EditorGUIUtility.TrTextContent("Indirect Specular Intensity", "Sets the multiplier for reflected specular lighting."));
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."));
GUI.enabled = HDUtils.hdrpSettings.supportLightLayers;
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."));
GUI.enabled = true;

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."));
GUI.enabled = HDUtils.hdrpSettings.supportLightLayers;
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."));
GUI.enabled = true;

PropertyField(m_ReflectionProbeIntensityMultiplier, EditorGUIUtility.TrTextContent("Reflection/Planar Probe Intensity Multiplier", "Sets the intensity multiplier for Reflection/Planar Probes."));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;

namespace UnityEngine.Rendering.HighDefinition
{
Expand All @@ -8,9 +9,54 @@ namespace UnityEngine.Rendering.HighDefinition
[Serializable, VolumeComponentMenu("Lighting/Indirect Lighting Controller")]
public class IndirectLightingController : VolumeComponent
{
/// <summary>Indirect specular intensity multiplier, between 0 and 1</summary>
public MinFloatParameter indirectSpecularIntensity = new MinFloatParameter(1.0f, 0.0f);
/// <summary>Indirect diffuse intensity multiplier, between 0 and 1</summary>
public MinFloatParameter indirectDiffuseIntensity = new MinFloatParameter(1.0f, 0.0f);
[UnityEngine.Serialization.FormerlySerializedAs("indirectDiffuseIntensity")]
/// <summary>Indirect diffuse lighting multiplier, between 0 and 1</summary>
public MinFloatParameter indirectDiffuseLightingMultiplier = new MinFloatParameter(1.0f, 0.0f);
/// Controls which layer will be affected by the indirect diffuse lighting multiplier
public LightLayerEnumParameter indirectDiffuseLightingLayers = new LightLayerEnumParameter(LightLayerEnum.LightLayerDefault);

/// <summary>Reflection lighting multiplier, between 0 and 1</summary>
public MinFloatParameter reflectionLightingMultiplier = new MinFloatParameter(1.0f, 0.0f);
/// Controls which layer will be affected by the reflection lighting multiplier
public LightLayerEnumParameter reflectionLightingLayers = new LightLayerEnumParameter(LightLayerEnum.LightLayerDefault);

[UnityEngine.Serialization.FormerlySerializedAs("indirectSpecularIntensity")]
/// <summary>Reflection probe intensity multiplier, between 0 and 1</summary>
public MinFloatParameter reflectionProbeIntensityMultiplier = new MinFloatParameter(1.0f, 0.0f);

/// <summary>
/// Returns a mask of reflection lighting layers as uint and handle the case of Everything as being 0xFF and not -1
/// </summary>
/// <returns></returns>
public uint GetReflectionLightingLayers()
{
int value = (int)reflectionLightingLayers.GetValue<LightLayerEnum>();
return value < 0 ? (uint)LightLayerEnum.Everything : (uint)value;
}

/// <summary>
/// Returns a mask of indirect diffuse lighting layers as uint and handle the case of Everything as being 0xFF and not -1
/// </summary>
/// <returns></returns>
public uint GetIndirectDiffuseLightingLayers()
{
int value = (int)indirectDiffuseLightingLayers.GetValue<LightLayerEnum>();
return value < 0 ? (uint)LightLayerEnum.Everything : (uint)value;
}

/// <summary>
/// Sky Ambient Mode volume parameter.
/// </summary>
[Serializable, DebuggerDisplay(k_DebuggerDisplay)]
public sealed class LightLayerEnumParameter : VolumeParameter<LightLayerEnum>
{
/// <summary>
/// Light Layer Enum parameterconstructor.
/// </summary>
/// <param name="value">Light Layer Enum parameter.</param>
/// <param name="overrideState">Initial override value.</param>
public LightLayerEnumParameter(LightLayerEnum value, bool overrideState = false)
: base(value, overrideState) { }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1905,7 +1905,7 @@ internal bool GetEnvLightData(CommandBuffer cmd, HDCamera hdCamera, in Processed
envLightData.lightLayers = hdCamera.frameSettings.IsEnabled(FrameSettingsField.LightLayers) ? probe.lightLayersAsUInt : uint.MaxValue;
envLightData.influenceShapeType = influence.envShape;
envLightData.weight = processedProbe.weight;
envLightData.multiplier = probe.multiplier * m_indirectLightingController.indirectSpecularIntensity.value;
envLightData.multiplier = probe.multiplier * m_indirectLightingController.reflectionProbeIntensityMultiplier.value;
envLightData.rangeCompressionFactorCompensation = Mathf.Max(probe.rangeCompressionFactor, 1e-6f);
envLightData.influenceExtents = influence.extents;
switch (influence.envShape)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,9 @@ void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BS
);

// Apply control from the indirect lighting volume settings (Remember there is no emissive here at this step)
builtinDataProbeVolumes.bakeDiffuseLighting *= _IndirectLightingMultiplier.x;
builtinDataProbeVolumes.backBakeDiffuseLighting *= _IndirectLightingMultiplier.x;
float indirectDiffuseMultiplier = GetIndirectDiffuseMultiplier(builtinData.renderingLayers);
builtinDataProbeVolumes.bakeDiffuseLighting *= indirectDiffuseMultiplier;
builtinDataProbeVolumes.backBakeDiffuseLighting *= indirectDiffuseMultiplier;

#ifdef MODIFY_BAKED_DIFFUSE_LIGHTING
#ifdef DEBUG_DISPLAY
Expand Down Expand Up @@ -538,14 +539,19 @@ void LightLoop( float3 V, PositionInputs posInput, PreLightData preLightData, BS
BuiltinData builtInDataSSGI;
ZERO_INITIALIZE(BuiltinData, builtInDataSSGI);
builtInDataSSGI.bakeDiffuseLighting = LOAD_TEXTURE2D_X(_IndirectDiffuseTexture, posInput.positionSS).xyz * GetInverseCurrentExposureMultiplier();
builtInDataSSGI.bakeDiffuseLighting *= _IndirectLightingMultiplier.x;
float indirectDiffuseMultiplier = GetIndirectDiffuseMultiplier(builtinData.renderingLayers);
builtInDataSSGI.bakeDiffuseLighting *= indirectDiffuseMultiplier;
ModifyBakedDiffuseLighting(V, posInput, preLightData, bsdfData, builtInDataSSGI);
builtinData.bakeDiffuseLighting += builtInDataSSGI.bakeDiffuseLighting;
}
#endif

ApplyDebugToLighting(context, builtinData, aggregateLighting);

// Note: We can't apply the IndirectDiffuseMultiplier here as with GBuffer, Emissive is part of the bakeDiffuseLighting.
// so IndirectDiffuseMultiplier is apply in PostInitBuiltinData or related location (like for probe volume)
aggregateLighting.indirect.specularReflected *= GetIndirectSpecularMultiplier(builtinData.renderingLayers);

// Also Apply indiret diffuse (GI)
// PostEvaluateBSDF will perform any operation wanted by the material and sum everything into diffuseLighting and specularLighting
PostEvaluateBSDF( context, V, posInput, preLightData, bsdfData, builtinData, aggregateLighting, lightLoopOutput);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ void PostInitBuiltinData( float3 V, PositionInputs posInput, SurfaceData surfa
// color in case of lit deferred for example and avoid material to have to deal with it

// Note: We only apply indirect multiplier for Material pass mode, for lightloop mode, the multiplier will be apply in lightloop
builtinData.bakeDiffuseLighting *= _IndirectLightingMultiplier.x;
builtinData.backBakeDiffuseLighting *= _IndirectLightingMultiplier.x;
float multiplier = GetIndirectDiffuseMultiplier(builtinData.renderingLayers);
builtinData.bakeDiffuseLighting *= multiplier;
builtinData.backBakeDiffuseLighting *= multiplier;
#endif

#ifdef MODIFY_BAKED_DIFFUSE_LIGHTING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,12 @@ void UpdateShaderVariablesGlobalCB(HDCamera hdCamera, CommandBuffer cmd)
ScreenSpaceRefraction ssRefraction = hdCamera.volumeStack.GetComponent<ScreenSpaceRefraction>();
m_ShaderVariablesGlobalCB._SSRefractionInvScreenWeightDistance = 1.0f / ssRefraction.screenFadeDistance.value;

m_ShaderVariablesGlobalCB._IndirectLightingMultiplier = new Vector4(hdCamera.volumeStack.GetComponent<IndirectLightingController>().indirectDiffuseIntensity.value, 0, 0, 0);
IndirectLightingController indirectLightingController = hdCamera.volumeStack.GetComponent<IndirectLightingController>();
m_ShaderVariablesGlobalCB._IndirectDiffuseLightingMultiplier = indirectLightingController.indirectDiffuseLightingMultiplier.value;
m_ShaderVariablesGlobalCB._IndirectDiffuseLightingLayers = hdCamera.frameSettings.IsEnabled(FrameSettingsField.LightLayers) ? indirectLightingController.GetIndirectDiffuseLightingLayers() : uint.MaxValue;
m_ShaderVariablesGlobalCB._ReflectionLightingMultiplier = indirectLightingController.reflectionLightingMultiplier.value;
m_ShaderVariablesGlobalCB._ReflectionLightingLayers = hdCamera.frameSettings.IsEnabled(FrameSettingsField.LightLayers) ? indirectLightingController.GetReflectionLightingLayers() : uint.MaxValue;

m_ShaderVariablesGlobalCB._OffScreenRendering = 0;
m_ShaderVariablesGlobalCB._OffScreenDownsampleFactor = 1;
m_ShaderVariablesGlobalCB._ReplaceDiffuseForIndirect = hdCamera.frameSettings.IsEnabled(FrameSettingsField.ReplaceDiffuseForIndirect) ? 1.0f : 0.0f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,4 @@ void INDIRECT_DIFFUSE_INTEGRATION_UPSCALE(uint3 dispatchThreadId : SV_DispatchTh
_UpscaledIndirectDiffuseTextureRW[COORD_TEXTURE2D_X(targetCoord)] = float4(resultSum.xyz / resultSum.w, 1.0);
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,17 @@ float GetInversePreviousExposureMultiplier()
return rcp(exposure + (exposure == 0.0)); // zero-div guard
}

// Helper function for indirect control volume
float GetIndirectDiffuseMultiplier(uint renderingLayers)
{
return (_IndirectDiffuseLightingLayers & renderingLayers) ? _IndirectDiffuseLightingMultiplier : 1.0f;
}

float GetIndirectSpecularMultiplier(uint renderingLayers)
{
return (_ReflectionLightingLayers & renderingLayers) ? _ReflectionLightingMultiplier : 1.0f;
}

// Functions to clamp UVs to use when RTHandle system is used.

float2 ClampAndScaleUV(float2 UV, float2 texelSize, float numberOfTexels)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ unsafe struct ShaderVariablesGlobal
public float _ReplaceDiffuseForIndirect;

public Vector4 _AmbientOcclusionParam; // xyz occlusion color, w directLightStrenght
public Vector4 _IndirectLightingMultiplier; // .x indirect diffuse multiplier (use with indirect lighting volume controler)

public float _IndirectDiffuseLightingMultiplier;
public uint _IndirectDiffuseLightingLayers;
public float _ReflectionLightingMultiplier;
public uint _ReflectionLightingLayers;

public float _MicroShadowOpacity;
public uint _EnableProbeVolumes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ GLOBAL_CBUFFER_START(ShaderVariablesGlobal, b0)
float _ContactShadowOpacity;
float _ReplaceDiffuseForIndirect;
float4 _AmbientOcclusionParam;
float4 _IndirectLightingMultiplier;
float _IndirectDiffuseLightingMultiplier;
uint _IndirectDiffuseLightingLayers;
float _ReflectionLightingMultiplier;
uint _ReflectionLightingLayers;
float _MicroShadowOpacity;
uint _EnableProbeVolumes;
uint _ProbeVolumeCount;
Expand Down