浏览代码

Moved resolution of sky rendering into global light loop settings in the HDRP asset (from the individual sky settings).

/feature-ReflectionProbeFit
Julien Ignace 7 年前
当前提交
978e07e4
共有 13 个文件被更改,包括 212 次插入193 次删除
  1. 1
      ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.Styles.cs
  2. 3
      ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
  3. 3
      ScriptableRenderPipeline/HDRenderPipeline/Editor/Sky/SkySettingsEditor.cs
  4. 75
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.asset
  5. 1
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/GlobalLightLoopSettings.cs
  6. 24
      ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs
  7. 2
      ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISky.cs
  8. 2
      ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSky.cs
  9. 87
      ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs
  10. 134
      ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyRenderingContext.cs
  11. 5
      ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettings.cs
  12. 57
      ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyUpdateContext.cs
  13. 11
      ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyUpdateContext.cs.meta

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


public readonly GUIContent pointCookieSize = new GUIContent("Point Cookie Size");
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 defaultFrameSettings = new GUIContent("Default Frame Settings");

3
ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs


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

m_ReflectionCubemapSize = properties.Find(x => x.renderPipelineSettings.lightLoopSettings.reflectionCubemapSize);
// 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);
// FrameSettings
// LightLoop settings

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

3
ScriptableRenderPipeline/HDRenderPipeline/Editor/Sky/SkySettingsEditor.cs


{
public abstract class SkySettingsEditor : VolumeComponentEditor
{
SerializedDataParameter m_SkyResolution;
SerializedDataParameter m_SkyExposure;
SerializedDataParameter m_SkyMultiplier;
SerializedDataParameter m_SkyRotation;

{
var o = new PropertyFetcher<SkySettings>(serializedObject);
m_SkyResolution = Unpack(o.Find(x => x.resolution));
m_SkyExposure = Unpack(o.Find(x => x.exposure));
m_SkyMultiplier = Unpack(o.Find(x => x.multiplier));
m_SkyRotation = Unpack(o.Find(x => x.rotation));

protected void CommonSkySettingsGUI()
{
PropertyField(m_SkyResolution);
PropertyField(m_SkyExposure);
PropertyField(m_SkyMultiplier);
PropertyField(m_SkyRotation);

75
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipelineAsset.asset


m_EditorClassIdentifier:
m_RenderPipelineResources: {fileID: 11400000, guid: 3ce144cff5783da45aa5d4fdc2da14b7,
type: 2}
defaultFrameSettings:
lightingSettings:
enableShadow: 1
enableSSR: 1
enableSSAO: 1
enableSSSAndTransmission: 1
diffuseGlobalDimmer: 1
specularGlobalDimmer: 1
renderSettings:
enableForwardRenderingOnly: 1
enableDepthPrepassWithDeferredRendering: 0
enableAlphaTestOnlyInDeferredPrepass: 0
enableTransparentPrePass: 1
enableMotionVectors: 1
enableDBuffer: 1
enableAtmosphericScattering: 1
enableRoughRefraction: 1
enableTransparentPostPass: 1
enableDistortion: 1
enablePostprocess: 1
enableStereo: 0
enableAsyncCompute: 0
enableOpaqueObjects: 1
enableTransparentObjects: 1
enableMSAA: 0
enableMaterialDisplayDebug: 0
enableShadowMask: 0
serializedFrameSettings:
enableShadow: 1
enableSSR: 1
enableSSAO: 1
enableSSSAndTransmission: 1
diffuseGlobalDimmer: 1
specularGlobalDimmer: 1
enableForwardRenderingOnly: 0
enableDepthPrepassWithDeferredRendering: 0
enableAlphaTestOnlyInDeferredPrepass: 0
enableTransparentPrePass: 1
enableMotionVectors: 1
enableObjectMotionVectors: 1
enableDBuffer: 1
enableAtmosphericScattering: 1
enableRoughRefraction: 1
enableTransparentPostPass: 1
enableDistortion: 1
enablePostprocess: 1
enableStereo: 0
enableAsyncCompute: 0
enableOpaqueObjects: 1
enableTransparentObjects: 1
enableMSAA: 0
enableShadowMask: 0
lightLoopSettings:
enableTileAndCluster: 1
enableComputeLightEvaluation: 1

enableBigTilePrepass: 1
isFptlEnabled: 1
m_globalFrameSettings: {fileID: 0}
m_sssSettings: {fileID: 0}
renderPipelineSettings:
supportShadowMask: 1
supportSSR: 1
supportSSAO: 1
supportSSSAndTransmission: 1
supportDBuffer: 0
supportMSAA: 0
supportAsyncCompute: 0
lightLoopSettings:
spotCookieSize: 128
cookieTexArraySize: 16
pointCookieSize: 512
cubeCookieTexArraySize: 16
reflectionProbeCacheSize: 128
reflectionCubemapSize: 128
reflectionCacheCompressed: 0
skyReflectionSize: 256
shadowInitParams:
shadowAtlasWidth: 4096
shadowAtlasHeight: 4096
sssSettings: {fileID: 0}
m_DefaultDiffuseMaterial: {fileID: 2100000, guid: 73c176f402d2c2f4d929aa5da7585d17,
type: 2}
m_DefaultShader: {fileID: 4800000, guid: 6e4ae4064600d784cac1e41a9e6f2e59, type: 3}

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


public int reflectionProbeCacheSize = 128;
public int reflectionCubemapSize = 128;
public bool reflectionCacheCompressed = false;
public SkyResolution skyReflectionSize = SkyResolution.SkyResolution256;
}
}

24
ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs


public int GetShadowAtlasCount()
{
return (int)m_ShadowMgr.GetShadowMapCount();
return (m_ShadowMgr == null) ? 0 : (int)m_ShadowMgr.GetShadowMapCount();
}
public void UpdateCullingParameters(ref ScriptableCullingParameters cullingParams)

if (GetEnvLightData(cmd, camera, probe))
{
GetEnvLightVolumeDataAndBound(probe, lightVolumeType, worldToView);
GetEnvLightVolumeDataAndBound(probe, lightVolumeType, worldToView);
// We make the light position camera-relative as late as possible in order
// to allow the preceding code to work with the absolute world space coordinates.
if (ShaderConfig.s_CameraRelativeRendering != 0)
{
// Caution: 'EnvLightData.positionWS' is camera-relative after this point.
int n = m_lightList.envLights.Count;
EnvLightData envLightData = m_lightList.envLights[n - 1];
envLightData.positionWS -= camPosWS;
m_lightList.envLights[n - 1] = envLightData;
// We make the light position camera-relative as late as possible in order
// to allow the preceding code to work with the absolute world space coordinates.
if (ShaderConfig.s_CameraRelativeRendering != 0)
{
// Caution: 'EnvLightData.positionWS' is camera-relative after this point.
int n = m_lightList.envLights.Count;
EnvLightData envLightData = m_lightList.envLights[n - 1];
envLightData.positionWS -= camPosWS;
m_lightList.envLights[n - 1] = envLightData;
}
}
}
}

2
ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISky.cs


[Tooltip("Cubemap used to render the sky.")]
public CubemapParameter skyHDRI = new CubemapParameter(null);
public override SkyRenderer GetRenderer()
public override SkyRenderer CreateRenderer()
{
return new HDRISkyRenderer(this);
}

2
ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSky.cs


public ColorParameter groundColor = new ColorParameter(new Color(0.369f, 0.349f, 0.341f, 1.0f));
public BoolParameter enableSunDisk = new BoolParameter(true);
public override SkyRenderer GetRenderer()
public override SkyRenderer CreateRenderer()
{
return new ProceduralSkyRenderer(this);
}

87
ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs


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

SkyRenderingContext m_VisualSky;
// This is optional and is used only to compute ambient probe and sky reflection for
SkyUpdateContext m_VisualSky = new SkyUpdateContext();
// This is optional and is used only to compute ambient probe and sky reflection
SkyRenderingContext m_LightingOverrideSky;
SkyUpdateContext m_LightingOverrideSky = new SkyUpdateContext();
SkyRenderingContext m_BakingSky;
SkyUpdateContext m_BakingSky = new SkyUpdateContext();
public Texture skyReflection
{
get
{
if (m_LightingOverrideSky.skySettings != null)
return m_LightingOverrideSky.reflectionTexture;
else
return m_VisualSky.reflectionTexture;
}
}
// The sky rendering contexts holds the render textures used by the sky system.
// We need to have a separate one for the baking sky because we have to keep it alive regardless of the visual/override sky (because it's set in the lighting panel skybox material).
SkyRenderingContext m_BakingSkyRenderingContext;
SkyRenderingContext m_SkyRenderingContext;
public Texture skyReflection { get { return m_SkyRenderingContext.reflectionTexture; } }
void UpdateCurrentSkySettings()
{

m_VisualSky.skySettings = newSkySettings;
m_BakingSky.skySettings = SkySettings.GetBakingSkySettings();
m_LightingOverrideSky.skySettings = null;
UpdateRenderData();
}
// Sets the global MIP-mapped cubemap '_SkyTexture' in the shader.

cmd.SetGlobalFloat(HDShaderIDs._SkyTextureMipCount, mipCount);
}
public void UpdateRenderData()
{
m_BakingSky.RebuildTextures();
m_VisualSky.RebuildTextures();
m_LightingOverrideSky.RebuildTextures();
m_LastFrameUpdated = -1;
}
// For now, both these rendering context will allocate render textures
// In theory, when we have a lighting override we don't need any cubemaps from the visual sky so we could avoid allocating them
m_VisualSky = new SkyRenderingContext(true, iblFilterGGX);
m_LightingOverrideSky = new SkyRenderingContext(true, iblFilterGGX);
// Here we don't need convolution supports because this sky will never need to generate it (only sky cubemap for GI system)
m_BakingSky = new SkyRenderingContext(false, iblFilterGGX);
m_BakingSkyRenderingContext = new SkyRenderingContext(iblFilterGGX, (int)hdAsset.renderPipelineSettings.lightLoopSettings.skyReflectionSize, false);
m_SkyRenderingContext = new SkyRenderingContext(iblFilterGGX, (int)hdAsset.renderPipelineSettings.lightLoopSettings.skyReflectionSize, true);
m_OpaqueAtmScatteringMaterial = CoreUtils.CreateEngineMaterial(hdAsset.renderPipelineResources.opaqueAtmosphericScattering);
}

m_BakingSky.Cleanup();
m_VisualSky.Cleanup();
m_LightingOverrideSky.Cleanup();
m_BakingSkyRenderingContext.Cleanup();
m_SkyRenderingContext.Cleanup();
}
public bool IsSkyValid()

{
// Here we update the global SkyMaterial so that it uses our baking sky cubemap. This way, next time the GI is baked, the right sky will be present.
float intensity = m_BakingSky.IsValid() ? 1.0f : 0.0f; // Eliminate all diffuse if we don't have a skybox (meaning for now the background is black in HDRP)
m_StandardSkyboxMaterial.SetTexture("_Tex", m_BakingSky.cubemapRT);
RenderSettings.skybox = m_StandardSkyboxMaterial; // Setup this material as the default to be use in RenderSettings
RenderSettings.ambientIntensity = intensity;
RenderSettings.ambientMode = AmbientMode.Skybox; // Force skybox for our HDRI
RenderSettings.reflectionIntensity = intensity;
RenderSettings.customReflection = null;
m_StandardSkyboxMaterial.SetTexture("_Tex", m_BakingSkyRenderingContext.cubemapRT);
RenderSettings.skybox = m_StandardSkyboxMaterial; // Setup this material as the default to be use in RenderSettings
RenderSettings.ambientIntensity = intensity;
RenderSettings.ambientMode = AmbientMode.Skybox; // Force skybox for our HDRI
RenderSettings.reflectionIntensity = intensity;
RenderSettings.customReflection = null;
DynamicGI.UpdateEnvironment();
DynamicGI.UpdateEnvironment();
m_NeedUpdateBakingSky = false;
m_NeedUpdateBakingSky = false;
}
if (m_NeedUpdateRealtimeEnv)

UpdateCurrentSkySettings();
m_NeedUpdateBakingSky = m_BakingSky.UpdateEnvironment(camera, sunLight, m_UpdateRequired, cmd);
if (m_LightingOverrideSky.IsValid())
{
m_NeedUpdateRealtimeEnv = m_LightingOverrideSky.UpdateEnvironment(camera, sunLight, m_UpdateRequired, cmd);
}
else
{
m_NeedUpdateRealtimeEnv = m_VisualSky.UpdateEnvironment(camera, sunLight, 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);
m_LastFrameUpdated = Time.frameCount;
SetGlobalSkyTexture(cmd);

public void RenderSky(HDCamera camera, Light sunLight, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, CommandBuffer cmd)
{
m_VisualSky.RenderSky(camera, sunLight, colorBuffer, depthBuffer, cmd);
m_SkyRenderingContext.RenderSky(m_VisualSky, camera, sunLight, colorBuffer, depthBuffer, cmd);
}
public void RenderOpaqueAtmosphericScattering(CommandBuffer cmd)

return null;
}
int resolution = (int)m_VisualSky.skySettings.resolution.value;
RenderTexture skyCubemap = m_SkyRenderingContext.cubemapRT;
int resolution = skyCubemap.width;
var tempRT = new RenderTexture(resolution * 6, resolution, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear)
{

int offset = 0;
for (int i = 0; i < 6; ++i)
{
UnityEngine.Graphics.SetRenderTarget(m_VisualSky.cubemapRT, 0, (CubemapFace)i);
UnityEngine.Graphics.SetRenderTarget(skyCubemap, 0, (CubemapFace)i);
temp.ReadPixels(new Rect(0, 0, resolution, resolution), offset, 0);
temp.Apply();
offset += resolution;

134
ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyRenderingContext.cs


{
internal class SkyRenderingContext
{
SkySettings m_SkySettings;
SkyRenderer m_Renderer;
RenderTexture m_SkyboxCubemapRT;
RenderTexture m_SkyboxGGXCubemapRT;
RenderTexture m_SkyboxMarginalRowCdfRT;

Matrix4x4[] m_faceCameraInvViewProjectionMatrix = new Matrix4x4[6];
bool m_SupportsConvolution = false;
bool m_SupportsMIS = false;
int m_SkyParametersHash = -1;
float m_CurrentUpdateTime = 0.0f;
int m_UpdatedFramesRequired = 1; // The first frame after the scene load is currently not rendered correctly
bool m_SupportsConvolution = false;
bool m_NeedUpdate = true;
public SkySettings skySettings
{
get { return m_SkySettings; }
set
{
if (m_SkySettings == value)
return;
if (m_Renderer != null)
{
m_Renderer.Cleanup();
m_Renderer = null;
}
m_SkyParametersHash = -1;
m_SkySettings = value;
m_UpdatedFramesRequired = 1;
if (value != null)
{
m_Renderer = value.GetRenderer();
m_Renderer.Build();
}
}
}
public SkyRenderer renderer { get { return m_Renderer; } }
public SkyRenderingContext(bool supportsConvolution, IBLFilterGGX filterGGX)
public SkyRenderingContext(IBLFilterGGX filterGGX, int resolution, bool supportsConvolution)
m_SupportsConvolution = supportsConvolution;
m_SupportsConvolution = supportsConvolution;
RebuildTextures(resolution);
public void RebuildTextures()
public void RebuildTextures(int resolution)
int resolution = 256;
bool useMIS = false;
// Parameters not set yet. We need them for the resolution.
if (skySettings != null)
{
resolution = (int)skySettings.resolution.value;
useMIS = skySettings.useMIS;
}
if(updateNeeded)
if (updateNeeded)
{
CoreUtils.Destroy(m_SkyboxCubemapRT);
CoreUtils.Destroy(m_SkyboxGGXCubemapRT);

}
if (!useMIS && (m_SkyboxConditionalCdfRT != null))
if (!m_SupportsMIS && (m_SkyboxConditionalCdfRT != null))
{
CoreUtils.Destroy(m_SkyboxConditionalCdfRT);
CoreUtils.Destroy(m_SkyboxMarginalRowCdfRT);

{
m_SkyboxCubemapRT = new RenderTexture(resolution, resolution, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear)
{
hideFlags = HideFlags.DontSave,
dimension = TextureDimension.Cube,
useMipMap = true,
autoGenerateMips = false, // We will generate regular mipmap for filtered importance sampling manually

{
m_SkyboxGGXCubemapRT = new RenderTexture(resolution, resolution, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear)
{
hideFlags = HideFlags.DontSave,
dimension = TextureDimension.Cube,
useMipMap = true,
autoGenerateMips = false,

}
if (useMIS && (m_SkyboxConditionalCdfRT == null))
if (m_SupportsMIS && (m_SkyboxConditionalCdfRT == null))
{
// Temporary, it should be dependent on the sky resolution
int width = (int)LightSamplingParameters.TextureWidth;

m_SkyboxMarginalRowCdfRT = new RenderTexture(height + 1, 1, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear)
{
hideFlags = HideFlags.DontSave,
useMipMap = false,
autoGenerateMips = false,
enableRandomWrite = true,

// TODO: switch the format to R16 (once it's available) to save some bandwidth.
m_SkyboxConditionalCdfRT = new RenderTexture(width, height, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear)
{
hideFlags = HideFlags.DontSave,
useMipMap = false,
autoGenerateMips = false,
enableRandomWrite = true,

m_CubemapScreenSize = new Vector4((float)resolution, (float)resolution, 1.0f / (float)resolution, 1.0f / (float)resolution);
if(updateNeeded)
if (updateNeeded)
m_UpdatedFramesRequired = 1; // Special case. Even if update mode is set to OnDemand, we need to regenerate the environment after destroying the texture.
m_NeedUpdate = true; // Special case. Even if update mode is set to OnDemand, we need to regenerate the environment after destroying the texture.
public void RebuildSkyMatrices(int resolution)
{

m_faceCameraInvViewProjectionMatrix[i] = HDUtils.GetViewProjectionMatrix(lookAt, cubeProj).inverse;
}
}
public bool IsValid()
{
return m_Renderer != null && m_Renderer.IsValid();
}
public void Cleanup()
{
CoreUtils.Destroy(m_SkyboxCubemapRT);

if (m_Renderer != null)
m_Renderer.Cleanup();
void RenderSkyToCubemap()
void RenderSkyToCubemap(SkyUpdateContext skyContext)
{
for (int i = 0; i < 6; ++i)
{

m_BuiltinParameters.depthBuffer = BuiltinSkyParameters.nullRT;
CoreUtils.SetRenderTarget(m_BuiltinParameters.commandBuffer, m_SkyboxCubemapRT, ClearFlag.None, 0, (CubemapFace)i);
m_Renderer.RenderSky(m_BuiltinParameters, true);
skyContext.renderer.RenderSky(m_BuiltinParameters, true);
}
// Generate mipmap for our cubemap

void RenderCubemapGGXConvolution()
void RenderCubemapGGXConvolution(SkyUpdateContext skyContext)
if (skySettings.useMIS)
if (skyContext.skySettings.useMIS && m_SupportsMIS)
m_IBLFilterGGX.FilterCubemapMIS(m_BuiltinParameters.commandBuffer, m_SkyboxCubemapRT, m_SkyboxGGXCubemapRT, m_SkyboxConditionalCdfRT, m_SkyboxMarginalRowCdfRT);
else
m_IBLFilterGGX.FilterCubemap(m_BuiltinParameters.commandBuffer, m_SkyboxCubemapRT, m_SkyboxGGXCubemapRT);

public bool UpdateEnvironment(HDCamera camera, Light sunLight, bool updateRequired, CommandBuffer cmd)
public bool UpdateEnvironment(SkyUpdateContext skyContext, HDCamera camera, Light sunLight, bool updateRequired, CommandBuffer cmd)
if (IsValid())
if (skyContext.IsValid())
m_CurrentUpdateTime += Time.deltaTime;
skyContext.currentUpdateTime += Time.deltaTime;
m_BuiltinParameters.commandBuffer = cmd;
m_BuiltinParameters.sunLight = sunLight;

int sunHash = 0;
if (sunLight != null)
sunHash = (sunLight.GetHashCode() * 23 + sunLight.transform.position.GetHashCode()) * 23 + sunLight.transform.rotation.GetHashCode();
int skyHash = sunHash * 23 + m_SkySettings.GetHashCode();
int skyHash = sunHash * 23 + skyContext.skySettings.GetHashCode();
bool forceUpdate = (updateRequired || m_UpdatedFramesRequired > 0);
bool forceUpdate = (updateRequired || skyContext.updatedFramesRequired > 0 || m_NeedUpdate);
(m_SkySettings.updateMode == EnvironementUpdateMode.OnChanged && skyHash != m_SkyParametersHash) ||
(m_SkySettings.updateMode == EnvironementUpdateMode.Realtime && m_CurrentUpdateTime > m_SkySettings.updatePeriod))
(skyContext.skySettings.updateMode == EnvironementUpdateMode.OnChanged && skyHash != skyContext.skyParametersHash) ||
(skyContext.skySettings.updateMode == EnvironementUpdateMode.Realtime && skyContext.currentUpdateTime > skyContext.skySettings.updatePeriod))
RenderSkyToCubemap();
RenderSkyToCubemap(skyContext);
if(m_SupportsConvolution)
if (m_SupportsConvolution)
RenderCubemapGGXConvolution();
RenderCubemapGGXConvolution(skyContext);
m_SkyParametersHash = skyHash;
m_CurrentUpdateTime = 0.0f;
m_UpdatedFramesRequired--;
skyContext.skyParametersHash = skyHash;
skyContext.currentUpdateTime = 0.0f;
skyContext.updatedFramesRequired--;
m_NeedUpdate = false;
#if UNITY_EDITOR
#if UNITY_EDITOR
m_SkyboxCubemapRT.imageContentsHash = new Hash128((uint)m_SkySettings.GetHashCode(), 0, 0, 0);
#endif
m_SkyboxCubemapRT.imageContentsHash = new Hash128((uint)skyContext.skySettings.GetHashCode(), 0, 0, 0);
#endif
if (m_SkyParametersHash != 0)
if (skyContext.skyParametersHash != 0)
if(m_SupportsConvolution)
if (m_SupportsConvolution)
m_SkyParametersHash = 0;
skyContext.skyParametersHash = 0;
result = true;
}
}

public void RenderSky(HDCamera camera, Light sunLight, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, CommandBuffer cmd)
public void RenderSky(SkyUpdateContext skyContext, HDCamera camera, Light sunLight, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, CommandBuffer cmd)
if (IsValid())
if (skyContext.IsValid())
{
using (new ProfilingSample(cmd, "Sky Pass"))
{

m_BuiltinParameters.colorBuffer = colorBuffer;
m_BuiltinParameters.depthBuffer = depthBuffer;
m_Renderer.SetRenderTargets(m_BuiltinParameters);
m_Renderer.RenderSky(m_BuiltinParameters, false);
skyContext.renderer.SetRenderTargets(m_BuiltinParameters);
skyContext.renderer.RenderSky(m_BuiltinParameters, false);
}
}
}

5
ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettings.cs


public FloatParameter exposure = new FloatParameter(0.0f);
[Tooltip("Intensity multiplier for the sky.")]
public MinFloatParameter multiplier = new MinFloatParameter(1.0f, 0.0f);
[Tooltip("Resolution of the environment lighting generated from the sky.")]
public SkyResolutionParameter resolution = new SkyResolutionParameter(SkyResolution.SkyResolution256);
[Tooltip("Specify how the environment lighting should be updated.")]
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).")]

// TODO: Fixme once we switch to .Net 4.6+
//>>>
hash = hash * 23 + ((int)resolution.value).GetHashCode(); // Enum.GetHashCode generates garbage on .NET 3.5... Wtf !?
hash = hash * 23 + ((int)updateMode.value).GetHashCode();
//<<<

}
public abstract SkyRenderer GetRenderer();
public abstract SkyRenderer CreateRenderer();
}
}

57
ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyUpdateContext.cs


using UnityEngine.Rendering;
using System;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
internal class SkyUpdateContext
{
SkySettings m_SkySettings;
SkyRenderer m_Renderer;
public int skyParametersHash = -1;
public float currentUpdateTime = 0.0f;
public int updatedFramesRequired = 1; // The first frame after the scene load is currently not rendered correctly
public SkySettings skySettings
{
get { return m_SkySettings; }
set
{
if (m_SkySettings == value)
return;
if (m_Renderer != null)
{
m_Renderer.Cleanup();
m_Renderer = null;
}
skyParametersHash = -1;
m_SkySettings = value;
updatedFramesRequired = 1;
currentUpdateTime = 0.0f;
if (value != null)
{
m_Renderer = value.CreateRenderer();
m_Renderer.Build();
}
}
}
public SkyRenderer renderer { get { return m_Renderer; } }
public bool IsValid()
{
return m_Renderer != null && m_Renderer.IsValid();
}
public void Cleanup()
{
if (m_Renderer != null)
m_Renderer.Cleanup();
}
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyUpdateContext.cs.meta


fileFormatVersion: 2
guid: 7f0f3fd17c0272440b8aab72eb5068be
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存