浏览代码

Added Sky Lighting Override through layers specific interpolation volumes.

/feature-ReflectionProbeFit
Julien Ignace 7 年前
当前提交
71b6b5f0
共有 9 个文件被更改,包括 82 次插入25 次删除
  1. 3
      ScriptableRenderPipeline/Core/CoreRP/Volume/VolumeManager.cs
  2. 18
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDAdditionalCameraData.cs
  3. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDRenderPipelineInspector.Styles.cs
  4. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDRenderPipelineInspector.cs
  5. 17
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs
  6. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipelineAsset.asset
  7. 1
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/GlobalLightLoopSettings.cs
  8. 58
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/SkyManager.cs
  9. 3
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/SkyUpdateContext.cs

3
ScriptableRenderPipeline/Core/CoreRP/Volume/VolumeManager.cs


foreach (var volume in kvp.Value)
{
if (!volume.enabled)
continue;
T component;
if (volume.TryGet(out component) && component.active)
return true;

18
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDAdditionalCameraData.cs


};
public RenderingPath renderingPath;
[Tooltip("Layer Mask used for the volume interpolation for this camera.")]
public LayerMask volumeLayerMask = -1;
public FrameSettings serializedFrameSettings = new FrameSettings(); // Serialize frameSettings
public FrameSettings serializedFrameSettings = new FrameSettings(); // Serialize frameSettings
// Not serialized, not visible
FrameSettings m_FrameSettings = new FrameSettings();

}
bool isRegisterDebug = false;
Camera m_camera;
string m_CameraRegisterName;
bool m_IsDebugRegistered = false;
Camera m_camera;
string m_CameraRegisterName;
if (!isRegisterDebug)
if (!m_IsDebugRegistered)
isRegisterDebug = true;
m_IsDebugRegistered = true;
if (isRegisterDebug)
if (m_IsDebugRegistered)
isRegisterDebug = false;
m_IsDebugRegistered = false;
}
}

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDRenderPipelineInspector.Styles.cs


public readonly GUIContent reflectionCubemapSize = new GUIContent("Reflection Cubemap Size");
public readonly GUIContent reflectionCacheCompressed = new GUIContent("Compress Reflection Probe Cache");
public readonly GUIContent skyReflectionSize = new GUIContent("Sky Reflection Size");
public readonly GUIContent skyLightingOverride = new GUIContent("Sky Lighting Override Mask", "This layer mask will define in which layers the sky system will look for sky settings volumes for lighting override.");
public readonly GUIContent defaultFrameSettings = new GUIContent("Default Frame Settings");

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDRenderPipelineInspector.cs


// Commented out until we have proper realtime BC6H compression
//SerializedProperty m_ReflectionCacheCompressed;
SerializedProperty m_SkyReflectionSize;
SerializedProperty m_SkyLightingOverrideLayerMask;
// FrameSettings
// LightLoop settings

// Commented out until we have proper realtime BC6H compression
//m_ReflectionCacheCompressed = properties.Find(x => x.globalFrameSettings.lightLoopSettings.reflectionCacheCompressed);
m_SkyReflectionSize = properties.Find(x => x.renderPipelineSettings.lightLoopSettings.skyReflectionSize);
m_SkyLightingOverrideLayerMask = properties.Find(x => x.renderPipelineSettings.lightLoopSettings.skyLightingOverrideLayerMask);
// FrameSettings
// LightLoop settings

// Commented out until we have proper realtime BC6H compression
//EditorGUILayout.PropertyField(m_ReflectionCacheCompressed, s_Styles.reflectionCacheCompressed);
EditorGUILayout.PropertyField(m_SkyReflectionSize, s_Styles.skyReflectionSize);
EditorGUILayout.PropertyField(m_SkyLightingOverrideLayerMask, s_Styles.skyLightingOverride);
if (EditorGUI.EndChangeCheck())
{
HackSetDirty(hdAsset); // Repaint

17
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


using (new ProfilingSample(cmd, "Volume Update", GetSampler(CustomSamplerId.VolumeUpdate)))
{
// TODO: Transform & layer should be configurable per camera
VolumeManager.instance.Update(camera.transform, -1);
LayerMask layerMask = -1;
if(additionalCameraData != null)
{
layerMask = additionalCameraData.volumeLayerMask;
}
else
{
// Temporary hack. For scene view, by default, we don't want to have the lighting override layers in the current sky.
// This is arbitrary and should be editable in the scene view somehow.
if(camera.cameraType == CameraType.SceneView)
{
layerMask = (-1 & ~m_Asset.renderPipelineSettings.lightLoopSettings.skyLightingOverrideLayerMask);
}
}
VolumeManager.instance.Update(camera.transform, layerMask);
}
}

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipelineAsset.asset


reflectionCubemapSize: 128
reflectionCacheCompressed: 0
skyReflectionSize: 256
skyLightingOverrideLayerMask:
serializedVersion: 2
m_Bits: 256
shadowInitParams:
shadowAtlasWidth: 4096
shadowAtlasHeight: 4096

1
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/LightLoop/GlobalLightLoopSettings.cs


public int reflectionCubemapSize = 128;
public bool reflectionCacheCompressed = false;
public SkyResolution skyReflectionSize = SkyResolution.SkyResolution256;
public LayerMask skyLightingOverrideLayerMask = 0;
}
}

58
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/SkyManager.cs


Material m_BlitCubemapMaterial;
Material m_OpaqueAtmScatteringMaterial;
int m_LastFrameUpdated = -1;
bool m_UpdateRequired = false;
bool m_NeedUpdateRealtimeEnv = false;
bool m_NeedUpdateBakingSky = false;

SkyRenderingContext m_BakingSkyRenderingContext;
SkyRenderingContext m_SkyRenderingContext;
// This interpolation volume stack is used to interpolate the lighting override separately from the visual sky.
// If a sky setting is present in this volume then it will be used for lighting override.
VolumeStack m_LightingOverrideVolumeStack;
LayerMask m_LightingOverrideLayerMask = -1;
void UpdateCurrentSkySettings()
SkySettings GetSkySetting(VolumeStack stack)
SkySettings newSkySettings = null;
var visualEnv = VolumeManager.instance.stack.GetComponent<VisualEnvironment>();
SkySettings result;
var visualEnv = stack.GetComponent<VisualEnvironment>();
newSkySettings = VolumeManager.instance.stack.GetComponent<HDRISky>();
result = stack.GetComponent<HDRISky>();
newSkySettings = VolumeManager.instance.stack.GetComponent<ProceduralSky>();
result = stack.GetComponent<ProceduralSky>();
default:
result = null;
break;
m_VisualSky.skySettings = newSkySettings;
return result;
}
void UpdateCurrentSkySettings(HDCamera camera)
{
m_VisualSky.skySettings = GetSkySetting(VolumeManager.instance.stack);
m_LightingOverrideSky.skySettings = null;
// Update needs to happen before testing if the component is active other internal data structure are not properly updated yet.
VolumeManager.instance.Update(m_LightingOverrideVolumeStack, camera.camera.transform, m_LightingOverrideLayerMask);
if(VolumeManager.instance.IsComponentActiveInMask<VisualEnvironment>(m_LightingOverrideLayerMask))
{
SkySettings newSkyOverride = GetSkySetting(m_LightingOverrideVolumeStack);
if(m_LightingOverrideSky.skySettings != null && newSkyOverride == null)
{
// When we switch from override to no override, we need to make sure that the visual sky will actually be properly re-rendered.
// Resetting the visual sky hash will ensure that.
m_VisualSky.skyParametersHash = -1;
}
m_LightingOverrideSky.skySettings = newSkyOverride;
}
else
{
m_LightingOverrideSky.skySettings = null;
}
}
// Sets the global MIP-mapped cubemap '_SkyTexture' in the shader.

m_StandardSkyboxMaterial = CoreUtils.CreateEngineMaterial(hdAsset.renderPipelineResources.skyboxCubemap);
m_BlitCubemapMaterial = CoreUtils.CreateEngineMaterial(hdAsset.renderPipelineResources.blitCubemap);
m_OpaqueAtmScatteringMaterial = CoreUtils.CreateEngineMaterial(hdAsset.renderPipelineResources.opaqueAtmosphericScattering);
m_LightingOverrideVolumeStack = VolumeManager.instance.CreateStack();
m_LightingOverrideLayerMask = hdAsset.renderPipelineSettings.lightLoopSettings.skyLightingOverrideLayerMask;
}
public void Cleanup()

public bool IsSkyValid()
{
return m_VisualSky.IsValid();
return m_VisualSky.IsValid() || m_LightingOverrideSky.IsValid();
}

if (Shader.GetGlobalTexture(HDShaderIDs._SkyTexture) == null)
cmd.SetGlobalTexture(HDShaderIDs._SkyTexture, CoreUtils.magentaCubeTexture);
if (m_LastFrameUpdated == Time.frameCount)
return;
// This is done here because we need to wait for one frame that the command buffer is executed before using the resulting textures.
if (m_NeedUpdateBakingSky)
{

if (m_NeedUpdateRealtimeEnv)
{
// TODO: Here we need to do that in case we are using real time GI. Unfortunately we don't have a way to check that atm.
// Moreover we still need Async readback from texture in command buffers first.
UpdateCurrentSkySettings();
UpdateCurrentSkySettings(camera);
m_NeedUpdateBakingSky = m_BakingSkyRenderingContext.UpdateEnvironment(m_BakingSky, camera, sunLight, m_UpdateRequired, cmd);
SkyUpdateContext currentSky = m_LightingOverrideSky.IsValid() ? m_LightingOverrideSky : m_VisualSky;

m_LastFrameUpdated = Time.frameCount;
SetGlobalSkyTexture(cmd);
if (IsSkyValid())

3
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/SkyUpdateContext.cs


public bool IsValid()
{
return m_Renderer != null && m_Renderer.IsValid();
// We need to check m_SkySettings in addition to the renderer because it can be "nulled" when destroying the volume containing the settings (as it's a ScriptableObject) without the context knowing about it.
return m_Renderer != null && m_Renderer.IsValid() && m_SkySettings != null;
}
public void Cleanup()

正在加载...
取消
保存