浏览代码

Added an explicit option in SkySettings (only supported for now in Procedural Sky) to enable or disable the rendering of the sun disk when baking light and reflection probes.

This allows us to fix some bugs and discrepancy with the current framework.
/main
Julien Ignace 6 年前
当前提交
5b782e23
共有 9 个文件被更改,包括 59 次插入28 次删除
  1. 4
      com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/HDRISky/HDRISkyEditor.cs
  2. 4
      com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/ProceduralSky/ProceduralSkyEditor.cs
  3. 38
      com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/SkySettingsEditor.cs
  4. 2
      com.unity.render-pipelines.high-definition/HDRP/Sky/HDRISky/HDRISkyRenderer.cs
  5. 25
      com.unity.render-pipelines.high-definition/HDRP/Sky/ProceduralSky/ProceduralSkyRenderer.cs
  6. 4
      com.unity.render-pipelines.high-definition/HDRP/Sky/SkyManager.cs
  7. 2
      com.unity.render-pipelines.high-definition/HDRP/Sky/SkyRenderer.cs
  8. 5
      com.unity.render-pipelines.high-definition/HDRP/Sky/SkyRenderingContext.cs
  9. 3
      com.unity.render-pipelines.high-definition/HDRP/Sky/SkySettings.cs

4
com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/HDRISky/HDRISkyEditor.cs


EditorGUILayout.Space();
base.CommonSkySettingsGUI();
uint uiElements = 0xFFFFFFFF;
uiElements &= ~(uint)(SkySettingsUIElement.IncludeSunInBaking);
base.CommonSkySettingsGUI(uiElements);
}
}
}

4
com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/ProceduralSky/ProceduralSkyEditor.cs


EditorGUILayout.Space();
base.CommonSkySettingsGUI(false);
uint uiElements = 0xFFFFFFFF;
uiElements &= ~(uint)(SkySettingsUIElement.Rotation);
base.CommonSkySettingsGUI(uiElements);
}
}
}

38
com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/SkySettingsEditor.cs


{
public abstract class SkySettingsEditor : VolumeComponentEditor
{
[System.Flags]
protected enum SkySettingsUIElement
{
Exposure = 1 << 0,
Multiplier = 1 << 1,
Rotation = 1 << 2,
UpdateMode = 1 << 3,
IncludeSunInBaking = 1 << 4
}
SerializedDataParameter m_IncludeSunInBaking;
public override void OnEnable()
{

m_SkyRotation = Unpack(o.Find(x => x.rotation));
m_EnvUpdateMode = Unpack(o.Find(x => x.updateMode));
m_EnvUpdatePeriod = Unpack(o.Find(x => x.updatePeriod));
m_IncludeSunInBaking = Unpack(o.Find(x => x.includeSunInBaking));
protected void CommonSkySettingsGUI(bool enableRotation = true)
protected void CommonSkySettingsGUI(uint uiElementMask = 0xFFFFFFFF)
PropertyField(m_SkyExposure);
PropertyField(m_SkyMultiplier);
if (enableRotation)
if ((uiElementMask & (uint)SkySettingsUIElement.Exposure) != 0)
PropertyField(m_SkyExposure);
if ((uiElementMask & (uint)SkySettingsUIElement.Multiplier) != 0)
PropertyField(m_SkyMultiplier);
if ((uiElementMask & (uint)SkySettingsUIElement.Rotation) != 0)
PropertyField(m_EnvUpdateMode);
if (!m_EnvUpdateMode.value.hasMultipleDifferentValues && m_EnvUpdateMode.value.intValue == (int)EnvironementUpdateMode.Realtime)
if ((uiElementMask & (uint)SkySettingsUIElement.UpdateMode) != 0)
EditorGUI.indentLevel++;
PropertyField(m_EnvUpdatePeriod);
EditorGUI.indentLevel--;
PropertyField(m_EnvUpdateMode);
if (!m_EnvUpdateMode.value.hasMultipleDifferentValues && m_EnvUpdateMode.value.intValue == (int)EnvironementUpdateMode.Realtime)
{
EditorGUI.indentLevel++;
PropertyField(m_EnvUpdatePeriod);
EditorGUI.indentLevel--;
}
if ((uiElementMask & (uint)SkySettingsUIElement.IncludeSunInBaking) != 0)
PropertyField(m_IncludeSunInBaking);
}
}
}

2
com.unity.render-pipelines.high-definition/HDRP/Sky/HDRISky/HDRISkyRenderer.cs


}
}
public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderForCubemap)
public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderForCubemap, bool renderSunDisk)
{
m_SkyHDRIMaterial.SetTexture(HDShaderIDs._Cubemap, m_HdriSkyParams.hdriSky);
m_SkyHDRIMaterial.SetVector(HDShaderIDs._SkyParam, new Vector4(GetExposure(m_HdriSkyParams, builtinParams.debugSettings), m_HdriSkyParams.multiplier, -m_HdriSkyParams.rotation, 0.0f)); // -rotation to match Legacy...

25
com.unity.render-pipelines.high-definition/HDRP/Sky/ProceduralSky/ProceduralSkyRenderer.cs


}
}
public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderForCubemap)
public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderForCubemap, bool renderSunDisk)
// Default values when no sun is provided
float sunSize = 0.0f;
sunSize = m_ProceduralSkyParams.sunSize;
m_ProceduralSkyMaterial.SetVector(HDShaderIDs._SkyParam, new Vector4(GetExposure(m_ProceduralSkyParams, builtinParams.debugSettings), m_ProceduralSkyParams.multiplier, 0.0f, 0.0f));
m_ProceduralSkyMaterial.SetFloat(_SunSizeParam, m_ProceduralSkyParams.sunSize);
m_ProceduralSkyMaterial.SetFloat(_SunSizeConvergenceParam, m_ProceduralSkyParams.sunSizeConvergence);
m_ProceduralSkyMaterial.SetFloat(_AtmoshpereThicknessParam, m_ProceduralSkyParams.atmosphereThickness);
m_ProceduralSkyMaterial.SetColor(_SkyTintParam, m_ProceduralSkyParams.skyTint);
m_ProceduralSkyMaterial.SetColor(_GroundColorParam, m_ProceduralSkyParams.groundColor);
m_ProceduralSkyMaterial.SetColor(_SunColorParam, sunColor);
m_ProceduralSkyMaterial.SetVector(_SunDirectionParam, sunDirection);
if (!renderSunDisk)
sunSize = 0.0f;
// This matrix needs to be updated at the draw call frequency.
m_PropertyBlock.SetVector(HDShaderIDs._SkyParam, new Vector4(GetExposure(m_ProceduralSkyParams, builtinParams.debugSettings), m_ProceduralSkyParams.multiplier, 0.0f, 0.0f));
m_PropertyBlock.SetFloat(_SunSizeParam, sunSize);
m_PropertyBlock.SetFloat(_SunSizeConvergenceParam, m_ProceduralSkyParams.sunSizeConvergence);
m_PropertyBlock.SetFloat(_AtmoshpereThicknessParam, m_ProceduralSkyParams.atmosphereThickness);
m_PropertyBlock.SetColor(_SkyTintParam, m_ProceduralSkyParams.skyTint);
m_PropertyBlock.SetColor(_GroundColorParam, m_ProceduralSkyParams.groundColor);
m_PropertyBlock.SetColor(_SunColorParam, sunColor);
m_PropertyBlock.SetVector(_SunDirectionParam, sunDirection);
m_PropertyBlock.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, builtinParams.pixelCoordToViewDirMatrix);
CoreUtils.DrawFullScreen(builtinParams.commandBuffer, m_ProceduralSkyMaterial, m_PropertyBlock, renderForCubemap ? 0 : 1);

4
com.unity.render-pipelines.high-definition/HDRP/Sky/SkyManager.cs


m_NeedUpdateRealtimeEnv = false;
}
// For the baking sky, we don't want to take the sun into account because we usually won't include it (this would cause double highlight in the reflection for example).
// So we pass null so that's it doesn't affect the hash and the rendering.
m_NeedUpdateBakingSky = m_BakingSkyRenderingContext.UpdateEnvironment(m_BakingSky, camera, null, m_UpdateRequired, cmd);
m_NeedUpdateBakingSky = m_BakingSkyRenderingContext.UpdateEnvironment(m_BakingSky, camera, sunLight, m_UpdateRequired, cmd);
SkyUpdateContext currentSky = m_LightingOverrideSky.IsValid() ? m_LightingOverrideSky : m_VisualSky;
m_NeedUpdateRealtimeEnv = m_SkyRenderingContext.UpdateEnvironment(currentSky, camera, sunLight, m_UpdateRequired, cmd);

2
com.unity.render-pipelines.high-definition/HDRP/Sky/SkyRenderer.cs


public abstract void Cleanup();
public abstract void SetRenderTargets(BuiltinSkyParameters builtinParams);
// renderForCubemap: When rendering into a cube map, no depth buffer is available so user has to make sure not to use depth testing or the depth texture.
public abstract void RenderSky(BuiltinSkyParameters builtinParams, bool renderForCubemap);
public abstract void RenderSky(BuiltinSkyParameters builtinParams, bool renderForCubemap, bool renderSunDisk);
public abstract bool IsValid();
protected float GetExposure(SkySettings skySettings, DebugDisplaySettings debugSettings)

5
com.unity.render-pipelines.high-definition/HDRP/Sky/SkyRenderingContext.cs


m_BuiltinParameters.hdCamera = null;
CoreUtils.SetRenderTarget(m_BuiltinParameters.commandBuffer, m_SkyboxCubemapRT, ClearFlag.None, 0, (CubemapFace)i);
skyContext.renderer.RenderSky(m_BuiltinParameters, true);
skyContext.renderer.RenderSky(m_BuiltinParameters, true, skyContext.skySettings.includeSunInBaking);
}
// Generate mipmap for our cubemap

m_BuiltinParameters.debugSettings = debugSettings;
skyContext.renderer.SetRenderTargets(m_BuiltinParameters);
skyContext.renderer.RenderSky(m_BuiltinParameters, false);
// When rendering the visual sky for reflection probes, we need to remove the sun disk if skySettings.includeSunInBaking is false.
skyContext.renderer.RenderSky(m_BuiltinParameters, false, hdCamera.camera.cameraType != CameraType.Reflection || skyContext.skySettings.includeSunInBaking);
}
}
}

3
com.unity.render-pipelines.high-definition/HDRP/Sky/SkySettings.cs


public EnvUpdateParameter updateMode = new EnvUpdateParameter(EnvironementUpdateMode.OnChanged);
[Tooltip("If environment update is set to realtime, period in seconds at which it is updated (0.0 means every frame).")]
public MinFloatParameter updatePeriod = new MinFloatParameter(0.0f, 0.0f);
[Tooltip("If set to true, the sun disk will be used in baked lighting (ambient and reflection probes).")]
public BoolParameter includeSunInBaking = new BoolParameter(false);
// Unused for now. In the future we might want to expose this option for very high range skies.
bool m_useMIS = false;

//<<<
hash = hash * 23 + updatePeriod.GetHashCode();
hash = hash * 23 + includeSunInBaking.GetHashCode();
return hash;
}
}

正在加载...
取消
保存