浏览代码

Ported Legacy Unity procedural sky to HDRP and renamed our ProceduralSky to BlacksmithSky (pending removal)

/stochastic_alpha_test
Julien Ignace 7 年前
当前提交
6b9ad1a2
共有 45 个文件被更改,包括 1708 次插入458 次删除
  1. 35
      ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs
  2. 40
      ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/Editor/HDRISkyEditor.cs
  3. 2
      ScriptableRenderPipeline/HDRenderPipeline/Sky/HDRISky/HDRISkyRenderer.cs
  4. 4
      ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky.meta
  5. 4
      ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Editor.meta
  6. 143
      ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Editor/ProceduralSkyEditor.cs
  7. 2
      ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Editor/ProceduralSkyEditor.cs.meta
  8. 182
      ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyRenderer.cs
  9. 2
      ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyRenderer.cs.meta
  10. 158
      ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkySettings.cs
  11. 2
      ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkySettings.cs.meta
  12. 4
      ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Resources.meta
  13. 4
      ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs
  14. 2
      ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyRenderer.cs
  15. 2
      ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/Resources/SkyBlacksmith.shader
  16. 10
      SampleScenes/HDTest/SkyFogTest.meta
  17. 534
      SampleScenes/HDTest/SkyFogTest.unity
  18. 9
      SampleScenes/HDTest/SkyFogTest.unity.meta
  19. 9
      ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky.meta
  20. 10
      ScriptableRenderPipeline/HDRenderPipeline/Sky/Editor.meta
  21. 313
      ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Resources/ProceduralSky.shader
  22. 9
      ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Resources/ProceduralSky.shader.meta
  23. 21
      SampleScenes/HDTest/SkyFogTest/SkyFogHDRISky.asset
  24. 10
      SampleScenes/HDTest/SkyFogTest/SkyFogHDRISky.asset.meta
  25. 26
      SampleScenes/HDTest/SkyFogTest/SkyFogProceduralSky.asset
  26. 10
      SampleScenes/HDTest/SkyFogTest/SkyFogProceduralSky.asset.meta
  27. 177
      ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/BlacksmithSkyRenderer.cs
  28. 12
      ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/BlacksmithSkyRenderer.cs.meta
  29. 165
      ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/BlacksmithSkySettings.cs
  30. 12
      ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/BlacksmithSkySettings.cs.meta
  31. 9
      ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/Editor.meta
  32. 155
      ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/Editor/BlacksmithSkyEditor.cs
  33. 12
      ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/Editor/BlacksmithSkyEditor.cs.meta
  34. 9
      ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/Resources.meta
  35. 55
      ScriptableRenderPipeline/HDRenderPipeline/Sky/Editor/SkySettingsEditor.cs
  36. 13
      ScriptableRenderPipeline/HDRenderPipeline/Sky/Editor/SkySettingsEditor.cs.meta
  37. 0
      /ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/Resources/SkyBlacksmith.shader.meta
  38. 0
      /ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/Resources/AtmosphericScattering.hlsl.meta
  39. 0
      /ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/Resources/AtmosphericScattering.hlsl
  40. 0
      /ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/Resources/SkyBlacksmith.shader

35
ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs


class DoCreateNewAssetSSSProfile : DoCreateNewAsset<SubsurfaceScatteringProfile> {}
class DoCreateNewAssetCommonSettings : DoCreateNewAsset<CommonSettings> {}
class DoCreateNewAssetHDRISkySettings : DoCreateNewAsset<HDRISkySettings> {}
class DoCreateNewAssetBlacksmithSkySettings : DoCreateNewAsset<BlacksmithSkySettings> {}
[MenuItem("Assets/Create/HDRenderPipeline/Subsurface Scattering Profile", priority = 666)]
static void MenuCreateSubsurfaceScatteringProfile()
[MenuItem("Assets/Create/HDRenderPipeline/Common Settings", priority = 700)]
static void MenuCreateCommonSettings()
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateNewAssetSSSProfile>(), "New SSS Profile.asset", icon, null);
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateNewAssetCommonSettings>(), "New CommonSettings.asset", icon, null);
[MenuItem("Assets/Create/HDRenderPipeline/Common Settings", priority = 677)]
static void MenuCreateCommonSettings()
[MenuItem("Assets/Create/HDRenderPipeline/Ambient Occlusion Settings", priority = 701)]
static void MenuCreateSSAOSettings()
{
var icon = EditorGUIUtility.FindTexture("ScriptableObject Icon");
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateNewAssetSSAOSettings>(), "New AmbientOcclusionSettings.asset", icon, null);
}
[MenuItem("Assets/Create/HDRenderPipeline/Subsurface Scattering Profile", priority = 702)]
static void MenuCreateSubsurfaceScatteringProfile()
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateNewAssetCommonSettings>(), "New CommonSettings.asset", icon, null);
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateNewAssetSSSProfile>(), "New SSS Profile.asset", icon, null);
[MenuItem("Assets/Create/HDRenderPipeline/HDRISky Settings", priority = 678)]
[MenuItem("Assets/Create/HDRenderPipeline/HDRISky Settings", priority = 750)]
static void MenuCreateHDRISkySettings()
{
var icon = EditorGUIUtility.FindTexture("ScriptableObject Icon");

[MenuItem("Assets/Create/HDRenderPipeline/ProceduralSky Settings", priority = 679)]
static void MenuCreateProceduralSkySettings()
[MenuItem("Assets/Create/HDRenderPipeline/BlacksmithSky Settings", priority = 751)]
static void MenuCreateBlacksmithSkySettings()
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateNewAssetProceduralSkySettings>(), "New ProceduralSkySettings.asset", icon, null);
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateNewAssetBlacksmithSkySettings>(), "New BlacksmithSkySettings.asset", icon, null);
[MenuItem("Assets/Create/HDRenderPipeline/Ambient Occlusion Settings", priority = 680)]
static void MenuCreateSSAOSettings()
[MenuItem("Assets/Create/HDRenderPipeline/ProceduralSky Settings", priority = 752)]
static void MenuCreateProceduralSkySettings()
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateNewAssetSSAOSettings>(), "New AmbientOcclusionSettings.asset", icon, null);
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateNewAssetProceduralSkySettings>(), "New ProceduralSkySettings.asset", icon, null);
}
}

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


{
[CanEditMultipleObjects]
[CustomEditor(typeof(HDRISkySettings))]
public class HDRISkyParametersEditor
: Editor
public class HDRISkySettingsEditor
: SkySettingsEditor
public readonly GUIContent skyResolution = new GUIContent("Resolution", "Resolution of the environment lighting generated from the sky.");
public readonly GUIContent skyExposure = new GUIContent("Exposure", "Exposure of the sky in EV.");
public readonly GUIContent skyRotation = new GUIContent("Rotation", "Rotation of the sky.");
public readonly GUIContent skyMultiplier = new GUIContent("Multiplier", "Intensity multiplier for the sky.");
public readonly GUIContent environmentUpdateMode = new GUIContent("Environment Update Mode", "Specify how the environment lighting should be updated.");
public 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 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.");
}
private static Styles s_Styles = null;

}
private SerializedProperty m_SkyHDRI;
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;
base.OnEnable();
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");
}
public override void OnInspectorGUI()

EditorGUILayout.PropertyField(m_SkyHDRI, styles.skyHDRI);
EditorGUILayout.PropertyField(m_SkyResolution, styles.skyResolution);
EditorGUILayout.PropertyField(m_SkyExposure, styles.skyExposure);
EditorGUILayout.PropertyField(m_SkyMultiplier, styles.skyMultiplier);
EditorGUILayout.PropertyField(m_SkyRotation, styles.skyRotation);
EditorGUILayout.PropertyField(m_EnvUpdateMode, styles.environmentUpdateMode);
if (!m_EnvUpdateMode.hasMultipleDifferentValues && m_EnvUpdateMode.intValue == (int)EnvironementUpdateMode.Realtime)
{
EditorGUILayout.PropertyField(m_EnvUpdatePeriod, styles.environmentUpdatePeriod);
}
EditorGUILayout.PropertyField(m_LightingOverride, styles.lightingOverride);
EditorGUILayout.Space();
base.CommonSkySettingsGUI();
serializedObject.ApplyModifiedProperties();
}

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


}
}
public override void RenderSky(BuiltinSkyParameters builtinParams, SkySettings skyParameters, bool renderForCubemap)
public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderForCubemap)
{
m_SkyHDRIMaterial.SetTexture(HDShaderIDs._Cubemap, m_HdriSkyParams.skyHDRI);
m_SkyHDRIMaterial.SetVector(HDShaderIDs._SkyParam, new Vector4(m_HdriSkyParams.exposure, m_HdriSkyParams.multiplier, m_HdriSkyParams.rotation, 0.0f));

4
ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky.meta


fileFormatVersion: 2
guid: 65f9231eb40b6914eb24ea0b555778f0
guid: 3b82dc4603e0dc94a8845a0e0b716046
timeCreated: 1481646017
timeCreated: 1481626018
licenseType: Pro
DefaultImporter:
userData:

4
ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Editor.meta


fileFormatVersion: 2
guid: 00372bf7f144a724bba68a081fd79e78
guid: b0f1613f908d934488f326668e5ab334
timeCreated: 1481646149
timeCreated: 1481635912
licenseType: Pro
DefaultImporter:
userData:

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


{
[CanEditMultipleObjects]
[CustomEditor(typeof(ProceduralSkySettings))]
public class ProceduralSkySettingsEditor : Editor
public class ProceduralSkySettingsEditor
: SkySettingsEditor
private float heightFogHeight = 0.0f;
public readonly GUIContent skyHDRI = new GUIContent("HDRI");
public readonly GUIContent skyResolution = new GUIContent("Resolution");
public readonly GUIContent skyExposure = new GUIContent("Exposure");
public readonly GUIContent skyRotation = new GUIContent("Rotation");
public readonly GUIContent skyMultiplier = new GUIContent("Multiplier");
public 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.");
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");
}
private static Styles s_Styles = null;

}
}
private SerializedProperty m_SkyHDRI;
private SerializedProperty m_SkyResolution;
private SerializedProperty m_SkyExposure;
private SerializedProperty m_SkyMultiplier;
private SerializedProperty m_SkyRotation;
private SerializedProperty m_LightingOverride;
private SerializedProperty m_updateMode;
private SerializedProperty m_updatePeriod;
private SerializedProperty m_worldScaleExponent;
private SerializedProperty m_maxSkyDistance;
private SerializedProperty m_worldMieColorIntensity;
private SerializedProperty m_worldMieColorRamp;
private SerializedProperty m_worldMieDensity;
private SerializedProperty m_worldMieNearScatterPush;
private SerializedProperty m_worldMiePhaseAnisotropy;
private SerializedProperty m_worldRayleighColorIntensity;
private SerializedProperty m_worldRayleighColorRamp;
private SerializedProperty m_worldRayleighDensity;
private SerializedProperty m_worldRayleighNearScatterPush;
private SerializedProperty m_heightSeaLevel;
private SerializedProperty m_heightDistance;
private SerializedProperty m_heightMieDensity;
private SerializedProperty m_heightMieNearScatterPush;
private SerializedProperty m_heightRayleighColor;
private SerializedProperty m_heightRayleighDensity;
private SerializedProperty m_heightRayleighIntensity;
private SerializedProperty m_heightRayleighNearScatterPush;
private SerializedProperty m_SunSize;
private SerializedProperty m_SunSizeConvergence;
private SerializedProperty m_AtmosphericThickness;
private SerializedProperty m_SkyTint;
private SerializedProperty m_GroundColor;
private SerializedProperty m_EnableSunDisk;
m_SkyHDRI = serializedObject.FindProperty("skyHDRI");
m_SkyResolution = serializedObject.FindProperty("resolution");
m_SkyExposure = serializedObject.FindProperty("exposure");
m_SkyMultiplier = serializedObject.FindProperty("multiplier");
m_SkyRotation = serializedObject.FindProperty("rotation");
m_updateMode = serializedObject.FindProperty("updateMode");
m_updatePeriod = serializedObject.FindProperty("updatePeriod");
m_LightingOverride = serializedObject.FindProperty("lightingOverride");
m_maxSkyDistance = serializedObject.FindProperty("maxSkyDistance");
m_worldScaleExponent = serializedObject.FindProperty("worldScaleExponent");
m_worldMieColorIntensity = serializedObject.FindProperty("worldMieColorIntensity");
m_worldMieColorRamp = serializedObject.FindProperty("worldMieColorRamp");
m_worldMieDensity = serializedObject.FindProperty("worldMieDensity");
m_worldMieNearScatterPush = serializedObject.FindProperty("worldMieNearScatterPush");
m_worldMiePhaseAnisotropy = serializedObject.FindProperty("worldMiePhaseAnisotropy");
m_worldRayleighColorIntensity = serializedObject.FindProperty("worldRayleighColorIntensity");
m_worldRayleighColorRamp = serializedObject.FindProperty("worldRayleighColorRamp");
m_worldRayleighDensity = serializedObject.FindProperty("worldRayleighDensity");
m_worldRayleighNearScatterPush = serializedObject.FindProperty("worldRayleighNearScatterPush");
m_heightSeaLevel = serializedObject.FindProperty("heightSeaLevel");
m_heightDistance = serializedObject.FindProperty("heightDistance");
m_heightMieDensity = serializedObject.FindProperty("heightMieDensity");
m_heightMieNearScatterPush = serializedObject.FindProperty("heightMieNearScatterPush");
m_heightRayleighColor = serializedObject.FindProperty("heightRayleighColor");
m_heightRayleighDensity = serializedObject.FindProperty("heightRayleighDensity");
m_heightRayleighIntensity = serializedObject.FindProperty("heightRayleighIntensity");
m_heightRayleighNearScatterPush = serializedObject.FindProperty("heightRayleighNearScatterPush");
base.OnEnable();
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");
}
public override void OnInspectorGUI()

EditorGUILayout.LabelField(new GUIContent("Skydome"), EditorStyles.boldLabel);
EditorGUILayout.PropertyField(m_SkyHDRI, styles.skyHDRI);
EditorGUILayout.PropertyField(m_SkyResolution, styles.skyResolution);
EditorGUILayout.PropertyField(m_SkyExposure, styles.skyExposure);
EditorGUILayout.PropertyField(m_SkyMultiplier, styles.skyMultiplier);
EditorGUILayout.PropertyField(m_SkyRotation, styles.skyRotation);
EditorGUILayout.PropertyField(m_updateMode);
EditorGUILayout.PropertyField(m_updatePeriod);
EditorGUILayout.PropertyField(m_LightingOverride, styles.lightingOverride);
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);
EditorGUILayout.LabelField(new GUIContent("Atmosphere"), EditorStyles.boldLabel);
EditorGUILayout.PropertyField(m_worldMieDensity, new GUIContent("Density"));
m_worldRayleighDensity.floatValue = m_worldMieDensity.floatValue;
EditorGUILayout.PropertyField(m_worldScaleExponent, new GUIContent("Global scale"));
EditorGUILayout.PropertyField(m_maxSkyDistance, new GUIContent("Sky distance"));
EditorGUILayout.Space();
EditorGUILayout.PropertyField(m_worldMieColorRamp);
EditorGUILayout.PropertyField(m_worldMieColorIntensity);
EditorGUILayout.PropertyField(m_worldMieNearScatterPush);
EditorGUILayout.PropertyField(m_worldMiePhaseAnisotropy);
EditorGUILayout.Space();
EditorGUILayout.PropertyField(m_worldRayleighColorRamp);
EditorGUILayout.PropertyField(m_worldRayleighColorIntensity);
//EditorGUILayout.PropertyField(m_worldRayleighDensity);
EditorGUILayout.PropertyField(m_worldRayleighNearScatterPush);
EditorGUILayout.Space();
EditorGUILayout.LabelField(new GUIContent("Height fog"), EditorStyles.boldLabel);
heightFogHeight = EditorGUILayout.FloatField(new GUIContent("Height"), heightFogHeight);
EditorGUILayout.PropertyField(m_heightDistance, new GUIContent("Falloff"));
m_heightSeaLevel.floatValue = heightFogHeight + m_heightDistance.floatValue * 2.0f - 2.0f;
EditorGUILayout.PropertyField(m_heightMieDensity, new GUIContent("Density"));
m_heightRayleighDensity.floatValue = m_heightMieDensity.floatValue;
EditorGUILayout.PropertyField(m_heightMieNearScatterPush);
EditorGUILayout.PropertyField(m_heightRayleighColor);
//EditorGUILayout.PropertyField(m_heightRayleighDensity);
EditorGUILayout.PropertyField(m_heightRayleighIntensity);
EditorGUILayout.PropertyField(m_heightRayleighNearScatterPush);
//base.DrawDefaultInspector();
base.CommonSkySettingsGUI();
serializedObject.ApplyModifiedProperties();
}

2
ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Editor/ProceduralSkyEditor.cs.meta


fileFormatVersion: 2
guid: 40b56ef8d02cefa49ab82e6b7df9266b
guid: c0dee295943199545a69be3662dc5d1b
timeCreated: 1481635925
licenseType: Pro
MonoImporter:

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


{
public class ProceduralSkyRenderer : SkyRenderer
{
Material m_ProceduralSkyMaterial = null; // Renders a cubemap into a render texture (can be cube or 2D)
private ProceduralSkySettings m_ProceduralSkySettings;
Material m_SkyProceduralMaterial;
MaterialPropertyBlock m_PropertyBlock;
ProceduralSkySettings m_ProceduralSkyParams;
readonly int _SunSizeParam = Shader.PropertyToID("_SunSize");
readonly int _SunSizeConvergenceParam = Shader.PropertyToID("_SunSizeConvergence");
readonly int _AtmoshpereThicknessParam = Shader.PropertyToID("_AtmosphereThickness");
readonly int _SkyTintParam = Shader.PropertyToID("_SkyTint");
readonly int _GroundColorParam = Shader.PropertyToID("_GroundColor");
readonly int _SunColorParam = Shader.PropertyToID("_SunColor");
readonly int _SunDirectionParam = Shader.PropertyToID("_SunDirection");
public ProceduralSkyRenderer(ProceduralSkySettings proceduralSkySettings)
public ProceduralSkyRenderer(ProceduralSkySettings proceduralSkyParams)
m_ProceduralSkySettings = proceduralSkySettings;
m_ProceduralSkyParams = proceduralSkyParams;
m_PropertyBlock = new MaterialPropertyBlock();
m_ProceduralSkyMaterial = CoreUtils.CreateEngineMaterial("Hidden/HDRenderPipeline/Sky/SkyProcedural");
m_SkyProceduralMaterial = CoreUtils.CreateEngineMaterial("Hidden/HDRenderPipeline/Sky/SkyProcedural");
CoreUtils.Destroy(m_ProceduralSkyMaterial);
}
public override bool IsSkyValid()
{
if (m_ProceduralSkyMaterial == null || m_ProceduralSkySettings == null)
return false;
return m_ProceduralSkySettings.skyHDRI != null &&
m_ProceduralSkySettings.worldMieColorRamp != null &&
m_ProceduralSkySettings.worldRayleighColorRamp != null;
CoreUtils.Destroy(m_SkyProceduralMaterial);
// We do not bind the depth buffer as a depth-stencil target since it is
// bound as a color texture which is then sampled from within the shader.
CoreUtils.SetRenderTarget(builtinParams.commandBuffer, builtinParams.colorBuffer);
}
void SetKeywords(BuiltinSkyParameters builtinParams, ProceduralSkySettings param, bool renderForCubemap)
{
// Ensure that all preprocessor symbols are initially undefined.
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_PER_PIXEL");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_DEBUG");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_OCCLUSION");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_OCCLUSION_EDGE_FIXUP");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_OCCLUSION_FULLSKY");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_SUNRAYS");
m_ProceduralSkyMaterial.DisableKeyword("PERFORM_SKY_OCCLUSION_TEST");
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_PER_PIXEL");
/*
if (useOcclusion)
if (builtinParams.depthBuffer == BuiltinSkyParameters.nullRT)
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_OCCLUSION");
if(occlusionDepthFixup && occlusionDownscale != OcclusionDownscale.x1)
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_OCCLUSION_EDGE_FIXUP");
if(occlusionFullSky)
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_OCCLUSION_FULLSKY");
CoreUtils.SetRenderTarget(builtinParams.commandBuffer, builtinParams.colorBuffer);
*/
// Expected to be valid for the sky pass, and invalid for the cube map generation pass.
if (!renderForCubemap)
else
m_ProceduralSkyMaterial.EnableKeyword("PERFORM_SKY_OCCLUSION_TEST");
}
if (param.debugMode != ProceduralSkySettings.ScatterDebugMode.None)
{
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_DEBUG");
CoreUtils.SetRenderTarget(builtinParams.commandBuffer, builtinParams.colorBuffer, builtinParams.depthBuffer);
void SetUniforms(BuiltinSkyParameters builtinParams, ProceduralSkySettings param, bool renderForCubemap, ref MaterialPropertyBlock properties)
public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderForCubemap)
properties.SetTexture("_Cubemap", param.skyHDRI);
properties.SetVector("_SkyParam", new Vector4(param.exposure, param.multiplier, param.rotation, 0.0f));
properties.SetMatrix("_InvViewProjMatrix", builtinParams.invViewProjMatrix);
properties.SetVector("_CameraPosWS", builtinParams.cameraPosWS);
properties.SetVector("_ScreenSize", builtinParams.screenSize);
m_ProceduralSkyMaterial.SetInt("_AtmosphericsDebugMode", (int)param.debugMode);
Vector3 sunDirection = (builtinParams.sunLight != null) ? -builtinParams.sunLight.transform.forward : Vector3.zero;
m_ProceduralSkyMaterial.SetVector("_SunDirection", sunDirection);
var pixelRect = new Rect(0f, 0f, builtinParams.screenSize.x, builtinParams.screenSize.y);
var scale = 1.0f; //(float)(int)occlusionDownscale;
var depthTextureScaledTexelSize = new Vector4(scale / pixelRect.width,
scale / pixelRect.height,
-scale / pixelRect.width,
-scale / pixelRect.height);
properties.SetVector("_DepthTextureScaledTexelSize", depthTextureScaledTexelSize);
CoreUtils.SetKeyword(m_SkyProceduralMaterial, "_ENABLE_SUN_DISK", m_ProceduralSkyParams.enableSunDisk);
/*
m_ProceduralSkyMaterial.SetFloat("_ShadowBias", useOcclusion ? occlusionBias : 1f);
m_ProceduralSkyMaterial.SetFloat("_ShadowBiasIndirect", useOcclusion ? occlusionBiasIndirect : 1f);
m_ProceduralSkyMaterial.SetFloat("_ShadowBiasClouds", useOcclusion ? occlusionBiasClouds : 1f);
m_ProceduralSkyMaterial.SetVector("_ShadowBiasSkyRayleighMie", useOcclusion ? new Vector4(occlusionBiasSkyRayleigh, occlusionBiasSkyMie, 0f, 0f) : Vector4.zero);
m_ProceduralSkyMaterial.SetFloat("_OcclusionDepthThreshold", occlusionDepthThreshold);
m_ProceduralSkyMaterial.SetVector("_OcclusionTexture_TexelSize", ???);
*/
m_ProceduralSkyMaterial.SetFloat("_WorldScaleExponent", param.worldScaleExponent);
m_ProceduralSkyMaterial.SetFloat("_WorldNormalDistanceRcp", 1f / param.worldNormalDistance);
m_ProceduralSkyMaterial.SetFloat("_WorldMieNearScatterPush", -Mathf.Pow(Mathf.Abs(param.worldMieNearScatterPush), param.worldScaleExponent) * Mathf.Sign(param.worldMieNearScatterPush));
m_ProceduralSkyMaterial.SetFloat("_WorldRayleighNearScatterPush", -Mathf.Pow(Mathf.Abs(param.worldRayleighNearScatterPush), param.worldScaleExponent) * Mathf.Sign(param.worldRayleighNearScatterPush));
m_ProceduralSkyMaterial.SetFloat("_WorldRayleighDensity", -param.worldRayleighDensity / 100000f);
m_ProceduralSkyMaterial.SetFloat("_WorldMieDensity", -param.worldMieDensity / 100000f);
m_ProceduralSkyMaterial.SetFloat("_SkyDepth", 1.0f / param.maxSkyDistance);
Color sunColor = Color.white;
Vector3 sunDirection = Vector3.zero;
if(builtinParams.sunLight != null)
{
sunColor = builtinParams.sunLight.color * builtinParams.sunLight.intensity;
sunDirection = -builtinParams.sunLight.transform.forward;
}
var rayleighColorM20 = param.worldRayleighColorRamp.Evaluate(0.00f);
var rayleighColorM10 = param.worldRayleighColorRamp.Evaluate(0.25f);
var rayleighColorO00 = param.worldRayleighColorRamp.Evaluate(0.50f);
var rayleighColorP10 = param.worldRayleighColorRamp.Evaluate(0.75f);
var rayleighColorP20 = param.worldRayleighColorRamp.Evaluate(1.00f);
m_SkyProceduralMaterial.SetVector(HDShaderIDs._SkyParam, new Vector4(m_ProceduralSkyParams.exposure, m_ProceduralSkyParams.multiplier, m_ProceduralSkyParams.rotation, 0.0f));
m_SkyProceduralMaterial.SetFloat(_SunSizeParam, m_ProceduralSkyParams.sunSize);
m_SkyProceduralMaterial.SetFloat(_SunSizeConvergenceParam, m_ProceduralSkyParams.sunSizeConvergence);
m_SkyProceduralMaterial.SetFloat(_AtmoshpereThicknessParam, m_ProceduralSkyParams.atmosphereThickness);
m_SkyProceduralMaterial.SetColor(_SkyTintParam, m_ProceduralSkyParams.skyTint);
m_SkyProceduralMaterial.SetColor(_GroundColorParam, m_ProceduralSkyParams.groundColor);
m_SkyProceduralMaterial.SetColor(_SunColorParam, sunColor);
m_SkyProceduralMaterial.SetVector(_SunDirectionParam, sunDirection);
var mieColorM20 = param.worldMieColorRamp.Evaluate(0.00f);
var mieColorO00 = param.worldMieColorRamp.Evaluate(0.50f);
var mieColorP20 = param.worldMieColorRamp.Evaluate(1.00f);
// This matrix needs to be updated at the draw call frequency.
m_PropertyBlock.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, builtinParams.pixelCoordToViewDirMatrix);
m_ProceduralSkyMaterial.SetVector("_RayleighColorM20", (Vector4)rayleighColorM20 * param.worldRayleighColorIntensity);
m_ProceduralSkyMaterial.SetVector("_RayleighColorM10", (Vector4)rayleighColorM10 * param.worldRayleighColorIntensity);
m_ProceduralSkyMaterial.SetVector("_RayleighColorO00", (Vector4)rayleighColorO00 * param.worldRayleighColorIntensity);
m_ProceduralSkyMaterial.SetVector("_RayleighColorP10", (Vector4)rayleighColorP10 * param.worldRayleighColorIntensity);
m_ProceduralSkyMaterial.SetVector("_RayleighColorP20", (Vector4)rayleighColorP20 * param.worldRayleighColorIntensity);
m_ProceduralSkyMaterial.SetVector("_MieColorM20", (Vector4)mieColorM20 * param.worldMieColorIntensity);
m_ProceduralSkyMaterial.SetVector("_MieColorO00", (Vector4)mieColorO00 * param.worldMieColorIntensity);
m_ProceduralSkyMaterial.SetVector("_MieColorP20", (Vector4)mieColorP20 * param.worldMieColorIntensity);
m_ProceduralSkyMaterial.SetFloat("_HeightNormalDistanceRcp", 1f / param.heightNormalDistance);
m_ProceduralSkyMaterial.SetFloat("_HeightMieNearScatterPush", -Mathf.Pow(Mathf.Abs(param.heightMieNearScatterPush), param.worldScaleExponent) * Mathf.Sign(param.heightMieNearScatterPush));
m_ProceduralSkyMaterial.SetFloat("_HeightRayleighNearScatterPush", -Mathf.Pow(Mathf.Abs(param.heightRayleighNearScatterPush), param.worldScaleExponent) * Mathf.Sign(param.heightRayleighNearScatterPush));
// m_ProceduralSkyMaterial.SetFloat("_HeightRayleighDensity", -param.heightRayleighDensity / 100000f);
// m_ProceduralSkyMaterial.SetFloat("_HeightMieDensity", -param.heightMieDensity / 100000f);
m_ProceduralSkyMaterial.SetFloat("_HeightSeaLevel", param.heightSeaLevel);
m_ProceduralSkyMaterial.SetVector("_HeightPlaneShift", param.heightPlaneShift);
m_ProceduralSkyMaterial.SetFloat("_HeightDistanceRcp", 1f / param.heightDistance);
m_ProceduralSkyMaterial.SetVector("_HeightRayleighColor", (Vector4)param.heightRayleighColor * param.heightRayleighIntensity);
m_ProceduralSkyMaterial.SetFloat("_HeightExtinctionFactor", param.heightExtinctionFactor);
m_ProceduralSkyMaterial.SetVector("_RayleighInScatterPct", new Vector4(1f - param.worldRayleighIndirectScatter, param.worldRayleighIndirectScatter, 0f, 0f));
m_ProceduralSkyMaterial.SetFloat("_RayleighExtinctionFactor", param.worldRayleighExtinctionFactor);
m_ProceduralSkyMaterial.SetFloat("_MiePhaseAnisotropy", param.worldMiePhaseAnisotropy);
m_ProceduralSkyMaterial.SetFloat("_MieExtinctionFactor", param.worldMieExtinctionFactor);
// Since we use the material for rendering the sky both into the cubemap, and
// during the fullscreen pass, setting the 'PERFORM_SKY_OCCLUSION_TEST' keyword has no effect.
properties.SetFloat("_DisableSkyOcclusionTest", renderForCubemap ? 1.0f : 0.0f);
// We do not render the height fog into the sky IBL cubemap.
properties.SetFloat("_HeightRayleighDensity", renderForCubemap ? -0.0f : -param.heightRayleighDensity / 100000f);
properties.SetFloat("_HeightMieDensity", renderForCubemap ? -0.0f : -param.heightMieDensity / 100000f);
properties.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, builtinParams.pixelCoordToViewDirMatrix);
CoreUtils.DrawFullScreen(builtinParams.commandBuffer, m_SkyProceduralMaterial, m_PropertyBlock, renderForCubemap ? 0 : 1);
override public void RenderSky(BuiltinSkyParameters builtinParams, SkySettings skyParameters, bool renderForCubemap)
public override bool IsSkyValid()
MaterialPropertyBlock properties = new MaterialPropertyBlock();
// Define select preprocessor symbols.
SetKeywords(builtinParams, m_ProceduralSkySettings, renderForCubemap);
// Set shader constants.
SetUniforms(builtinParams, m_ProceduralSkySettings, renderForCubemap, ref properties);
CoreUtils.DrawFullScreen(builtinParams.commandBuffer, m_ProceduralSkyMaterial, properties);
return true;
}
}
}

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


fileFormatVersion: 2
guid: 476423447c1989948a128fc0a0b27413
guid: 2b673ee33719b0d47bdddf170bc4e3ff
timeCreated: 1481631774
licenseType: Pro
MonoImporter:

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


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[ExecuteInEditMode]
public enum OcclusionDownscale { x1 = 1, x2 = 2, x4 = 4 }
public enum OcclusionSamples { x64 = 0, x164 = 1, x244 = 2 }
public enum ScatterDebugMode { None, Scattering, Occlusion, OccludedScattering, Rayleigh, Mie, Height }
[Header("Global Settings")]
public float worldMieColorIntensity = 1f;
public Gradient worldMieColorRamp = null;
public float worldMieDensity = 15f;
public float worldMieExtinctionFactor = 0f;
public float worldMieNearScatterPush = 0f;
public float worldMiePhaseAnisotropy = 0.9f;
public float worldNormalDistance = 1000f;
public float worldRayleighColorIntensity = 1f;
public Gradient worldRayleighColorRamp = null;
public float worldRayleighDensity = 10f;
public float worldRayleighExtinctionFactor = 1.1f;
public float worldRayleighIndirectScatter = 0.33f;
public float worldRayleighNearScatterPush = 0f;
[Header("Height Settings")]
public float heightDistance = 50f;
public float heightExtinctionFactor = 1.1f;
public float heightMieDensity = 0f;
public float heightMieNearScatterPush = 0f;
public float heightNormalDistance = 1000f;
public Vector3 heightPlaneShift = Vector3.zero;
public Color heightRayleighColor = Color.white;
public float heightRayleighDensity = 10f;
public float heightRayleighIntensity = 1f;
public float heightRayleighNearScatterPush = 0f;
public float heightSeaLevel = 0f;
/*
[Header("Scatter Occlusion")]
public bool useOcclusion = false;
public bool occlusionFullSky = false;
public bool occlusionDepthFixup = true;
public float occlusionBias = 0f;
public float occlusionBiasClouds = 0.3f;
public float occlusionBiasIndirect = 0.6f;
public float occlusionBiasSkyMie = 0.4f;
public float occlusionBiasSkyRayleigh = 0.2f;
public float occlusionDepthThreshold = 25f;
public OcclusionDownscale occlusionDownscale = OcclusionDownscale.x2;
public OcclusionSamples occlusionSamples = OcclusionSamples.x64;
*/
[Header("Other")]
public Cubemap skyHDRI = null;
// public Shader atmosphericShader = null;
// public Shader occlusionShader = null;
public float worldScaleExponent = 1.0f;
public float maxSkyDistance = 4000.0f;
public ScatterDebugMode debugMode = ScatterDebugMode.None;
// Camera m_currentCamera;
// UnityEngine.Rendering.CommandBuffer m_occlusionCmdAfterShadows, m_occlusionCmdBeforeScreen;
void Awake()
{
if (worldRayleighColorRamp == null)
{
worldRayleighColorRamp = new Gradient();
worldRayleighColorRamp.SetKeys(
new[] { new GradientColorKey(new Color(0.3f, 0.4f, 0.6f), 0f),
new GradientColorKey(new Color(0.5f, 0.6f, 0.8f), 1f) },
new[] { new GradientAlphaKey(1f, 0f),
new GradientAlphaKey(1f, 1f) }
);
}
if (worldMieColorRamp == null)
{
worldMieColorRamp = new Gradient();
worldMieColorRamp.SetKeys(
new[] { new GradientColorKey(new Color(0.95f, 0.75f, 0.5f), 0f),
new GradientColorKey(new Color(1f, 0.9f, 8.0f), 1f) },
new[] { new GradientAlphaKey(1f, 0f),
new GradientAlphaKey(1f, 1f) }
);
}
}
public void OnValidate()
{
worldMieDensity = Mathf.Clamp(worldMieDensity, 0f, 1000f);
worldMiePhaseAnisotropy = Mathf.Clamp01(worldMiePhaseAnisotropy);
worldMieNearScatterPush = Mathf.Clamp(worldMieNearScatterPush, -200f, 300f);
worldNormalDistance = Mathf.Clamp(worldNormalDistance, 1f, 10000f);
worldRayleighDensity = Mathf.Clamp(worldRayleighDensity, 0, 1000f);
worldRayleighIndirectScatter = Mathf.Clamp(worldRayleighIndirectScatter, 0f, 1f);
worldRayleighNearScatterPush = Mathf.Clamp(worldRayleighNearScatterPush, -200f, 300f);
heightMieDensity = Mathf.Clamp(heightMieDensity, 0, 1000f);
heightMieNearScatterPush = Mathf.Clamp(heightMieNearScatterPush, -200f, 300f);
heightNormalDistance = Mathf.Clamp(heightNormalDistance, 1f, 10000f);
heightRayleighDensity = Mathf.Clamp(heightRayleighDensity, 0, 1000f);
heightRayleighNearScatterPush = Mathf.Clamp(heightRayleighNearScatterPush, -200f, 300f);
worldScaleExponent = Mathf.Clamp(worldScaleExponent, 1f, 2f);
maxSkyDistance = Mathf.Clamp(maxSkyDistance, 1.0f, 1000000.0f);
/*
occlusionBias = Mathf.Clamp01(occlusionBias);
occlusionBiasClouds = Mathf.Clamp01(occlusionBiasClouds);
occlusionBiasIndirect = Mathf.Clamp01(occlusionBiasIndirect);
occlusionBiasSkyMie = Mathf.Clamp01(occlusionBiasSkyMie);
occlusionBiasSkyRayleigh = Mathf.Clamp01(occlusionBiasSkyRayleigh);
*/
}
[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()
{

unchecked
{
hash = hash * 23 + worldMieColorIntensity.GetHashCode();
hash = worldMieColorRamp != null ? hash * 23 + worldMieColorRamp.GetHashCode() : hash;
hash = hash * 23 + worldMieDensity.GetHashCode();
hash = hash * 23 + worldMieExtinctionFactor.GetHashCode();
hash = hash * 23 + worldMieNearScatterPush.GetHashCode();
hash = hash * 23 + worldMiePhaseAnisotropy.GetHashCode();
hash = hash * 23 + worldNormalDistance.GetHashCode();
hash = hash * 23 + worldRayleighColorIntensity.GetHashCode();
hash = worldRayleighColorRamp != null ? hash * 23 + worldRayleighColorRamp.GetHashCode() : hash;
hash = hash * 23 + worldRayleighDensity.GetHashCode();
hash = hash * 23 + worldRayleighExtinctionFactor.GetHashCode();
hash = hash * 23 + worldRayleighIndirectScatter.GetHashCode();
hash = hash * 23 + worldRayleighNearScatterPush.GetHashCode();
hash = hash * 23 + heightDistance.GetHashCode();
hash = hash * 23 + heightExtinctionFactor.GetHashCode();
hash = hash * 23 + heightMieDensity.GetHashCode();
hash = hash * 23 + heightMieNearScatterPush.GetHashCode();
hash = hash * 23 + heightNormalDistance.GetHashCode();
hash = hash * 23 + heightPlaneShift.GetHashCode();
hash = hash * 23 + heightRayleighColor.GetHashCode();
hash = hash * 23 + heightRayleighDensity.GetHashCode();
hash = hash * 23 + heightRayleighIntensity.GetHashCode();
hash = hash * 23 + heightRayleighNearScatterPush.GetHashCode();
hash = hash * 23 + heightSeaLevel.GetHashCode();
hash = skyHDRI != null ? hash * 23 + skyHDRI.GetHashCode() : hash;
hash = hash * 23 + worldScaleExponent.GetHashCode();
hash = hash * 23 + maxSkyDistance.GetHashCode();
hash = hash * 23 + debugMode.GetHashCode();
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;

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


fileFormatVersion: 2
guid: 54bcd1d5cb4984847971142e9444d2fb
guid: 3df29e7cc05fbec4aa43e06ea875565d
timeCreated: 1481631764
licenseType: Pro
MonoImporter:

4
ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Resources.meta


fileFormatVersion: 2
guid: 455c6cbc5c8be404c8ed6ff8b38d1155
guid: 3c4549341d53b5e479e9514d5b0e2a3b
timeCreated: 1481646141
timeCreated: 1481636169
licenseType: Pro
DefaultImporter:
userData:

4
ScriptableRenderPipeline/HDRenderPipeline/Sky/SkyManager.cs


builtinParams.depthBuffer = BuiltinSkyParameters.nullRT;
CoreUtils.SetRenderTarget(builtinParams.commandBuffer, target, ClearFlag.None, 0, (CubemapFace)i);
m_Renderer.RenderSky(builtinParams, skySettings, true);
m_Renderer.RenderSky(builtinParams, true);
}
// Generate mipmap for our cubemap

m_BuiltinParameters.depthBuffer = depthBuffer;
m_Renderer.SetRenderTargets(m_BuiltinParameters);
m_Renderer.RenderSky(m_BuiltinParameters, skySettings, false);
m_Renderer.RenderSky(m_BuiltinParameters, false);
}
}
}

2
ScriptableRenderPipeline/HDRenderPipeline/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, SkySettings skyParameters, bool renderForCubemap);
public abstract void RenderSky(BuiltinSkyParameters builtinParams, bool renderForCubemap);
public abstract bool IsSkyValid();
}
}

2
ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/Resources/SkyBlacksmith.shader


Shader "Hidden/HDRenderPipeline/Sky/SkyProcedural"
Shader "Hidden/HDRenderPipeline/Sky/SkyBlacksmith"
{
SubShader
{

10
SampleScenes/HDTest/SkyFogTest.meta


fileFormatVersion: 2
guid: 2154938a6af2f324990e61b493a65c15
folderAsset: yes
timeCreated: 1507624145
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

534
SampleScenes/HDTest/SkyFogTest.unity


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 8
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 0
m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1}
m_SkyboxMaterial: {fileID: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.18392481, g: 0.22375022, b: 0.3024745, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 11
m_GIWorkflowMode: 0
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_TemporalCoherenceThreshold: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 1
m_LightmapEditorSettings:
serializedVersion: 9
m_Resolution: 2
m_BakeResolution: 40
m_TextureWidth: 1024
m_TextureHeight: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_MixedBakeMode: 2
m_BakeBackend: 0
m_PVRSampling: 1
m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500
m_PVRBounces: 2
m_PVRFilterTypeDirect: 0
m_PVRFilterTypeIndirect: 0
m_PVRFilterTypeAO: 0
m_PVRFilteringMode: 1
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5
m_PVRFilteringGaussRadiusAO: 2
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
m_PVRFilteringAtrousPositionSigmaIndirect: 2
m_PVRFilteringAtrousPositionSigmaAO: 1
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
manualTileSize: 0
tileSize: 256
accuratePlacement: 0
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &60359362
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 60359364}
- component: {fileID: 60359363}
- component: {fileID: 60359366}
- component: {fileID: 60359365}
m_Layer: 0
m_Name: Directional Light
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!108 &60359363
Light:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 60359362}
m_Enabled: 1
serializedVersion: 8
m_Type: 1
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 1
m_Range: 10
m_SpotAngle: 30
m_CookieSize: 10
m_Shadows:
m_Type: 1
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 1
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_Lightmapping: 4
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &60359364
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 60359362}
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!114 &60359365
MonoBehaviour:
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 60359362}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c6c2871f720b2af4e9210febdac74517, type: 3}
m_Name:
m_EditorClassIdentifier:
shadowResolution: 1024
shadowDimmer: 1
shadowFadeDistance: 10000
shadowCascadeCount: 4
shadowCascadeRatios:
- 0.05
- 0.2
- 0.3
shadowCascadeBorders:
- 0.2
- 0.2
- 0.2
- 0.2
shadowAlgorithm: 0
shadowVariant: 0
shadowPrecision: 0
shadowData:
format: 0
data: 0bd7a33b0000803f
shadowDatas:
- format: 0
data: 0bd7a33b0000803f
--- !u!114 &60359366
MonoBehaviour:
m_ObjectHideFlags: 2
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 60359362}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7a68c43fe1f2a47cfa234b5eeaa98012, type: 3}
m_Name:
m_EditorClassIdentifier:
m_InnerSpotPercent: 0
lightDimmer: 1
fadeDistance: 10000
affectDiffuse: 1
affectSpecular: 1
lightTypeExtent: 0
spotLightShape: 0
shapeLength: 0.5
shapeWidth: 0.5
shapeRadius: 0
maxSmoothness: 1
applyRangeAttenuation: 1
useOldInspector: 0
featuresFoldout: 1
showAdditionalSettings: 1
--- !u!1 &142686423
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 142686427}
- component: {fileID: 142686426}
- component: {fileID: 142686425}
- component: {fileID: 142686424}
m_Layer: 0
m_Name: Sphere
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!23 &142686424
MeshRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 142686423}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 2100000, guid: 948836267934e104294e03adad5c7bf7, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!135 &142686425
SphereCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 142686423}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Radius: 0.5
m_Center: {x: 0, y: 0, z: 0}
--- !u!33 &142686426
MeshFilter:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 142686423}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &142686427
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 142686423}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1.336, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &185241297
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 185241299}
- component: {fileID: 185241298}
m_Layer: 0
m_Name: Scene Settings
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &185241298
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 185241297}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0e34c98127e05d340ba44a1d4a734454, type: 3}
m_Name:
m_EditorClassIdentifier:
m_CommonSettings: {fileID: 0}
m_SkySettings: {fileID: 11400000, guid: 7d119d7ec4e5e964d92d40232696fa43, type: 2}
m_SsaoSettings: {fileID: 0}
--- !u!4 &185241299
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 185241297}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1208684576
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1208684580}
- component: {fileID: 1208684579}
- component: {fileID: 1208684578}
- component: {fileID: 1208684577}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &1208684577
AudioListener:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1208684576}
m_Enabled: 1
--- !u!124 &1208684578
Behaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1208684576}
m_Enabled: 1
--- !u!20 &1208684579
Camera:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1208684576}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 0
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!4 &1208684580
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1208684576}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1664461187
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1664461191}
- component: {fileID: 1664461190}
- component: {fileID: 1664461189}
- component: {fileID: 1664461188}
m_Layer: 0
m_Name: Plane
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!23 &1664461188
MeshRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1664461187}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 2100000, guid: 948836267934e104294e03adad5c7bf7, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!64 &1664461189
MeshCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1664461187}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 3
m_Convex: 0
m_CookingOptions: 14
m_SkinWidth: 0.01
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!33 &1664461190
MeshFilter:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1664461187}
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &1664461191
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1664461187}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 50, y: 50, z: 50}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

9
SampleScenes/HDTest/SkyFogTest.unity.meta


fileFormatVersion: 2
guid: c8035f90c465bcc49b6a194bf4a62860
timeCreated: 1507624085
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

9
ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky.meta


fileFormatVersion: 2
guid: 65f9231eb40b6914eb24ea0b555778f0
folderAsset: yes
timeCreated: 1481646017
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

10
ScriptableRenderPipeline/HDRenderPipeline/Sky/Editor.meta


fileFormatVersion: 2
guid: 09f0f3359d1afd440a042038fa83eccb
folderAsset: yes
timeCreated: 1507627712
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

313
ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Resources/ProceduralSky.shader


// ==================================================================================================
// This shader is a copy of sky-procedural available in legacy Unity
// It's been ported to HDRP in order to have a basic procedural sky
// It has been left mostly untouched but has been adapted to run per-pixel instead of per vertex
// ==================================================================================================
Shader "Hidden/HDRenderPipeline/Sky/SkyProcedural"
{
HLSLINCLUDE
#pragma vertex Vert
#pragma fragment Frag
#pragma target 4.5
#pragma only_renderers d3d11 ps4 metal // TEMP: until we go further in dev
#pragma multi_compile _ _ENABLE_SUN_DISK
#include "../../../../Core/ShaderLibrary/Color.hlsl"
#include "../../../../Core/ShaderLibrary/Common.hlsl"
#include "../../../../Core/ShaderLibrary/CommonLighting.hlsl"
float4 _SkyParam; // x exposure, y multiplier, z rotation
float4x4 _PixelCoordToViewDirWS; // Actually just 3x3, but Unity can only set 4x4
float _SunSize;
float _SunSizeConvergence;
float _AtmosphereThickness;
float4 _SkyTint;
float4 _GroundColor;
float4 _SunColor;
float3 _SunDirection;
struct Attributes
{
uint vertexID : SV_VertexID;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
};
Varyings Vert(Attributes input)
{
Varyings output;
output.positionCS = GetFullScreenTriangleVertexPosition(input.vertexID, UNITY_RAW_FAR_CLIP_VALUE);
return output;
}
// RGB wavelengths
// .35 (.62=158), .43 (.68=174), .525 (.75=190)
static const float3 kDefaultScatteringWavelength = float3(.65, .57, .475);
static const float3 kVariableRangeForScatteringWavelength = float3(.15, .15, .15);
#define OUTER_RADIUS 1.025
static const float kOuterRadius = OUTER_RADIUS;
static const float kOuterRadius2 = OUTER_RADIUS*OUTER_RADIUS;
static const float kInnerRadius = 1.0;
static const float kInnerRadius2 = 1.0;
static const float kCameraHeight = 0.0001;
#define kRAYLEIGH (lerp(0.0, 0.0025, pow(_AtmosphereThickness,2.5))) // Rayleigh constant
#define kMIE 0.0010 // Mie constant
#define kSUN_BRIGHTNESS 20.0 // Sun brightness
#define kMAX_SCATTER 50.0 // Maximum scattering value, to prevent math overflows on Adrenos
static const float kHDSundiskIntensityFactor = 15.0;
static const float kSimpleSundiskIntensityFactor = 27.0;
static const float kSunScale = 400.0 * kSUN_BRIGHTNESS;
static const float kKmESun = kMIE * kSUN_BRIGHTNESS;
static const float kKm4PI = kMIE * 4.0 * 3.14159265;
static const float kScale = 1.0 / (OUTER_RADIUS - 1.0);
static const float kScaleDepth = 0.25;
static const float kScaleOverScaleDepth = (1.0 / (OUTER_RADIUS - 1.0)) / 0.25;
static const float kSamples = 2.0; // THIS IS UNROLLED MANUALLY, DON'T TOUCH
#define MIE_G (-0.990)
#define MIE_G2 0.9801
#define SKY_GROUND_THRESHOLD 0.02
// Calculates the Rayleigh phase function
float getRayleighPhase(float eyeCos2)
{
return 0.75 + 0.75*eyeCos2;
}
float getRayleighPhase(float3 light, float3 ray)
{
float eyeCos = dot(light, ray);
return getRayleighPhase(eyeCos * eyeCos);
}
float scale(float inCos)
{
float x = 1.0 - inCos;
return 0.25 * exp(-0.00287 + x*(0.459 + x*(3.83 + x*(-6.80 + x*5.25))));
}
// Calculates the Mie phase function
float getMiePhase(float eyeCos, float eyeCos2)
{
float temp = 1.0 + MIE_G2 - 2.0 * MIE_G * eyeCos;
temp = pow(temp, pow(_SunSize,0.65) * 10);
temp = max(temp,1.0e-4); // prevent division by zero, esp. in float precision
temp = 1.5 * ((1.0 - MIE_G2) / (2.0 + MIE_G2)) * (1.0 + eyeCos2) / temp;
#if defined(UNITY_COLORSPACE_GAMMA) && SKYBOX_COLOR_IN_TARGET_COLOR_SPACE
temp = pow(temp, .454545);
#endif
return temp;
}
// Calculates the sun shape
float calcSunAttenuation(float3 lightPos, float3 ray)
{
float focusedEyeCos = pow(saturate(dot(lightPos, ray)), _SunSizeConvergence);
return getMiePhase(-focusedEyeCos, focusedEyeCos * focusedEyeCos);
}
float4 Frag(Varyings input) : SV_Target
{
// Points towards the camera
float3 viewDirWS = normalize(mul(float3(input.positionCS.xy, 1.0), (float3x3)_PixelCoordToViewDirWS));
// Reverse it to point into the scene
float3 dir = -viewDirWS;
// Rotate direction
float phi = DegToRad(_SkyParam.z);
float cosPhi, sinPhi;
sincos(phi, sinPhi, cosPhi);
float3 rotDirX = float3(cosPhi, 0, -sinPhi);
float3 rotDirY = float3(sinPhi, 0, cosPhi);
dir = float3(dot(rotDirX, dir), dir.y, dot(rotDirY, dir));
float3 kScatteringWavelength = lerp (
kDefaultScatteringWavelength-kVariableRangeForScatteringWavelength,
kDefaultScatteringWavelength+kVariableRangeForScatteringWavelength,
float3(1,1,1) - _SkyTint); // using Tint in sRGB gamma allows for more visually linear interpolation and to keep (.5) at (128, gray in sRGB) point
float3 kInvWavelength = 1.0 / pow(kScatteringWavelength, 4);
float kKrESun = kRAYLEIGH * kSUN_BRIGHTNESS;
float kKr4PI = kRAYLEIGH * 4.0 * 3.14159265;
float3 cameraPos = float3(0,kInnerRadius + kCameraHeight,0); // The camera's current position
// Get the ray from the camera to the vertex and its length (which is the far point of the ray passing through the atmosphere)
float3 eyeRay = dir; // normalize(mul((float3x3)unity_ObjectToWorld, v.vertex.xyz));
float far = 0.0;
float3 cIn = float3(0.0, 0.0, 0.0);
float3 cOut = float3(0.0, 0.0, 0.0);
float3 groundColor = float3(0.0, 0.0, 0.0);
float3 skyColor = float3(0.0, 0.0, 0.0);
// Modification for per-pixel procedural sky:
// Contrary to the legacy version that is run per-vertex, this version is per pixel.
// The fact that it was run per-vertex means that the colors were never computed at the horizon.
// Now that it's per vertex, we reach the limitation of the computation at the horizon where a very bright line appears.
// To avoid that, we clampe the height of the eye ray just above and below the horizon for sky and ground respectively.
// Another modification to make this work was to add ground and sky contribution instead of lerping between them.
// For this to work we also needed to change slightly the computation so that cIn and cOut factor computed for the sky did not affect ground and vice versa (it was the case before) so that we can add both contribution without adding energy
float horizonThreshold = 0.02;
if(eyeRay.y >= 0.0)
{
float3 clampedEyeRay = eyeRay;
clampedEyeRay.y = max(clampedEyeRay.y, horizonThreshold);
// Sky
// Calculate the length of the "atmosphere"
far = sqrt(kOuterRadius2 + kInnerRadius2 * clampedEyeRay.y * clampedEyeRay.y - kInnerRadius2) - kInnerRadius * clampedEyeRay.y;
float3 pos = cameraPos + far * clampedEyeRay;
// Calculate the ray's starting position, then calculate its scattering offset
float height = kInnerRadius + kCameraHeight;
float depth = exp(kScaleOverScaleDepth * (-kCameraHeight));
float startAngle = dot(clampedEyeRay, cameraPos) / height;
float startOffset = depth*scale(startAngle);
// Initialize the scattering loop variables
float sampleLength = far / kSamples;
float scaledLength = sampleLength * kScale;
float3 sampleRay = clampedEyeRay * sampleLength;
float3 samplePoint = cameraPos + sampleRay * 0.5;
// Now loop through the sample rays
float3 frontColor = float3(0.0, 0.0, 0.0);
for(int i=0; i<int(kSamples); i++)
{
float sampleHeight = length(samplePoint);
float sampleDepth = exp(kScaleOverScaleDepth * (kInnerRadius - sampleHeight));
float lightAngle = dot(_SunDirection.xyz, samplePoint) / sampleHeight;
float cameraAngle = dot(clampedEyeRay, samplePoint) / sampleHeight;
float scatter = (startOffset + sampleDepth*(scale(lightAngle) - scale(cameraAngle)));
float3 attenuate = exp(-clamp(scatter, 0.0, kMAX_SCATTER) * (kInvWavelength * kKr4PI + kKm4PI));
frontColor += attenuate * (sampleDepth * scaledLength);
samplePoint += sampleRay;
}
// Finally, scale the Mie and Rayleigh colors and set up the varying variables for the pixel shader
cIn = frontColor * (kInvWavelength * kKrESun);
cOut = frontColor * kKmESun;
skyColor = _SkyParam.y * (cIn * getRayleighPhase(_SunDirection.xyz, -eyeRay));
}
else
{
float3 clampedEyeRay = eyeRay;
clampedEyeRay.y = min(clampedEyeRay.y, -horizonThreshold);
// Ground
far = (-kCameraHeight) / (min(-0.001, clampedEyeRay.y));
float3 pos = cameraPos + far * clampedEyeRay;
// Calculate the ray's starting position, then calculate its scattering offset
float depth = exp((-kCameraHeight) * (1.0/kScaleDepth));
float cameraAngle = dot(-clampedEyeRay, pos);
float lightAngle = dot(_SunDirection.xyz, pos);
float cameraScale = scale(cameraAngle);
float lightScale = scale(lightAngle);
float cameraOffset = depth*cameraScale;
float temp = (lightScale + cameraScale);
// Initialize the scattering loop variables
float sampleLength = far / kSamples;
float scaledLength = sampleLength * kScale;
float3 sampleRay = clampedEyeRay * sampleLength;
float3 samplePoint = cameraPos + sampleRay * 0.5;
// Now loop through the sample rays
float3 frontColor = float3(0.0, 0.0, 0.0);
float3 attenuate;
{
float sampleHeight = length(samplePoint);
float sampleDepth = exp(kScaleOverScaleDepth * (kInnerRadius - sampleHeight));
float scatter = sampleDepth*temp - cameraOffset;
attenuate = exp(-clamp(scatter, 0.0, kMAX_SCATTER) * (kInvWavelength * kKr4PI + kKm4PI));
frontColor += attenuate * (sampleDepth * scaledLength);
samplePoint += sampleRay;
}
cIn = frontColor * (kInvWavelength * kKrESun + kKmESun);
cOut = clamp(attenuate, 0.0, 1.0);
groundColor = _SkyParam.y * (cIn + _GroundColor * _GroundColor * cOut);
}
float3 sunColor = float3(0.0, 0.0, 0.0);
#if _ENABLE_SUN_DISK
// The sun should have a stable intensity in its course in the sky. Moreover it should match the highlight of a purely specular material.
// This matching was done using the standard shader BRDF1 on the 5/31/2017
// Finally we want the sun to be always bright even in LDR thus the normalization of the lightColor for low intensity.
float lightColorIntensity = clamp(length(_SunColor.xyz), 0.25, 1);
sunColor = kHDSundiskIntensityFactor * saturate(cOut) * _SunColor.xyz / lightColorIntensity;
#endif
float3 col = float3(0.0, 0.0, 0.0);
// if y > 1 [eyeRay.y < -SKY_GROUND_THRESHOLD] - ground
// if y >= 0 and < 1 [eyeRay.y <= 0 and > -SKY_GROUND_THRESHOLD] - horizon
// if y < 0 [eyeRay.y > 0] - sky
float y = -eyeRay.y / SKY_GROUND_THRESHOLD;
col = groundColor + skyColor;
#if _ENABLE_SUN_DISK
if(y < 0.0)
{
col += sunColor * calcSunAttenuation(_SunDirection.xyz, eyeRay);
}
#endif
return float4(col * exp2(_SkyParam.x), 1.0);
}
ENDHLSL
SubShader
{
Pass
{
ZWrite Off
ZTest Always
Blend Off
Cull Off
HLSLPROGRAM
ENDHLSL
}
Pass
{
ZWrite Off
ZTest LEqual
Blend Off
Cull Off
HLSLPROGRAM
ENDHLSL
}
}
Fallback Off
}

9
ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Resources/ProceduralSky.shader.meta


fileFormatVersion: 2
guid: ec63f47fd265df243a7b1d40f9ef7fe7
timeCreated: 1479239909
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

21
SampleScenes/HDTest/SkyFogTest/SkyFogHDRISky.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 59b6606ef2548734bb6d11b9d160bc7e, type: 3}
m_Name: SkyFogHDRISky
m_EditorClassIdentifier:
rotation: 0
exposure: 0
multiplier: 1
resolution: 256
updateMode: 0
updatePeriod: 0
lightingOverride: {fileID: 0}
skyHDRI: {fileID: 8900000, guid: a615f6de0224d55408b4e74da3b0bac0, type: 3}

10
SampleScenes/HDTest/SkyFogTest/SkyFogHDRISky.asset.meta


fileFormatVersion: 2
guid: 2647470268f148548bb957878139fc56
timeCreated: 1507624166
licenseType: Pro
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

26
SampleScenes/HDTest/SkyFogTest/SkyFogProceduralSky.asset


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3df29e7cc05fbec4aa43e06ea875565d, type: 3}
m_Name: SkyFogProceduralSky
m_EditorClassIdentifier:
rotation: 0
exposure: 0
multiplier: 1.3
resolution: 256
updateMode: 0
updatePeriod: 0
lightingOverride: {fileID: 0}
sunSize: 0.04
sunSizeConvergence: 5
atmosphereThickness: 1
skyTint: {r: 0.5019608, g: 0.5019608, b: 0.5019608, a: 1}
groundColor: {r: 0.36862746, g: 0.34901962, b: 0.34117648, a: 1}
enableSunDisk: 1

10
SampleScenes/HDTest/SkyFogTest/SkyFogProceduralSky.asset.meta


fileFormatVersion: 2
guid: 7d119d7ec4e5e964d92d40232696fa43
timeCreated: 1507634536
licenseType: Pro
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

177
ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/BlacksmithSkyRenderer.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public class BlacksmithSkyRenderer : SkyRenderer
{
Material m_ProceduralSkyMaterial = null; // Renders a cubemap into a render texture (can be cube or 2D)
private BlacksmithSkySettings m_ProceduralSkySettings;
public BlacksmithSkyRenderer(BlacksmithSkySettings proceduralSkySettings)
{
m_ProceduralSkySettings = proceduralSkySettings;
}
public override void Build()
{
m_ProceduralSkyMaterial = CoreUtils.CreateEngineMaterial("Hidden/HDRenderPipeline/Sky/SkyProcedural");
}
public override void Cleanup()
{
CoreUtils.Destroy(m_ProceduralSkyMaterial);
}
public override bool IsSkyValid()
{
if (m_ProceduralSkyMaterial == null || m_ProceduralSkySettings == null)
return false;
return m_ProceduralSkySettings.skyHDRI != null &&
m_ProceduralSkySettings.worldMieColorRamp != null &&
m_ProceduralSkySettings.worldRayleighColorRamp != null;
}
public override void SetRenderTargets(BuiltinSkyParameters builtinParams)
{
// We do not bind the depth buffer as a depth-stencil target since it is
// bound as a color texture which is then sampled from within the shader.
CoreUtils.SetRenderTarget(builtinParams.commandBuffer, builtinParams.colorBuffer);
}
void SetKeywords(BuiltinSkyParameters builtinParams, BlacksmithSkySettings param, bool renderForCubemap)
{
// Ensure that all preprocessor symbols are initially undefined.
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_PER_PIXEL");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_DEBUG");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_OCCLUSION");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_OCCLUSION_EDGE_FIXUP");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_OCCLUSION_FULLSKY");
m_ProceduralSkyMaterial.DisableKeyword("ATMOSPHERICS_SUNRAYS");
m_ProceduralSkyMaterial.DisableKeyword("PERFORM_SKY_OCCLUSION_TEST");
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_PER_PIXEL");
/*
if (useOcclusion)
{
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_OCCLUSION");
if(occlusionDepthFixup && occlusionDownscale != OcclusionDownscale.x1)
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_OCCLUSION_EDGE_FIXUP");
if(occlusionFullSky)
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_OCCLUSION_FULLSKY");
}
*/
// Expected to be valid for the sky pass, and invalid for the cube map generation pass.
if (!renderForCubemap)
{
m_ProceduralSkyMaterial.EnableKeyword("PERFORM_SKY_OCCLUSION_TEST");
}
if (param.debugMode != BlacksmithSkySettings.ScatterDebugMode.None)
{
m_ProceduralSkyMaterial.EnableKeyword("ATMOSPHERICS_DEBUG");
}
}
void SetUniforms(BuiltinSkyParameters builtinParams, BlacksmithSkySettings param, bool renderForCubemap, ref MaterialPropertyBlock properties)
{
properties.SetTexture("_Cubemap", param.skyHDRI);
properties.SetVector("_SkyParam", new Vector4(param.exposure, param.multiplier, param.rotation, 0.0f));
properties.SetMatrix("_InvViewProjMatrix", builtinParams.invViewProjMatrix);
properties.SetVector("_CameraPosWS", builtinParams.cameraPosWS);
properties.SetVector("_ScreenSize", builtinParams.screenSize);
m_ProceduralSkyMaterial.SetInt("_AtmosphericsDebugMode", (int)param.debugMode);
Vector3 sunDirection = (builtinParams.sunLight != null) ? -builtinParams.sunLight.transform.forward : Vector3.zero;
m_ProceduralSkyMaterial.SetVector("_SunDirection", sunDirection);
var pixelRect = new Rect(0f, 0f, builtinParams.screenSize.x, builtinParams.screenSize.y);
var scale = 1.0f; //(float)(int)occlusionDownscale;
var depthTextureScaledTexelSize = new Vector4(scale / pixelRect.width,
scale / pixelRect.height,
-scale / pixelRect.width,
-scale / pixelRect.height);
properties.SetVector("_DepthTextureScaledTexelSize", depthTextureScaledTexelSize);
/*
m_ProceduralSkyMaterial.SetFloat("_ShadowBias", useOcclusion ? occlusionBias : 1f);
m_ProceduralSkyMaterial.SetFloat("_ShadowBiasIndirect", useOcclusion ? occlusionBiasIndirect : 1f);
m_ProceduralSkyMaterial.SetFloat("_ShadowBiasClouds", useOcclusion ? occlusionBiasClouds : 1f);
m_ProceduralSkyMaterial.SetVector("_ShadowBiasSkyRayleighMie", useOcclusion ? new Vector4(occlusionBiasSkyRayleigh, occlusionBiasSkyMie, 0f, 0f) : Vector4.zero);
m_ProceduralSkyMaterial.SetFloat("_OcclusionDepthThreshold", occlusionDepthThreshold);
m_ProceduralSkyMaterial.SetVector("_OcclusionTexture_TexelSize", ???);
*/
m_ProceduralSkyMaterial.SetFloat("_WorldScaleExponent", param.worldScaleExponent);
m_ProceduralSkyMaterial.SetFloat("_WorldNormalDistanceRcp", 1f / param.worldNormalDistance);
m_ProceduralSkyMaterial.SetFloat("_WorldMieNearScatterPush", -Mathf.Pow(Mathf.Abs(param.worldMieNearScatterPush), param.worldScaleExponent) * Mathf.Sign(param.worldMieNearScatterPush));
m_ProceduralSkyMaterial.SetFloat("_WorldRayleighNearScatterPush", -Mathf.Pow(Mathf.Abs(param.worldRayleighNearScatterPush), param.worldScaleExponent) * Mathf.Sign(param.worldRayleighNearScatterPush));
m_ProceduralSkyMaterial.SetFloat("_WorldRayleighDensity", -param.worldRayleighDensity / 100000f);
m_ProceduralSkyMaterial.SetFloat("_WorldMieDensity", -param.worldMieDensity / 100000f);
m_ProceduralSkyMaterial.SetFloat("_SkyDepth", 1.0f / param.maxSkyDistance);
var rayleighColorM20 = param.worldRayleighColorRamp.Evaluate(0.00f);
var rayleighColorM10 = param.worldRayleighColorRamp.Evaluate(0.25f);
var rayleighColorO00 = param.worldRayleighColorRamp.Evaluate(0.50f);
var rayleighColorP10 = param.worldRayleighColorRamp.Evaluate(0.75f);
var rayleighColorP20 = param.worldRayleighColorRamp.Evaluate(1.00f);
var mieColorM20 = param.worldMieColorRamp.Evaluate(0.00f);
var mieColorO00 = param.worldMieColorRamp.Evaluate(0.50f);
var mieColorP20 = param.worldMieColorRamp.Evaluate(1.00f);
m_ProceduralSkyMaterial.SetVector("_RayleighColorM20", (Vector4)rayleighColorM20 * param.worldRayleighColorIntensity);
m_ProceduralSkyMaterial.SetVector("_RayleighColorM10", (Vector4)rayleighColorM10 * param.worldRayleighColorIntensity);
m_ProceduralSkyMaterial.SetVector("_RayleighColorO00", (Vector4)rayleighColorO00 * param.worldRayleighColorIntensity);
m_ProceduralSkyMaterial.SetVector("_RayleighColorP10", (Vector4)rayleighColorP10 * param.worldRayleighColorIntensity);
m_ProceduralSkyMaterial.SetVector("_RayleighColorP20", (Vector4)rayleighColorP20 * param.worldRayleighColorIntensity);
m_ProceduralSkyMaterial.SetVector("_MieColorM20", (Vector4)mieColorM20 * param.worldMieColorIntensity);
m_ProceduralSkyMaterial.SetVector("_MieColorO00", (Vector4)mieColorO00 * param.worldMieColorIntensity);
m_ProceduralSkyMaterial.SetVector("_MieColorP20", (Vector4)mieColorP20 * param.worldMieColorIntensity);
m_ProceduralSkyMaterial.SetFloat("_HeightNormalDistanceRcp", 1f / param.heightNormalDistance);
m_ProceduralSkyMaterial.SetFloat("_HeightMieNearScatterPush", -Mathf.Pow(Mathf.Abs(param.heightMieNearScatterPush), param.worldScaleExponent) * Mathf.Sign(param.heightMieNearScatterPush));
m_ProceduralSkyMaterial.SetFloat("_HeightRayleighNearScatterPush", -Mathf.Pow(Mathf.Abs(param.heightRayleighNearScatterPush), param.worldScaleExponent) * Mathf.Sign(param.heightRayleighNearScatterPush));
// m_ProceduralSkyMaterial.SetFloat("_HeightRayleighDensity", -param.heightRayleighDensity / 100000f);
// m_ProceduralSkyMaterial.SetFloat("_HeightMieDensity", -param.heightMieDensity / 100000f);
m_ProceduralSkyMaterial.SetFloat("_HeightSeaLevel", param.heightSeaLevel);
m_ProceduralSkyMaterial.SetVector("_HeightPlaneShift", param.heightPlaneShift);
m_ProceduralSkyMaterial.SetFloat("_HeightDistanceRcp", 1f / param.heightDistance);
m_ProceduralSkyMaterial.SetVector("_HeightRayleighColor", (Vector4)param.heightRayleighColor * param.heightRayleighIntensity);
m_ProceduralSkyMaterial.SetFloat("_HeightExtinctionFactor", param.heightExtinctionFactor);
m_ProceduralSkyMaterial.SetVector("_RayleighInScatterPct", new Vector4(1f - param.worldRayleighIndirectScatter, param.worldRayleighIndirectScatter, 0f, 0f));
m_ProceduralSkyMaterial.SetFloat("_RayleighExtinctionFactor", param.worldRayleighExtinctionFactor);
m_ProceduralSkyMaterial.SetFloat("_MiePhaseAnisotropy", param.worldMiePhaseAnisotropy);
m_ProceduralSkyMaterial.SetFloat("_MieExtinctionFactor", param.worldMieExtinctionFactor);
// Since we use the material for rendering the sky both into the cubemap, and
// during the fullscreen pass, setting the 'PERFORM_SKY_OCCLUSION_TEST' keyword has no effect.
properties.SetFloat("_DisableSkyOcclusionTest", renderForCubemap ? 1.0f : 0.0f);
// We do not render the height fog into the sky IBL cubemap.
properties.SetFloat("_HeightRayleighDensity", renderForCubemap ? -0.0f : -param.heightRayleighDensity / 100000f);
properties.SetFloat("_HeightMieDensity", renderForCubemap ? -0.0f : -param.heightMieDensity / 100000f);
properties.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, builtinParams.pixelCoordToViewDirMatrix);
}
override public void RenderSky(BuiltinSkyParameters builtinParams, bool renderForCubemap)
{
MaterialPropertyBlock properties = new MaterialPropertyBlock();
// Define select preprocessor symbols.
SetKeywords(builtinParams, m_ProceduralSkySettings, renderForCubemap);
// Set shader constants.
SetUniforms(builtinParams, m_ProceduralSkySettings, renderForCubemap, ref properties);
CoreUtils.DrawFullScreen(builtinParams.commandBuffer, m_ProceduralSkyMaterial, properties);
}
}
}

12
ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/BlacksmithSkyRenderer.cs.meta


fileFormatVersion: 2
guid: 476423447c1989948a128fc0a0b27413
timeCreated: 1481631774
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

165
ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/BlacksmithSkySettings.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[ExecuteInEditMode]
[DisallowMultipleComponent]
public class BlacksmithSkySettings : SkySettings
{
public enum OcclusionDownscale { x1 = 1, x2 = 2, x4 = 4 }
public enum OcclusionSamples { x64 = 0, x164 = 1, x244 = 2 }
public enum ScatterDebugMode { None, Scattering, Occlusion, OccludedScattering, Rayleigh, Mie, Height }
[Header("Global Settings")]
public float worldMieColorIntensity = 1f;
public Gradient worldMieColorRamp = null;
public float worldMieDensity = 15f;
public float worldMieExtinctionFactor = 0f;
public float worldMieNearScatterPush = 0f;
public float worldMiePhaseAnisotropy = 0.9f;
public float worldNormalDistance = 1000f;
public float worldRayleighColorIntensity = 1f;
public Gradient worldRayleighColorRamp = null;
public float worldRayleighDensity = 10f;
public float worldRayleighExtinctionFactor = 1.1f;
public float worldRayleighIndirectScatter = 0.33f;
public float worldRayleighNearScatterPush = 0f;
[Header("Height Settings")]
public float heightDistance = 50f;
public float heightExtinctionFactor = 1.1f;
public float heightMieDensity = 0f;
public float heightMieNearScatterPush = 0f;
public float heightNormalDistance = 1000f;
public Vector3 heightPlaneShift = Vector3.zero;
public Color heightRayleighColor = Color.white;
public float heightRayleighDensity = 10f;
public float heightRayleighIntensity = 1f;
public float heightRayleighNearScatterPush = 0f;
public float heightSeaLevel = 0f;
/*
[Header("Scatter Occlusion")]
public bool useOcclusion = false;
public bool occlusionFullSky = false;
public bool occlusionDepthFixup = true;
public float occlusionBias = 0f;
public float occlusionBiasClouds = 0.3f;
public float occlusionBiasIndirect = 0.6f;
public float occlusionBiasSkyMie = 0.4f;
public float occlusionBiasSkyRayleigh = 0.2f;
public float occlusionDepthThreshold = 25f;
public OcclusionDownscale occlusionDownscale = OcclusionDownscale.x2;
public OcclusionSamples occlusionSamples = OcclusionSamples.x64;
*/
[Header("Other")]
public Cubemap skyHDRI = null;
// public Shader atmosphericShader = null;
// public Shader occlusionShader = null;
public float worldScaleExponent = 1.0f;
public float maxSkyDistance = 4000.0f;
public ScatterDebugMode debugMode = ScatterDebugMode.None;
// Camera m_currentCamera;
// UnityEngine.Rendering.CommandBuffer m_occlusionCmdAfterShadows, m_occlusionCmdBeforeScreen;
void Awake()
{
if (worldRayleighColorRamp == null)
{
worldRayleighColorRamp = new Gradient();
worldRayleighColorRamp.SetKeys(
new[] { new GradientColorKey(new Color(0.3f, 0.4f, 0.6f), 0f),
new GradientColorKey(new Color(0.5f, 0.6f, 0.8f), 1f) },
new[] { new GradientAlphaKey(1f, 0f),
new GradientAlphaKey(1f, 1f) }
);
}
if (worldMieColorRamp == null)
{
worldMieColorRamp = new Gradient();
worldMieColorRamp.SetKeys(
new[] { new GradientColorKey(new Color(0.95f, 0.75f, 0.5f), 0f),
new GradientColorKey(new Color(1f, 0.9f, 8.0f), 1f) },
new[] { new GradientAlphaKey(1f, 0f),
new GradientAlphaKey(1f, 1f) }
);
}
}
public void OnValidate()
{
worldMieDensity = Mathf.Clamp(worldMieDensity, 0f, 1000f);
worldMiePhaseAnisotropy = Mathf.Clamp01(worldMiePhaseAnisotropy);
worldMieNearScatterPush = Mathf.Clamp(worldMieNearScatterPush, -200f, 300f);
worldNormalDistance = Mathf.Clamp(worldNormalDistance, 1f, 10000f);
worldRayleighDensity = Mathf.Clamp(worldRayleighDensity, 0, 1000f);
worldRayleighIndirectScatter = Mathf.Clamp(worldRayleighIndirectScatter, 0f, 1f);
worldRayleighNearScatterPush = Mathf.Clamp(worldRayleighNearScatterPush, -200f, 300f);
heightMieDensity = Mathf.Clamp(heightMieDensity, 0, 1000f);
heightMieNearScatterPush = Mathf.Clamp(heightMieNearScatterPush, -200f, 300f);
heightNormalDistance = Mathf.Clamp(heightNormalDistance, 1f, 10000f);
heightRayleighDensity = Mathf.Clamp(heightRayleighDensity, 0, 1000f);
heightRayleighNearScatterPush = Mathf.Clamp(heightRayleighNearScatterPush, -200f, 300f);
worldScaleExponent = Mathf.Clamp(worldScaleExponent, 1f, 2f);
maxSkyDistance = Mathf.Clamp(maxSkyDistance, 1.0f, 1000000.0f);
/*
occlusionBias = Mathf.Clamp01(occlusionBias);
occlusionBiasClouds = Mathf.Clamp01(occlusionBiasClouds);
occlusionBiasIndirect = Mathf.Clamp01(occlusionBiasIndirect);
occlusionBiasSkyMie = Mathf.Clamp01(occlusionBiasSkyMie);
occlusionBiasSkyRayleigh = Mathf.Clamp01(occlusionBiasSkyRayleigh);
*/
}
public override SkyRenderer GetRenderer()
{
return new BlacksmithSkyRenderer(this);
}
public override int GetHashCode()
{
int hash = base.GetHashCode();
unchecked
{
hash = hash * 23 + worldMieColorIntensity.GetHashCode();
hash = worldMieColorRamp != null ? hash * 23 + worldMieColorRamp.GetHashCode() : hash;
hash = hash * 23 + worldMieDensity.GetHashCode();
hash = hash * 23 + worldMieExtinctionFactor.GetHashCode();
hash = hash * 23 + worldMieNearScatterPush.GetHashCode();
hash = hash * 23 + worldMiePhaseAnisotropy.GetHashCode();
hash = hash * 23 + worldNormalDistance.GetHashCode();
hash = hash * 23 + worldRayleighColorIntensity.GetHashCode();
hash = worldRayleighColorRamp != null ? hash * 23 + worldRayleighColorRamp.GetHashCode() : hash;
hash = hash * 23 + worldRayleighDensity.GetHashCode();
hash = hash * 23 + worldRayleighExtinctionFactor.GetHashCode();
hash = hash * 23 + worldRayleighIndirectScatter.GetHashCode();
hash = hash * 23 + worldRayleighNearScatterPush.GetHashCode();
hash = hash * 23 + heightDistance.GetHashCode();
hash = hash * 23 + heightExtinctionFactor.GetHashCode();
hash = hash * 23 + heightMieDensity.GetHashCode();
hash = hash * 23 + heightMieNearScatterPush.GetHashCode();
hash = hash * 23 + heightNormalDistance.GetHashCode();
hash = hash * 23 + heightPlaneShift.GetHashCode();
hash = hash * 23 + heightRayleighColor.GetHashCode();
hash = hash * 23 + heightRayleighDensity.GetHashCode();
hash = hash * 23 + heightRayleighIntensity.GetHashCode();
hash = hash * 23 + heightRayleighNearScatterPush.GetHashCode();
hash = hash * 23 + heightSeaLevel.GetHashCode();
hash = skyHDRI != null ? hash * 23 + skyHDRI.GetHashCode() : hash;
hash = hash * 23 + worldScaleExponent.GetHashCode();
hash = hash * 23 + maxSkyDistance.GetHashCode();
hash = hash * 23 + debugMode.GetHashCode();
}
return hash;
}
}
}

12
ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/BlacksmithSkySettings.cs.meta


fileFormatVersion: 2
guid: 54bcd1d5cb4984847971142e9444d2fb
timeCreated: 1481631764
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/Editor.meta


fileFormatVersion: 2
guid: 00372bf7f144a724bba68a081fd79e78
folderAsset: yes
timeCreated: 1481646149
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

155
ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/Editor/BlacksmithSkyEditor.cs


using UnityEngine;
using UnityEditor;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[CanEditMultipleObjects]
[CustomEditor(typeof(BlacksmithSkySettings))]
public class BlacksmithSkySettingsEditor : Editor
{
private float heightFogHeight = 0.0f;
private class Styles
{
public readonly GUIContent skyHDRI = new GUIContent("HDRI");
public readonly GUIContent skyResolution = new GUIContent("Resolution");
public readonly GUIContent skyExposure = new GUIContent("Exposure");
public readonly GUIContent skyRotation = new GUIContent("Rotation");
public readonly GUIContent skyMultiplier = new GUIContent("Multiplier");
public 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.");
}
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_SkyHDRI;
private SerializedProperty m_SkyResolution;
private SerializedProperty m_SkyExposure;
private SerializedProperty m_SkyMultiplier;
private SerializedProperty m_SkyRotation;
private SerializedProperty m_LightingOverride;
private SerializedProperty m_updateMode;
private SerializedProperty m_updatePeriod;
private SerializedProperty m_worldScaleExponent;
private SerializedProperty m_maxSkyDistance;
private SerializedProperty m_worldMieColorIntensity;
private SerializedProperty m_worldMieColorRamp;
private SerializedProperty m_worldMieDensity;
private SerializedProperty m_worldMieNearScatterPush;
private SerializedProperty m_worldMiePhaseAnisotropy;
private SerializedProperty m_worldRayleighColorIntensity;
private SerializedProperty m_worldRayleighColorRamp;
private SerializedProperty m_worldRayleighDensity;
private SerializedProperty m_worldRayleighNearScatterPush;
private SerializedProperty m_heightSeaLevel;
private SerializedProperty m_heightDistance;
private SerializedProperty m_heightMieDensity;
private SerializedProperty m_heightMieNearScatterPush;
private SerializedProperty m_heightRayleighColor;
private SerializedProperty m_heightRayleighDensity;
private SerializedProperty m_heightRayleighIntensity;
private SerializedProperty m_heightRayleighNearScatterPush;
void OnEnable()
{
m_SkyHDRI = serializedObject.FindProperty("skyHDRI");
m_SkyResolution = serializedObject.FindProperty("resolution");
m_SkyExposure = serializedObject.FindProperty("exposure");
m_SkyMultiplier = serializedObject.FindProperty("multiplier");
m_SkyRotation = serializedObject.FindProperty("rotation");
m_updateMode = serializedObject.FindProperty("updateMode");
m_updatePeriod = serializedObject.FindProperty("updatePeriod");
m_LightingOverride = serializedObject.FindProperty("lightingOverride");
m_maxSkyDistance = serializedObject.FindProperty("maxSkyDistance");
m_worldScaleExponent = serializedObject.FindProperty("worldScaleExponent");
m_worldMieColorIntensity = serializedObject.FindProperty("worldMieColorIntensity");
m_worldMieColorRamp = serializedObject.FindProperty("worldMieColorRamp");
m_worldMieDensity = serializedObject.FindProperty("worldMieDensity");
m_worldMieNearScatterPush = serializedObject.FindProperty("worldMieNearScatterPush");
m_worldMiePhaseAnisotropy = serializedObject.FindProperty("worldMiePhaseAnisotropy");
m_worldRayleighColorIntensity = serializedObject.FindProperty("worldRayleighColorIntensity");
m_worldRayleighColorRamp = serializedObject.FindProperty("worldRayleighColorRamp");
m_worldRayleighDensity = serializedObject.FindProperty("worldRayleighDensity");
m_worldRayleighNearScatterPush = serializedObject.FindProperty("worldRayleighNearScatterPush");
m_heightSeaLevel = serializedObject.FindProperty("heightSeaLevel");
m_heightDistance = serializedObject.FindProperty("heightDistance");
m_heightMieDensity = serializedObject.FindProperty("heightMieDensity");
m_heightMieNearScatterPush = serializedObject.FindProperty("heightMieNearScatterPush");
m_heightRayleighColor = serializedObject.FindProperty("heightRayleighColor");
m_heightRayleighDensity = serializedObject.FindProperty("heightRayleighDensity");
m_heightRayleighIntensity = serializedObject.FindProperty("heightRayleighIntensity");
m_heightRayleighNearScatterPush = serializedObject.FindProperty("heightRayleighNearScatterPush");
}
public override void OnInspectorGUI()
{
serializedObject.Update();
EditorGUILayout.LabelField(new GUIContent("Skydome"), EditorStyles.boldLabel);
EditorGUILayout.PropertyField(m_SkyHDRI, styles.skyHDRI);
EditorGUILayout.PropertyField(m_SkyResolution, styles.skyResolution);
EditorGUILayout.PropertyField(m_SkyExposure, styles.skyExposure);
EditorGUILayout.PropertyField(m_SkyMultiplier, styles.skyMultiplier);
EditorGUILayout.PropertyField(m_SkyRotation, styles.skyRotation);
EditorGUILayout.PropertyField(m_updateMode);
EditorGUILayout.PropertyField(m_updatePeriod);
EditorGUILayout.PropertyField(m_LightingOverride, styles.lightingOverride);
EditorGUILayout.Space();
EditorGUILayout.LabelField(new GUIContent("Atmosphere"), EditorStyles.boldLabel);
EditorGUILayout.PropertyField(m_worldMieDensity, new GUIContent("Density"));
m_worldRayleighDensity.floatValue = m_worldMieDensity.floatValue;
EditorGUILayout.PropertyField(m_worldScaleExponent, new GUIContent("Global scale"));
EditorGUILayout.PropertyField(m_maxSkyDistance, new GUIContent("Sky distance"));
EditorGUILayout.Space();
EditorGUILayout.PropertyField(m_worldMieColorRamp);
EditorGUILayout.PropertyField(m_worldMieColorIntensity);
EditorGUILayout.PropertyField(m_worldMieNearScatterPush);
EditorGUILayout.PropertyField(m_worldMiePhaseAnisotropy);
EditorGUILayout.Space();
EditorGUILayout.PropertyField(m_worldRayleighColorRamp);
EditorGUILayout.PropertyField(m_worldRayleighColorIntensity);
//EditorGUILayout.PropertyField(m_worldRayleighDensity);
EditorGUILayout.PropertyField(m_worldRayleighNearScatterPush);
EditorGUILayout.Space();
EditorGUILayout.LabelField(new GUIContent("Height fog"), EditorStyles.boldLabel);
heightFogHeight = EditorGUILayout.FloatField(new GUIContent("Height"), heightFogHeight);
EditorGUILayout.PropertyField(m_heightDistance, new GUIContent("Falloff"));
m_heightSeaLevel.floatValue = heightFogHeight + m_heightDistance.floatValue * 2.0f - 2.0f;
EditorGUILayout.PropertyField(m_heightMieDensity, new GUIContent("Density"));
m_heightRayleighDensity.floatValue = m_heightMieDensity.floatValue;
EditorGUILayout.PropertyField(m_heightMieNearScatterPush);
EditorGUILayout.PropertyField(m_heightRayleighColor);
//EditorGUILayout.PropertyField(m_heightRayleighDensity);
EditorGUILayout.PropertyField(m_heightRayleighIntensity);
EditorGUILayout.PropertyField(m_heightRayleighNearScatterPush);
//base.DrawDefaultInspector();
serializedObject.ApplyModifiedProperties();
}
}
}

12
ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/Editor/BlacksmithSkyEditor.cs.meta


fileFormatVersion: 2
guid: 40b56ef8d02cefa49ab82e6b7df9266b
timeCreated: 1481635925
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/Resources.meta


fileFormatVersion: 2
guid: 455c6cbc5c8be404c8ed6ff8b38d1155
folderAsset: yes
timeCreated: 1481646141
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

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


using System.Collections;
using UnityEngine;
using UnityEditor;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
public abstract class SkySettingsEditor
: Editor
{
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.");
}
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;
protected void OnEnable()
{
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");
}
protected void CommonSkySettingsGUI()
{
EditorGUILayout.PropertyField(m_SkyResolution, SkySettingsStyles.skyResolution);
EditorGUILayout.PropertyField(m_SkyExposure, SkySettingsStyles.skyExposure);
EditorGUILayout.PropertyField(m_SkyMultiplier, SkySettingsStyles.skyMultiplier);
EditorGUILayout.PropertyField(m_SkyRotation, SkySettingsStyles.skyRotation);
EditorGUILayout.PropertyField(m_EnvUpdateMode, SkySettingsStyles.environmentUpdateMode);
if (!m_EnvUpdateMode.hasMultipleDifferentValues && m_EnvUpdateMode.intValue == (int)EnvironementUpdateMode.Realtime)
{
EditorGUILayout.PropertyField(m_EnvUpdatePeriod, SkySettingsStyles.environmentUpdatePeriod);
}
EditorGUILayout.PropertyField(m_LightingOverride, SkySettingsStyles.lightingOverride);
}
}
}

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


fileFormatVersion: 2
guid: 88383d4257a1cb74bbfaef0546ce7e38
timeCreated: 1507627721
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Resources/SkyProcedural.shader.meta → /ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/Resources/SkyBlacksmith.shader.meta

/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Resources/AtmosphericScattering.hlsl.meta → /ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/Resources/AtmosphericScattering.hlsl.meta

/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Resources/AtmosphericScattering.hlsl → /ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/Resources/AtmosphericScattering.hlsl

/ScriptableRenderPipeline/HDRenderPipeline/Sky/ProceduralSky/Resources/SkyProcedural.shader → /ScriptableRenderPipeline/HDRenderPipeline/Sky/BlacksmithlSky/Resources/SkyBlacksmith.shader

正在加载...
取消
保存