浏览代码

Porting sky/fog systems to Interpolation volumes.

/main
Julien Ignace 7 年前
当前提交
10007208
共有 36 个文件被更改,包括 512 次插入439 次删除
  1. 7
      SampleScenes/HDTest/GlobalIlluminationTest/TestRealtime.cs
  2. 19
      ScriptableRenderPipeline/Core/CoreUtils.cs
  3. 17
      ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs
  4. 31
      ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  5. 2
      ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/SceneSettingsManager.cs
  6. 59
      ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/AtmosphericScattering.cs
  7. 11
      ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/AtmosphericScattering.hlsl
  8. 112
      ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/Editor/AtmosphericScatteringEditor.cs
  9. 4
      ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/Editor/AtmosphericScatteringEditor.cs.meta
  10. 77
      ScriptableRenderPipeline/HDRenderPipeline/Sky/Editor/SkySettingsEditor.cs
  11. 2
      ScriptableRenderPipeline/HDRenderPipeline/Sky/Editor/SkySettingsEditor.cs.meta
  12. 36
      ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/Editor/HDRISkyEditor.cs
  13. 3
      ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/Editor/HDRISkyEditor.cs.meta
  14. 4
      ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISkyRenderer.cs
  15. 68
      ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Editor/ProceduralSkyEditor.cs
  16. 4
      ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyRenderer.cs
  17. 89
      ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs
  18. 38
      ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettings.cs
  19. 28
      ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/Editor/ExponentialFogEditor.cs
  20. 11
      ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/Editor/ExponentialFogEditor.cs.meta
  21. 32
      ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/Editor/LinearFogEditor.cs
  22. 11
      ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/Editor/LinearFogEditor.cs.meta
  23. 25
      ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/ExponentialFog.cs
  24. 11
      ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/ExponentialFog.cs.meta
  25. 26
      ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/LinearFog.cs
  26. 11
      ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/LinearFog.cs.meta
  27. 26
      ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISky.cs
  28. 36
      ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSky.cs
  29. 51
      ScriptableRenderPipeline/HDRenderPipeline/Sky/VisualEnvironment.cs
  30. 11
      ScriptableRenderPipeline/HDRenderPipeline/Sky/VisualEnvironment.cs.meta
  31. 25
      ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISkySettings.cs
  32. 39
      ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkySettings.cs
  33. 12
      ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettingsSingleton.cs.meta
  34. 13
      ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettingsSingleton.cs
  35. 0
      /ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISky.cs.meta
  36. 0
      /ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSky.cs.meta

7
SampleScenes/HDTest/GlobalIlluminationTest/TestRealtime.cs


using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
public class TestRealtime : MonoBehaviour

{
if (m_SceneSettings != null)
{
HDRISkySettings skyParams = m_SceneSettings.GetComponent<HDRISkySettings>();
if (skyParams)
skyParams.rotation = (skyParams.rotation + Time.deltaTime * m_RotationSpeed) % 360.0f;
HDRISky skyParams = VolumeManager.instance.GetComponent<HDRISky>();
if (skyParams != null)
skyParams.rotation.value = (skyParams.rotation + Time.deltaTime * m_RotationSpeed) % 360.0f;
}
}
}

19
ScriptableRenderPipeline/Core/CoreUtils.cs


public static void ClearCubemap(CommandBuffer cmd, RenderTargetIdentifier buffer, Color clearColor)
{
// We should have the option to clear mip maps here, but since RenderTargetIdentifier, we can't know the number to clear...
// So for now, we won't do it.
}
public static void ClearCubemap(CommandBuffer cmd, RenderTexture renderTexture, Color clearColor, bool clearMips = false)
{
int mipCount = 1;
if (renderTexture.useMipMap && clearMips)
{
mipCount = (int)Mathf.Log((float)renderTexture.width, 2.0f) + 1;
}
for (int i = 0; i < 6; ++i)
{
for (int mip = 0; mip < mipCount; ++ mip )
{
SetRenderTarget(cmd, new RenderTargetIdentifier(renderTexture), ClearFlag.Color, clearColor, mip, (CubemapFace)i);
}
}
}
// Draws a full screen triangle as a faster alternative to drawing a full screen quad.

17
ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs


}
class DoCreateNewAssetCommonSettings : DoCreateNewAsset<CommonSettings> {}
class DoCreateNewAssetHDRISkySettings : DoCreateNewAsset<HDRISkySettings> {}
class DoCreateNewAssetProceduralSkySettings : DoCreateNewAsset<ProceduralSkySettings> {}
class DoCreateNewAssetSubsurfaceScatteringSettings : DoCreateNewAsset<SubsurfaceScatteringSettings> {}
[MenuItem("Assets/Create/Render Pipeline/High Definition/Common Settings", priority = CoreUtils.assetCreateMenuPriority2)]

var icon = EditorGUIUtility.FindTexture("ScriptableObject Icon");
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateNewAssetSubsurfaceScatteringSettings>(), "New SSS Settings.asset", icon, null);
}
[MenuItem("Assets/Create/Render Pipeline/High Definition/HDRISky Settings", priority = CoreUtils.assetCreateMenuPriority2)]
static void MenuCreateHDRISkySettings()
{
var icon = EditorGUIUtility.FindTexture("ScriptableObject Icon");
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateNewAssetHDRISkySettings>(), "New HDRISkySettings.asset", icon, null);
}
[MenuItem("Assets/Create/Render Pipeline/High Definition/ProceduralSky Settings", priority = CoreUtils.assetCreateMenuPriority2)]
static void MenuCreateProceduralSkySettings()
{
var icon = EditorGUIUtility.FindTexture("ScriptableObject Icon");
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateNewAssetProceduralSkySettings>(), "New ProceduralSkySettings.asset", icon, null);
}
}
}

31
ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


}
CommonSettings.Settings m_CommonSettings = CommonSettings.Settings.s_Defaultsettings;
SkySettings m_SkySettings = null;
static public CustomSampler GetSampler(CustomSamplerId id)
{

return CommonSettingsSingleton.overrideSettings.settings;
return m_CommonSettings;
}
}
public SkySettings skySettingsToUse
{
get
{
if (SkySettingsSingleton.overrideSettings)
return SkySettingsSingleton.overrideSettings;
return m_SkySettings;
}
}

m_LightLoop.Build(asset.renderPipelineResources, asset.globalRenderingSettings, asset.tileSettings, asset.globalTextureSettings, asset.shadowInitParams, m_ShadowSettings, m_IBLFilterGGX);
m_SkyManager.Build(asset.renderPipelineResources, m_IBLFilterGGX);
m_SkyManager.skySettings = skySettingsToUse;
m_DebugDisplaySettings.RegisterDebug();
m_DebugFullScreenTempRT = HDShaderIDs._DebugFullScreenTexture;

// TODO: This is the wrong way to handle resize/allocation. We can have several different camera here, mean that the loop on camera will allocate and deallocate
// the below buffer which is bad. Best is to have a set of buffer for each camera that is persistent and reallocate resource if need
// For now consider we have only one camera that go to this code, the main one.
m_SkyManager.skySettings = skySettingsToUse;
m_SkyManager.Resize(camera.nearClipPlane, camera.farClipPlane); // TODO: Also a bad naming, here we just want to realloc texture if skyparameters change (useful for lookdev)
bool resolutionChanged = camera.pixelWidth != m_CurrentWidth || camera.pixelHeight != m_CurrentHeight;

m_LightLoop.BuildGPULightLists(camera, cmd, m_CameraDepthStencilBufferRT, GetStencilTexture());
}
// Caution: We require sun light here as some sky use the sun light to render, mean UpdateSkyEnvironment
// must be call after BuildGPULightLists.
// TODO: Try to arrange code so we can trigger this call earlier and use async compute here to run sky convolution during other passes (once we move convolution shader to compute).
UpdateSkyEnvironment(hdCamera, cmd);
// Caution: We require sun light here as some sky use the sun light to render, mean UpdateSkyEnvironment
// must be call after BuildGPULightLists.
// TODO: Try to arrange code so we can trigger this call earlier and use async compute here to run sky convolution during other passes (once we move convolution shader to compute).
UpdateSkyEnvironment(hdCamera, cmd);
RenderDeferredLighting(hdCamera, cmd);

void RenderSky(HDCamera hdCamera, CommandBuffer cmd)
{
m_SkyManager.RenderSky(hdCamera, m_LightLoop.GetCurrentSunLight(), m_CameraColorBufferRT, m_CameraDepthStencilBufferRT, cmd, m_DebugDisplaySettings);
m_SkyManager.RenderOpaqueAtmosphericScattering(cmd);
// Rendering the sky is the first time in the frame where we need fog parameters so we push them here for the whole frame.
var visualEnv = VolumeManager.instance.GetComponent<VisualEnvironment>();
visualEnv.PushFogShaderParameters(cmd, m_DebugDisplaySettings.renderingDebugSettings);
m_SkyManager.RenderSky(hdCamera, m_LightLoop.GetCurrentSunLight(), m_CameraColorBufferRT, m_CameraDepthStencilBufferRT, cmd);
if(visualEnv.fogType != AtmosphericScattering.FogType.None)
m_SkyManager.RenderOpaqueAtmosphericScattering(cmd);
}
public Texture2D ExportSkyToTexture()

2
ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/SceneSettingsManager.cs


if (settings)
{
CommonSettingsSingleton.overrideSettings = settings.commonSettings;
SkySettingsSingleton.overrideSettings = settings.skySettings;
SkySettingsSingleton.overrideSettings = null;
}
}
}

59
ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/AtmosphericScattering.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[Serializable]
public class AtmosphericScatteringSettings
public abstract class AtmosphericScattering : VolumeComponent
{
[GenerateHLSL]
public enum FogType

Exponential
}
[Serializable]
public sealed class FogTypeParameter : VolumeParameter<FogType> { }
[GenerateHLSL]
public enum FogColorMode

}
[Serializable]
public sealed class FogColorParameter : VolumeParameter<FogColorMode> { }
private readonly static int m_FogColorParam = Shader.PropertyToID("_FogColor");
private readonly static int m_FogColorDensityParam = Shader.PropertyToID("_FogColorDensity");
// Linear Fog
private readonly static int m_LinearFogParam = Shader.PropertyToID("_LinearFogParameters");
// Exp Fog
private readonly static int m_ExpFogParam = Shader.PropertyToID("_ExpFogParameters");
public FogType type;
public FogColorMode colorMode = FogColorMode.SkyColor;
public Color fogColor = Color.grey;
[Range(0.0f, 1.0f)]
public float mipFogMaxMip = 1.0f;
public float mipFogNear = 0.0f;
public float mipFogFar = 1000.0f;
public FogColorParameter colorMode = new FogColorParameter { value = FogColorMode.SkyColor };
[Tooltip("Constant Fog Color")]
public ColorParameter color = new ColorParameter { value = Color.grey };
public ClampedFloatParameter density = new ClampedFloatParameter { value = 1.0f, min = 0.0f, max = 1.0f };
[Tooltip("Maximum mip map used for mip fog (0 being lowest and 1 highest mip).")]
public ClampedFloatParameter mipFogMaxMip = new ClampedFloatParameter { value = 1.0f, min = 0.0F, max = 1.0f };
[Tooltip("Distance at which minimum mip of blurred sky texture is used as fog color.")]
public ClampedFloatParameter mipFogNear = new ClampedFloatParameter { value = 0.0f, min = 0.0f, clampMode = ParameterClampMode.Min };
[Tooltip("Distance at which maximum mip of blurred sky texture is used as fog color.")]
public ClampedFloatParameter mipFogFar = new ClampedFloatParameter { value = 1000.0f, min = 0.0f, clampMode = ParameterClampMode.Min };
// Linear Fog
[Range(0.0f, 1.0f)]
public float linearFogDensity = 1.0f;
public float linearFogStart = 500.0f;
public float linearFogEnd = 1000.0f;
public abstract void PushShaderParameters(CommandBuffer cmd, RenderingDebugSettings renderingDebug);
// Exponential fog
//[Min(0.0f)] Not available until 2018.1
public float expFogDistance = 100.0f;
[Range(0.0f, 1.0f)]
public float expFogDensity = 1.0f;
public bool NeedFogRendering()
public static void PushNeutralShaderParameters(CommandBuffer cmd)
return type != FogType.None;
cmd.SetGlobalFloat(m_TypeParam, (float)FogType.None);
public void PushShaderParameters(CommandBuffer cmd, RenderingDebugSettings renderingDebug)
public void PushShaderParametersCommon(CommandBuffer cmd, FogType type, RenderingDebugSettings renderingDebug)
cmd.SetGlobalFloat(m_ColorModeParam, (float)colorMode);
cmd.SetGlobalColor(m_FogColorParam, fogColor);
cmd.SetGlobalFloat(m_ColorModeParam, (float)colorMode.value);
cmd.SetGlobalColor(m_FogColorDensityParam, new Color(color.value.r, color.value.g, color.value.b, density));
// Linear Fog
cmd.SetGlobalVector(m_LinearFogParam, new Vector4(linearFogStart, linearFogEnd, 1.0f / (linearFogEnd - linearFogStart), linearFogDensity));
// Exp fog
cmd.SetGlobalVector(m_ExpFogParam, new Vector4(Mathf.Max(0.0f, expFogDistance), expFogDensity, 0.0f, 0.0f));
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/AtmosphericScattering.hlsl


float _AtmosphericScatteringType;
// Common
float _FogColorMode;
float4 _FogColor;
float4 _FogColorDensity; // color in rgb, density in alpha
float4 _MipFogParameters;
// Linear fog
float4 _LinearFogParameters;

#define _MipFogFar _MipFogParameters.y
#define _MipFogMaxMip _MipFogParameters.z
#define _FogDensity _FogColorDensity.w
#define _FogColor _FogColorDensity
#define _LinearFogDensity _LinearFogParameters.w
#define _ExpFogDensity _ExpFogParameters.y
float3 GetFogColor(PositionInputs posInput)
{

if (_AtmosphericScatteringType == FOGTYPE_EXPONENTIAL)
{
float3 fogColor = GetFogColor(posInput);
float fogFactor = _ExpFogDensity * (1.0f - Transmittance(OpticalDepthHomogeneous(1.0f / _ExpFogDistance, posInput.linearDepth)));
float fogFactor = _FogDensity * (1.0f - Transmittance(OpticalDepthHomogeneous(1.0f / _ExpFogDistance, posInput.linearDepth)));
float fogFactor = _LinearFogDensity * saturate((posInput.linearDepth - _LinearFogStart) * _LinearFogOneOverRange);
float fogFactor = _FogDensity * saturate((posInput.linearDepth - _LinearFogStart) * _LinearFogOneOverRange);
return float4(fogColor, fogFactor);
}
else // NONE

112
ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/Editor/AtmosphericScatteringEditor.cs


using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.Experimental.Rendering;
public class AtmosphericScatteringEditor
public class AtmosphericScatteringEditor : VolumeComponentEditor
private class Styles
{
public readonly GUIContent fog = new GUIContent("Fog Parameters");
public readonly GUIContent type = new GUIContent("Type", "Type of fog.");
public readonly GUIContent colorMode = new GUIContent("Color Mode");
public readonly GUIContent color = new GUIContent("Color", "Constant Fog Color");
public readonly GUIContent mipFogNear = new GUIContent("Mip Fog Near", "Distance at which minimum mip of blurred sky texture is used as fog color.");
public readonly GUIContent mipFogFar = new GUIContent("Mip Fog Far", "Distance at which maximum mip of blurred sky texture is used as fog color.");
public readonly GUIContent mipFogMaxMip = new GUIContent("Mip Fog Max Mip", "Maximum mip map used for mip fog (0 being lowest and 1 heighest mip).");
public readonly GUIContent linearFogDensity = new GUIContent("Fog Density");
public readonly GUIContent linearFogStart = new GUIContent("Fog Start Distance");
public readonly GUIContent linearFogEnd = new GUIContent("Fog End Distance");
public readonly GUIContent expFogDensity = new GUIContent("Fog Density");
public readonly GUIContent expFogDistance = new GUIContent("Fog Distance");
}
private static Styles s_Styles = null;
private static Styles styles { get { if (s_Styles == null) s_Styles = new Styles(); return s_Styles; } }
private SerializedProperty m_Type;
private SerializedProperty m_ColorMode;
private SerializedProperty m_Color;
private SerializedProperty m_MipFogNear;
private SerializedProperty m_MipFogFar;
private SerializedProperty m_MipFogMaxMip;
SerializedDataParameter m_Density;
SerializedDataParameter m_ColorMode;
SerializedDataParameter m_Color;
SerializedDataParameter m_MipFogNear;
SerializedDataParameter m_MipFogFar;
SerializedDataParameter m_MipFogMaxMip;
private SerializedProperty m_LinearFogDensity;
private SerializedProperty m_LinearFogStart;
private SerializedProperty m_LinearFogEnd;
public override void OnEnable()
{
var o = new PropertyFetcher<AtmosphericScattering>(serializedObject);
private SerializedProperty m_ExpFogDistance;
private SerializedProperty m_ExpFogDensity;
m_Density = Unpack(o.Find(x => x.density));
public void OnEnable(SerializedProperty atmScatterProperty)
{
m_Type = atmScatterProperty.FindPropertyRelative("type");
m_ColorMode = atmScatterProperty.FindPropertyRelative("colorMode");
m_Color = atmScatterProperty.FindPropertyRelative("fogColor");
m_MipFogNear = atmScatterProperty.FindPropertyRelative("mipFogNear");
m_MipFogFar = atmScatterProperty.FindPropertyRelative("mipFogFar");
m_MipFogMaxMip = atmScatterProperty.FindPropertyRelative("mipFogMaxMip");
// Linear Fog
m_LinearFogDensity = atmScatterProperty.FindPropertyRelative("linearFogDensity");
m_LinearFogStart = atmScatterProperty.FindPropertyRelative("linearFogStart");
m_LinearFogEnd = atmScatterProperty.FindPropertyRelative("linearFogEnd");
// Exp fog
m_ExpFogDistance = atmScatterProperty.FindPropertyRelative("expFogDistance");
m_ExpFogDensity = atmScatterProperty.FindPropertyRelative("expFogDensity");
m_ColorMode = Unpack(o.Find(x => x.colorMode));
m_Color = Unpack(o.Find(x => x.color));
m_MipFogNear = Unpack(o.Find(x => x.mipFogNear));
m_MipFogFar = Unpack(o.Find(x => x.mipFogFar));
m_MipFogMaxMip = Unpack(o.Find(x => x.mipFogMaxMip));
public void OnGUI()
public override void OnInspectorGUI()
EditorGUILayout.LabelField(styles.fog, EditorStyles.boldLabel);
EditorGUILayout.PropertyField(m_Type, styles.type);
if(!m_Type.hasMultipleDifferentValues)
PropertyField(m_Density);
PropertyField(m_ColorMode);
EditorGUI.indentLevel++;
if(!m_ColorMode.value.hasMultipleDifferentValues && (AtmosphericScattering.FogColorMode)m_ColorMode.value.intValue == AtmosphericScattering.FogColorMode.ConstantColor)
if((AtmosphericScatteringSettings.FogType)m_Type.intValue != AtmosphericScatteringSettings.FogType.None)
{
EditorGUILayout.PropertyField(m_ColorMode, styles.colorMode);
if(!m_ColorMode.hasMultipleDifferentValues && (AtmosphericScatteringSettings.FogColorMode)m_ColorMode.intValue == AtmosphericScatteringSettings.FogColorMode.ConstantColor)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_Color, styles.color);
EditorGUI.indentLevel--;
}
else
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_MipFogNear, styles.mipFogNear);
EditorGUILayout.PropertyField(m_MipFogFar, styles.mipFogFar);
EditorGUILayout.PropertyField(m_MipFogMaxMip, styles.mipFogMaxMip);
EditorGUI.indentLevel--;
}
if ((AtmosphericScatteringSettings.FogType)m_Type.intValue == AtmosphericScatteringSettings.FogType.Linear)
{
EditorGUILayout.PropertyField(m_LinearFogDensity, styles.linearFogDensity);
EditorGUILayout.PropertyField(m_LinearFogStart, styles.linearFogStart);
EditorGUILayout.PropertyField(m_LinearFogEnd, styles.linearFogEnd);
}
else if((AtmosphericScatteringSettings.FogType)m_Type.intValue == AtmosphericScatteringSettings.FogType.Exponential)
{
EditorGUILayout.PropertyField(m_ExpFogDensity, styles.expFogDensity);
EditorGUILayout.PropertyField(m_ExpFogDistance, styles.expFogDistance);
}
}
PropertyField(m_Color);
else
{
PropertyField(m_MipFogNear);
PropertyField(m_MipFogFar);
PropertyField(m_MipFogMaxMip);
}
EditorGUI.indentLevel--;
}
}
}

4
ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/Editor/AtmosphericScatteringEditor.cs.meta


fileFormatVersion: 2
guid: 2215770abb40237488238a9db6de9dab
timeCreated: 1507718622
licenseType: Pro
guid: c3407086574724b42a5b445435853d88
MonoImporter:
externalObjects: {}
serializedVersion: 2

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


using System.Collections;
using UnityEngine;
using UnityEditor;
using UnityEditor.Experimental.Rendering;
public abstract class SkySettingsEditor
: Editor
public abstract class SkySettingsEditor : VolumeComponentEditor
static protected class SkySettingsStyles
{
public static readonly GUIContent skyResolution = new GUIContent("Resolution", "Resolution of the environment lighting generated from the sky.");
public static readonly GUIContent skyExposure = new GUIContent("Exposure", "Exposure of the sky in EV.");
public static readonly GUIContent skyRotation = new GUIContent("Rotation", "Rotation of the sky.");
public static readonly GUIContent skyMultiplier = new GUIContent("Multiplier", "Intensity multiplier for the sky.");
public static readonly GUIContent environmentUpdateMode = new GUIContent("Environment Update Mode", "Specify how the environment lighting should be updated.");
public static readonly GUIContent environmentUpdatePeriod = new GUIContent("Environment Update Period", "If environment update is set to realtime, period in seconds at which it is updated (0.0 means every frame).");
public static readonly GUIContent lightingOverride = new GUIContent("Lighting Override", "If a lighting override cubemap is provided, this cubemap will be used to compute lighting instead of the result from the visible sky.");
}
SerializedDataParameter m_SkyResolution;
SerializedDataParameter m_SkyExposure;
SerializedDataParameter m_SkyMultiplier;
SerializedDataParameter m_SkyRotation;
SerializedDataParameter m_EnvUpdateMode;
SerializedDataParameter m_EnvUpdatePeriod;
SerializedDataParameter m_LightingOverride;
private SerializedProperty m_SkyResolution;
private SerializedProperty m_SkyExposure;
private SerializedProperty m_SkyMultiplier;
private SerializedProperty m_SkyRotation;
private SerializedProperty m_EnvUpdateMode;
private SerializedProperty m_EnvUpdatePeriod;
private SerializedProperty m_LightingOverride;
private AtmosphericScatteringEditor m_AtmosphericScatteringEditor = new AtmosphericScatteringEditor();
void OnEnable()
public override void OnEnable()
InitializeProperties();
}
var o = new PropertyFetcher<SkySettings>(serializedObject);
virtual protected void InitializeProperties()
{
m_SkyResolution = serializedObject.FindProperty("resolution");
m_SkyExposure = serializedObject.FindProperty("exposure");
m_SkyMultiplier = serializedObject.FindProperty("multiplier");
m_SkyRotation = serializedObject.FindProperty("rotation");
m_EnvUpdateMode = serializedObject.FindProperty("updateMode");
m_EnvUpdatePeriod = serializedObject.FindProperty("updatePeriod");
m_LightingOverride = serializedObject.FindProperty("lightingOverride");
SerializedProperty atmosphericScattering = serializedObject.FindProperty("atmosphericScatteringSettings");
m_AtmosphericScatteringEditor.OnEnable(atmosphericScattering);
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));
m_EnvUpdateMode = Unpack(o.Find(x => x.updateMode));
m_EnvUpdatePeriod = Unpack(o.Find(x => x.updatePeriod));
m_LightingOverride = Unpack(o.Find(x => x.lightingOverride));
EditorGUILayout.PropertyField(m_SkyResolution, SkySettingsStyles.skyResolution);
EditorGUILayout.PropertyField(m_SkyExposure, SkySettingsStyles.skyExposure);
EditorGUILayout.PropertyField(m_SkyMultiplier, SkySettingsStyles.skyMultiplier);
EditorGUILayout.PropertyField(m_SkyRotation, SkySettingsStyles.skyRotation);
PropertyField(m_SkyResolution);
PropertyField(m_SkyExposure);
PropertyField(m_SkyMultiplier);
PropertyField(m_SkyRotation);
EditorGUILayout.PropertyField(m_EnvUpdateMode, SkySettingsStyles.environmentUpdateMode);
if (!m_EnvUpdateMode.hasMultipleDifferentValues && m_EnvUpdateMode.intValue == (int)EnvironementUpdateMode.Realtime)
PropertyField(m_EnvUpdateMode);
if (!m_EnvUpdateMode.value.hasMultipleDifferentValues && m_EnvUpdateMode.value.intValue == (int)EnvironementUpdateMode.Realtime)
EditorGUILayout.PropertyField(m_EnvUpdatePeriod, SkySettingsStyles.environmentUpdatePeriod);
EditorGUI.indentLevel++;
PropertyField(m_EnvUpdatePeriod);
EditorGUI.indentLevel--;
EditorGUILayout.PropertyField(m_LightingOverride, SkySettingsStyles.lightingOverride);
EditorGUILayout.Space();
m_AtmosphericScatteringEditor.OnGUI();
PropertyField(m_LightingOverride);
}
}
}

2
ScriptableRenderPipeline/HDRenderPipeline/Sky/Editor/SkySettingsEditor.cs.meta


fileFormatVersion: 2
guid: 88383d4257a1cb74bbfaef0546ce7e38
timeCreated: 1507627721
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2

36
ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/Editor/HDRISkyEditor.cs


using UnityEngine;
using UnityEditor;
using UnityEditor.Experimental.Rendering;
[CustomEditor(typeof(HDRISkySettings))]
public class HDRISkySettingsEditor
[VolumeComponentEditor(typeof(HDRISky))]
public class HDRISkyEditor
private class Styles
{
public readonly GUIContent skyHDRI = new GUIContent("HDRI", "Cubemap used to render the sky.");
}
private static Styles s_Styles = null;
private static Styles styles
{
get
{
if (s_Styles == null)
s_Styles = new Styles();
return s_Styles;
}
}
SerializedDataParameter m_SkyHDRI;
private SerializedProperty m_SkyHDRI;
protected override void InitializeProperties()
public override void OnEnable()
base.InitializeProperties();
base.OnEnable();
m_SkyHDRI = serializedObject.FindProperty("skyHDRI");
var o = new PropertyFetcher<HDRISky>(serializedObject);
m_SkyHDRI = Unpack(o.Find(x => x.skyHDRI));
serializedObject.Update();
EditorGUILayout.PropertyField(m_SkyHDRI, styles.skyHDRI);
PropertyField(m_SkyHDRI);
serializedObject.ApplyModifiedProperties();
}
}
}

3
ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/Editor/HDRISkyEditor.cs.meta


fileFormatVersion: 2
guid: 09663e580f1cc7b409d7ddc7923ec152
timeCreated: 1481635925
licenseType: Pro
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0

4
ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISkyRenderer.cs


{
Material m_SkyHDRIMaterial; // Renders a cubemap into a render texture (can be cube or 2D)
MaterialPropertyBlock m_PropertyBlock;
HDRISkySettings m_HdriSkyParams;
HDRISky m_HdriSkyParams;
public HDRISkyRenderer(HDRISkySettings hdriSkyParams)
public HDRISkyRenderer(HDRISky hdriSkyParams)
{
m_HdriSkyParams = hdriSkyParams;
m_PropertyBlock = new MaterialPropertyBlock();

68
ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Editor/ProceduralSkyEditor.cs


using UnityEngine;
using UnityEditor;
using UnityEditor.Experimental.Rendering;
[CustomEditor(typeof(ProceduralSkySettings))]
[VolumeComponentEditor(typeof(ProceduralSky))]
private class Styles
{
public readonly GUIContent sunSize = new GUIContent("Sun Size");
public readonly GUIContent sunSizeConvergence = new GUIContent("Sun Size Convergence");
public readonly GUIContent atmosphereThickness = new GUIContent("Atmosphere Thickness");
public readonly GUIContent skyTint = new GUIContent("SkyTint");
public readonly GUIContent groundColor = new GUIContent("Ground Color");
public readonly GUIContent enableSunDisk = new GUIContent("Enable Sun Disk");
}
SerializedDataParameter m_SunSize;
SerializedDataParameter m_SunSizeConvergence;
SerializedDataParameter m_AtmosphericThickness;
SerializedDataParameter m_SkyTint;
SerializedDataParameter m_GroundColor;
SerializedDataParameter m_EnableSunDisk;
private static Styles s_Styles = null;
private static Styles styles
public override void OnEnable()
get
{
if (s_Styles == null)
s_Styles = new Styles();
return s_Styles;
}
}
private SerializedProperty m_SunSize;
private SerializedProperty m_SunSizeConvergence;
private SerializedProperty m_AtmosphericThickness;
private SerializedProperty m_SkyTint;
private SerializedProperty m_GroundColor;
private SerializedProperty m_EnableSunDisk;
base.OnEnable();
protected override void InitializeProperties()
{
base.InitializeProperties();
var o = new PropertyFetcher<ProceduralSky>(serializedObject);
m_SunSize = serializedObject.FindProperty("sunSize");
m_SunSizeConvergence = serializedObject.FindProperty("sunSizeConvergence");
m_AtmosphericThickness = serializedObject.FindProperty("atmosphereThickness");
m_SkyTint = serializedObject.FindProperty("skyTint");
m_GroundColor = serializedObject.FindProperty("groundColor");
m_EnableSunDisk = serializedObject.FindProperty("enableSunDisk");
m_SunSize = Unpack(o.Find(x => x.sunSize));
m_SunSizeConvergence = Unpack(o.Find(x => x.sunSizeConvergence));
m_AtmosphericThickness = Unpack(o.Find(x => x.atmosphereThickness));
m_SkyTint = Unpack(o.Find(x => x.skyTint));
m_GroundColor = Unpack(o.Find(x => x.groundColor));
m_EnableSunDisk = Unpack(o.Find(x => x.enableSunDisk));
serializedObject.Update();
EditorGUILayout.PropertyField(m_EnableSunDisk, styles.enableSunDisk);
EditorGUILayout.PropertyField(m_SunSize, styles.sunSize);
EditorGUILayout.PropertyField(m_SunSizeConvergence, styles.sunSizeConvergence);
EditorGUILayout.PropertyField(m_AtmosphericThickness, styles.atmosphereThickness);
EditorGUILayout.PropertyField(m_SkyTint, styles.skyTint);
EditorGUILayout.PropertyField(m_GroundColor, styles.groundColor);
PropertyField(m_EnableSunDisk);
PropertyField(m_SunSize);
PropertyField(m_SunSizeConvergence);
PropertyField(m_AtmosphericThickness);
PropertyField(m_SkyTint);
PropertyField(m_GroundColor);
serializedObject.ApplyModifiedProperties();
}
}
}

4
ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyRenderer.cs


{
Material m_SkyProceduralMaterial;
MaterialPropertyBlock m_PropertyBlock;
ProceduralSkySettings m_ProceduralSkyParams;
ProceduralSky m_ProceduralSkyParams;
readonly int _SunSizeParam = Shader.PropertyToID("_SunSize");
readonly int _SunSizeConvergenceParam = Shader.PropertyToID("_SunSizeConvergence");

readonly int _SunColorParam = Shader.PropertyToID("_SunColor");
readonly int _SunDirectionParam = Shader.PropertyToID("_SunDirection");
public ProceduralSkyRenderer(ProceduralSkySettings proceduralSkyParams)
public ProceduralSkyRenderer(ProceduralSky proceduralSkyParams)
{
m_ProceduralSkyParams = proceduralSkyParams;
m_PropertyBlock = new MaterialPropertyBlock();

89
ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs


bool m_useMIS = false;
SkySettings m_SkySettings;
public SkySettings skySettings
public Texture skyReflection { get { return m_SkyboxGGXCubemapRT; } }
void UpdateCurrentSkySettings()
set
SkySettings newSkySettings = null;
var visualEnv = VolumeManager.instance.GetComponent<VisualEnvironment>();
switch(visualEnv.skyType.value)
if (m_SkySettings == value)
return;
case SkyType.HDRISky:
{
newSkySettings = VolumeManager.instance.GetComponent<HDRISky>();
break;
}
case SkyType.ProceduralSky:
{
newSkySettings = VolumeManager.instance.GetComponent<ProceduralSky>();
break;
}
}
if (m_SkySettings == newSkySettings)
return;
if (m_Renderer != null)
{
m_Renderer.Cleanup();
m_Renderer = null;
}
if (m_Renderer != null)
{
m_Renderer.Cleanup();
m_Renderer = null;
}
m_SkyParametersHash = -1;
m_SkySettings = value;
m_UpdatedFramesRequired = 2;
m_SkyParametersHash = -1;
m_SkySettings = newSkySettings;
m_UpdatedFramesRequired = 2;
if (value != null)
{
m_Renderer = value.GetRenderer();
m_Renderer.Build();
}
if (newSkySettings != null)
{
m_Renderer = newSkySettings.GetRenderer();
m_Renderer.Build();
get { return m_SkySettings; }
public Texture skyReflection { get { return m_SkyboxGGXCubemapRT; } }
void RebuildTextures(SkySettings skySettings)
{

if (skySettings != null)
resolution = (int)skySettings.resolution;
resolution = (int)skySettings.resolution.value;
if ((m_SkyboxCubemapRT != null) && (m_SkyboxCubemapRT.width != resolution))
{

{
var lookAt = Matrix4x4.LookAt(Vector3.zero, CoreUtils.lookAtList[i], CoreUtils.upVectorList[i]);
var worldToView = lookAt * Matrix4x4.Scale(new Vector3(1.0f, 1.0f, -1.0f)); // Need to scale -1.0 on Z to match what is being done in the camera.wolrdToCameraMatrix API. ...
var screenSize = new Vector4((int)m_SkySettings.resolution, (int)m_SkySettings.resolution, 1.0f / (int)m_SkySettings.resolution, 1.0f / (int)m_SkySettings.resolution);
var screenSize = new Vector4((int)m_SkySettings.resolution.value, (int)m_SkySettings.resolution.value, 1.0f / (int)m_SkySettings.resolution.value, 1.0f / (int)m_SkySettings.resolution.value);
m_facePixelCoordToViewDirMatrices[i] = HDUtils.ComputePixelCoordToWorldSpaceViewDirectionMatrix(0.5f * Mathf.PI, screenSize, worldToView, true);
m_faceCameraInvViewProjectionMatrix[i] = HDUtils.GetViewProjectionMatrix(lookAt, cubeProj).inverse;

public void Resize(float nearPlane, float farPlane)
{
// When loading RenderDoc, RenderTextures will go null
RebuildTextures(skySettings);
RebuildTextures(m_SkySettings);
RebuildSkyMatrices(nearPlane, farPlane);
}

if (m_LastFrameUpdated == Time.frameCount)
return;
UpdateCurrentSkySettings();
m_LastFrameUpdated = Time.frameCount;
// We need one frame delay for this update to work since DynamicGI.UpdateEnvironment is executed directly but the renderloop is not (so we need to wait for the sky texture to be rendered first)

int sunHash = 0;
if(sunLight != null)
sunHash = (sunLight.GetHashCode() * 23 + sunLight.transform.position.GetHashCode()) * 23 + sunLight.transform.rotation.GetHashCode();
int skyHash = sunHash * 23 + skySettings.GetHashCode();
int skyHash = sunHash * 23 + m_SkySettings.GetHashCode();
(skySettings.updateMode == EnvironementUpdateMode.OnChanged && skyHash != m_SkyParametersHash) ||
(skySettings.updateMode == EnvironementUpdateMode.Realtime && m_CurrentUpdateTime > skySettings.updatePeriod))
(m_SkySettings.updateMode == EnvironementUpdateMode.OnChanged && skyHash != m_SkyParametersHash) ||
(m_SkySettings.updateMode == EnvironementUpdateMode.Realtime && m_CurrentUpdateTime > m_SkySettings.updatePeriod))
{
using (new ProfilingSample(cmd, "Sky Environment Pass"))
{

// Note that m_SkyboxCubemapRT is created with auto-generate mipmap, it mean that here we have also our mipmap correctly box filtered for importance sampling.
if(m_SkySettings.lightingOverride == null)
RenderSkyToCubemap(m_BuiltinParameters, skySettings, m_SkyboxCubemapRT);
if(m_SkySettings.lightingOverride.value == null)
RenderSkyToCubemap(m_BuiltinParameters, m_SkySettings, m_SkyboxCubemapRT);
// In case the user overrides the lighting, we already have a cubemap ready but we need to blit it anyway for potential resize and so that we can generate proper mipmaps for enlighten.
else
BlitCubemap(cmd, m_SkySettings.lightingOverride, m_SkyboxCubemapRT);

#if UNITY_EDITOR
// In the editor when we change the sky we want to make the GI dirty so when baking again the new sky is taken into account.
// Changing the hash of the rendertarget allow to say that GI is dirty
m_SkyboxCubemapRT.imageContentsHash = new Hash128((uint)skySettings.GetHashCode(), 0, 0, 0);
m_SkyboxCubemapRT.imageContentsHash = new Hash128((uint)m_SkySettings.GetHashCode(), 0, 0, 0);
#endif
}
}

{
using (new ProfilingSample(cmd, "Reset Sky Environment"))
{
// Clear temp cubemap and redo GGX from black and then feed it to enlighten for default light probe.
CoreUtils.ClearCubemap(cmd, m_SkyboxCubemapRT, Color.black);
RenderCubemapGGXConvolution(cmd, m_SkyboxCubemapRT, m_SkyboxGGXCubemapRT);
CoreUtils.ClearCubemap(cmd, m_SkyboxGGXCubemapRT, Color.black, true);
m_SkyParametersHash = 0;
m_NeedLowLevelUpdateEnvironment = true;

}
public void RenderSky(HDCamera camera, Light sunLight, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, CommandBuffer cmd, DebugDisplaySettings debugSettings)
public void RenderSky(HDCamera camera, Light sunLight, RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, CommandBuffer cmd)
// Rendering the sky is the first time in the frame where we need fog parameters so we push them here for the whole frame.
m_SkySettings.atmosphericScatteringSettings.PushShaderParameters(cmd, debugSettings.renderingDebugSettings);
m_BuiltinParameters.commandBuffer = cmd;
m_BuiltinParameters.sunLight = sunLight;
m_BuiltinParameters.pixelCoordToViewDirMatrix = HDUtils.ComputePixelCoordToWorldSpaceViewDirectionMatrix(camera.camera.fieldOfView * Mathf.Deg2Rad, camera.screenSize, camera.viewMatrix, false);

{
using (new ProfilingSample(cmd, "Opaque Atmospheric Scattering"))
{
if(skySettings != null && skySettings.atmosphericScatteringSettings.NeedFogRendering())
{
CoreUtils.DrawFullScreen(cmd, m_OpaqueAtmScatteringMaterial);
}
CoreUtils.DrawFullScreen(cmd, m_OpaqueAtmScatteringMaterial);
}
}

return null;
}
int resolution = (int)m_SkySettings.resolution;
int resolution = (int)m_SkySettings.resolution.value;
var tempRT = new RenderTexture(resolution * 6, resolution, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear)
{

38
ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettings.cs


using System;
[ExecuteInEditMode]
public abstract class SkySettings : ScriptableObject
[Serializable]
public sealed class SkyResolutionParameter : VolumeParameter<SkyResolution> { }
[Serializable]
public sealed class EnvUpdateParameter : VolumeParameter<EnvironementUpdateMode> { }
public abstract class SkySettings : VolumeComponent
[Range(0,360)]
public float rotation = 0.0f;
public float exposure = 0.0f;
public float multiplier = 1.0f;
public SkyResolution resolution = SkyResolution.SkyResolution256;
public EnvironementUpdateMode updateMode = EnvironementUpdateMode.OnChanged;
public float updatePeriod = 0.0f;
public Cubemap lightingOverride = null;
public AtmosphericScatteringSettings atmosphericScatteringSettings = new AtmosphericScatteringSettings();
[Tooltip("Rotation of the sky.")]
public ClampedFloatParameter rotation = new ClampedFloatParameter { value = 0.0f, min = 0.0f, max = 360.0f };
[Tooltip("Exposure of the sky in EV.")]
public FloatParameter exposure = new FloatParameter { value = 0.0f };
[Tooltip("Intensity multiplier for the sky.")]
public ClampedFloatParameter multiplier = new ClampedFloatParameter { value = 1.0f, min = 0.0f, clampMode = ParameterClampMode.Min };
[Tooltip("Resolution of the environment lighting generated from the sky.")]
public SkyResolutionParameter resolution = new SkyResolutionParameter { value = SkyResolution.SkyResolution256 };
[Tooltip("Specify how the environment lighting should be updated.")]
public EnvUpdateParameter updateMode = new EnvUpdateParameter { value = EnvironementUpdateMode.OnChanged };
[Tooltip("If environment update is set to realtime, period in seconds at which it is updated (0.0 means every frame).")]
public ClampedFloatParameter updatePeriod = new ClampedFloatParameter { value = 0.0f, min = 0.0f, clampMode = ParameterClampMode.Min };
[Tooltip("If a lighting override cubemap is provided, this cubemap will be used to compute lighting instead of the result from the visible sky.")]
public CubemapParameter lightingOverride = new CubemapParameter { value = null };
public override int GetHashCode()
{

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

28
ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/Editor/ExponentialFogEditor.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.Experimental.Rendering;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[VolumeComponentEditor(typeof(ExponentialFog))]
public class ExponentialFogEditor : AtmosphericScatteringEditor
{
private SerializedDataParameter m_FogDistance;
public override void OnEnable()
{
base.OnEnable();
var o = new PropertyFetcher<ExponentialFog>(serializedObject);
m_FogDistance = Unpack(o.Find(x => x.fogDistance));
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
PropertyField(m_FogDistance);
}
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/Editor/ExponentialFogEditor.cs.meta


fileFormatVersion: 2
guid: e551cbe9c454e5847ab25b6476285bdc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

32
ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/Editor/LinearFogEditor.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.Experimental.Rendering;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[VolumeComponentEditor(typeof(LinearFog))]
public class LinearFogEditor : AtmosphericScatteringEditor
{
private SerializedDataParameter m_FogStart;
private SerializedDataParameter m_FogEnd;
public override void OnEnable()
{
base.OnEnable();
var o = new PropertyFetcher<LinearFog>(serializedObject);
m_FogStart = Unpack(o.Find(x => x.fogStart));
m_FogEnd = Unpack(o.Find(x => x.fogEnd));
}
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
PropertyField(m_FogStart);
PropertyField(m_FogEnd);
}
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/Editor/LinearFogEditor.cs.meta


fileFormatVersion: 2
guid: 54c746d584e88ea46b46b03ad311c0ac
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

25
ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/ExponentialFog.cs


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public class ExponentialFog : AtmosphericScattering
{
// Exp Fog
private readonly static int m_ExpFogParam = Shader.PropertyToID("_ExpFogParameters");
// Exponential fog
public ClampedFloatParameter fogDistance = new ClampedFloatParameter { value = 100.0f, min = 0.0f, clampMode = ParameterClampMode.Min };
public override void PushShaderParameters(CommandBuffer cmd, RenderingDebugSettings renderingDebug)
{
PushShaderParametersCommon(cmd, FogType.Exponential, renderingDebug);
cmd.SetGlobalVector(m_ExpFogParam, new Vector4(Mathf.Max(0.0f, fogDistance), 0.0f, 0.0f, 0.0f));
}
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/ExponentialFog.cs.meta


fileFormatVersion: 2
guid: 2150ee00179b2f4418ea8b21a7e98eea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

26
ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/LinearFog.cs


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public class LinearFog : AtmosphericScattering
{
private readonly static int m_LinearFogParam = Shader.PropertyToID("_LinearFogParameters");
// Linear Fog
public ClampedFloatParameter fogStart = new ClampedFloatParameter { value = 500.0f, min = 0.0f, clampMode = ParameterClampMode.Min };
public ClampedFloatParameter fogEnd = new ClampedFloatParameter { value = 1000.0f, min = 0.0f, clampMode = ParameterClampMode.Min };
public override void PushShaderParameters(CommandBuffer cmd, RenderingDebugSettings renderingDebug)
{
PushShaderParametersCommon(cmd, FogType.Linear, renderingDebug);
// Linear Fog
cmd.SetGlobalVector(m_LinearFogParam, new Vector4(fogStart, fogEnd, 1.0f / (fogEnd - fogStart), 0.0f));
}
}
}

11
ScriptableRenderPipeline/HDRenderPipeline/Sky/AtmosphericScattering/LinearFog.cs.meta


fileFormatVersion: 2
guid: eb673446a9a2dfa408924fe9a56322e0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

26
ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISky.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[DisallowMultipleComponent]
public class HDRISky : SkySettings
{
[Tooltip("Cubemap used to render the sky.")]
public CubemapParameter skyHDRI = new CubemapParameter { value = null };
public override SkyRenderer GetRenderer()
{
return new HDRISkyRenderer(this);
}
public override int GetHashCode()
{
int hash = base.GetHashCode();
unchecked
{
hash = skyHDRI.value != null ? hash * 23 + skyHDRI.GetHashCode() : hash;
}
return hash;
}
}
}

36
ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSky.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[DisallowMultipleComponent]
public class ProceduralSky : SkySettings
{
public ClampedFloatParameter sunSize = new ClampedFloatParameter { value = 0.04f, min = 0.0f, max = 1.0f };
public ClampedFloatParameter sunSizeConvergence = new ClampedFloatParameter { value = 5.0f, min = 1.0f, max = 10.0f };
public ClampedFloatParameter atmosphereThickness = new ClampedFloatParameter { value = 1.0f, min = 0.0f, max = 5.0f };
public ColorParameter skyTint = new ColorParameter { value = new Color(0.5f, 0.5f, 0.5f, 1.0f) };
public ColorParameter groundColor = new ColorParameter { value = new Color(0.369f, 0.349f, 0.341f, 1.0f) };
public BoolParameter enableSunDisk = new BoolParameter { value = true };
public override SkyRenderer GetRenderer()
{
return new ProceduralSkyRenderer(this);
}
public override int GetHashCode()
{
int hash = base.GetHashCode();
unchecked
{
hash = hash * 23 + sunSize.GetHashCode();
hash = hash * 23 + sunSizeConvergence.GetHashCode();
hash = hash * 23 + atmosphereThickness.GetHashCode();
hash = hash * 23 + skyTint.GetHashCode();
hash = hash * 23 + groundColor.GetHashCode();
hash = hash * 23 + multiplier.GetHashCode();
hash = hash * 23 + enableSunDisk.GetHashCode();
}
return hash;
}
}
}

51
ScriptableRenderPipeline/HDRenderPipeline/Sky/VisualEnvironment.cs


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
// TODO instead of hardcoing this, we need to generate the information from the existing sky currently implemented.
public enum SkyType
{
None,
HDRISky,
ProceduralSky
}
[Serializable]
public sealed class SkyTypeParameter : VolumeParameter<SkyType> { }
[Serializable]
public sealed class VisualEnvironment : VolumeComponent
{
public SkyTypeParameter skyType = new SkyTypeParameter { value = SkyType.ProceduralSky };
public AtmosphericScattering.FogTypeParameter fogType = new AtmosphericScattering.FogTypeParameter { value = AtmosphericScattering.FogType.None };
public void PushFogShaderParameters(CommandBuffer cmd, RenderingDebugSettings renderingDebug)
{
switch(fogType.value)
{
case AtmosphericScattering.FogType.None:
{
AtmosphericScattering.PushNeutralShaderParameters(cmd);
break;
}
case AtmosphericScattering.FogType.Linear:
{
var fogSettings = VolumeManager.instance.GetComponent<LinearFog>();
fogSettings.PushShaderParameters(cmd, renderingDebug);
break;
}
case AtmosphericScattering.FogType.Exponential:
{
var fogSettings = VolumeManager.instance.GetComponent<ExponentialFog>();
fogSettings.PushShaderParameters(cmd, renderingDebug);
break;
}
}
}
}
}

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


fileFormatVersion: 2
guid: 0d7593b3a9277ac4696b20006c21dde2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

25
ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISkySettings.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[DisallowMultipleComponent]
public class HDRISkySettings : SkySettings
{
public Cubemap skyHDRI;
public override SkyRenderer GetRenderer()
{
return new HDRISkyRenderer(this);
}
public override int GetHashCode()
{
int hash = base.GetHashCode();
unchecked
{
hash = skyHDRI != null ? hash * 23 + skyHDRI.GetHashCode() : hash;
}
return hash;
}
}
}

39
ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkySettings.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[DisallowMultipleComponent]
public class ProceduralSkySettings : SkySettings
{
[Range(0.0f,1.0f)]
public float sunSize = 0.04f;
[Range(1.0f,10.0f)]
public float sunSizeConvergence = 5.0f;
[Range(0.0f,5.0f)]
public float atmosphereThickness = 1.0f;
public Color skyTint = new Color(0.5f, 0.5f, 0.5f, 1.0f);
public Color groundColor = new Color(0.369f, 0.349f, 0.341f, 1.0f);
public bool enableSunDisk = true;
public override SkyRenderer GetRenderer()
{
return new ProceduralSkyRenderer(this);
}
public override int GetHashCode()
{
int hash = base.GetHashCode();
unchecked
{
hash = hash * 23 + sunSize.GetHashCode();
hash = hash * 23 + sunSizeConvergence.GetHashCode();
hash = hash * 23 + atmosphereThickness.GetHashCode();
hash = hash * 23 + skyTint.GetHashCode();
hash = hash * 23 + groundColor.GetHashCode();
hash = hash * 23 + multiplier.GetHashCode();
hash = hash * 23 + enableSunDisk.GetHashCode();
}
return hash;
}
}
}

12
ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettingsSingleton.cs.meta


fileFormatVersion: 2
guid: 6b9acc7ad27501c4bbcd5d6d5a7fb218
timeCreated: 1485096567
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

13
ScriptableRenderPipeline/HDRenderPipeline/Sky/SkySettingsSingleton.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public class SkySettingsSingleton : Singleton<SkySettingsSingleton>
{
SkySettings m_Settings { get; set; }
public static SkySettings overrideSettings
{
get { return instance.m_Settings; }
set { instance.m_Settings = value; }
}
}
}

/ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISkySettings.cs.meta → /ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISky.cs.meta

/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkySettings.cs.meta → /ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSky.cs.meta

正在加载...
取消
保存