浏览代码

Cleanup HDRI sky code

/main
Antoine Lelievre 6 年前
当前提交
d33e5edc
共有 7 个文件被更改,包括 12 次插入41 次删除
  1. 14
      com.unity.render-pipelines.high-definition/HDRP/Editor/Sky/HDRISky/HDRISkyEditor.cs
  2. 1
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs
  3. 6
      com.unity.render-pipelines.high-definition/HDRP/Sky/HDRISky/HDRISky.shader
  4. 20
      com.unity.render-pipelines.high-definition/HDRP/Sky/HDRISky/HDRISkyRenderer.cs
  5. 2
      com.unity.render-pipelines.high-definition/HDRP/Sky/SkyRenderer.cs
  6. 6
      com.unity.render-pipelines.high-definition/HDRP/Sky/SkyRenderingContext.cs
  7. 4
      com.unity.render-pipelines.high-definition/HDRP/Sky/SkySettings.cs

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


public override void OnInspectorGUI()
{
EditorGUI.BeginChangeCheck();
PropertyField(m_hdriSky);
if (EditorGUI.EndChangeCheck())
GetUpperHemisphereLuxValue();
PropertyField(m_hdriSky);
EditorGUILayout.Space();
PropertyField(m_IntensityMode);
EditorGUILayout.Space();
PropertyField(m_IntensityMode);
if (EditorGUI.EndChangeCheck())
GetUpperHemisphereLuxValue();
if (m_IntensityMode.value.enumValueIndex == (int)SkyIntensityMode.Lux)
{

1
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs


public static readonly int _Cubemap = Shader.PropertyToID("_Cubemap");
public static readonly int _InvOmegaP = Shader.PropertyToID("_InvOmegaP");
public static readonly int _SkyParam = Shader.PropertyToID("_SkyParam");
public static readonly int _SkyIntensity = Shader.PropertyToID("_SkyIntensity");
public static readonly int _PixelCoordToViewDirWS = Shader.PropertyToID("_PixelCoordToViewDirWS");
public static readonly int _Size = Shader.PropertyToID("_Size");

6
com.unity.render-pipelines.high-definition/HDRP/Sky/HDRISky/HDRISky.shader


TEXTURECUBE(_Cubemap);
SAMPLER(sampler_Cubemap);
TEXTURE2D(_SkyIntensity);
SAMPLER(sampler_SkyIntensity);
float4 _SkyParam; // x exposure, y multiplier, z rotation, w lux
float4x4 _PixelCoordToViewDirWS; // Actually just 3x3, but Unity can only set 4x4

float3 rotDirY = float3(sinPhi, 0, cosPhi);
dir = float3(dot(rotDirX, dir), dir.y, dot(rotDirY, dir));
float intensity = _SkyParam.w / SAMPLE_TEXTURE2D_LOD(_SkyIntensity, sampler_SkyIntensity, float2(0.5, 0.5), 0).x;
float3 skyColor = ClampToFloat16Max(SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir, 0).rgb * exp2(_SkyParam.x) * _SkyParam.y * intensity);
float3 skyColor = ClampToFloat16Max(SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir, 0).rgb * exp2(_SkyParam.x) * _SkyParam.y);
return float4(skyColor, 1.0);
}

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


}
}
public override void UpdateSky(BuiltinSkyParameters builtinParams)
{
using (new ProfilingSample(builtinParams.commandBuffer, "Get hdri skybox intensity"))
{
// if (m_HdriSkyParams.updateHDRISkyIntensity)
}
}
float lux = (m_HdriSkyParams.skyIntensityMode == SkyIntensityMode.Lux) ? m_HdriSkyParams.lux.value : 1;
float multiplier = (m_HdriSkyParams.skyIntensityMode == SkyIntensityMode.Exposure) ? m_HdriSkyParams.multiplier.value : 1;
float luxMultiplier = m_HdriSkyParams.desiredLuxValue.value / m_HdriSkyParams.upperHemisphereLuxValue.value;
float multiplier = (m_HdriSkyParams.skyIntensityMode == SkyIntensityMode.Exposure) ? m_HdriSkyParams.multiplier.value : luxMultiplier;
m_SkyHDRIMaterial.SetVector(HDShaderIDs._SkyParam, new Vector4(exposure, multiplier, -m_HdriSkyParams.rotation, lux)); // -rotation to match Legacy...
m_SkyHDRIMaterial.SetVector(HDShaderIDs._SkyParam, new Vector4(exposure, multiplier, -m_HdriSkyParams.rotation, 0.0f)); // -rotation to match Legacy...
// Bind a white texture if the intensity mode isn't lux so we sample an intensity of 1
// if (m_HdriSkyParams.skyIntensityMode == SkyIntensityMode.Lux)
// m_SkyHDRIMaterial.SetTexture(HDShaderIDs._SkyIntensity, m_IntensityTexture);
// else
m_SkyHDRIMaterial.SetTexture(HDShaderIDs._SkyIntensity, Texture2D.whiteTexture);
// This matrix needs to be updated at the draw call frequency.
m_PropertyBlock.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, builtinParams.pixelCoordToViewDirMatrix);

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


public abstract void RenderSky(BuiltinSkyParameters builtinParams, bool renderForCubemap, bool renderSunDisk);
public abstract bool IsValid();
public virtual void UpdateSky(BuiltinSkyParameters builtinParams) {}
protected float GetExposure(SkySettings skySettings, DebugDisplaySettings debugSettings)
{
float debugExposure = 0.0f;

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


m_BuiltinParameters.colorBuffer = m_SkyboxCubemapRT;
m_BuiltinParameters.depthBuffer = null;
m_BuiltinParameters.hdCamera = null;
skyContext.renderer.UpdateSky(m_BuiltinParameters);
CoreUtils.SetRenderTarget(m_BuiltinParameters.commandBuffer, m_SkyboxCubemapRT, ClearFlag.None, 0, (CubemapFace)i);
skyContext.renderer.RenderSky(m_BuiltinParameters, true, skyContext.skySettings.includeSunInBaking);

{
using (new ProfilingSample(cmd, "Sky Environment Pass"))
{
skyContext.skySettings.updateHDRISkyIntensity.value = true;
using (new ProfilingSample(cmd, "Update Env: Generate Lighting Cubemap"))
{
RenderSkyToCubemap(skyContext);

m_BuiltinParameters.depthBuffer = depthBuffer;
m_BuiltinParameters.hdCamera = hdCamera;
m_BuiltinParameters.debugSettings = debugSettings;
skyContext.renderer.UpdateSky(m_BuiltinParameters);
skyContext.renderer.SetRenderTargets(m_BuiltinParameters);
// When rendering the visual sky for reflection probes, we need to remove the sun disk if skySettings.includeSunInBaking is false.

4
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);
[HideInInspector]
public BoolParameter updateHDRISkyIntensity = new BoolParameter(false);
[Tooltip("If set to true, the sun disk will be used in baked lighting (ambient and reflection probes).")]
public BoolParameter includeSunInBaking = new BoolParameter(false);

hash = hash * 23 + rotation.GetHashCode();
hash = hash * 23 + exposure.GetHashCode();
hash = hash * 23 + multiplier.GetHashCode();
hash = hash * 23 + lux.GetHashCode();
hash = hash * 23 + desiredLuxValue.GetHashCode();
// TODO: Fixme once we switch to .Net 4.6+
//>>>

正在加载...
取消
保存