From e8895fd7332f02ae4a55ccdcd74213e8d5e8911d Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Mon, 20 Jul 2020 19:19:41 +0200 Subject: [PATCH 01/10] Update CloudLayer Editor --- .../Editor/Volume/VolumeComponentEditor.cs | 73 +++--- .../Runtime/Volume/VolumeComponent.cs | 31 ++- .../Editor/Sky/CloudLayer/CloudLayerEditor.cs | 184 +++++++------ .../Runtime/Debug/DebugDisplay.cs | 75 ++++-- .../Runtime/Debug/VolumeDebug.cs | 44 +--- .../Runtime/Sky/CloudLayer/CloudLayer.cs | 241 +++++++++++++----- 6 files changed, 382 insertions(+), 266 deletions(-) diff --git a/com.unity.render-pipelines.core/Editor/Volume/VolumeComponentEditor.cs b/com.unity.render-pipelines.core/Editor/Volume/VolumeComponentEditor.cs index 49d9c310abd..e633db69fae 100644 --- a/com.unity.render-pipelines.core/Editor/Volume/VolumeComponentEditor.cs +++ b/com.unity.render-pipelines.core/Editor/Volume/VolumeComponentEditor.cs @@ -180,16 +180,27 @@ internal void Init(VolumeComponent target, Editor inspector) } - class ParameterSorter : Comparer<(GUIContent displayName, int displayOrder, SerializedDataParameter param)> + void GetFields(object o, List<(FieldInfo, SerializedProperty)> infos, SerializedProperty prop = null) { - public override int Compare((GUIContent displayName, int displayOrder, SerializedDataParameter param) x, (GUIContent displayName, int displayOrder, SerializedDataParameter param) y) + if (o == null) + return; + + var fields = o.GetType() + .GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); + + foreach (var field in fields) { - if (x.displayOrder < y.displayOrder) - return -1; - else if (x.displayOrder == y.displayOrder) - return 0; - else - return 1; + if (field.FieldType.IsSubclassOf(typeof(VolumeParameter))) + { + if ((field.GetCustomAttributes(typeof(HideInInspector), false).Length == 0) && + ((field.GetCustomAttributes(typeof(SerializeField), false).Length > 0) || + (field.IsPublic && field.GetCustomAttributes(typeof(NonSerializedAttribute), false).Length == 0))) + infos.Add((field, prop == null ? + serializedObject.FindProperty(field.Name) : prop.FindPropertyRelative(field.Name))); + } + else if (!field.FieldType.IsArray && field.FieldType.IsClass) + GetFields(field.GetValue(o), infos, prop == null ? + serializedObject.FindProperty(field.Name) : prop.FindPropertyRelative(field.Name)); } } @@ -202,37 +213,27 @@ public override int Compare((GUIContent displayName, int displayOrder, Serialize /// public virtual void OnEnable() { - m_Parameters = new List<(GUIContent, int, SerializedDataParameter)>(); - // Grab all valid serializable field on the VolumeComponent // TODO: Should only be done when needed / on demand as this can potentially be wasted CPU when a custom editor is in use - var fields = target.GetType() - .GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) - .Where(t => t.FieldType.IsSubclassOf(typeof(VolumeParameter))) - .Where(t => - (t.IsPublic && t.GetCustomAttributes(typeof(NonSerializedAttribute), false).Length == 0) || - (t.GetCustomAttributes(typeof(SerializeField), false).Length > 0) - ) - .Where(t => t.GetCustomAttributes(typeof(HideInInspector), false).Length == 0) - .ToList(); - - // Prepare all serialized objects for this editor - foreach (var field in fields) - { - var property = serializedObject.FindProperty(field.Name); - var name = ""; - var order = 0; - var attr = (DisplayInfoAttribute[])field.GetCustomAttributes(typeof(DisplayInfoAttribute), true); - if (attr.Length != 0) - { - name = attr[0].name; - order = attr[0].order; - } + var fields = new List<(FieldInfo, SerializedProperty)>(); + GetFields(target, fields); + + m_Parameters = fields + .Select(t => { + var name = ""; + var order = 0; + var attr = (DisplayInfoAttribute[])t.Item1.GetCustomAttributes(typeof(DisplayInfoAttribute), true); + if (attr.Length != 0) + { + name = attr[0].name; + order = attr[0].order; + } - var parameter = new SerializedDataParameter(property); - m_Parameters.Add((new GUIContent(name), order, parameter)); - } - m_Parameters.Sort(new ParameterSorter()); + var parameter = new SerializedDataParameter(t.Item2); + return (new GUIContent(name), order, parameter); + }) + .OrderBy(t => t.order) + .ToList(); } /// diff --git a/com.unity.render-pipelines.core/Runtime/Volume/VolumeComponent.cs b/com.unity.render-pipelines.core/Runtime/Volume/VolumeComponent.cs index cc57e064e26..df1a22e7637 100644 --- a/com.unity.render-pipelines.core/Runtime/Volume/VolumeComponent.cs +++ b/com.unity.render-pipelines.core/Runtime/Volume/VolumeComponent.cs @@ -77,6 +77,27 @@ public class VolumeComponent : ScriptableObject [SerializeField] bool m_AdvancedMode = false; // Editor-only #pragma warning restore 414 + + /// + /// Extracts all the s defined in this class and nested classes. + /// + static void GetParameters(object o, List parameters) + { + if (o == null) + return; + + var fields = o.GetType() + .GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) + .OrderBy(t => t.MetadataToken); // Guaranteed order + + foreach (var field in fields) + { + if (field.FieldType.IsSubclassOf(typeof(VolumeParameter))) + parameters.Add((VolumeParameter)field.GetValue(o)); + else if (!field.FieldType.IsArray && field.FieldType.IsClass) + GetParameters(field.GetValue(o), parameters); + } + } /// /// Unity calls this method when it loads the class. @@ -87,13 +108,9 @@ public class VolumeComponent : ScriptableObject protected virtual void OnEnable() { // Automatically grab all fields of type VolumeParameter for this instance - parameters = this.GetType() - .GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) - .Where(t => t.FieldType.IsSubclassOf(typeof(VolumeParameter))) - .OrderBy(t => t.MetadataToken) // Guaranteed order - .Select(t => (VolumeParameter)t.GetValue(this)) - .ToList() - .AsReadOnly(); + var fields = new List(); + GetParameters(this, fields); + parameters = fields.AsReadOnly(); foreach (var parameter in parameters) parameter.OnEnable(); diff --git a/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs b/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs index 5e1a85eb026..062d333ef48 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs @@ -10,124 +10,116 @@ namespace UnityEditor.Rendering.HighDefinition [VolumeComponentEditor(typeof(CloudLayer))] class CloudLayerEditor : VolumeComponentEditor { - SerializedDataParameter m_Enabled; - - SerializedDataParameter m_CloudMap; - SerializedDataParameter m_UpperHemisphereOnly; - SerializedDataParameter m_Tint; - SerializedDataParameter m_IntensityMultiplier; - SerializedDataParameter m_Rotation; - - SerializedDataParameter m_EnableDistortion; - SerializedDataParameter m_Procedural; - SerializedDataParameter m_Flowmap; - SerializedDataParameter m_ScrollDirection; - SerializedDataParameter m_ScrollSpeed; - - GUIContent[] m_DistortionModes = { new GUIContent("Procedural"), new GUIContent("Flowmap") }; - int[] m_DistortionModeValues = { 1, 0 }; - - MaterialEditor materialEditor = null; - - public override void OnEnable() + struct CloudLightingParameter { - var o = new PropertyFetcher(serializedObject); - - m_Enabled = Unpack(o.Find(x => x.enabled)); - - m_CloudMap = Unpack(o.Find(x => x.cloudMap)); - m_UpperHemisphereOnly = Unpack(o.Find(x => x.upperHemisphereOnly)); - m_Tint = Unpack(o.Find(x => x.tint)); - m_IntensityMultiplier = Unpack(o.Find(x => x.intensityMultiplier)); - m_Rotation = Unpack(o.Find(x => x.rotation)); - - m_EnableDistortion = Unpack(o.Find(x => x.enableDistortion)); - m_Procedural = Unpack(o.Find(x => x.procedural)); - m_Flowmap = Unpack(o.Find(x => x.flowmap)); - m_ScrollDirection = Unpack(o.Find(x => x.scrollDirection)); - m_ScrollSpeed = Unpack(o.Find(x => x.scrollSpeed)); + public SerializedDataParameter mode; + public SerializedDataParameter steps; + public SerializedDataParameter thickness; + public SerializedDataParameter castShadows; + } - CreateEditor(m_CloudMap); + struct CloudMapParameter + { + public SerializedDataParameter cloudMap; + public SerializedDataParameter[] opacities; + public SerializedDataParameter rotation; + public SerializedDataParameter tint; + public SerializedDataParameter intensityMultiplier; + public CloudLightingParameter lighting; } - public override void OnDisable () + CloudMapParameter UnpackCloudMap(SerializedProperty serializedProperty) { - if (materialEditor != null) - Object.DestroyImmediate(materialEditor); + var p = new RelativePropertyFetcher(serializedProperty); + var l = new RelativePropertyFetcher(p.Find(x => x.lighting)); - base.OnDisable(); + return new CloudMapParameter + { + cloudMap = Unpack(p.Find(x => x.cloudMap)), + opacities = new SerializedDataParameter[] + { + Unpack(p.Find(x => x.opacityR)), + Unpack(p.Find(x => x.opacityG)), + Unpack(p.Find(x => x.opacityB)), + Unpack(p.Find(x => x.opacityA)) + }, + rotation = Unpack(p.Find(x => x.rotation)), + tint = Unpack(p.Find(x => x.tint)), + intensityMultiplier = Unpack(p.Find(x => x.intensityMultiplier)), + lighting = new CloudLightingParameter + { + mode = Unpack(l.Find(x => x.lighting)), + steps = Unpack(l.Find(x => x.steps)), + thickness = Unpack(l.Find(x => x.thickness)), + castShadows = Unpack(l.Find(x => x.castShadows)), + } + }; } - bool IsMapFormatInvalid(SerializedDataParameter map) + void PropertyField(CloudMapParameter map, int index) { - if (!map.overrideState.boolValue || map.value.objectReferenceValue == null) - return false; - var tex = map.value.objectReferenceValue; - if (!tex.GetType().IsSubclassOf(typeof(Texture))) - return true; - return (tex as Texture).dimension != TextureDimension.Tex2D; + EditorGUILayout.Space(); + EditorGUILayout.LabelField($"Map {(index == 0 ? 'A' : 'B')}", EditorStyles.miniLabel); + + PropertyField(map.cloudMap); + EditorGUI.indentLevel++; + for (int i = 0; i < 4; i++) + PropertyField(map.opacities[i]); + EditorGUI.indentLevel--; + PropertyField(map.rotation); + PropertyField(map.tint); + PropertyField(map.intensityMultiplier); + + EditorGUILayout.Space(); + EditorGUILayout.LabelField($"Map {(index == 0 ? 'A' : 'B')} Lighting", EditorStyles.miniLabel); + PropertyField(map.lighting.mode); + if (map.lighting.mode.value.intValue == (int)CloudLightingMode.Raymarching) + { + EditorGUI.indentLevel++; + PropertyField(map.lighting.steps); + PropertyField(map.lighting.thickness); + EditorGUI.indentLevel--; + } + PropertyField(map.lighting.castShadows); } - void CreateEditor(SerializedDataParameter map) - { - if (materialEditor != null) - Object.DestroyImmediate(materialEditor); - var tex = map.value.objectReferenceValue as CustomRenderTexture; - if (tex != null && tex.material != null) - materialEditor = (MaterialEditor)Editor.CreateEditor(tex.material); - } + SerializedDataParameter m_Opacity, m_UpperHemisphereOnly; + SerializedDataParameter m_Mode, m_Layers; + CloudMapParameter[] m_Maps; - public override void OnInspectorGUI() + public override void OnEnable() { - PropertyField(m_Enabled, new GUIContent("Enable")); + base.OnEnable(); + + var o = new PropertyFetcher(serializedObject); - EditorGUI.BeginChangeCheck (); - PropertyField(m_CloudMap); - if (EditorGUI.EndChangeCheck()) - CreateEditor(m_CloudMap); + m_Opacity = Unpack(o.Find(x => x.opacity)); + m_UpperHemisphereOnly = Unpack(o.Find(x => x.upperHemisphereOnly)); + m_Mode = Unpack(o.Find(x => x.mode)); + m_Layers = Unpack(o.Find(x => x.layers)); - if (IsMapFormatInvalid(m_CloudMap)) - EditorGUILayout.HelpBox("The cloud map needs to be a 2D Texture in LatLong layout.", MessageType.Info); + m_Maps = new CloudMapParameter[] { + UnpackCloudMap(o.Find(x => x.mapA)), + UnpackCloudMap(o.Find(x => x.mapB)) + }; + } + public override void OnInspectorGUI() + { + PropertyField(m_Opacity); PropertyField(m_UpperHemisphereOnly); - PropertyField(m_Tint); - PropertyField(m_IntensityMultiplier); - PropertyField(m_Rotation); - PropertyField(m_EnableDistortion); - if (m_EnableDistortion.value.boolValue) + PropertyField(m_Mode); + if (m_Mode.value.intValue == (int)CloudLayerMode.CloudMap) { EditorGUI.indentLevel++; - - using (new EditorGUILayout.HorizontalScope()) - { - DrawOverrideCheckbox(m_Procedural); - using (new EditorGUI.DisabledScope(!m_Procedural.overrideState.boolValue)) - m_Procedural.value.boolValue = EditorGUILayout.IntPopup(new GUIContent("Distortion Mode"), (int)m_Procedural.value.intValue, m_DistortionModes, m_DistortionModeValues) == 1; - } - - if (!m_Procedural.value.boolValue) - { - EditorGUI.indentLevel++; - PropertyField(m_Flowmap); - if (IsMapFormatInvalid(m_Flowmap)) - EditorGUILayout.HelpBox("The flowmap needs to be a 2D Texture in LatLong layout.", MessageType.Info); - EditorGUI.indentLevel--; - } - - PropertyField(m_ScrollDirection); - PropertyField(m_ScrollSpeed); + PropertyField(m_Layers); EditorGUI.indentLevel--; - } - - - if (materialEditor != null) - { - EditorGUILayout.Space(); - materialEditor.DrawHeader(); - materialEditor.OnInspectorGUI(); - EditorGUILayout.Space(); + + PropertyField(m_Maps[0], 0); + if (m_Layers.value.intValue == (int)CloudMapMode.Double) + PropertyField(m_Maps[1], 1); } } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs index 0adb5eb2ff5..337484818ab 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using UnityEngine.Rendering.HighDefinition.Attributes; namespace UnityEngine.Rendering.HighDefinition @@ -1384,18 +1385,14 @@ DebugUI.Widget makeWidget(string name, VolumeParameter param) } }; } - - Type type = data.volumeDebugSettings.selectedComponentType; - - var fields = type - .GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) - .Where(t => t.FieldType.IsSubclassOf(typeof(VolumeParameter))) - .OrderBy(t => t.Name); + + Type selectedType = data.volumeDebugSettings.selectedComponentType; + var stackComponent = data.volumeDebugSettings.selectedCameraVolumeStack.GetComponent(selectedType); var volumes = data.volumeDebugSettings.GetVolumes(); var table = new DebugUI.Table() { displayName = "Parameter", isReadOnly = true }; - var inst = (VolumeComponent)ScriptableObject.CreateInstance(type); + var inst = (VolumeComponent)ScriptableObject.CreateInstance(selectedType); // First row for volume info float timer = 0.0f, refreshRate = 0.2f; @@ -1446,35 +1443,57 @@ DebugUI.Widget makeWidget(string name, VolumeParameter param) row.children.Add(new DebugUI.Value() { displayName = "Default Value", getter = () => "" }); table.children.Add(row); - // One row per parameter - foreach (var f in fields) + // Build rows - recursively handles nested parameters + var rows = new List(); + void AddParameterRows(Type type) { - var fieldName = f.Name; - var attr = (DisplayInfoAttribute[])f.GetCustomAttributes(typeof(DisplayInfoAttribute), true); - if (attr.Length != 0) - fieldName = attr[0].name; + void AddRow(FieldInfo f) + { + var fieldName = f.Name; + var attr = (DisplayInfoAttribute[])f.GetCustomAttributes(typeof(DisplayInfoAttribute), true); + if (attr.Length != 0) + fieldName = attr[0].name; #if UNITY_EDITOR - // Would be nice to have the equivalent for the runtime debug. - else - fieldName = UnityEditor.ObjectNames.NicifyVariableName(fieldName); + // Would be nice to have the equivalent for the runtime debug. + else + fieldName = UnityEditor.ObjectNames.NicifyVariableName(fieldName); #endif + int currentParam = rows.Count; + row = new DebugUI.Table.Row() + { + displayName = fieldName, + children = { makeWidget("Interpolated Value", stackComponent.parameters[currentParam]) } + }; - row = new DebugUI.Table.Row() - { - displayName = fieldName, - children = { makeWidget("Interpolated Value", data.volumeDebugSettings.GetParameter(f)) } - }; + foreach (var volume in volumes) + { + VolumeParameter param = null; + var profile = volume.HasInstantiatedProfile() ? volume.profile : volume.sharedProfile; + if (profile.TryGet(selectedType, out VolumeComponent component) && component.parameters[currentParam].overrideState) + param = component.parameters[currentParam]; + row.children.Add(makeWidget(volume.name + " (" + profile.name + ")", param)); + } - foreach (var volume in volumes) + row.children.Add(makeWidget("Default Value", inst.parameters[currentParam])); + rows.Add(row); + } + + var fields = type + .GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) + .OrderBy(t => t.MetadataToken); + foreach (var field in fields) { - var profile = volume.HasInstantiatedProfile() ? volume.profile : volume.sharedProfile; - row.children.Add(makeWidget(volume.name + " (" + profile.name + ")", data.volumeDebugSettings.GetParameter(volume, f))); + var fieldType = field.FieldType; + if (fieldType.IsSubclassOf(typeof(VolumeParameter))) + AddRow(field); + else if (!fieldType.IsArray && fieldType.IsClass) + AddParameterRows(fieldType); } - - row.children.Add(makeWidget("Default Value", data.volumeDebugSettings.GetParameter(inst, f))); - table.children.Add(row); } + AddParameterRows(selectedType); + foreach (var r in rows.OrderBy(t => t.displayName)) + table.children.Add(r); data.volumeDebugSettings.RefreshVolumes(volumes); for (int i = 0; i < volumes.Length; i++) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/VolumeDebug.cs b/com.unity.render-pipelines.high-definition/Runtime/Debug/VolumeDebug.cs index d538e731927..c2f67173710 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/VolumeDebug.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/VolumeDebug.cs @@ -251,43 +251,19 @@ public Volume[] GetVolumes() return VolumeManager.instance.GetVolumes(selectedCameraLayerMask).Reverse().ToArray(); } - VolumeParameter[,] savedStates = null; - VolumeParameter[,] GetStates() + int componentHash = 0; + int GetComponentHashCode() { - var fields = selectedComponentType - .GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance) - .Where(t => t.FieldType.IsSubclassOf(typeof(VolumeParameter))) - .ToArray(); - - VolumeParameter[,] states = new VolumeParameter[volumes.Length, fields.Length]; + int hash = 17; for (int i = 0; i < volumes.Length; i++) { var profile = volumes[i].HasInstantiatedProfile() ? volumes[i].profile : volumes[i].sharedProfile; if (!profile.TryGet(selectedComponentType, out VolumeComponent component)) continue; - - for (int j = 0; j < fields.Length; j++) - { - var param = GetParameter(component, fields[j]);; - states[i, j] = param.overrideState ? param : null; - } - } - return states; - } - - bool ChangedStates(VolumeParameter[,] newStates) - { - if (savedStates.GetLength(1) != newStates.GetLength(1)) - return true; - for (int i = 0; i < savedStates.GetLength(0); i++) - { - for (int j = 0; j < savedStates.GetLength(1); j++) - { - if ((savedStates[i, j] == null) != (newStates[i, j] == null)) - return true; - } + + hash = hash * 23 + component.GetHashCode(); } - return false; + return hash; } /// Updates the list of volumes and recomputes volume weights @@ -299,15 +275,15 @@ public bool RefreshVolumes(Volume[] newVolumes) if (volumes == null || !newVolumes.SequenceEqual(volumes)) { volumes = (Volume[])newVolumes.Clone(); - savedStates = GetStates(); + componentHash = GetComponentHashCode(); ret = true; } else { - var newStates = GetStates(); - if (savedStates == null || ChangedStates(newStates)) + int newHash = GetComponentHashCode(); + if (componentHash == 0 || componentHash != newHash) { - savedStates = newStates; + componentHash = newHash; ret = true; } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs index 31f980f39e1..5915a0711a5 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs @@ -2,6 +2,52 @@ namespace UnityEngine.Rendering.HighDefinition { + /// + /// Cloud Layer Mode. + /// + public enum CloudLayerMode + { + /// Cloud Map mode. + CloudMap, + /// CustomRenderTexture mode. + RenderTexture, + } + + /// + /// Cloud Map Mode. + /// + public enum CloudMapMode + { + /// One layer mode. + Single, + /// Two layer mode. + Double, + } + + /// + /// Distortion Mode. + /// + public enum DistortionMode + { + /// No distortion. + None, + /// Procedural distortion. + Procedural, + /// Distortion from a flowmap. + Flowmap, + } + + /// + /// Lighting Mode. + /// + public enum CloudLightingMode + { + /// No lighting. + None, + /// Lighting with 2D Raymarching. + Raymarching, + } + /// /// Cloud Layer Volume Component. /// This component setups the cloud layer for rendering. @@ -11,58 +57,130 @@ public class CloudLayer : VolumeComponent { /// Enable fog. [Tooltip("Check to have a cloud layer in the sky.")] - public BoolParameter enabled = new BoolParameter(false); - - /// Texture used to render the clouds. - [Tooltip("Specify the texture HDRP uses to render the clouds (in LatLong layout).")] - public TextureParameter cloudMap = new TextureParameter(null); + public ClampedFloatParameter opacity = new ClampedFloatParameter(1.0f, 0.0f, 1.0f); /// Enable to cover only the upper part of the sky. [Tooltip("Check this box if the cloud layer covers only the upper part of the sky.")] - public BoolParameter upperHemisphereOnly = new BoolParameter(true); - /// Color multiplier of the clouds. - [Tooltip("Specifies the color that HDRP uses to tint the clouds.")] - public ColorParameter tint = new ColorParameter(Color.white); - /// Intensity multipler of the clouds. - [Tooltip("Sets the intensity multiplier for the clouds.")] - public MinFloatParameter intensityMultiplier = new MinFloatParameter(1.0f, 0.0f); - /// Rotation of the clouds. - [Tooltip("Sets the rotation of the clouds.")] - public ClampedFloatParameter rotation = new ClampedFloatParameter(0.0f, 0.0f, 360.0f); - - /// Enable to have cloud distortion. - [Tooltip("Enable or disable cloud distortion.")] - public BoolParameter enableDistortion = new BoolParameter(false); - /// Enable to have a simple, procedural distorsion. - [Tooltip("If enabled, the clouds will be distorted by a constant wind.")] - public BoolParameter procedural = new BoolParameter(true); - /// Texture used to distort the UVs for the cloud layer. - [Tooltip("Specify the flowmap HDRP uses for cloud distortion (in LatLong layout).")] - public TextureParameter flowmap = new TextureParameter(null); - /// Direction of the distortion. - [Tooltip("Sets the rotation of the distortion (in degrees).")] - public ClampedFloatParameter scrollDirection = new ClampedFloatParameter(0.0f, 0.0f, 360.0f); - /// Speed of the distortion. - [Tooltip("Sets the cloud scrolling speed. The higher the value, the faster the clouds will move.")] - public MinFloatParameter scrollSpeed = new MinFloatParameter(1.0f, 0.0f); - - - private float scrollFactor = 0.0f, lastTime = 0.0f; + public BoolParameter upperHemisphereOnly = new BoolParameter(true); + /// . + [Tooltip("")] + public VolumeParameter mode = new VolumeParameter(); + /// . + [Tooltip("")] + public VolumeParameter layers = new VolumeParameter(); + + [Serializable] + public class CloudLighting + { + /// Distortion mode. + [Tooltip("Distortion mode.")] + public VolumeParameter lighting = new VolumeParameter(); - CloudLayer() + /// Number of raymarching steps. + [Tooltip("Number of raymarching steps.")] + public ClampedIntParameter steps = new ClampedIntParameter(4, 1, 10); + /// . + [Tooltip(".")] + public FloatParameter thickness = new FloatParameter(1.0f); + + /// Enable to cast shadows. + [Tooltip("Cast Shadows.")] + public BoolParameter castShadows = new BoolParameter(false); + } + + [Serializable] + public class CloudMap { - displayName = "CloudLayer (Preview)"; + /// Texture used to render the clouds. + [Tooltip("Specify the texture HDRP uses to render the clouds (in LatLong layout).")] + public TextureParameter cloudMap = new TextureParameter(null); + + /// Opacity of the red layer. + [Tooltip("Opacity of the red layer.")] + public ClampedFloatParameter opacityR = new ClampedFloatParameter(1.0f, 0.0f, 1.0f); + /// Opacity of the green layer. + [Tooltip("Opacity of the green layer.")] + public ClampedFloatParameter opacityG = new ClampedFloatParameter(1.0f, 0.0f, 1.0f); + /// Opacity of the blue layer. + [Tooltip("Opacity of the blue layer.")] + public ClampedFloatParameter opacityB = new ClampedFloatParameter(1.0f, 0.0f, 1.0f); + /// Opacity of the alpha layer. + [Tooltip("Opacity of the alpha layer.")] + public ClampedFloatParameter opacityA = new ClampedFloatParameter(1.0f, 0.0f, 1.0f); + + /// Rotation of the clouds. + [Tooltip("Sets the rotation of the clouds.")] + public ClampedFloatParameter rotation = new ClampedFloatParameter(0.0f, 0.0f, 360.0f); + /// Color multiplier of the clouds. + [Tooltip("Specifies the color that HDRP uses to tint the clouds.")] + public ColorParameter tint = new ColorParameter(Color.white); + /// Intensity multipler of the clouds. + [Tooltip("Sets the intensity multiplier for the clouds.")] + public MinFloatParameter intensityMultiplier = new MinFloatParameter(1.0f, 0.0f); + + /// Distortion mode. + [Tooltip("Distortion mode.")] + public VolumeParameter distortion = new VolumeParameter(); + /// Direction of the distortion. + [Tooltip("Sets the rotation of the distortion (in degrees).")] + public ClampedFloatParameter scrollDirection = new ClampedFloatParameter(0.0f, 0.0f, 360.0f); + /// Speed of the distortion. + [Tooltip("Sets the cloud scrolling speed. The higher the value, the faster the clouds will move.")] + public MinFloatParameter scrollSpeed = new MinFloatParameter(1.0f, 0.0f); + /// Texture used to distort the UVs for the cloud layer. + [Tooltip("Specify the flowmap HDRP uses for cloud distortion (in LatLong layout).")] + public TextureParameter flowmap = new TextureParameter(null); + + public CloudLighting lighting = new CloudLighting(); + + internal float scrollFactor = 0.0f; + + internal (Vector4, Vector4) GetParameters() + { + float dir = -Mathf.Deg2Rad * scrollDirection.value; + Vector4 tintAndIntensity = tint.value; + tintAndIntensity.w = intensityMultiplier.value; + return (new Vector4(rotation.value / 360.0f, scrollFactor, Mathf.Cos(dir), Mathf.Sin(dir)), tintAndIntensity); + } + + public override int GetHashCode() + { + int hash = base.GetHashCode(); + + unchecked + { + hash = hash * 23 + cloudMap.GetHashCode(); + hash = hash * 23 + opacityR.GetHashCode(); + hash = hash * 23 + opacityG.GetHashCode(); + hash = hash * 23 + opacityB.GetHashCode(); + hash = hash * 23 + opacityA.GetHashCode(); + hash = hash * 23 + rotation.GetHashCode(); + hash = hash * 23 + tint.GetHashCode(); + hash = hash * 23 + intensityMultiplier.GetHashCode(); + hash = hash * 23 + distortion.GetHashCode(); + hash = hash * 23 + scrollDirection.GetHashCode(); + hash = hash * 23 + scrollSpeed.GetHashCode(); + hash = hash * 23 + flowmap.GetHashCode(); + hash = hash * 23 + lighting.lighting.GetHashCode(); + hash = hash * 23 + lighting.steps.GetHashCode(); + hash = hash * 23 + lighting.thickness.GetHashCode(); + hash = hash * 23 + lighting.castShadows.GetHashCode(); + } + + return hash; + } } - /// - /// Returns the shader parameters of the cloud layer. - /// - /// The shader parameters of the cloud layer. - public Vector4 GetParameters() + public CloudMap mapA = new CloudMap(); + public CloudMap mapB = new CloudMap(); + + + private float lastTime = 0.0f; + + CloudLayer() { - float rot = -Mathf.Deg2Rad*scrollDirection.value; - float upper = upperHemisphereOnly.value ? 1.0f : -1.0f; - return new Vector4(upper * (rotation.value / 360.0f + 1), scrollFactor, Mathf.Cos(rot), Mathf.Sin(rot)); + displayName = "CloudLayer (Preview)"; + } /// Sets keywords and parameters on a sky material to render the cloud layer. @@ -70,27 +188,25 @@ public Vector4 GetParameters() /// The sky material to change. public static void Apply(CloudLayer layer, Material skyMaterial) { - if (layer != null && layer.enabled.value == true) + if (layer != null && layer.opacity.value != 0.0f) { - layer.scrollFactor += layer.scrollSpeed.value * (Time.time - layer.lastTime) * 0.01f; + layer.mapA.scrollFactor += layer.mapA.scrollSpeed.value * (Time.time - layer.lastTime) * 0.01f; layer.lastTime = Time.time; - Vector4 cloudParam = layer.GetParameters(); - Vector4 cloudParam2 = layer.tint.value; - cloudParam2.w = layer.intensityMultiplier.value; + (Vector4, Vector4) paramsA = layer.mapA.GetParameters(); skyMaterial.EnableKeyword("USE_CLOUD_MAP"); - skyMaterial.SetTexture(HDShaderIDs._CloudMap, layer.cloudMap.value); - skyMaterial.SetVector(HDShaderIDs._CloudParam, cloudParam); - skyMaterial.SetVector(HDShaderIDs._CloudParam2, cloudParam2); + skyMaterial.SetTexture(HDShaderIDs._CloudMap, layer.mapA.cloudMap.value); + skyMaterial.SetVector(HDShaderIDs._CloudParam, paramsA.Item1); + skyMaterial.SetVector(HDShaderIDs._CloudParam2, paramsA.Item2); - if (layer.enableDistortion.value == true) + if (layer.mapA.distortion.value != DistortionMode.None) { skyMaterial.EnableKeyword("USE_CLOUD_MOTION"); - if (layer.procedural.value == true) + if (layer.mapA.distortion.value == DistortionMode.Procedural) skyMaterial.DisableKeyword("USE_CLOUD_MAP"); else - skyMaterial.SetTexture(HDShaderIDs._CloudFlowmap, layer.flowmap.value); + skyMaterial.SetTexture(HDShaderIDs._CloudFlowmap, layer.mapA.flowmap.value); } else skyMaterial.DisableKeyword("USE_CLOUD_MOTION"); @@ -112,17 +228,12 @@ public override int GetHashCode() unchecked { - hash = hash * 23 + cloudMap.GetHashCode(); - hash = hash * 23 + flowmap.GetHashCode(); - hash = hash * 23 + enabled.GetHashCode(); + hash = hash * 23 + opacity.GetHashCode(); hash = hash * 23 + upperHemisphereOnly.GetHashCode(); - hash = hash * 23 + tint.GetHashCode(); - hash = hash * 23 + intensityMultiplier.GetHashCode(); - hash = hash * 23 + rotation.GetHashCode(); - hash = hash * 23 + enableDistortion.GetHashCode(); - hash = hash * 23 + procedural.GetHashCode(); - hash = hash * 23 + scrollDirection.GetHashCode(); - hash = hash * 23 + scrollSpeed.GetHashCode(); + hash = hash * 23 + mode.GetHashCode(); + hash = hash * 23 + layers.GetHashCode(); + hash = hash * 23 + mapA.GetHashCode(); + hash = hash * 23 + mapB.GetHashCode(); } return hash; From 74341ee7cd1b8a10c0410ac1efd7d1919a86e9e3 Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Tue, 21 Jul 2020 13:07:01 +0200 Subject: [PATCH 02/10] Cloud rendering context --- .../RenderPipeline/HDRenderPipelineUI.Skin.cs | 2 + .../RenderPipeline/HDRenderPipelineUI.cs | 3 + .../SerializedGlobalLightLoopSettings.cs | 4 + .../Editor/Sky/CloudLayer/CloudLayerEditor.cs | 163 ++++++++++---- .../LightLoop/GlobalLightLoopSettings.cs | 6 + .../Runtime/RenderPipeline/HDProfileId.cs | 1 + .../RenderPipeline/RenderPipelineResources.cs | 2 + .../HDRenderPipelineResources.asset | 2 +- .../Runtime/Sky/CloudLayer/CloudLayer.cs | 208 ++++++++++++------ .../Runtime/Sky/CloudLayer/CloudLayer.hlsl | 29 +-- .../Sky/CloudLayer/CloudTextureBaking.compute | 39 ++++ .../CloudTextureBaking.compute.meta | 9 + .../Runtime/Sky/CloudRenderingContext.cs | 35 +++ .../Runtime/Sky/CloudRenderingContext.cs.meta | 11 + .../Sky/GradientSky/GradientSkyRenderer.cs | 2 +- .../Runtime/Sky/HDRISky/HDRISkyRenderer.cs | 2 +- .../PhysicallyBasedSkyRenderer.cs | 2 +- .../Runtime/Sky/SkyManager.cs | 202 +++++++++++++++++ .../Runtime/Sky/SkyUpdateContext.cs | 7 +- 19 files changed, 596 insertions(+), 133 deletions(-) create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute.meta create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs.meta diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.Skin.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.Skin.cs index 4591cd5cf67..364247c64e8 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.Skin.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.Skin.cs @@ -164,6 +164,8 @@ public class GeneralSection public static readonly GUIContent skyReflectionSizeContent = EditorGUIUtility.TrTextContent("Reflection Size", "Specifies the maximum resolution of the cube map HDRP uses to represent the sky."); public static readonly GUIContent skyLightingOverrideMaskContent = EditorGUIUtility.TrTextContent("Lighting Override Mask", "Specifies the layer mask HDRP uses to override sky lighting."); public const string skyLightingHelpBoxContent = "Be careful, Sky Lighting Override Mask is set to Everything. This is most likely a mistake as it serves no purpose."; + public static readonly GUIContent cloudTextureSizeContent = EditorGUIUtility.TrTextContent("Cloud Texture Size", "Specifies the maximum resolution of the texture HDRP uses to represent the clouds."); + public static readonly GUIContent cloudShadowsSizeContent = EditorGUIUtility.TrTextContent("Cloud Shadows Size", "Specifies the maximum resolution of the texture HDRP uses to represent the cloud shadows."); public static readonly GUIContent maxDirectionalContent = EditorGUIUtility.TrTextContent("Maximum Directional on Screen", "Sets the maximum number of Directional Lights HDRP can handle on screen at once."); public static readonly GUIContent maxPonctualContent = EditorGUIUtility.TrTextContent("Maximum Punctual on Screen", "Sets the maximum number of Point and Spot Lights HDRP can handle on screen at once."); diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs index 3fee70ab462..7c587d27a41 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/HDRenderPipelineUI.cs @@ -313,6 +313,9 @@ static void Drawer_SectionSky(SerializedHDRenderPipelineAsset serialized, Editor { EditorGUILayout.HelpBox(Styles.skyLightingHelpBoxContent, MessageType.Warning); } + + EditorGUILayout.PropertyField(serialized.renderPipelineSettings.lightLoopSettings.cloudTextureSize, Styles.cloudTextureSizeContent); + EditorGUILayout.PropertyField(serialized.renderPipelineSettings.lightLoopSettings.cloudShadowsSize, Styles.cloudShadowsSizeContent); } static private bool m_ShowLightLayerNames = false; diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/SerializedGlobalLightLoopSettings.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/SerializedGlobalLightLoopSettings.cs index 32694a101e0..799f18eba06 100644 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/SerializedGlobalLightLoopSettings.cs +++ b/com.unity.render-pipelines.high-definition/Editor/RenderPipeline/Settings/SerializedGlobalLightLoopSettings.cs @@ -21,6 +21,8 @@ class SerializedGlobalLightLoopSettings public SerializedProperty skyReflectionSize; public SerializedProperty skyLightingOverrideLayerMask; public SerializedProperty supportFabricConvolution; + public SerializedProperty cloudTextureSize; + public SerializedProperty cloudShadowsSize; public SerializedProperty maxDirectionalLightsOnScreen; public SerializedProperty maxPunctualLightsOnScreen; public SerializedProperty maxAreaLightsOnScreen; @@ -50,6 +52,8 @@ public SerializedGlobalLightLoopSettings(SerializedProperty root) skyReflectionSize = root.Find((GlobalLightLoopSettings s) => s.skyReflectionSize); skyLightingOverrideLayerMask = root.Find((GlobalLightLoopSettings s) => s.skyLightingOverrideLayerMask); supportFabricConvolution = root.Find((GlobalLightLoopSettings s) => s.supportFabricConvolution); + cloudTextureSize = root.Find((GlobalLightLoopSettings s) => s.cloudTextureSize); + cloudShadowsSize = root.Find((GlobalLightLoopSettings s) => s.cloudShadowsSize); maxDirectionalLightsOnScreen = root.Find((GlobalLightLoopSettings s) => s.maxDirectionalLightsOnScreen); maxPunctualLightsOnScreen = root.Find((GlobalLightLoopSettings s) => s.maxPunctualLightsOnScreen); diff --git a/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs b/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs index 062d333ef48..cd8792c6178 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs @@ -10,6 +10,17 @@ namespace UnityEditor.Rendering.HighDefinition [VolumeComponentEditor(typeof(CloudLayer))] class CloudLayerEditor : VolumeComponentEditor { + struct CloudSettingsParameter + { + public SerializedDataParameter rotation; + public SerializedDataParameter tint; + public SerializedDataParameter intensityMultiplier; + public SerializedDataParameter distortion; + public SerializedDataParameter scrollDirection; + public SerializedDataParameter scrollSpeed; + public SerializedDataParameter flowmap; + } + struct CloudLightingParameter { public SerializedDataParameter mode; @@ -22,16 +33,49 @@ struct CloudMapParameter { public SerializedDataParameter cloudMap; public SerializedDataParameter[] opacities; - public SerializedDataParameter rotation; - public SerializedDataParameter tint; - public SerializedDataParameter intensityMultiplier; + public CloudSettingsParameter settings; public CloudLightingParameter lighting; } + struct CloudCRTParameter + { + public SerializedDataParameter cloudCRT; + public CloudSettingsParameter settings; + public CloudLightingParameter lighting; + } + + CloudSettingsParameter UnpackCloudSettings(SerializedProperty serializedProperty) + { + var p = new RelativePropertyFetcher(serializedProperty); + + return new CloudSettingsParameter + { + rotation = Unpack(p.Find(x => x.rotation)), + tint = Unpack(p.Find(x => x.tint)), + intensityMultiplier = Unpack(p.Find(x => x.intensityMultiplier)), + distortion = Unpack(p.Find(x => x.distortion)), + scrollDirection = Unpack(p.Find(x => x.scrollDirection)), + scrollSpeed = Unpack(p.Find(x => x.scrollSpeed)), + flowmap = Unpack(p.Find(x => x.flowmap)), + }; + } + + CloudLightingParameter UnpackCloudLighting(SerializedProperty serializedProperty) + { + var p = new RelativePropertyFetcher(serializedProperty); + + return new CloudLightingParameter + { + mode = Unpack(p.Find(x => x.lighting)), + steps = Unpack(p.Find(x => x.steps)), + thickness = Unpack(p.Find(x => x.thickness)), + castShadows = Unpack(p.Find(x => x.castShadows)), + }; + } + CloudMapParameter UnpackCloudMap(SerializedProperty serializedProperty) { var p = new RelativePropertyFetcher(serializedProperty); - var l = new RelativePropertyFetcher(p.Find(x => x.lighting)); return new CloudMapParameter { @@ -43,50 +87,27 @@ CloudMapParameter UnpackCloudMap(SerializedProperty serializedProperty) Unpack(p.Find(x => x.opacityB)), Unpack(p.Find(x => x.opacityA)) }, - rotation = Unpack(p.Find(x => x.rotation)), - tint = Unpack(p.Find(x => x.tint)), - intensityMultiplier = Unpack(p.Find(x => x.intensityMultiplier)), - lighting = new CloudLightingParameter - { - mode = Unpack(l.Find(x => x.lighting)), - steps = Unpack(l.Find(x => x.steps)), - thickness = Unpack(l.Find(x => x.thickness)), - castShadows = Unpack(l.Find(x => x.castShadows)), - } + settings = UnpackCloudSettings(p.Find(x => x.settings)), + lighting = UnpackCloudLighting(p.Find(x => x.lighting)), }; } - void PropertyField(CloudMapParameter map, int index) + CloudCRTParameter UnpackCloudCRT(SerializedProperty serializedProperty) { - EditorGUILayout.Space(); - EditorGUILayout.LabelField($"Map {(index == 0 ? 'A' : 'B')}", EditorStyles.miniLabel); + var p = new RelativePropertyFetcher(serializedProperty); - PropertyField(map.cloudMap); - EditorGUI.indentLevel++; - for (int i = 0; i < 4; i++) - PropertyField(map.opacities[i]); - EditorGUI.indentLevel--; - PropertyField(map.rotation); - PropertyField(map.tint); - PropertyField(map.intensityMultiplier); - - EditorGUILayout.Space(); - EditorGUILayout.LabelField($"Map {(index == 0 ? 'A' : 'B')} Lighting", EditorStyles.miniLabel); - PropertyField(map.lighting.mode); - if (map.lighting.mode.value.intValue == (int)CloudLightingMode.Raymarching) + return new CloudCRTParameter { - EditorGUI.indentLevel++; - PropertyField(map.lighting.steps); - PropertyField(map.lighting.thickness); - EditorGUI.indentLevel--; - } - PropertyField(map.lighting.castShadows); + cloudCRT = Unpack(p.Find(x => x.cloudCRT)), + settings = UnpackCloudSettings(p.Find(x => x.settings)), + lighting = UnpackCloudLighting(p.Find(x => x.lighting)) + }; } - SerializedDataParameter m_Opacity, m_UpperHemisphereOnly; SerializedDataParameter m_Mode, m_Layers; CloudMapParameter[] m_Maps; + CloudCRTParameter m_Crt; public override void OnEnable() { @@ -103,6 +124,61 @@ public override void OnEnable() UnpackCloudMap(o.Find(x => x.mapA)), UnpackCloudMap(o.Find(x => x.mapB)) }; + + m_Crt = UnpackCloudCRT(o.Find(x => x.crt)); + } + + + + void PropertyField(CloudSettingsParameter settings) + { + PropertyField(settings.rotation); + PropertyField(settings.tint); + PropertyField(settings.intensityMultiplier); + + PropertyField(settings.distortion); + if (settings.distortion.value.intValue != (int)CloudDistortionMode.None) + { + EditorGUI.indentLevel++; + PropertyField(settings.scrollDirection); + PropertyField(settings.scrollSpeed); + if (settings.distortion.value.intValue == (int)CloudDistortionMode.Flowmap) + { + PropertyField(settings.flowmap); + } + EditorGUI.indentLevel--; + } + } + + void PropertyField(CloudLightingParameter lighting, string label) + { + EditorGUILayout.Space(); + EditorGUILayout.LabelField(label, EditorStyles.miniLabel); + + PropertyField(lighting.mode); + if (lighting.mode.value.intValue == (int)CloudLightingMode.Raymarching) + { + EditorGUI.indentLevel++; + PropertyField(lighting.steps); + PropertyField(lighting.thickness); + EditorGUI.indentLevel--; + } + PropertyField(lighting.castShadows); + } + + void PropertyField(CloudMapParameter map, string label) + { + EditorGUILayout.Space(); + EditorGUILayout.LabelField(label, EditorStyles.miniLabel); + + PropertyField(map.cloudMap); + EditorGUI.indentLevel++; + for (int i = 0; i < 4; i++) + PropertyField(map.opacities[i]); + EditorGUI.indentLevel--; + + PropertyField(map.settings); + PropertyField(map.lighting, label + " Lighting"); } public override void OnInspectorGUI() @@ -117,9 +193,18 @@ public override void OnInspectorGUI() PropertyField(m_Layers); EditorGUI.indentLevel--; - PropertyField(m_Maps[0], 0); + PropertyField(m_Maps[0], "Map A"); if (m_Layers.value.intValue == (int)CloudMapMode.Double) - PropertyField(m_Maps[1], 1); + PropertyField(m_Maps[1], "Map B"); + } + else if (m_Mode.value.intValue == (int)CloudLayerMode.RenderTexture) + { + EditorGUILayout.Space(); + EditorGUILayout.LabelField("Custom Render Texture", EditorStyles.miniLabel); + + PropertyField(m_Crt.cloudCRT); + PropertyField(m_Crt.settings); + PropertyField(m_Crt.lighting, "Lighting"); } } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/GlobalLightLoopSettings.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/GlobalLightLoopSettings.cs index 2324e7d6c3d..396d3a05f09 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/GlobalLightLoopSettings.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/GlobalLightLoopSettings.cs @@ -127,6 +127,8 @@ public struct GlobalLightLoopSettings skyReflectionSize = SkyResolution.SkyResolution256, skyLightingOverrideLayerMask = 0, + cloudTextureSize = CloudResolution.CloudResolution1024x512, + cloudShadowsSize = CloudShadowsResolution.CloudShadowsResolution64, maxDirectionalLightsOnScreen = 16, maxPunctualLightsOnScreen = 512, @@ -169,6 +171,10 @@ public struct GlobalLightLoopSettings public LayerMask skyLightingOverrideLayerMask; /// Enable fabric specific convolution for probes and sky lighting. public bool supportFabricConvolution; + /// Resolution of the cloud texture. + public CloudResolution cloudTextureSize; + /// Resolution of the cloud shadows texture. + public CloudShadowsResolution cloudShadowsSize; /// Maximum number of directional lights at the same time on screen. public int maxDirectionalLightsOnScreen; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs index ade14e2603c..2fc9c4053ac 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs @@ -88,6 +88,7 @@ internal enum HDProfileId AreaLightCookieConvolution, UpdateSkyEnvironmentConvolution, + BakeCloudTexture, RenderSkyToCubemap, UpdateSkyEnvironment, UpdateSkyAmbientProbe, diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPipelineResources.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPipelineResources.cs index e22df5c7f02..0253b929ea2 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPipelineResources.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPipelineResources.cs @@ -138,6 +138,8 @@ public sealed class ShaderResources public Shader skyboxCubemapPS; [Reload("Runtime/Sky/GradientSky/GradientSky.shader")] public Shader gradientSkyPS; + [Reload("Runtime/Sky/CloudLayer/CloudTextureBaking.compute")] + public ComputeShader bakeCloudTextureCS; [Reload("Runtime/Sky/AmbientProbeConvolution.compute")] public ComputeShader ambientProbeConvolutionCS; [Reload("Runtime/Sky/PhysicallyBasedSky/GroundIrradiancePrecomputation.compute")] diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset index 5f32a722114..a0c1aa79b91 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset @@ -71,6 +71,7 @@ MonoBehaviour: integrateHdriSkyPS: {fileID: 4800000, guid: 48db2705cf2856d4e893eb30a6892d1b, type: 3} skyboxCubemapPS: {fileID: 103, guid: 0000000000000000f000000000000000, type: 0} gradientSkyPS: {fileID: 4800000, guid: 2b5d4f1b26f03dc4a873b093e0c4adb1, type: 3} + bakeCloudTextureCS: {fileID: 7200000, guid: ab3c4e1fdc13358468dc6ee4caf14fc2, type: 3} ambientProbeConvolutionCS: {fileID: 7200000, guid: 6d048f7b1bd45e840b4e79ec92639fa8, type: 3} groundIrradiancePrecomputationCS: {fileID: 7200000, guid: eb6ae6f326207ee4d987a3e5adddf63a, type: 3} inScatteredRadiancePrecomputationCS: {fileID: 7200000, guid: 70c69d514688f8545855680760d77418, type: 3} @@ -142,7 +143,6 @@ MonoBehaviour: dofGatherCS: {fileID: 7200000, guid: 1e6b16a7970a1494db74b1d3d007d1cc, type: 3} DoFCoCPyramidCS: {fileID: 7200000, guid: df41a69211c03fe479b63a8bed3bfbb4, type: 3} contrastAdaptiveSharpenCS: {fileID: 7200000, guid: 560896aec2f412c48995be35551a4ac6, type: 3} - VTFeedbackDownsample: {fileID: 7200000, guid: 32d963548086c2c439aeb23a93e9a00a, type: 3} accumulationCS: {fileID: 7200000, guid: ed80add7a217efa468d137d6f7c668f3, type: 3} alphaInjectionPS: {fileID: 4800000, guid: 4edd96259a5e8b44c90479928f0cd11e, type: 3} chromaKeyingPS: {fileID: 4800000, guid: 49feb6b111e82ec4eb6d3d08e4b6903e, type: 3} diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs index 5915a0711a5..30bcfe425c1 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs @@ -25,9 +25,9 @@ public enum CloudMapMode } /// - /// Distortion Mode. + /// Cloud Distortion Mode. /// - public enum DistortionMode + public enum CloudDistortionMode { /// No distortion. None, @@ -68,23 +68,95 @@ public class CloudLayer : VolumeComponent [Tooltip("")] public VolumeParameter layers = new VolumeParameter(); + [Serializable] + public class CloudSettings + { + /// Rotation of the clouds. + [Tooltip("Sets the rotation of the clouds.")] + public ClampedFloatParameter rotation = new ClampedFloatParameter(0.0f, 0.0f, 360.0f); + /// Color multiplier of the clouds. + [Tooltip("Specifies the color that HDRP uses to tint the clouds.")] + public ColorParameter tint = new ColorParameter(Color.white); + /// Intensity multipler of the clouds. + [Tooltip("Sets the intensity multiplier for the clouds.")] + public MinFloatParameter intensityMultiplier = new MinFloatParameter(1.0f, 0.0f); + + /// Distortion mode. + [Tooltip("Distortion mode.")] + public VolumeParameter distortion = new VolumeParameter(); + /// Direction of the distortion. + [Tooltip("Sets the rotation of the distortion (in degrees).")] + public ClampedFloatParameter scrollDirection = new ClampedFloatParameter(0.0f, 0.0f, 360.0f); + /// Speed of the distortion. + [Tooltip("Sets the cloud scrolling speed. The higher the value, the faster the clouds will move.")] + public MinFloatParameter scrollSpeed = new MinFloatParameter(1.0f, 0.0f); + /// Texture used to distort the UVs for the cloud layer. + [Tooltip("Specify the flowmap HDRP uses for cloud distortion (in LatLong layout).")] + public TextureParameter flowmap = new TextureParameter(null); + + internal float scrollFactor = 0.0f; + + + internal Vector4 GetBakingParameters() + { + Vector4 param = tint.value; + param.w = rotation.value / 360.0f; + return param; + } + + internal Vector4 GetRenderingParameters() + { + float dir = -Mathf.Deg2Rad * scrollDirection.value; + return new Vector4(intensityMultiplier.value, scrollFactor, Mathf.Cos(dir), Mathf.Sin(dir)); + } + + internal int GetBakingHashCode() + { + int hash = 17; + + unchecked + { + hash = hash * 23 + rotation.GetHashCode(); + hash = hash * 23 + tint.GetHashCode(); + } + + return hash; + } + } + [Serializable] public class CloudLighting { /// Distortion mode. [Tooltip("Distortion mode.")] public VolumeParameter lighting = new VolumeParameter(); - /// Number of raymarching steps. [Tooltip("Number of raymarching steps.")] - public ClampedIntParameter steps = new ClampedIntParameter(4, 1, 10); + public ClampedIntParameter steps = new ClampedIntParameter(4, 1, 10); /// . [Tooltip(".")] - public FloatParameter thickness = new FloatParameter(1.0f); + public FloatParameter thickness = new FloatParameter(1.0f); /// Enable to cast shadows. [Tooltip("Cast Shadows.")] - public BoolParameter castShadows = new BoolParameter(false); + public BoolParameter castShadows = new BoolParameter(false); + + + internal int GetBakingHashCode(ref bool castShadows) + { + int hash = 17; + + unchecked + { + hash = hash * 23 + lighting.GetHashCode(); + hash = hash * 23 + steps.GetHashCode(); + hash = hash * 23 + thickness.GetHashCode(); + hash = hash * 23 + castShadows.GetHashCode(); + } + + castShadows |= this.castShadows.value; + return hash; + } } [Serializable] @@ -107,44 +179,15 @@ public class CloudMap [Tooltip("Opacity of the alpha layer.")] public ClampedFloatParameter opacityA = new ClampedFloatParameter(1.0f, 0.0f, 1.0f); - /// Rotation of the clouds. - [Tooltip("Sets the rotation of the clouds.")] - public ClampedFloatParameter rotation = new ClampedFloatParameter(0.0f, 0.0f, 360.0f); - /// Color multiplier of the clouds. - [Tooltip("Specifies the color that HDRP uses to tint the clouds.")] - public ColorParameter tint = new ColorParameter(Color.white); - /// Intensity multipler of the clouds. - [Tooltip("Sets the intensity multiplier for the clouds.")] - public MinFloatParameter intensityMultiplier = new MinFloatParameter(1.0f, 0.0f); - - /// Distortion mode. - [Tooltip("Distortion mode.")] - public VolumeParameter distortion = new VolumeParameter(); - /// Direction of the distortion. - [Tooltip("Sets the rotation of the distortion (in degrees).")] - public ClampedFloatParameter scrollDirection = new ClampedFloatParameter(0.0f, 0.0f, 360.0f); - /// Speed of the distortion. - [Tooltip("Sets the cloud scrolling speed. The higher the value, the faster the clouds will move.")] - public MinFloatParameter scrollSpeed = new MinFloatParameter(1.0f, 0.0f); - /// Texture used to distort the UVs for the cloud layer. - [Tooltip("Specify the flowmap HDRP uses for cloud distortion (in LatLong layout).")] - public TextureParameter flowmap = new TextureParameter(null); - + public CloudSettings settings = new CloudSettings(); public CloudLighting lighting = new CloudLighting(); - internal float scrollFactor = 0.0f; + public Vector4 Opacities => new Vector4(opacityR.value, opacityG.value, opacityB.value, opacityA.value); - internal (Vector4, Vector4) GetParameters() - { - float dir = -Mathf.Deg2Rad * scrollDirection.value; - Vector4 tintAndIntensity = tint.value; - tintAndIntensity.w = intensityMultiplier.value; - return (new Vector4(rotation.value / 360.0f, scrollFactor, Mathf.Cos(dir), Mathf.Sin(dir)), tintAndIntensity); - } - public override int GetHashCode() + internal int GetBakingHashCode(ref bool castShadows) { - int hash = base.GetHashCode(); + int hash = 17; unchecked { @@ -153,18 +196,35 @@ public override int GetHashCode() hash = hash * 23 + opacityG.GetHashCode(); hash = hash * 23 + opacityB.GetHashCode(); hash = hash * 23 + opacityA.GetHashCode(); - hash = hash * 23 + rotation.GetHashCode(); - hash = hash * 23 + tint.GetHashCode(); - hash = hash * 23 + intensityMultiplier.GetHashCode(); - hash = hash * 23 + distortion.GetHashCode(); - hash = hash * 23 + scrollDirection.GetHashCode(); - hash = hash * 23 + scrollSpeed.GetHashCode(); - hash = hash * 23 + flowmap.GetHashCode(); - - hash = hash * 23 + lighting.lighting.GetHashCode(); - hash = hash * 23 + lighting.steps.GetHashCode(); - hash = hash * 23 + lighting.thickness.GetHashCode(); - hash = hash * 23 + lighting.castShadows.GetHashCode(); + + hash = hash * 23 + settings.GetBakingHashCode(); + hash = hash * 23 + lighting.GetBakingHashCode(ref castShadows); + } + + return hash; + } + } + + [Serializable] + public class CloudCRT + { + /// Texture used to render the clouds. + [Tooltip("Specify the CustomRenderTexture HDRP uses to render the clouds (in LatLong layout).")] + public TextureParameter cloudCRT = new TextureParameter(null); + + public CloudSettings settings = new CloudSettings(); + public CloudLighting lighting = new CloudLighting(); + + + internal int GetBakingHashCode(ref bool castShadows) + { + int hash = 17; + + unchecked + { + hash = hash * 23 + cloudCRT.GetHashCode(); + hash = hash * 23 + settings.GetBakingHashCode(); + hash = hash * 23 + lighting.GetBakingHashCode(ref castShadows); } return hash; @@ -173,10 +233,11 @@ public override int GetHashCode() public CloudMap mapA = new CloudMap(); public CloudMap mapB = new CloudMap(); - + public CloudCRT crt = new CloudCRT(); private float lastTime = 0.0f; + CloudLayer() { displayName = "CloudLayer (Preview)"; @@ -186,27 +247,29 @@ public override int GetHashCode() /// Sets keywords and parameters on a sky material to render the cloud layer. /// The cloud layer to apply. /// The sky material to change. - public static void Apply(CloudLayer layer, Material skyMaterial) + public static void Apply(BuiltinSkyParameters builtinParams, Material skyMaterial) { + var layer = builtinParams.cloudLayer; if (layer != null && layer.opacity.value != 0.0f) { - layer.mapA.scrollFactor += layer.mapA.scrollSpeed.value * (Time.time - layer.lastTime) * 0.01f; + layer.mapA.settings.scrollFactor += layer.mapA.settings.scrollSpeed.value * (Time.time - layer.lastTime) * 0.01f; layer.lastTime = Time.time; - (Vector4, Vector4) paramsA = layer.mapA.GetParameters(); + Vector4 params1 = new Vector4(layer.opacity.value, layer.upperHemisphereOnly.value?1:0, 0, 0); + Vector4 params2 = layer.mapA.settings.GetRenderingParameters(); skyMaterial.EnableKeyword("USE_CLOUD_MAP"); - skyMaterial.SetTexture(HDShaderIDs._CloudMap, layer.mapA.cloudMap.value); - skyMaterial.SetVector(HDShaderIDs._CloudParam, paramsA.Item1); - skyMaterial.SetVector(HDShaderIDs._CloudParam2, paramsA.Item2); + skyMaterial.SetTexture("_CloudTexture", builtinParams.cloudTexture); + skyMaterial.SetVector("_CloudParams1", params1); + skyMaterial.SetVector("_CloudParams2", params2); - if (layer.mapA.distortion.value != DistortionMode.None) + if (layer.mapA.settings.distortion.value != CloudDistortionMode.None) { skyMaterial.EnableKeyword("USE_CLOUD_MOTION"); - if (layer.mapA.distortion.value == DistortionMode.Procedural) + if (layer.mapA.settings.distortion.value == CloudDistortionMode.Procedural) skyMaterial.DisableKeyword("USE_CLOUD_MAP"); else - skyMaterial.SetTexture(HDShaderIDs._CloudFlowmap, layer.mapA.flowmap.value); + skyMaterial.SetTexture(HDShaderIDs._CloudFlowmap, layer.mapA.settings.flowmap.value); } else skyMaterial.DisableKeyword("USE_CLOUD_MOTION"); @@ -218,22 +281,23 @@ public static void Apply(CloudLayer layer, Material skyMaterial) } } - /// - /// Returns the hash code of the HDRI sky parameters. - /// - /// The hash code of the HDRI sky parameters. - public override int GetHashCode() + internal int GetBakingHashCode(out bool castShadows) { - int hash = base.GetHashCode(); + int hash = 17; + castShadows = false; unchecked { - hash = hash * 23 + opacity.GetHashCode(); - hash = hash * 23 + upperHemisphereOnly.GetHashCode(); hash = hash * 23 + mode.GetHashCode(); - hash = hash * 23 + layers.GetHashCode(); - hash = hash * 23 + mapA.GetHashCode(); - hash = hash * 23 + mapB.GetHashCode(); + if (mode.value == CloudLayerMode.CloudMap) + { + hash = hash * 23 + layers.GetHashCode(); + hash = hash * 23 + mapA.GetBakingHashCode(ref castShadows); + if (layers.value == CloudMapMode.Double) + hash = hash * 23 + mapB.GetBakingHashCode(ref castShadows); + } + else + hash = hash * 23 + crt.GetBakingHashCode(ref castShadows); } return hash; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl index 67cff3b0161..1ce567ac35f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl @@ -1,31 +1,27 @@ #ifndef __CLOUDLAYER_H__ #define __CLOUDLAYER_H__ -TEXTURE2D(_CloudMap); -SAMPLER(sampler_CloudMap); +TEXTURE2D(_CloudTexture); +SAMPLER(sampler_CloudTexture); TEXTURE2D(_CloudFlowmap); SAMPLER(sampler_CloudFlowmap); -float4 _CloudParam; // x upper hemisphere only / rotation, y scroll factor, zw scroll direction (cosPhi and sinPhi) -float4 _CloudParam2; // xyz tint, w intensity +float4 _CloudParams1; // x upper hemisphere only / rotation, y scroll factor, zw scroll direction (cosPhi and sinPhi) +float4 _CloudParams2; // xyz tint, w intensity -#define _CloudUpperHemisphere _CloudParam.x > 0 -#define _CloudRotation abs(_CloudParam.x) -#define _CloudScrollFactor _CloudParam.y -#define _CloudScrollDirection _CloudParam.zw -#define _CloudTint _CloudParam2.xyz -#define _CloudIntensity _CloudParam2.w +#define _CloudOpacity _CloudParams1.x +#define _CloudUpperHemisphere _CloudParams1.y +#define _CloudIntensity _CloudParams2.x +#define _CloudScrollFactor _CloudParams2.y +#define _CloudScrollDirection _CloudParams2.zw #define USE_CLOUD_LAYER defined(USE_CLOUD_MAP) || (!defined(USE_CLOUD_MAP) && defined(USE_CLOUD_MOTION)) float4 sampleCloud(float3 dir) { float2 coords = GetLatLongCoords(dir, _CloudUpperHemisphere); - coords.x = frac(coords.x + _CloudRotation); - float4 cloudLayerColor = SAMPLE_TEXTURE2D_LOD(_CloudMap, sampler_CloudMap, coords, 0).r; - cloudLayerColor.rgb *= _CloudTint * _CloudIntensity * cloudLayerColor.a; - return cloudLayerColor; + return SAMPLE_TEXTURE2D_LOD(_CloudTexture, sampler_CloudTexture, coords, 0); } float3 CloudRotationUp(float3 p, float2 cos_sin) @@ -71,7 +67,7 @@ float GetCloudOpacity(float3 dir) { #if USE_CLOUD_LAYER if (dir.y >= 0 || !_CloudUpperHemisphere) - return GetDistordedCloudColor(dir).a; + return GetDistordedCloudColor(dir).a * _CloudOpacity; else #endif @@ -82,7 +78,7 @@ float3 ApplyCloudLayer(float3 dir, float3 sky) { #if USE_CLOUD_LAYER if (dir.y >= 0 || !_CloudUpperHemisphere) - sky += GetDistordedCloudColor(dir).rgb; + sky += GetDistordedCloudColor(dir).rgb * _CloudIntensity * _CloudOpacity; #endif return sky; @@ -91,7 +87,6 @@ float3 ApplyCloudLayer(float3 dir, float3 sky) #undef _CloudUpperHemisphere #undef _CloudScrollFactor #undef _CloudScrollDirection -#undef _CloudTint #undef _CloudIntensity #undef USE_CLOUD_LAYER diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute new file mode 100644 index 00000000000..c04bab3c06d --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute @@ -0,0 +1,39 @@ +#pragma only_renderers d3d11 playstation xboxone vulkan metal switch + +#pragma multi_compile_local _ USE_CLOUD_MAP +#pragma multi_compile_local _ USE_CLOUD_MOTION + +#pragma kernel BakeCloudTexture KERNEL_NAME=BakeCloudTexture + +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyUtils.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + +TEXTURE2D(_CloudMap); +SAMPLER(sampler_CloudMap); + +RW_TEXTURE2D(float4, _CloudTextureOutput); + +static const float res = 1.0f / 512.0f; +CBUFFER_START(cb0) +float3 _SunDirection; +float4 _Opacities; +float4 _Params; +CBUFFER_END + +#define _CloudTint _Params.xyz +#define _CloudRotation _Params.w + +[numthreads(8, 8, 1)] +void KERNEL_NAME(uint2 dispatchThreadId : SV_DispatchThreadID) +{ + float2 uv = float2(dispatchThreadId.x * res, dispatchThreadId.y * res * 2.0f); + + uv.x = frac(uv.x + _CloudRotation); + float4 cloudLayerColor = SAMPLE_TEXTURE2D_LOD(_CloudMap, sampler_CloudMap, uv, 0); + float4 clouds = cloudLayerColor * _Opacities; + float opacity = max(max(clouds.r, clouds.g), max(clouds.b, clouds.a)); + + _CloudTextureOutput[dispatchThreadId] = float4(opacity * _CloudTint, opacity); +} diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute.meta b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute.meta new file mode 100644 index 00000000000..2292664b277 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: ab3c4e1fdc13358468dc6ee4caf14fc2 +ComputeShaderImporter: + externalObjects: {} + currentAPIMask: 2097156 + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs new file mode 100644 index 00000000000..36355e04971 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs @@ -0,0 +1,35 @@ +using System; +using UnityEngine.Experimental.Rendering; + +namespace UnityEngine.Rendering.HighDefinition +{ + internal class CloudRenderingContext + { + public RTHandle cloudTextureRT { get; private set; } + public RTHandle cloudShadowsRT { get; private set; } = null; + public bool supportShadows { get; private set; } + + internal bool ambientProbeIsReady = false; + + public CloudRenderingContext(int resolution, bool supportShadows, int shadowResolution) + { + this.supportShadows = supportShadows; + + cloudTextureRT = RTHandles.Alloc(resolution, resolution / 2, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, + dimension: TextureDimension.Tex2D, enableRandomWrite: true, useMipMap: false, + filterMode: FilterMode.Bilinear, name: "Cloud Texture"); + + if (supportShadows) + cloudShadowsRT = RTHandles.Alloc(shadowResolution, shadowResolution, colorFormat: GraphicsFormat.R8_SNorm, + dimension: TextureDimension.Tex2D, enableRandomWrite: true, useMipMap: false, + filterMode: FilterMode.Bilinear, name: "Cloud Shadows"); + } + + public void Cleanup() + { + RTHandles.Release(cloudTextureRT); + if (cloudShadowsRT != null) + CoreUtils.Destroy(cloudShadowsRT); + } + } +} diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs.meta b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs.meta new file mode 100644 index 00000000000..53cf4cce6d1 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1713e42af36be95469184eeb66771780 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/GradientSky/GradientSkyRenderer.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/GradientSky/GradientSkyRenderer.cs index 0ca6941d630..3cf46cfc61a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/GradientSky/GradientSkyRenderer.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/GradientSky/GradientSkyRenderer.cs @@ -35,7 +35,7 @@ public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderFo m_GradientSkyMaterial.SetFloat(_GradientDiffusion, gradientSky.gradientDiffusion.value); m_GradientSkyMaterial.SetFloat(HDShaderIDs._SkyIntensity, GetSkyIntensity(gradientSky, builtinParams.debugSettings)); - CloudLayer.Apply(builtinParams.cloudLayer, m_GradientSkyMaterial); + CloudLayer.Apply(builtinParams, m_GradientSkyMaterial); // This matrix needs to be updated at the draw call frequency. m_PropertyBlock.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, builtinParams.pixelCoordToViewDirMatrix); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISkyRenderer.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISkyRenderer.cs index 5b274165cdc..98297521328 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISkyRenderer.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISkyRenderer.cs @@ -170,7 +170,7 @@ public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderFo shadowFilter |= unchecked((uint)LightFeatureFlags.Area); m_SkyHDRIMaterial.SetInt(HDShaderIDs._BackplateShadowFilter, unchecked((int)shadowFilter)); - CloudLayer.Apply(builtinParams.cloudLayer, m_SkyHDRIMaterial); + CloudLayer.Apply(builtinParams, m_SkyHDRIMaterial); // This matrix needs to be updated at the draw call frequency. m_PropertyBlock.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, builtinParams.pixelCoordToViewDirMatrix); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSkyRenderer.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSkyRenderer.cs index 01c708534ba..d22313b5ea8 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSkyRenderer.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSkyRenderer.cs @@ -503,7 +503,7 @@ public override void RenderSky(BuiltinSkyParameters builtinParams, bool renderFo int pass = (renderForCubemap ? 0 : 2); - CloudLayer.Apply(builtinParams.cloudLayer, m_PbrSkyMaterial); + CloudLayer.Apply(builtinParams, m_PbrSkyMaterial); CoreUtils.DrawFullScreen(builtinParams.commandBuffer, m_PbrSkyMaterial, s_PbrSkyMaterialProperties, pass); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs index 4bd8e47cb1e..8b6ed5c7198 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs @@ -25,6 +25,38 @@ public enum SkyResolution SkyResolution4096 = 4096 } + /// + /// Resolution of the cloud texture. + /// + [Serializable] + public enum CloudResolution + { + /// Size 256x128 + CloudResolution256x128 = 256, + /// Size 512x256 + CloudResolution512x256 = 512, + /// Size 1024x512 + CloudResolution1024x512 = 1024, + /// Size 2048x1024 + CloudResolution2048x1024 = 2048, + } + + /// + /// Resolution of the cloud shadow. + /// + [Serializable] + public enum CloudShadowsResolution + { + /// Size 64 + CloudShadowsResolution64 = 64, + /// Size 128 + CloudShadowsResolution128 = 128, + /// Size 256 + CloudShadowsResolution256 = 256, + /// Size 512 + CloudShadowsResolution512 = 512, + } + /// /// Environment lighting update mode. /// @@ -67,12 +99,39 @@ public class BuiltinSkyParameters public SkySettings skySettings; /// Current cloud layer. public CloudLayer cloudLayer; + /// Baked cloud texture. + public RTHandle cloudTexture; /// Current debug dsplay settings. public DebugDisplaySettings debugSettings; /// Null color buffer render target identifier. public static RenderTargetIdentifier nullRT = -1; } + struct CachedCloudContext + { + public CloudRenderingContext renderingContext; + public int hash; + public int refCount; + + public void Reset() + { + // We keep around the rendering context to avoid useless allocation if they get reused. + hash = 0; + refCount = 0; + } + + public void Cleanup() + { + Reset(); + + if (renderingContext != null) + { + renderingContext.Cleanup(); + renderingContext = null; + } + } + } + struct CachedSkyContext { public Type type; @@ -110,6 +169,8 @@ class SkyManager bool m_UpdateRequired = false; bool m_StaticSkyUpdateRequired = false; int m_Resolution; + int m_CloudResolution; + int m_CloudShadowsResolution; // Sky used for static lighting. It will be used for ambient lighting if Ambient Mode is set to Static (even when realtime GI is enabled) // It will also be used for lightmap and light probe baking @@ -153,7 +214,13 @@ class SkyManager int m_ComputeAmbientProbeKernel; CubemapArray m_BlackCubemapArray; + // Shared resources for cloud rendering. + ComputeShader m_BakeCloudTextureCS; + int m_BakeCloudTextureKernel; + readonly int m_CloudTextureOutputParam = Shader.PropertyToID("_CloudTextureOutput"); + // 2 by default: Static sky + one dynamic. Will grow if needed. + DynamicArray m_CachedCloudContexts = new DynamicArray(2); DynamicArray m_CachedSkyContexts = new DynamicArray(2); public SkyManager() @@ -295,6 +362,13 @@ public void Build(HDRenderPipelineAsset hdAsset, RenderPipelineResources default } InitializeBlackCubemapArray(); + + + m_CloudResolution = (int)hdAsset.currentPlatformRenderPipelineSettings.lightLoopSettings.cloudTextureSize; + m_CloudShadowsResolution = (int)hdAsset.currentPlatformRenderPipelineSettings.lightLoopSettings.cloudShadowsSize; + + m_BakeCloudTextureCS = hdrp.renderPipelineResources.shaders.bakeCloudTextureCS; + m_BakeCloudTextureKernel = m_BakeCloudTextureCS.FindKernel("BakeCloudTexture"); } void InitializeBlackCubemapArray() @@ -335,6 +409,8 @@ public void Cleanup() for (int i = 0; i < m_CachedSkyContexts.size; ++i) m_CachedSkyContexts[i].Cleanup(); + for (int i = 0; i < m_CachedCloudContexts.size; ++i) + m_CachedCloudContexts[i].Cleanup(); m_StaticLightingSky.Cleanup(); lightingOverrideVolumeStack.Dispose(); @@ -529,6 +605,29 @@ void RenderCubemapGGXConvolution(SkyUpdateContext skyContext) } } + void BakeCloudTexture(SkyUpdateContext skyContext, Light sunLight) + { + var cmd = m_BuiltinParameters.commandBuffer; + using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.BakeCloudTexture))) + { + var renderingContext = m_CachedCloudContexts[skyContext.cachedCloudRenderingContextId].renderingContext; + var layer = skyContext.cloudLayer; + + cmd.SetComputeVectorParam(m_BakeCloudTextureCS, "_SunDirection", sunLight.transform.forward); + cmd.SetComputeVectorParam(m_BakeCloudTextureCS, "_Opacities", layer.mapA.Opacities); + cmd.SetComputeVectorParam(m_BakeCloudTextureCS, "_Params", layer.mapA.settings.GetBakingParameters()); + cmd.SetComputeTextureParam(m_BakeCloudTextureCS, m_BakeCloudTextureKernel, "_CloudMap", layer.mapA.cloudMap.value); + cmd.SetComputeTextureParam(m_BakeCloudTextureCS, m_BakeCloudTextureKernel, m_CloudTextureOutputParam, renderingContext.cloudTextureRT); + + const int groupSizeX = 8; + const int groupSizeY = 8; + int threadGroupX = (m_CloudResolution + (groupSizeX - 1)) / groupSizeX; + int threadGroupY = (m_CloudResolution/2 + (groupSizeY - 1)) / groupSizeY; + + cmd.DispatchCompute(m_BakeCloudTextureCS, m_BakeCloudTextureKernel, threadGroupX, threadGroupY, 1); + } + } + // We do our own hash here because Unity does not provide correct hash for builtin types // Moreover, we don't want to test every single parameters of the light so we filter them here in this specific function. int GetSunLightHashCode(Light light) @@ -554,6 +653,77 @@ int GetSunLightHashCode(Light light) } + // Returns whether or not the cloud data should be updated + bool AcquireCloudRenderingContext(SkyUpdateContext updateContext, int newHash, bool supportShadows) + { + int id = updateContext.cachedCloudRenderingContextId; + // Release the old context if needed. + if (id != -1 && m_CachedCloudContexts[id].hash != 0) + { + ref var oldContext = ref m_CachedCloudContexts[id]; + if (oldContext.hash != newHash) + ReleaseCachedCloudContext(id); + else + return false; + } + + // Else allocate a new one + int firstFreeContext = -1; + for (int i = 0; i < m_CachedCloudContexts.size; ++i) + { + // Try to find a matching slot + if (m_CachedCloudContexts[i].hash == newHash) + { + m_CachedCloudContexts[i].refCount++; + updateContext.cachedCloudRenderingContextId = i; + return false; + } + + // Find the first available slot in case we don't find a matching one. + if (firstFreeContext == -1 && m_CachedCloudContexts[i].hash == 0) + firstFreeContext = i; + } + + if (firstFreeContext == -1) + firstFreeContext = m_CachedCloudContexts.Add(new CachedCloudContext()); + + ref var context = ref m_CachedCloudContexts[firstFreeContext]; + context.hash = newHash; + context.refCount = 1; + + if (context.renderingContext != null && context.renderingContext.supportShadows != supportShadows) + { + context.renderingContext.Cleanup(); + context.renderingContext = null; + } + if (context.renderingContext == null) + context.renderingContext = new CloudRenderingContext(m_CloudResolution, supportShadows, 10); + + updateContext.cachedCloudRenderingContextId = firstFreeContext; + + return true; + } + + internal void ReleaseCachedCloudContext(int id) + { + if (id == -1) + return; + + ref var cachedContext = ref m_CachedCloudContexts[id]; + + // This can happen if 2 cameras use the same context and release it in the same frame. + // The first release the context but the next one will still have this id. + if (cachedContext.refCount == 0) + { + Debug.Assert(cachedContext.renderingContext == null); // Context should already have been cleaned up. + return; + } + + cachedContext.refCount--; + if (cachedContext.refCount == 0) + cachedContext.Reset(); + } + void AllocateNewRenderingContext(SkyUpdateContext skyContext, int slot, int newHash, bool supportConvolution, in SphericalHarmonicsL2 previousAmbientProbe, string name) { Debug.Assert(m_CachedSkyContexts[slot].hash == 0); @@ -663,6 +833,15 @@ bool IsCachedContextValid(SkyUpdateContext skyContext) return id != -1 && (skyContext.skySettings.GetSkyRendererType() == m_CachedSkyContexts[id].type) && (m_CachedSkyContexts[id].hash != 0); } + + int ComputeCloudHash(CloudLayer layer, Light sunLight, out bool castShadows) + { + int hash = layer.GetBakingHashCode(out castShadows); + if (sunLight != null) + hash = hash * 23 + GetSunLightHashCode(sunLight); + return hash; + } + int ComputeSkyHash(HDCamera camera, SkyUpdateContext skyContext, Light sunLight, SkyAmbientMode ambientMode, bool staticSky = false) { int sunHash = 0; @@ -734,6 +913,24 @@ public void UpdateEnvironment( HDCamera hdCamera, m_BuiltinParameters.frameIndex = frameIndex; m_BuiltinParameters.skySettings = skyContext.skySettings; m_BuiltinParameters.cloudLayer = skyContext.cloudLayer; + m_BuiltinParameters.cloudTexture = null; + + if (skyContext.cloudLayer != null && skyContext.cloudLayer.opacity.value != 0.0f) + { + int cloudHash = ComputeCloudHash(skyContext.cloudLayer, sunLight, out bool castShadows); + // Acquire the rendering context, if the context was invalid or the hash has changed, + // this will request for an update. + if (AcquireCloudRenderingContext(skyContext, cloudHash, castShadows)) + BakeCloudTexture(skyContext, sunLight); + + var cloudContext = m_CachedCloudContexts[skyContext.cachedCloudRenderingContextId].renderingContext; + m_BuiltinParameters.cloudTexture = cloudContext.cloudTextureRT; + } + else if (skyContext.cachedCloudRenderingContextId != -1) + { + ReleaseCachedCloudContext(skyContext.cachedCloudRenderingContextId); + skyContext.cachedCloudRenderingContextId = -1; + } int skyHash = ComputeSkyHash(hdCamera, skyContext, sunLight, ambientMode, staticSky); bool forceUpdate = updateRequired; @@ -857,6 +1054,11 @@ internal void UpdateBuiltinParameters(SkyUpdateContext skyContext, HDCamera hdCa m_BuiltinParameters.frameIndex = frameIndex; m_BuiltinParameters.skySettings = skyContext.skySettings; m_BuiltinParameters.cloudLayer = skyContext.cloudLayer; + + int cloudHash = ComputeCloudHash(skyContext.cloudLayer, sunLight, out bool castShadows); + AcquireCloudRenderingContext(skyContext, cloudHash, castShadows); + var cloudContext = m_CachedCloudContexts[skyContext.cachedCloudRenderingContextId].renderingContext; + m_BuiltinParameters.cloudTexture = cloudContext.cloudTextureRT; } public void PreRenderSky(HDCamera hdCamera, Light sunLight, RTHandle colorBuffer, RTHandle normalBuffer, RTHandle depthBuffer, DebugDisplaySettings debugSettings, int frameIndex, CommandBuffer cmd) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyUpdateContext.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyUpdateContext.cs index 3f5fe859b87..908c24614a4 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyUpdateContext.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyUpdateContext.cs @@ -5,10 +5,12 @@ namespace UnityEngine.Rendering.HighDefinition internal class SkyUpdateContext { SkySettings m_SkySettings; - CloudLayer m_CloudLayer; public SkyRenderer skyRenderer { get; private set; } public int cachedSkyRenderingContextId = -1; + CloudLayer m_CloudLayer; + public int cachedCloudRenderingContextId = -1; + public int skyParametersHash = -1; public float currentUpdateTime = 0.0f; @@ -64,7 +66,10 @@ public void Cleanup() HDRenderPipeline hdrp = HDRenderPipeline.currentPipeline; if (hdrp != null) + { hdrp.skyManager.ReleaseCachedContext(cachedSkyRenderingContextId); + hdrp.skyManager.ReleaseCachedCloudContext(cachedCloudRenderingContextId); + } } public bool IsValid() From 0aaebbc46c79aef383123deee8c344744763ba80 Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Wed, 22 Jul 2020 11:00:23 +0200 Subject: [PATCH 03/10] Added second layer --- .../Runtime/Sky/CloudLayer/CloudLayer.cs | 12 ++++- .../Runtime/Sky/CloudLayer/CloudLayer.hlsl | 31 ++++++++---- .../Sky/CloudLayer/CloudTextureBaking.compute | 47 ++++++++++++------- .../Runtime/Sky/CloudRenderingContext.cs | 14 +++--- .../Runtime/Sky/SkyManager.cs | 46 +++++++++++++----- 5 files changed, 102 insertions(+), 48 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs index 30bcfe425c1..ee0aeac5a88 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs @@ -255,7 +255,11 @@ public static void Apply(BuiltinSkyParameters builtinParams, Material skyMateria layer.mapA.settings.scrollFactor += layer.mapA.settings.scrollSpeed.value * (Time.time - layer.lastTime) * 0.01f; layer.lastTime = Time.time; - Vector4 params1 = new Vector4(layer.opacity.value, layer.upperHemisphereOnly.value?1:0, 0, 0); + Vector4 params1 = new Vector4( + layer.opacity.value, + layer.upperHemisphereOnly.value?1:0, + (layer.mode.value == CloudLayerMode.CloudMap && layer.layers.value == CloudMapMode.Double)?1:0, + 0); Vector4 params2 = layer.mapA.settings.GetRenderingParameters(); skyMaterial.EnableKeyword("USE_CLOUD_MAP"); @@ -281,10 +285,11 @@ public static void Apply(BuiltinSkyParameters builtinParams, Material skyMateria } } - internal int GetBakingHashCode(out bool castShadows) + internal int GetBakingHashCode(out int numLayers, out bool castShadows) { int hash = 17; castShadows = false; + numLayers = 1; unchecked { @@ -294,7 +299,10 @@ internal int GetBakingHashCode(out bool castShadows) hash = hash * 23 + layers.GetHashCode(); hash = hash * 23 + mapA.GetBakingHashCode(ref castShadows); if (layers.value == CloudMapMode.Double) + { hash = hash * 23 + mapB.GetBakingHashCode(ref castShadows); + numLayers = 2; + } } else hash = hash * 23 + crt.GetBakingHashCode(ref castShadows); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl index 1ce567ac35f..72f9798b64e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl @@ -1,7 +1,7 @@ #ifndef __CLOUDLAYER_H__ #define __CLOUDLAYER_H__ -TEXTURE2D(_CloudTexture); +TEXTURE2D_ARRAY(_CloudTexture); SAMPLER(sampler_CloudTexture); TEXTURE2D(_CloudFlowmap); @@ -12,16 +12,17 @@ float4 _CloudParams2; // xyz tint, w intensity #define _CloudOpacity _CloudParams1.x #define _CloudUpperHemisphere _CloudParams1.y +#define _CloudDoubleLayer (_CloudParams1.z != 0.0) #define _CloudIntensity _CloudParams2.x #define _CloudScrollFactor _CloudParams2.y #define _CloudScrollDirection _CloudParams2.zw #define USE_CLOUD_LAYER defined(USE_CLOUD_MAP) || (!defined(USE_CLOUD_MAP) && defined(USE_CLOUD_MOTION)) -float4 sampleCloud(float3 dir) +float4 sampleCloud(float3 dir, int layer) { float2 coords = GetLatLongCoords(dir, _CloudUpperHemisphere); - return SAMPLE_TEXTURE2D_LOD(_CloudTexture, sampler_CloudTexture, coords, 0); + return SAMPLE_TEXTURE2D_ARRAY_LOD(_CloudTexture, sampler_CloudTexture, coords, layer, 0); } float3 CloudRotationUp(float3 p, float2 cos_sin) @@ -32,7 +33,7 @@ float3 CloudRotationUp(float3 p, float2 cos_sin) return float3(dot(rotDirX, p), p.y, dot(rotDirY, p)); } -float4 GetDistordedCloudColor(float3 dir) +float4 GetDistordedCloudColor(float3 dir, int layer) { #if USE_CLOUD_MOTION float2 alpha = frac(float2(_CloudScrollFactor, _CloudScrollFactor + 0.5)) - 0.5; @@ -52,33 +53,43 @@ float4 GetDistordedCloudColor(float3 dir) #endif // Sample twice - float4 color1 = sampleCloud(normalize(dir - alpha.x * dd)); - float4 color2 = sampleCloud(normalize(dir - alpha.y * dd)); + float4 color1 = sampleCloud(normalize(dir - alpha.x * dd), layer); + float4 color2 = sampleCloud(normalize(dir - alpha.y * dd), layer); // Blend color samples return lerp(color1, color2, abs(2.0 * alpha.x)); #else - return sampleCloud(dir); + return sampleCloud(dir, layer); #endif } float GetCloudOpacity(float3 dir) { + float opacity = 0; + #if USE_CLOUD_LAYER if (dir.y >= 0 || !_CloudUpperHemisphere) - return GetDistordedCloudColor(dir).a * _CloudOpacity; + { + opacity = GetDistordedCloudColor(dir, 0).a; + if (_CloudDoubleLayer) + opacity *= (1.0 - GetDistordedCloudColor(dir, 1).a); + } else #endif - return 0; + return opacity * _CloudOpacity; } float3 ApplyCloudLayer(float3 dir, float3 sky) { #if USE_CLOUD_LAYER if (dir.y >= 0 || !_CloudUpperHemisphere) - sky += GetDistordedCloudColor(dir).rgb * _CloudIntensity * _CloudOpacity; + { + if (_CloudDoubleLayer) + sky += GetDistordedCloudColor(dir, 1).rgb * _CloudIntensity * _CloudOpacity; + sky += GetDistordedCloudColor(dir, 0).rgb * _CloudIntensity * _CloudOpacity; + } #endif return sky; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute index c04bab3c06d..88065d82715 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute @@ -1,7 +1,6 @@ #pragma only_renderers d3d11 playstation xboxone vulkan metal switch -#pragma multi_compile_local _ USE_CLOUD_MAP -#pragma multi_compile_local _ USE_CLOUD_MOTION +#pragma multi_compile_local _ CLOUD_LAYER_DOUBLE_MODE #pragma kernel BakeCloudTexture KERNEL_NAME=BakeCloudTexture @@ -10,28 +9,44 @@ #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" -TEXTURE2D(_CloudMap); -SAMPLER(sampler_CloudMap); +#ifndef CLOUD_LAYER_DOUBLE_MODE + #define NUM_LAYERS 1 + #define LAYER 0 +#else + #define NUM_LAYERS 2 + #define LAYER dispatchThreadId.z +#endif -RW_TEXTURE2D(float4, _CloudTextureOutput); +TEXTURE2D(_CloudMapA); +SAMPLER(sampler_CloudMapA); + +TEXTURE2D(_CloudMapB); +SAMPLER(sampler_CloudMapB); + +RW_TEXTURE2D_ARRAY(float4, _CloudTextureOutput); -static const float res = 1.0f / 512.0f; CBUFFER_START(cb0) -float3 _SunDirection; -float4 _Opacities; -float4 _Params; +float4 _Params1; +float4 _Params2[NUM_LAYERS]; +float4 _Params3[NUM_LAYERS]; CBUFFER_END -#define _CloudTint _Params.xyz -#define _CloudRotation _Params.w +#define _SunDirection _Params1.xyz +#define _Resolution _Params1.w +#define _Opacities _Params2[LAYER] +#define _CloudTint _Params3[LAYER].xyz +#define _CloudRotation _Params3[LAYER].w -[numthreads(8, 8, 1)] -void KERNEL_NAME(uint2 dispatchThreadId : SV_DispatchThreadID) +[numthreads(8, 8, NUM_LAYERS)] +void KERNEL_NAME(uint3 dispatchThreadId : SV_DispatchThreadID) { - float2 uv = float2(dispatchThreadId.x * res, dispatchThreadId.y * res * 2.0f); - + float2 uv = float2(dispatchThreadId.x * _Resolution, dispatchThreadId.y * _Resolution * 2.0f); uv.x = frac(uv.x + _CloudRotation); - float4 cloudLayerColor = SAMPLE_TEXTURE2D_LOD(_CloudMap, sampler_CloudMap, uv, 0); + + float4 cloudLayerColor = LAYER == 0 ? + SAMPLE_TEXTURE2D_LOD(_CloudMapA, sampler_CloudMapA, uv, 0): + SAMPLE_TEXTURE2D_LOD(_CloudMapB, sampler_CloudMapB, uv, 0); + float4 clouds = cloudLayerColor * _Opacities; float opacity = max(max(clouds.r, clouds.g), max(clouds.b, clouds.a)); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs index 36355e04971..db09914968c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs @@ -6,17 +6,17 @@ namespace UnityEngine.Rendering.HighDefinition internal class CloudRenderingContext { public RTHandle cloudTextureRT { get; private set; } - public RTHandle cloudShadowsRT { get; private set; } = null; + public RTHandle cloudShadowsRT { get; private set; } + public int numLayers { get; private set; } public bool supportShadows { get; private set; } - internal bool ambientProbeIsReady = false; - - public CloudRenderingContext(int resolution, bool supportShadows, int shadowResolution) + public CloudRenderingContext(int resolution, int numLayers, bool supportShadows, int shadowResolution) { + this.numLayers = numLayers; this.supportShadows = supportShadows; - cloudTextureRT = RTHandles.Alloc(resolution, resolution / 2, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, - dimension: TextureDimension.Tex2D, enableRandomWrite: true, useMipMap: false, + cloudTextureRT = RTHandles.Alloc(resolution, resolution / 2, numLayers, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, + dimension: TextureDimension.Tex2DArray, enableRandomWrite: true, useMipMap: false, filterMode: FilterMode.Bilinear, name: "Cloud Texture"); if (supportShadows) @@ -28,7 +28,7 @@ public CloudRenderingContext(int resolution, bool supportShadows, int shadowReso public void Cleanup() { RTHandles.Release(cloudTextureRT); - if (cloudShadowsRT != null) + if (supportShadows) CoreUtils.Destroy(cloudShadowsRT); } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs index 8b6ed5c7198..8f12747034a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs @@ -613,12 +613,30 @@ void BakeCloudTexture(SkyUpdateContext skyContext, Light sunLight) var renderingContext = m_CachedCloudContexts[skyContext.cachedCloudRenderingContextId].renderingContext; var layer = skyContext.cloudLayer; - cmd.SetComputeVectorParam(m_BakeCloudTextureCS, "_SunDirection", sunLight.transform.forward); - cmd.SetComputeVectorParam(m_BakeCloudTextureCS, "_Opacities", layer.mapA.Opacities); - cmd.SetComputeVectorParam(m_BakeCloudTextureCS, "_Params", layer.mapA.settings.GetBakingParameters()); - cmd.SetComputeTextureParam(m_BakeCloudTextureCS, m_BakeCloudTextureKernel, "_CloudMap", layer.mapA.cloudMap.value); + Vector4 params1 = sunLight.transform.forward; + params1.w = 1.0f / (float)m_CloudResolution; + + cmd.SetComputeVectorParam(m_BakeCloudTextureCS, "_Params1", params1); cmd.SetComputeTextureParam(m_BakeCloudTextureCS, m_BakeCloudTextureKernel, m_CloudTextureOutputParam, renderingContext.cloudTextureRT); + if (renderingContext.numLayers == 1) + { + m_BakeCloudTextureCS.DisableKeyword("CLOUD_LAYER_DOUBLE_MODE"); + cmd.SetComputeVectorParam(m_BakeCloudTextureCS, "_Params2", layer.mapA.Opacities); + cmd.SetComputeVectorParam(m_BakeCloudTextureCS, "_Params3", layer.mapA.settings.GetBakingParameters()); + cmd.SetComputeTextureParam(m_BakeCloudTextureCS, m_BakeCloudTextureKernel, "_CloudMapA", layer.mapA.cloudMap.value); + } + else + { + m_BakeCloudTextureCS.EnableKeyword("CLOUD_LAYER_DOUBLE_MODE"); + cmd.SetComputeVectorArrayParam(m_BakeCloudTextureCS, "_Params2", new Vector4[] + { layer.mapA.Opacities, layer.mapB.Opacities }); + cmd.SetComputeVectorArrayParam(m_BakeCloudTextureCS, "_Params3", new Vector4[] + { layer.mapA.settings.GetBakingParameters(), layer.mapB.settings.GetBakingParameters() }); + cmd.SetComputeTextureParam(m_BakeCloudTextureCS, m_BakeCloudTextureKernel, "_CloudMapA", layer.mapA.cloudMap.value); + cmd.SetComputeTextureParam(m_BakeCloudTextureCS, m_BakeCloudTextureKernel, "_CloudMapB", layer.mapB.cloudMap.value); + } + const int groupSizeX = 8; const int groupSizeY = 8; int threadGroupX = (m_CloudResolution + (groupSizeX - 1)) / groupSizeX; @@ -654,7 +672,7 @@ int GetSunLightHashCode(Light light) // Returns whether or not the cloud data should be updated - bool AcquireCloudRenderingContext(SkyUpdateContext updateContext, int newHash, bool supportShadows) + bool AcquireCloudRenderingContext(SkyUpdateContext updateContext, int newHash, int numLayers, bool supportShadows) { int id = updateContext.cachedCloudRenderingContextId; // Release the old context if needed. @@ -691,13 +709,15 @@ bool AcquireCloudRenderingContext(SkyUpdateContext updateContext, int newHash, b context.hash = newHash; context.refCount = 1; - if (context.renderingContext != null && context.renderingContext.supportShadows != supportShadows) + if (context.renderingContext != null && + (context.renderingContext.numLayers != numLayers || + context.renderingContext.supportShadows != supportShadows)) { context.renderingContext.Cleanup(); context.renderingContext = null; } if (context.renderingContext == null) - context.renderingContext = new CloudRenderingContext(m_CloudResolution, supportShadows, 10); + context.renderingContext = new CloudRenderingContext(m_CloudResolution, numLayers, supportShadows, m_CloudShadowsResolution); updateContext.cachedCloudRenderingContextId = firstFreeContext; @@ -834,9 +854,9 @@ bool IsCachedContextValid(SkyUpdateContext skyContext) } - int ComputeCloudHash(CloudLayer layer, Light sunLight, out bool castShadows) + int ComputeCloudHash(CloudLayer layer, Light sunLight, out int numLayers, out bool castShadows) { - int hash = layer.GetBakingHashCode(out castShadows); + int hash = layer.GetBakingHashCode(out numLayers, out castShadows); if (sunLight != null) hash = hash * 23 + GetSunLightHashCode(sunLight); return hash; @@ -917,10 +937,10 @@ public void UpdateEnvironment( HDCamera hdCamera, if (skyContext.cloudLayer != null && skyContext.cloudLayer.opacity.value != 0.0f) { - int cloudHash = ComputeCloudHash(skyContext.cloudLayer, sunLight, out bool castShadows); + int cloudHash = ComputeCloudHash(skyContext.cloudLayer, sunLight, out int numLayers, out bool castShadows); // Acquire the rendering context, if the context was invalid or the hash has changed, // this will request for an update. - if (AcquireCloudRenderingContext(skyContext, cloudHash, castShadows)) + if (AcquireCloudRenderingContext(skyContext, cloudHash, numLayers, castShadows)) BakeCloudTexture(skyContext, sunLight); var cloudContext = m_CachedCloudContexts[skyContext.cachedCloudRenderingContextId].renderingContext; @@ -1055,8 +1075,8 @@ internal void UpdateBuiltinParameters(SkyUpdateContext skyContext, HDCamera hdCa m_BuiltinParameters.skySettings = skyContext.skySettings; m_BuiltinParameters.cloudLayer = skyContext.cloudLayer; - int cloudHash = ComputeCloudHash(skyContext.cloudLayer, sunLight, out bool castShadows); - AcquireCloudRenderingContext(skyContext, cloudHash, castShadows); + int cloudHash = ComputeCloudHash(skyContext.cloudLayer, sunLight, out int numLayers, out bool castShadows); + AcquireCloudRenderingContext(skyContext, cloudHash, numLayers, castShadows); var cloudContext = m_CachedCloudContexts[skyContext.cachedCloudRenderingContextId].renderingContext; m_BuiltinParameters.cloudTexture = cloudContext.cloudTextureRT; } From cb0985f763dfac399d8de0791055f5a19753f608 Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Mon, 27 Jul 2020 18:58:28 +0200 Subject: [PATCH 04/10] Distortion --- .../Texture/LayeredCloudTexture.png.meta | 4 +- .../Runtime/Sky/CloudLayer/CloudLayer.cs | 68 +++++--- .../Runtime/Sky/CloudLayer/CloudLayer.hlsl | 150 ++++++++++++------ .../Sky/CloudLayer/CloudTextureBaking.compute | 1 - .../Sky/GradientSky/GradientSky.shader | 2 + .../Runtime/Sky/HDRISky/HDRISky.shader | 2 + .../PhysicallyBasedSky.shader | 2 +- .../Runtime/Sky/SkyManager.cs | 18 ++- 8 files changed, 169 insertions(+), 78 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/LayeredCloudTexture.png.meta b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/LayeredCloudTexture.png.meta index 67487c86bb1..cf6878d50b3 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/LayeredCloudTexture.png.meta +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/LayeredCloudTexture.png.meta @@ -68,7 +68,7 @@ TextureImporter: maxTextureSize: 2048 resizeAlgorithm: 0 textureFormat: -1 - textureCompression: 1 + textureCompression: 2 compressionQuality: 50 crunchedCompression: 0 allowsAlphaSplitting: 0 @@ -80,7 +80,7 @@ TextureImporter: maxTextureSize: 2048 resizeAlgorithm: 0 textureFormat: -1 - textureCompression: 1 + textureCompression: 2 compressionQuality: 50 crunchedCompression: 0 allowsAlphaSplitting: 0 diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs index ee0aeac5a88..427beceeaac 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs @@ -57,7 +57,7 @@ public class CloudLayer : VolumeComponent { /// Enable fog. [Tooltip("Check to have a cloud layer in the sky.")] - public ClampedFloatParameter opacity = new ClampedFloatParameter(1.0f, 0.0f, 1.0f); + public ClampedFloatParameter opacity = new ClampedFloatParameter(0.0f, 0.0f, 1.0f); /// Enable to cover only the upper part of the sky. [Tooltip("Check this box if the cloud layer covers only the upper part of the sky.")] public BoolParameter upperHemisphereOnly = new BoolParameter(true); @@ -141,6 +141,8 @@ public class CloudLighting [Tooltip("Cast Shadows.")] public BoolParameter castShadows = new BoolParameter(false); + public int NumSteps => (lighting == CloudLightingMode.Raymarching) ? steps.value : 0; + internal int GetBakingHashCode(ref bool castShadows) { @@ -184,6 +186,25 @@ public class CloudMap public Vector4 Opacities => new Vector4(opacityR.value, opacityG.value, opacityB.value, opacityA.value); + internal void Apply(Material skyMaterial, string mapKeyword, string motionKeyword) + { + if (settings.distortion.value != CloudDistortionMode.None) + { + skyMaterial.EnableKeyword(motionKeyword); + if (settings.distortion.value == CloudDistortionMode.Flowmap) + { + skyMaterial.EnableKeyword(mapKeyword); + skyMaterial.SetTexture(HDShaderIDs._CloudFlowmap, settings.flowmap.value); + } + else + skyMaterial.DisableKeyword(mapKeyword); + } + else + { + skyMaterial.EnableKeyword(mapKeyword); + skyMaterial.DisableKeyword(motionKeyword); + } + } internal int GetBakingHashCode(ref bool castShadows) { @@ -250,38 +271,43 @@ internal int GetBakingHashCode(ref bool castShadows) public static void Apply(BuiltinSkyParameters builtinParams, Material skyMaterial) { var layer = builtinParams.cloudLayer; - if (layer != null && layer.opacity.value != 0.0f) + if (layer == null || layer.opacity.value == 0.0f) { - layer.mapA.settings.scrollFactor += layer.mapA.settings.scrollSpeed.value * (Time.time - layer.lastTime) * 0.01f; + skyMaterial.DisableKeyword("USE_CLOUD_MAP"); + skyMaterial.DisableKeyword("USE_CLOUD_MOTION"); + skyMaterial.DisableKeyword("USE_SECOND_CLOUD_MAP"); + skyMaterial.DisableKeyword("USE_SECOND_CLOUD_MOTION"); + return; + } + + if (layer.mode.value == CloudLayerMode.CloudMap) + { + float dt = (Time.time - layer.lastTime) * 0.01f; + layer.mapA.settings.scrollFactor += layer.mapA.settings.scrollSpeed.value * dt; + layer.mapB.settings.scrollFactor += layer.mapB.settings.scrollSpeed.value * dt; layer.lastTime = Time.time; Vector4 params1 = new Vector4( layer.opacity.value, layer.upperHemisphereOnly.value?1:0, - (layer.mode.value == CloudLayerMode.CloudMap && layer.layers.value == CloudMapMode.Double)?1:0, - 0); - Vector4 params2 = layer.mapA.settings.GetRenderingParameters(); + 0, 0); + Vector4[] params2 = { + layer.mapA.settings.GetRenderingParameters(), + layer.mapB.settings.GetRenderingParameters() + }; - skyMaterial.EnableKeyword("USE_CLOUD_MAP"); skyMaterial.SetTexture("_CloudTexture", builtinParams.cloudTexture); skyMaterial.SetVector("_CloudParams1", params1); - skyMaterial.SetVector("_CloudParams2", params2); + skyMaterial.SetVectorArray("_CloudParams2", params2); - if (layer.mapA.settings.distortion.value != CloudDistortionMode.None) + layer.mapA.Apply(skyMaterial, "USE_CLOUD_MAP", "USE_CLOUD_MOTION"); + if (layer.layers.value == CloudMapMode.Double) + layer.mapB.Apply(skyMaterial, "USE_SECOND_CLOUD_MAP", "USE_SECOND_CLOUD_MOTION"); + else { - skyMaterial.EnableKeyword("USE_CLOUD_MOTION"); - if (layer.mapA.settings.distortion.value == CloudDistortionMode.Procedural) - skyMaterial.DisableKeyword("USE_CLOUD_MAP"); - else - skyMaterial.SetTexture(HDShaderIDs._CloudFlowmap, layer.mapA.settings.flowmap.value); + skyMaterial.DisableKeyword("USE_SECOND_CLOUD_MAP"); + skyMaterial.DisableKeyword("USE_SECOND_CLOUD_MOTION"); } - else - skyMaterial.DisableKeyword("USE_CLOUD_MOTION"); - } - else - { - skyMaterial.DisableKeyword("USE_CLOUD_MAP"); - skyMaterial.DisableKeyword("USE_CLOUD_MOTION"); } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl index 72f9798b64e..d60cdaacf90 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl @@ -4,22 +4,36 @@ TEXTURE2D_ARRAY(_CloudTexture); SAMPLER(sampler_CloudTexture); -TEXTURE2D(_CloudFlowmap); -SAMPLER(sampler_CloudFlowmap); +TEXTURE2D(_CloudFlowmap1); +SAMPLER(sampler_CloudFlowmap1); + +TEXTURE2D(_CloudFlowmap2); +SAMPLER(sampler_CloudFlowmap2); + +float4 _CloudParams1; // x opacity, y upper hemisphere only +float4 _CloudParams2[2]; // For each layer: x intensity, y scroll factor, zw scroll direction (cosPhi and sinPhi) -float4 _CloudParams1; // x upper hemisphere only / rotation, y scroll factor, zw scroll direction (cosPhi and sinPhi) -float4 _CloudParams2; // xyz tint, w intensity +#define USE_CLOUD_LAYER (defined(USE_CLOUD_MAP) || defined(USE_CLOUD_MOTION)) +#define USE_SECOND_CLOUD_LAYER (defined(USE_SECOND_CLOUD_MAP) || defined(USE_SECOND_CLOUD_MOTION)) #define _CloudOpacity _CloudParams1.x -#define _CloudUpperHemisphere _CloudParams1.y -#define _CloudDoubleLayer (_CloudParams1.z != 0.0) -#define _CloudIntensity _CloudParams2.x -#define _CloudScrollFactor _CloudParams2.y -#define _CloudScrollDirection _CloudParams2.zw +#define _CloudUpperHemisphere (_CloudParams1.y != 0.0) -#define USE_CLOUD_LAYER defined(USE_CLOUD_MAP) || (!defined(USE_CLOUD_MAP) && defined(USE_CLOUD_MOTION)) +#define _CloudIntensity(l) _CloudParams2[l].x +#define _CloudScrollFactor(l) _CloudParams2[l].y +#define _CloudScrollDirection(l) _CloudParams2[l].zw -float4 sampleCloud(float3 dir, int layer) +struct CloudLayerData +{ + int index; + bool distort, use_flowmap; + + TEXTURE2D(flowmap); + SAMPLER(flowmapSampler); +}; + + +float4 SampleCloudMap(float3 dir, int layer) { float2 coords = GetLatLongCoords(dir, _CloudUpperHemisphere); return SAMPLE_TEXTURE2D_ARRAY_LOD(_CloudTexture, sampler_CloudTexture, coords, layer, 0); @@ -33,35 +47,78 @@ float3 CloudRotationUp(float3 p, float2 cos_sin) return float3(dot(rotDirX, p), p.y, dot(rotDirY, p)); } -float4 GetDistordedCloudColor(float3 dir, int layer) +CloudLayerData GetCloudLayer(int index) { -#if USE_CLOUD_MOTION - float2 alpha = frac(float2(_CloudScrollFactor, _CloudScrollFactor + 0.5)) - 0.5; - -#ifdef USE_CLOUD_MAP - float3 tangent = normalize(cross(dir, float3(0.0, 1.0, 0.0))); - float3 bitangent = cross(tangent, dir); + CloudLayerData layer; + layer.index = index; + layer.distort = false; + layer.use_flowmap = false; - float3 windDir = CloudRotationUp(dir, _CloudScrollDirection); - float2 flow = SAMPLE_TEXTURE2D_LOD(_CloudFlowmap, sampler_CloudFlowmap, GetLatLongCoords(windDir, _CloudUpperHemisphere), 0).rg * 2.0 - 1.0; + if (index == 0) + { + #if USE_CLOUD_MOTION + layer.distort = true; + #ifdef USE_CLOUD_MAP + layer.use_flowmap = true; + layer.flowmap = _CloudFlowmap1; + layer.flowmapSampler = sampler_CloudFlowmap1; + #endif + #endif + } + else + { + #if USE_SECOND_CLOUD_MOTION + layer.distort = true; + #ifdef USE_SECOND_CLOUD_MAP + layer.use_flowmap = true; + layer.flowmap = _CloudFlowmap2; + layer.flowmapSampler = sampler_CloudFlowmap2; + #endif + #endif + } - float3 dd = flow.x * tangent + flow.y * bitangent; -#else - float3 windDir = CloudRotationUp(float3(0, 0, 1), _CloudScrollDirection); - windDir.x *= -1.0; - float3 dd = windDir*sin(dir.y*PI*0.5); -#endif + return layer; +} - // Sample twice - float4 color1 = sampleCloud(normalize(dir - alpha.x * dd), layer); - float4 color2 = sampleCloud(normalize(dir - alpha.y * dd), layer); +float4 GetCloudLayerColor(float3 dir, int index) +{ + float4 color; - // Blend color samples - return lerp(color1, color2, abs(2.0 * alpha.x)); + CloudLayerData layer = GetCloudLayer(index); + if (layer.distort) + { + float2 alpha = frac(_CloudScrollFactor(layer.index) + float2(0.0, 0.5)) - 0.5; + float3 delta; + + if (layer.use_flowmap) + { + float3 tangent = normalize(cross(dir, float3(0.0, 1.0, 0.0))); + float3 bitangent = cross(tangent, dir); + + float3 windDir = CloudRotationUp(dir, _CloudScrollDirection(layer.index)); + float2 flow = SAMPLE_TEXTURE2D_LOD(layer.flowmap, layer.flowmapSampler, GetLatLongCoords(windDir, _CloudUpperHemisphere), 0).rg * 2.0 - 1.0; + delta = flow.x * tangent + flow.y * bitangent; + } + else + { + float3 windDir = CloudRotationUp(float3(0, 0, 1), _CloudScrollDirection(layer.index)); + windDir.x *= -1.0; + delta = windDir * sin(dir.y*PI*0.5); + } + + // Sample twice + float4 color1 = SampleCloudMap(normalize(dir - alpha.x * delta), layer.index); + float4 color2 = SampleCloudMap(normalize(dir - alpha.y * delta), layer.index); + + // Blend color samples + color = lerp(color1, color2, abs(2.0 * alpha.x)); + } + else + color = SampleCloudMap(dir, layer.index); -#else - return sampleCloud(dir, layer); -#endif + color.rgb *= _CloudIntensity(layer.index); + color.a *= _CloudOpacity; + return color; } float GetCloudOpacity(float3 dir) @@ -71,11 +128,11 @@ float GetCloudOpacity(float3 dir) #if USE_CLOUD_LAYER if (dir.y >= 0 || !_CloudUpperHemisphere) { - opacity = GetDistordedCloudColor(dir, 0).a; - if (_CloudDoubleLayer) - opacity *= (1.0 - GetDistordedCloudColor(dir, 1).a); + //opacity = GetDistordedCloudColor(dir, 0).a; +#if USE_SECOND_CLOUD_LAYER + //opacity *= (1.0 - GetDistordedCloudColor(dir, 1).a); +#endif } - else #endif return opacity * _CloudOpacity; @@ -86,20 +143,17 @@ float3 ApplyCloudLayer(float3 dir, float3 sky) #if USE_CLOUD_LAYER if (dir.y >= 0 || !_CloudUpperHemisphere) { - if (_CloudDoubleLayer) - sky += GetDistordedCloudColor(dir, 1).rgb * _CloudIntensity * _CloudOpacity; - sky += GetDistordedCloudColor(dir, 0).rgb * _CloudIntensity * _CloudOpacity; +#if USE_SECOND_CLOUD_LAYER + float4 cloudsB = GetCloudLayerColor(dir, 1); + sky = lerp(sky, cloudsB.rgb, cloudsB.a); +#endif + + float4 cloudsA = GetCloudLayerColor(dir, 0); + sky = lerp(sky, cloudsA.rgb, cloudsA.a); } #endif return sky; } -#undef _CloudUpperHemisphere -#undef _CloudScrollFactor -#undef _CloudScrollDirection -#undef _CloudIntensity - -#undef USE_CLOUD_LAYER - #endif // __CLOUDLAYER_H__ diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute index 88065d82715..0fbd217d63e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute @@ -6,7 +6,6 @@ #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyUtils.hlsl" -#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl" #include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" #ifndef CLOUD_LAYER_DOUBLE_MODE diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/GradientSky/GradientSky.shader b/com.unity.render-pipelines.high-definition/Runtime/Sky/GradientSky/GradientSky.shader index fd1c1c7907d..35cd14b639a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/GradientSky/GradientSky.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/GradientSky/GradientSky.shader @@ -10,6 +10,8 @@ Shader "Hidden/HDRP/Sky/GradientSky" #pragma multi_compile_local _ USE_CLOUD_MAP #pragma multi_compile_local _ USE_CLOUD_MOTION + #pragma multi_compile_local _ USE_SECOND_CLOUD_MAP + #pragma multi_compile_local _ USE_SECOND_CLOUD_MOTION #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader index 216a1643bc6..44c64cc932b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader @@ -15,6 +15,8 @@ Shader "Hidden/HDRP/Sky/HDRISky" #pragma multi_compile_local _ USE_CLOUD_MAP #pragma multi_compile_local _ USE_CLOUD_MOTION + #pragma multi_compile_local _ USE_SECOND_CLOUD_MAP + #pragma multi_compile_local _ USE_SECOND_CLOUD_MOTION #pragma multi_compile _ DEBUG_DISPLAY #pragma multi_compile SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader b/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader index 970a1e6088b..693fd6087f1 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader @@ -224,7 +224,7 @@ Shader "Hidden/HDRP/Sky/PbrSky" } // Hacky way to boost the clouds for PBR sky - skyColor += ApplyCloudLayer(-V, 0) * 1000; + skyColor = ApplyCloudLayer(-V, skyColor); skyColor += radiance * (1 - skyOpacity); skyColor *= _IntensityMultiplier; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs index 8f12747034a..c931762d549 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs @@ -1073,12 +1073,20 @@ internal void UpdateBuiltinParameters(SkyUpdateContext skyContext, HDCamera hdCa m_BuiltinParameters.debugSettings = debugSettings; m_BuiltinParameters.frameIndex = frameIndex; m_BuiltinParameters.skySettings = skyContext.skySettings; - m_BuiltinParameters.cloudLayer = skyContext.cloudLayer; - int cloudHash = ComputeCloudHash(skyContext.cloudLayer, sunLight, out int numLayers, out bool castShadows); - AcquireCloudRenderingContext(skyContext, cloudHash, numLayers, castShadows); - var cloudContext = m_CachedCloudContexts[skyContext.cachedCloudRenderingContextId].renderingContext; - m_BuiltinParameters.cloudTexture = cloudContext.cloudTextureRT; + if (skyContext.cloudLayer != null) + { + int cloudHash = ComputeCloudHash(skyContext.cloudLayer, sunLight, out int numLayers, out bool castShadows); + AcquireCloudRenderingContext(skyContext, cloudHash, numLayers, castShadows); + var cloudContext = m_CachedCloudContexts[skyContext.cachedCloudRenderingContextId].renderingContext; + m_BuiltinParameters.cloudLayer = skyContext.cloudLayer; + m_BuiltinParameters.cloudTexture = cloudContext.cloudTextureRT; + } + else + { + m_BuiltinParameters.cloudLayer = null; + m_BuiltinParameters.cloudTexture = null; + } } public void PreRenderSky(HDCamera hdCamera, Light sunLight, RTHandle colorBuffer, RTHandle normalBuffer, RTHandle depthBuffer, DebugDisplaySettings debugSettings, int frameIndex, CommandBuffer cmd) From 53053ecbd394e2d836a76821d68b1f745a8904d7 Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Tue, 28 Jul 2020 15:56:33 +0200 Subject: [PATCH 05/10] Basic cloud lighting --- .../Runtime/Sky/CloudLayer/CloudLayer.cs | 71 ++++++++---------- .../Runtime/Sky/CloudLayer/CloudLayer.hlsl | 41 +++++----- .../Sky/CloudLayer/CloudTextureBaking.compute | 74 ++++++++++++++++--- .../Runtime/Sky/CloudRenderingContext.cs | 2 +- .../PhysicallyBasedSky.shader | 7 +- .../Runtime/Sky/SkyManager.cs | 21 +++--- 6 files changed, 131 insertions(+), 85 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs index 427beceeaac..73607d94c13 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs @@ -79,7 +79,7 @@ public class CloudSettings public ColorParameter tint = new ColorParameter(Color.white); /// Intensity multipler of the clouds. [Tooltip("Sets the intensity multiplier for the clouds.")] - public MinFloatParameter intensityMultiplier = new MinFloatParameter(1.0f, 0.0f); + public MinFloatParameter intensityMultiplier = new MinFloatParameter(10.0f, 0.0f); /// Distortion mode. [Tooltip("Distortion mode.")] @@ -97,30 +97,13 @@ public class CloudSettings internal float scrollFactor = 0.0f; - internal Vector4 GetBakingParameters() - { - Vector4 param = tint.value; - param.w = rotation.value / 360.0f; - return param; - } - - internal Vector4 GetRenderingParameters() + internal (Vector4, Vector4) GetRenderingParameters() { float dir = -Mathf.Deg2Rad * scrollDirection.value; - return new Vector4(intensityMultiplier.value, scrollFactor, Mathf.Cos(dir), Mathf.Sin(dir)); - } - - internal int GetBakingHashCode() - { - int hash = 17; - - unchecked - { - hash = hash * 23 + rotation.GetHashCode(); - hash = hash * 23 + tint.GetHashCode(); - } - - return hash; + var params1 = new Vector4(Mathf.Cos(dir), Mathf.Sin(dir), scrollFactor, 0); + Vector4 params2 = tint.value; + params2.w = intensityMultiplier.value; + return (params1, params2); } } @@ -135,8 +118,8 @@ public class CloudLighting public ClampedIntParameter steps = new ClampedIntParameter(4, 1, 10); /// . [Tooltip(".")] - public FloatParameter thickness = new FloatParameter(1.0f); - + public ClampedFloatParameter thickness = new ClampedFloatParameter(1.0f, 0.0f, 2.0f); + /// Enable to cast shadows. [Tooltip("Cast Shadows.")] public BoolParameter castShadows = new BoolParameter(false); @@ -173,19 +156,31 @@ public class CloudMap public ClampedFloatParameter opacityR = new ClampedFloatParameter(1.0f, 0.0f, 1.0f); /// Opacity of the green layer. [Tooltip("Opacity of the green layer.")] - public ClampedFloatParameter opacityG = new ClampedFloatParameter(1.0f, 0.0f, 1.0f); + public ClampedFloatParameter opacityG = new ClampedFloatParameter(0.0f, 0.0f, 1.0f); /// Opacity of the blue layer. [Tooltip("Opacity of the blue layer.")] - public ClampedFloatParameter opacityB = new ClampedFloatParameter(1.0f, 0.0f, 1.0f); + public ClampedFloatParameter opacityB = new ClampedFloatParameter(0.0f, 0.0f, 1.0f); /// Opacity of the alpha layer. [Tooltip("Opacity of the alpha layer.")] - public ClampedFloatParameter opacityA = new ClampedFloatParameter(1.0f, 0.0f, 1.0f); + public ClampedFloatParameter opacityA = new ClampedFloatParameter(0.0f, 0.0f, 1.0f); public CloudSettings settings = new CloudSettings(); public CloudLighting lighting = new CloudLighting(); public Vector4 Opacities => new Vector4(opacityR.value, opacityG.value, opacityB.value, opacityA.value); + + internal (Vector4, Vector4) GetBakingParameters() + { + Vector4 parameters = new Vector4( + settings.rotation.value, + lighting.NumSteps, + lighting.thickness.value, + 0 + ); + return (Opacities, parameters); + } + internal void Apply(Material skyMaterial, string mapKeyword, string motionKeyword) { if (settings.distortion.value != CloudDistortionMode.None) @@ -218,7 +213,7 @@ internal int GetBakingHashCode(ref bool castShadows) hash = hash * 23 + opacityB.GetHashCode(); hash = hash * 23 + opacityA.GetHashCode(); - hash = hash * 23 + settings.GetBakingHashCode(); + hash = hash * 23 + settings.rotation.GetHashCode(); hash = hash * 23 + lighting.GetBakingHashCode(ref castShadows); } @@ -244,7 +239,7 @@ internal int GetBakingHashCode(ref bool castShadows) unchecked { hash = hash * 23 + cloudCRT.GetHashCode(); - hash = hash * 23 + settings.GetBakingHashCode(); + hash = hash * 23 + settings.rotation.GetHashCode(); hash = hash * 23 + lighting.GetBakingHashCode(ref castShadows); } @@ -287,18 +282,14 @@ public static void Apply(BuiltinSkyParameters builtinParams, Material skyMateria layer.mapB.settings.scrollFactor += layer.mapB.settings.scrollSpeed.value * dt; layer.lastTime = Time.time; - Vector4 params1 = new Vector4( - layer.opacity.value, - layer.upperHemisphereOnly.value?1:0, - 0, 0); - Vector4[] params2 = { - layer.mapA.settings.GetRenderingParameters(), - layer.mapB.settings.GetRenderingParameters() - }; + var paramsA = layer.mapA.settings.GetRenderingParameters(); + var paramsB = layer.mapB.settings.GetRenderingParameters(); + paramsA.Item1.w = layer.opacity.value; + paramsB.Item1.w = layer.upperHemisphereOnly.value ? 1 : 0; skyMaterial.SetTexture("_CloudTexture", builtinParams.cloudTexture); - skyMaterial.SetVector("_CloudParams1", params1); - skyMaterial.SetVectorArray("_CloudParams2", params2); + skyMaterial.SetVectorArray("_CloudParams1", new Vector4[]{ paramsA.Item1, paramsB.Item1 }); + skyMaterial.SetVectorArray("_CloudParams2", new Vector4[]{ paramsA.Item2, paramsB.Item2 }); layer.mapA.Apply(skyMaterial, "USE_CLOUD_MAP", "USE_CLOUD_MOTION"); if (layer.layers.value == CloudMapMode.Double) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl index d60cdaacf90..91884c6aabe 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl @@ -1,6 +1,9 @@ #ifndef __CLOUDLAYER_H__ #define __CLOUDLAYER_H__ +#define USE_CLOUD_LAYER (defined(USE_CLOUD_MAP) || defined(USE_CLOUD_MOTION)) +#define USE_SECOND_CLOUD_LAYER (defined(USE_SECOND_CLOUD_MAP) || defined(USE_SECOND_CLOUD_MOTION)) + TEXTURE2D_ARRAY(_CloudTexture); SAMPLER(sampler_CloudTexture); @@ -10,18 +13,16 @@ SAMPLER(sampler_CloudFlowmap1); TEXTURE2D(_CloudFlowmap2); SAMPLER(sampler_CloudFlowmap2); -float4 _CloudParams1; // x opacity, y upper hemisphere only -float4 _CloudParams2[2]; // For each layer: x intensity, y scroll factor, zw scroll direction (cosPhi and sinPhi) - -#define USE_CLOUD_LAYER (defined(USE_CLOUD_MAP) || defined(USE_CLOUD_MOTION)) -#define USE_SECOND_CLOUD_LAYER (defined(USE_SECOND_CLOUD_MAP) || defined(USE_SECOND_CLOUD_MOTION)) +float4 _CloudParams1[2]; +float4 _CloudParams2[2]; -#define _CloudOpacity _CloudParams1.x -#define _CloudUpperHemisphere (_CloudParams1.y != 0.0) +#define _CloudScrollDirection(l) _CloudParams1[l].xy +#define _CloudScrollFactor(l) _CloudParams1[l].z +#define _CloudOpacity _CloudParams1[0].w +#define _CloudUpperHemisphere (_CloudParams1[1].w != 0.0) -#define _CloudIntensity(l) _CloudParams2[l].x -#define _CloudScrollFactor(l) _CloudParams2[l].y -#define _CloudScrollDirection(l) _CloudParams2[l].zw +#define _CloudTint(l) _CloudParams2[l].xyz +#define _CloudIntensity(l) _CloudParams2[l].w struct CloudLayerData { @@ -33,10 +34,10 @@ struct CloudLayerData }; -float4 SampleCloudMap(float3 dir, int layer) +float2 SampleCloudMap(float3 dir, int layer) { float2 coords = GetLatLongCoords(dir, _CloudUpperHemisphere); - return SAMPLE_TEXTURE2D_ARRAY_LOD(_CloudTexture, sampler_CloudTexture, coords, layer, 0); + return SAMPLE_TEXTURE2D_ARRAY_LOD(_CloudTexture, sampler_CloudTexture, coords, layer, 0).rg; } float3 CloudRotationUp(float3 p, float2 cos_sin) @@ -82,7 +83,7 @@ CloudLayerData GetCloudLayer(int index) float4 GetCloudLayerColor(float3 dir, int index) { - float4 color; + float2 color; CloudLayerData layer = GetCloudLayer(index); if (layer.distort) @@ -107,8 +108,8 @@ float4 GetCloudLayerColor(float3 dir, int index) } // Sample twice - float4 color1 = SampleCloudMap(normalize(dir - alpha.x * delta), layer.index); - float4 color2 = SampleCloudMap(normalize(dir - alpha.y * delta), layer.index); + float2 color1 = SampleCloudMap(normalize(dir - alpha.x * delta), layer.index); + float2 color2 = SampleCloudMap(normalize(dir - alpha.y * delta), layer.index); // Blend color samples color = lerp(color1, color2, abs(2.0 * alpha.x)); @@ -116,9 +117,7 @@ float4 GetCloudLayerColor(float3 dir, int index) else color = SampleCloudMap(dir, layer.index); - color.rgb *= _CloudIntensity(layer.index); - color.a *= _CloudOpacity; - return color; + return float4(color.x * _CloudIntensity(layer.index) * _CloudTint(layer.index), color.y * _CloudOpacity); } float GetCloudOpacity(float3 dir) @@ -128,14 +127,14 @@ float GetCloudOpacity(float3 dir) #if USE_CLOUD_LAYER if (dir.y >= 0 || !_CloudUpperHemisphere) { - //opacity = GetDistordedCloudColor(dir, 0).a; #if USE_SECOND_CLOUD_LAYER - //opacity *= (1.0 - GetDistordedCloudColor(dir, 1).a); + opacity = GetCloudLayerColor(dir, 1).a; #endif + opacity = lerp(opacity, 1.0, GetCloudLayerColor(dir, 0).a); } #endif - return opacity * _CloudOpacity; + return opacity; } float3 ApplyCloudLayer(float3 dir, float3 sky) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute index 0fbd217d63e..7e131c841bc 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute @@ -22,7 +22,7 @@ SAMPLER(sampler_CloudMapA); TEXTURE2D(_CloudMapB); SAMPLER(sampler_CloudMapB); -RW_TEXTURE2D_ARRAY(float4, _CloudTextureOutput); +RW_TEXTURE2D_ARRAY(float2, _CloudTextureOutput); CBUFFER_START(cb0) float4 _Params1; @@ -31,10 +31,65 @@ float4 _Params3[NUM_LAYERS]; CBUFFER_END #define _SunDirection _Params1.xyz -#define _Resolution _Params1.w +#define _CloudUpperHemisphere (_Params1.w > 0) +#define _Resolution abs(_Params1.w) #define _Opacities _Params2[LAYER] -#define _CloudTint _Params3[LAYER].xyz -#define _CloudRotation _Params3[LAYER].w +#define _CloudRotation _Params3[LAYER].x +#define _LightingSteps _Params3[LAYER].y +#define _Thickness _Params3[LAYER].z + + +float3 InverseLatLong(float2 uv, bool upperHemisphereOnly) +{ + const float2 invAtan = float2(0.1591, 0.3183); + + uv.y = upperHemisphereOnly ? uv.y * 0.5 + 0.5 : uv.y; + uv = (uv - 0.5) / invAtan; + + float y = sin(uv.y); + float scale = sqrt(1.0 - y*y); + + return float3(sin(uv.x) * scale, y, cos(uv.x) * scale); +} + +float SampleCloudMap(TEXTURE2D(_CloudMap), SAMPLER(sampler_CloudMap), float2 uv, float4 weights) +{ + float4 cloudLayerColor = SAMPLE_TEXTURE2D_LOD(_CloudMap, sampler_CloudMap, uv, 0); + + float4 clouds = cloudLayerColor * weights; + return max(max(clouds.r, clouds.g), max(clouds.b, clouds.a)); +} + +float2 ComputeCloudLighting(TEXTURE2D(_CloudMap), SAMPLER(sampler_CloudMap), float2 uv, uint3 dispatchThreadId) +{ + float opacity = SampleCloudMap(_CloudMap, sampler_CloudMap, uv, _Opacities); + float2 finalColor = float2(1.0, opacity); + + int numSteps = (int)_LightingSteps; + if (numSteps != 0 && opacity != 0.0) + { + float3 sun = -_SunDirection; + float3 dir = InverseLatLong(uv, _CloudUpperHemisphere); + float3 marchStep = normalize(sun - dir) * 0.01; + + float density = opacity; + int i = 0; + while (++i < numSteps) + { + float3 ray = normalize(dir + marchStep * i); + + float2 coords = GetLatLongCoords(ray, _CloudUpperHemisphere); + density += SampleCloudMap(_CloudMap, sampler_CloudMap, coords, _Opacities); + } + density *= 3.0 / _LightingSteps; + + float angle = Smoothstep01(max(dot(sun, dir) - 0.7, 0.0)); + + finalColor.x = exp(-density * _Thickness * (1.0-angle/0.7)); + } + + return finalColor; +} [numthreads(8, 8, NUM_LAYERS)] void KERNEL_NAME(uint3 dispatchThreadId : SV_DispatchThreadID) @@ -42,12 +97,9 @@ void KERNEL_NAME(uint3 dispatchThreadId : SV_DispatchThreadID) float2 uv = float2(dispatchThreadId.x * _Resolution, dispatchThreadId.y * _Resolution * 2.0f); uv.x = frac(uv.x + _CloudRotation); - float4 cloudLayerColor = LAYER == 0 ? - SAMPLE_TEXTURE2D_LOD(_CloudMapA, sampler_CloudMapA, uv, 0): - SAMPLE_TEXTURE2D_LOD(_CloudMapB, sampler_CloudMapB, uv, 0); - - float4 clouds = cloudLayerColor * _Opacities; - float opacity = max(max(clouds.r, clouds.g), max(clouds.b, clouds.a)); + float2 cloudLayerColor = LAYER == 0 ? + ComputeCloudLighting(_CloudMapA, sampler_CloudMapA, uv, dispatchThreadId) : + ComputeCloudLighting(_CloudMapB, sampler_CloudMapB, uv, dispatchThreadId); - _CloudTextureOutput[dispatchThreadId] = float4(opacity * _CloudTint, opacity); + _CloudTextureOutput[dispatchThreadId] = cloudLayerColor; } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs index db09914968c..393a40c79f5 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs @@ -15,7 +15,7 @@ public CloudRenderingContext(int resolution, int numLayers, bool supportShadows, this.numLayers = numLayers; this.supportShadows = supportShadows; - cloudTextureRT = RTHandles.Alloc(resolution, resolution / 2, numLayers, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, + cloudTextureRT = RTHandles.Alloc(resolution, resolution / 2, numLayers, colorFormat: GraphicsFormat.R16G16_SFloat, dimension: TextureDimension.Tex2DArray, enableRandomWrite: true, useMipMap: false, filterMode: FilterMode.Bilinear, name: "Cloud Texture"); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader b/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader index 693fd6087f1..9ed024f5138 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader @@ -11,6 +11,8 @@ Shader "Hidden/HDRP/Sky/PbrSky" #pragma multi_compile_local _ USE_CLOUD_MAP #pragma multi_compile_local _ USE_CLOUD_MOTION + #pragma multi_compile_local _ USE_SECOND_CLOUD_MAP + #pragma multi_compile_local _ USE_SECOND_CLOUD_MOTION #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl" @@ -223,8 +225,9 @@ Shader "Hidden/HDRP/Sky/PbrSky" EvaluatePbrAtmosphere(_WorldSpaceCameraPos1, V, distAlongRay, renderSunDisk, skyColor, skyOpacity); } - // Hacky way to boost the clouds for PBR sky - skyColor = ApplyCloudLayer(-V, skyColor); + // Hacky way to boost the clouds to match other sky types + float cloudIntensity = 200.0; + skyColor = ApplyCloudLayer(-V, skyColor / cloudIntensity) * cloudIntensity; skyColor += radiance * (1 - skyOpacity); skyColor *= _IntensityMultiplier; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs index c931762d549..a0563f86501 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs @@ -614,27 +614,28 @@ void BakeCloudTexture(SkyUpdateContext skyContext, Light sunLight) var layer = skyContext.cloudLayer; Vector4 params1 = sunLight.transform.forward; - params1.w = 1.0f / (float)m_CloudResolution; + params1.w = (layer.upperHemisphereOnly.value ? 1.0f : -1.0f) / (float)m_CloudResolution; cmd.SetComputeVectorParam(m_BakeCloudTextureCS, "_Params1", params1); cmd.SetComputeTextureParam(m_BakeCloudTextureCS, m_BakeCloudTextureKernel, m_CloudTextureOutputParam, renderingContext.cloudTextureRT); + cmd.SetComputeTextureParam(m_BakeCloudTextureCS, m_BakeCloudTextureKernel, "_CloudMapA", layer.mapA.cloudMap.value); + var paramsA = layer.mapA.GetBakingParameters(); + if (renderingContext.numLayers == 1) { m_BakeCloudTextureCS.DisableKeyword("CLOUD_LAYER_DOUBLE_MODE"); - cmd.SetComputeVectorParam(m_BakeCloudTextureCS, "_Params2", layer.mapA.Opacities); - cmd.SetComputeVectorParam(m_BakeCloudTextureCS, "_Params3", layer.mapA.settings.GetBakingParameters()); - cmd.SetComputeTextureParam(m_BakeCloudTextureCS, m_BakeCloudTextureKernel, "_CloudMapA", layer.mapA.cloudMap.value); + cmd.SetComputeVectorParam(m_BakeCloudTextureCS, "_Params2", paramsA.Item1); + cmd.SetComputeVectorParam(m_BakeCloudTextureCS, "_Params3", paramsA.Item2); } else { - m_BakeCloudTextureCS.EnableKeyword("CLOUD_LAYER_DOUBLE_MODE"); - cmd.SetComputeVectorArrayParam(m_BakeCloudTextureCS, "_Params2", new Vector4[] - { layer.mapA.Opacities, layer.mapB.Opacities }); - cmd.SetComputeVectorArrayParam(m_BakeCloudTextureCS, "_Params3", new Vector4[] - { layer.mapA.settings.GetBakingParameters(), layer.mapB.settings.GetBakingParameters() }); - cmd.SetComputeTextureParam(m_BakeCloudTextureCS, m_BakeCloudTextureKernel, "_CloudMapA", layer.mapA.cloudMap.value); cmd.SetComputeTextureParam(m_BakeCloudTextureCS, m_BakeCloudTextureKernel, "_CloudMapB", layer.mapB.cloudMap.value); + var paramsB = layer.mapB.GetBakingParameters(); + + m_BakeCloudTextureCS.EnableKeyword("CLOUD_LAYER_DOUBLE_MODE"); + cmd.SetComputeVectorArrayParam(m_BakeCloudTextureCS, "_Params2", new Vector4[] { paramsA.Item1, paramsB.Item1 }); + cmd.SetComputeVectorArrayParam(m_BakeCloudTextureCS, "_Params3", new Vector4[] { paramsA.Item2, paramsB.Item2 }); } const int groupSizeX = 8; From 2deace43945d28b94ddc320b1e58c0a8e9344340 Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Wed, 29 Jul 2020 15:35:16 +0200 Subject: [PATCH 06/10] Cloud shadows --- .../Editor/Sky/CloudLayer/CloudLayerEditor.cs | 18 ++++ .../Runtime/Lighting/LightEvaluation.hlsl | 9 ++ .../Runtime/Lighting/LightLoop/LightLoop.cs | 2 + .../LightLoop/ShaderVariablesLightLoop.hlsl | 4 + .../Runtime/RenderPipeline/HDProfileId.cs | 1 + .../RenderPipeline/RenderPipelineResources.cs | 4 +- .../HDRenderPipelineResources.asset | 1 + .../ShaderLibrary/ShaderVariablesGlobal.cs | 4 +- .../ShaderVariablesGlobal.cs.hlsl | 4 +- ...aking.compute => BakeCloudTexture.compute} | 0 ...ute.meta => BakeCloudTexture.compute.meta} | 4 +- .../Runtime/Sky/CloudLayer/CloudLayer.cs | 95 +++++++++++++++---- .../Runtime/Sky/CloudLayer/CloudLayer.hlsl | 1 + .../CloudLayer/ComputeCloudShadows.compute | 58 +++++++++++ .../ComputeCloudShadows.compute.meta | 9 ++ .../Runtime/Sky/CloudRenderingContext.cs | 2 +- .../Runtime/Sky/SkyManager.cs | 42 +++++++- 17 files changed, 231 insertions(+), 27 deletions(-) rename com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/{CloudTextureBaking.compute => BakeCloudTexture.compute} (100%) rename com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/{CloudTextureBaking.compute.meta => BakeCloudTexture.compute.meta} (69%) create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/ComputeCloudShadows.compute create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/ComputeCloudShadows.compute.meta diff --git a/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs b/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs index cd8792c6178..9bf35c83518 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs @@ -106,6 +106,7 @@ CloudCRTParameter UnpackCloudCRT(SerializedProperty serializedProperty) SerializedDataParameter m_Opacity, m_UpperHemisphereOnly; SerializedDataParameter m_Mode, m_Layers; + SerializedDataParameter m_ShadowsOpacity, m_ShadowsScale; CloudMapParameter[] m_Maps; CloudCRTParameter m_Crt; @@ -120,6 +121,9 @@ public override void OnEnable() m_Mode = Unpack(o.Find(x => x.mode)); m_Layers = Unpack(o.Find(x => x.layers)); + m_ShadowsOpacity = Unpack(o.Find(x => x.shadowsOpacity)); + m_ShadowsScale = Unpack(o.Find(x => x.shadowsScale)); + m_Maps = new CloudMapParameter[] { UnpackCloudMap(o.Find(x => x.mapA)), UnpackCloudMap(o.Find(x => x.mapB)) @@ -194,8 +198,22 @@ public override void OnInspectorGUI() EditorGUI.indentLevel--; PropertyField(m_Maps[0], "Map A"); + bool cloudShadows = m_Maps[0].lighting.castShadows.value.boolValue; + if (m_Layers.value.intValue == (int)CloudMapMode.Double) + { PropertyField(m_Maps[1], "Map B"); + cloudShadows |= m_Maps[1].lighting.castShadows.value.boolValue; + } + + if (cloudShadows) + { + EditorGUILayout.Space(); + EditorGUILayout.LabelField("Cloud Shadows", EditorStyles.miniLabel); + + PropertyField(m_ShadowsOpacity, new GUIContent("Opacity")); + PropertyField(m_ShadowsScale, new GUIContent("Scale")); + } } else if (m_Mode.value.intValue == (int)CloudLayerMode.RenderTexture) { diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl index 493a656b1a3..79b66fa9f50 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl @@ -292,6 +292,15 @@ SHADOW_TYPE EvaluateShadow_Directional( LightLoopContext lightLoopContext, Posit g_DebugShadowAttenuation = shadow; #endif + // Cloud shadows + float3x3 lightToWorld = float3x3(light.right, light.up, light.forward); + float3 lightToSample = posInput.positionWS - light.positionRWS; + float3 positionLS = mul(lightToSample, transpose(lightToWorld)); + + float2 uv = positionLS.xy / _CloudShadowScale; + float cloudShadow = SAMPLE_TEXTURE2D_LOD(_CloudShadows, sampler_CloudShadows, uv, 0).r; + shadow = saturate(lerp(shadow, _CloudShadowOpacity, cloudShadow)); + return shadow; #else // LIGHT_EVALUATION_NO_SHADOWS return 1.0; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs index 425981847d7..1b8d3c6e353 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs @@ -3609,6 +3609,8 @@ unsafe void UpdateShaderVariablesGlobalLightLoop(ref ShaderVariablesGlobal cb, H // Misc cb._EnableSSRefraction = hdCamera.frameSettings.IsEnabled(FrameSettingsField.Refraction) ? 1u : 0u; + cb._CloudShadowOpacity = hdCamera.lightingSky.cloudLayer == null ? 1.0f : 1.0f - hdCamera.lightingSky.cloudLayer.shadowsOpacity.value; + cb._CloudShadowScale = hdCamera.lightingSky.cloudLayer == null ? 1.0f : hdCamera.lightingSky.cloudLayer.shadowsScale.value; } void PushLightDataGlobalParams(CommandBuffer cmd) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/ShaderVariablesLightLoop.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/ShaderVariablesLightLoop.hlsl index d7ed05ef52d..5e889c306ae 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/ShaderVariablesLightLoop.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/ShaderVariablesLightLoop.hlsl @@ -18,6 +18,10 @@ StructuredBuffer _EnvLightDatas; // Used by directional and spot lights TEXTURE2D(_CookieAtlas); +// Used by the main directional light +TEXTURE2D(_CloudShadows); +SAMPLER(sampler_CloudShadows); + // Use texture array for reflection (or LatLong 2D array for mobile) TEXTURECUBE_ARRAY_ABSTRACT(_EnvCubemapTextures); TEXTURE2D(_Env2DTextures); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs index 2fc9c4053ac..037f540d27e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDProfileId.cs @@ -92,6 +92,7 @@ internal enum HDProfileId RenderSkyToCubemap, UpdateSkyEnvironment, UpdateSkyAmbientProbe, + ComputeCloudShadows, PreRenderSky, RenderSky, OpaqueAtmosphericScattering, diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPipelineResources.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPipelineResources.cs index 0253b929ea2..4624802458e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPipelineResources.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPipelineResources.cs @@ -138,8 +138,10 @@ public sealed class ShaderResources public Shader skyboxCubemapPS; [Reload("Runtime/Sky/GradientSky/GradientSky.shader")] public Shader gradientSkyPS; - [Reload("Runtime/Sky/CloudLayer/CloudTextureBaking.compute")] + [Reload("Runtime/Sky/CloudLayer/BakeCloudTexture.compute")] public ComputeShader bakeCloudTextureCS; + [Reload("Runtime/Sky/CloudLayer/ComputeCloudShadows.compute")] + public ComputeShader computeCloudShadowsCS; [Reload("Runtime/Sky/AmbientProbeConvolution.compute")] public ComputeShader ambientProbeConvolutionCS; [Reload("Runtime/Sky/PhysicallyBasedSky/GroundIrradiancePrecomputation.compute")] diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset index a0c1aa79b91..b15422a7e9a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset @@ -72,6 +72,7 @@ MonoBehaviour: skyboxCubemapPS: {fileID: 103, guid: 0000000000000000f000000000000000, type: 0} gradientSkyPS: {fileID: 4800000, guid: 2b5d4f1b26f03dc4a873b093e0c4adb1, type: 3} bakeCloudTextureCS: {fileID: 7200000, guid: ab3c4e1fdc13358468dc6ee4caf14fc2, type: 3} + computeCloudShadowsCS: {fileID: 7200000, guid: 09410d5c082f02848be25be02bbe8edf, type: 3} ambientProbeConvolutionCS: {fileID: 7200000, guid: 6d048f7b1bd45e840b4e79ec92639fa8, type: 3} groundIrradiancePrecomputationCS: {fileID: 7200000, guid: eb6ae6f326207ee4d987a3e5adddf63a, type: 3} inScatteredRadiancePrecomputationCS: {fileID: 7200000, guid: 70c69d514688f8545855680760d77418, type: 3} diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs index 2deeaac0eee..eb0fa045937 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs @@ -191,7 +191,7 @@ unsafe struct ShaderVariablesGlobal public float _MicroShadowOpacity; public uint _EnableProbeVolumes; public uint _ProbeVolumeCount; - public float _Pad6; + public float _CloudShadowOpacity; public Vector4 _CookieAtlasSize; public Vector4 _CookieAtlasData; @@ -211,7 +211,7 @@ unsafe struct ShaderVariablesGlobal public uint _NumTileClusteredX; public uint _NumTileClusteredY; public int _EnvSliceSize; - public float _Pad7; + public float _CloudShadowScale; // Subsurface scattering // Use float4 to avoid any packing issue between compute and pixel shaders diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl index 38853ea6840..176f4b8881b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl @@ -104,7 +104,7 @@ GLOBAL_CBUFFER_START(ShaderVariablesGlobal, b0) float _MicroShadowOpacity; uint _EnableProbeVolumes; uint _ProbeVolumeCount; - float _Pad6; + float _CloudShadowOpacity; float4 _CookieAtlasSize; float4 _CookieAtlasData; float4 _PlanarAtlasData; @@ -119,7 +119,7 @@ GLOBAL_CBUFFER_START(ShaderVariablesGlobal, b0) uint _NumTileClusteredX; uint _NumTileClusteredY; int _EnvSliceSize; - float _Pad7; + float _CloudShadowScale; float4 _ShapeParamsAndMaxScatterDists[16]; float4 _TransmissionTintsAndFresnel0[16]; float4 _WorldScalesAndFilterRadiiAndThicknessRemaps[16]; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/BakeCloudTexture.compute similarity index 100% rename from com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute rename to com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/BakeCloudTexture.compute diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute.meta b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/BakeCloudTexture.compute.meta similarity index 69% rename from com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute.meta rename to com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/BakeCloudTexture.compute.meta index 2292664b277..5b584dadcdb 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudTextureBaking.compute.meta +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/BakeCloudTexture.compute.meta @@ -1,8 +1,8 @@ fileFormatVersion: 2 -guid: ab3c4e1fdc13358468dc6ee4caf14fc2 +guid: 5d4461b96f173b34792b6c8ae075651e ComputeShaderImporter: externalObjects: {} - currentAPIMask: 2097156 + currentAPIMask: 4 preprocessorOverride: 0 userData: assetBundleName: diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs index 73607d94c13..5ec9ebfd5ec 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs @@ -61,13 +61,21 @@ public class CloudLayer : VolumeComponent /// Enable to cover only the upper part of the sky. [Tooltip("Check this box if the cloud layer covers only the upper part of the sky.")] public BoolParameter upperHemisphereOnly = new BoolParameter(true); - /// . - [Tooltip("")] + /// Select the cloud layer mode. + [Tooltip("Choose the cloud layer mode;")] public VolumeParameter mode = new VolumeParameter(); - /// . - [Tooltip("")] + /// Choose the number of cloud layers. public VolumeParameter layers = new VolumeParameter(); - + + + /// Controls the opacity of the cloud shadows. + [Tooltip("Controls the opacity of the cloud shadows.")] + public ClampedFloatParameter shadowsOpacity = new ClampedFloatParameter(0.5f, 0.0f, 4.0f); + /// Controls the scale of the cloud shadows. + [Tooltip("Controls the scale of the cloud shadows.")] + public MinFloatParameter shadowsScale = new MinFloatParameter(500.0f, 0.0f); + + [Serializable] public class CloudSettings { @@ -116,18 +124,18 @@ public class CloudLighting /// Number of raymarching steps. [Tooltip("Number of raymarching steps.")] public ClampedIntParameter steps = new ClampedIntParameter(4, 1, 10); - /// . - [Tooltip(".")] - public ClampedFloatParameter thickness = new ClampedFloatParameter(1.0f, 0.0f, 2.0f); + /// Thickness of the clouds. + [Tooltip("Controls the thickness of the clouds.")] + public ClampedFloatParameter thickness = new ClampedFloatParameter(1, 0, 2); /// Enable to cast shadows. - [Tooltip("Cast Shadows.")] + [Tooltip("Enable or disable cloud shadows.")] public BoolParameter castShadows = new BoolParameter(false); - public int NumSteps => (lighting == CloudLightingMode.Raymarching) ? steps.value : 0; + internal int NumSteps => (lighting == CloudLightingMode.Raymarching) ? steps.value : 0; - internal int GetBakingHashCode(ref bool castShadows) + internal int GetBakingHashCode(ref bool cloudShadows) { int hash = 17; @@ -139,7 +147,7 @@ internal int GetBakingHashCode(ref bool castShadows) hash = hash * 23 + castShadows.GetHashCode(); } - castShadows |= this.castShadows.value; + cloudShadows |= castShadows.value; return hash; } } @@ -167,13 +175,13 @@ public class CloudMap public CloudSettings settings = new CloudSettings(); public CloudLighting lighting = new CloudLighting(); - public Vector4 Opacities => new Vector4(opacityR.value, opacityG.value, opacityB.value, opacityA.value); + internal Vector4 Opacities => new Vector4(opacityR.value, opacityG.value, opacityB.value, opacityA.value); internal (Vector4, Vector4) GetBakingParameters() { Vector4 parameters = new Vector4( - settings.rotation.value, + settings.rotation.value / 360.0f, lighting.NumSteps, lighting.thickness.value, 0 @@ -181,7 +189,7 @@ public class CloudMap return (Opacities, parameters); } - internal void Apply(Material skyMaterial, string mapKeyword, string motionKeyword) + internal bool Apply(Material skyMaterial, string mapKeyword, string motionKeyword) { if (settings.distortion.value != CloudDistortionMode.None) { @@ -189,7 +197,7 @@ internal void Apply(Material skyMaterial, string mapKeyword, string motionKeywor if (settings.distortion.value == CloudDistortionMode.Flowmap) { skyMaterial.EnableKeyword(mapKeyword); - skyMaterial.SetTexture(HDShaderIDs._CloudFlowmap, settings.flowmap.value); + return true; } else skyMaterial.DisableKeyword(mapKeyword); @@ -199,6 +207,28 @@ internal void Apply(Material skyMaterial, string mapKeyword, string motionKeywor skyMaterial.EnableKeyword(mapKeyword); skyMaterial.DisableKeyword(motionKeyword); } + return false; + } + + internal bool SetComputeParams(ComputeShader cs, string mapKeyword, string motionKeyword) + { + if (settings.distortion.value != CloudDistortionMode.None) + { + cs.EnableKeyword(motionKeyword); + if (settings.distortion.value == CloudDistortionMode.Flowmap) + { + cs.EnableKeyword(mapKeyword); + return true; + } + else + cs.DisableKeyword(mapKeyword); + } + else + { + cs.EnableKeyword(mapKeyword); + cs.DisableKeyword(motionKeyword); + } + return false; } internal int GetBakingHashCode(ref bool castShadows) @@ -291,9 +321,14 @@ public static void Apply(BuiltinSkyParameters builtinParams, Material skyMateria skyMaterial.SetVectorArray("_CloudParams1", new Vector4[]{ paramsA.Item1, paramsB.Item1 }); skyMaterial.SetVectorArray("_CloudParams2", new Vector4[]{ paramsA.Item2, paramsB.Item2 }); - layer.mapA.Apply(skyMaterial, "USE_CLOUD_MAP", "USE_CLOUD_MOTION"); + if (layer.mapA.Apply(skyMaterial, "USE_CLOUD_MAP", "USE_CLOUD_MOTION")) + skyMaterial.SetTexture("_CloudFlowmap1", layer.mapA.settings.flowmap.value); + if (layer.layers.value == CloudMapMode.Double) - layer.mapB.Apply(skyMaterial, "USE_SECOND_CLOUD_MAP", "USE_SECOND_CLOUD_MOTION"); + { + if (layer.mapB.Apply(skyMaterial, "USE_SECOND_CLOUD_MAP", "USE_SECOND_CLOUD_MOTION")) + skyMaterial.SetTexture("_CloudFlowmap2", layer.mapB.settings.flowmap.value); + } else { skyMaterial.DisableKeyword("USE_SECOND_CLOUD_MAP"); @@ -302,6 +337,30 @@ public static void Apply(BuiltinSkyParameters builtinParams, Material skyMateria } } + internal void SetComputeParams(CommandBuffer cmd, ComputeShader cs, int kernel) + { + var paramsA = mapA.settings.GetRenderingParameters(); + var paramsB = mapB.settings.GetRenderingParameters(); + paramsA.Item1.w = opacity.value; + paramsB.Item1.w = upperHemisphereOnly.value ? 1 : 0; + + cmd.SetComputeVectorArrayParam(cs, "_CloudParams1", new Vector4[]{ paramsA.Item1, paramsB.Item1 }); + + if (mapA.SetComputeParams(cs, "USE_CLOUD_MAP", "USE_CLOUD_MOTION")) + cmd.SetComputeTextureParam(cs, kernel, "_CloudFlowmap1", mapA.settings.flowmap.value); + + if (layers.value == CloudMapMode.Double) + { + if (mapB.SetComputeParams(cs, "USE_SECOND_CLOUD_MAP", "USE_SECOND_CLOUD_MOTION")) + cmd.SetComputeTextureParam(cs, kernel, "_CloudFlowmap2", mapB.settings.flowmap.value); + } + else + { + cs.DisableKeyword("USE_SECOND_CLOUD_MAP"); + cs.DisableKeyword("USE_SECOND_CLOUD_MOTION"); + } + } + internal int GetBakingHashCode(out int numLayers, out bool castShadows) { int hash = 17; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl index 91884c6aabe..c4b63a99750 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl @@ -21,6 +21,7 @@ float4 _CloudParams2[2]; #define _CloudOpacity _CloudParams1[0].w #define _CloudUpperHemisphere (_CloudParams1[1].w != 0.0) +// TODO: Those 2 params can be premultiplied #define _CloudTint(l) _CloudParams2[l].xyz #define _CloudIntensity(l) _CloudParams2[l].w diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/ComputeCloudShadows.compute b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/ComputeCloudShadows.compute new file mode 100644 index 00000000000..a05678865c1 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/ComputeCloudShadows.compute @@ -0,0 +1,58 @@ +#pragma only_renderers d3d11 playstation xboxone vulkan metal switch + +#pragma multi_compile_local _ USE_CLOUD_MAP +#pragma multi_compile_local _ USE_CLOUD_MOTION +#pragma multi_compile_local _ USE_SECOND_CLOUD_MAP +#pragma multi_compile_local _ USE_SECOND_CLOUD_MOTION + +#pragma kernel ComputeCloudShadows KERNEL_NAME=ComputeCloudShadows + +#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyUtils.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl" +#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl" + +RW_TEXTURE2D(float, _CloudShadowsOutput); + +float3 _SunDirection; +float _Resolution; + +static float3 tangent; +static float3 bitangent; + +float ComputeCloudShadow(float2 uv) +{ + const float width = 0.1; + float3 dir = -_SunDirection + uv.x * width * tangent + uv.y * width * bitangent; + + return GetCloudOpacity(dir); +} + +[numthreads(8, 8, 1)] +void KERNEL_NAME(uint2 dispatchThreadId : SV_DispatchThreadID) +{ + tangent = normalize(cross(-_SunDirection, float3(0.0, 1.0, 0.0))); + bitangent = cross(tangent, -_SunDirection); + + float2 uv = float2(dispatchThreadId.x * _Resolution, dispatchThreadId.y * _Resolution) * 2.0 - 1.0; + float shadow = ComputeCloudShadow(uv); + + // Blend with the other borders to make the texture tileable + const float border = 0.3; + float2 uv2 = uv - (1.0 - border); + float2 weights = saturate(uv2 / border); + + if (uv2.x > 0.0) + shadow = lerp(shadow, ComputeCloudShadow(uv - float2(2.0, 0.0)), weights.x); + + if (uv2.y > 0.0) + { + float shadow2 = ComputeCloudShadow(uv - float2(0.0, 2.0)); + if (uv2.x > 0.0) + shadow2 = lerp(shadow2, ComputeCloudShadow(uv - float2(2.0, 2.0)), weights.x); + + shadow = lerp(shadow, shadow2, weights.y); + } + + _CloudShadowsOutput[dispatchThreadId] = shadow; +} diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/ComputeCloudShadows.compute.meta b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/ComputeCloudShadows.compute.meta new file mode 100644 index 00000000000..84b1cb88ae3 --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/ComputeCloudShadows.compute.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 09410d5c082f02848be25be02bbe8edf +ComputeShaderImporter: + externalObjects: {} + currentAPIMask: 4 + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs index 393a40c79f5..62c9fef1856 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs @@ -29,7 +29,7 @@ public void Cleanup() { RTHandles.Release(cloudTextureRT); if (supportShadows) - CoreUtils.Destroy(cloudShadowsRT); + RTHandles.Release(cloudShadowsRT); } } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs index a0563f86501..865da7f4de8 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs @@ -218,6 +218,9 @@ class SkyManager ComputeShader m_BakeCloudTextureCS; int m_BakeCloudTextureKernel; readonly int m_CloudTextureOutputParam = Shader.PropertyToID("_CloudTextureOutput"); + ComputeShader m_ComputeCloudShadowsCS; + int m_ComputeCloudShadowsKernel; + readonly int m_CloudShadowsOutputParam = Shader.PropertyToID("_CloudShadowsOutput"); // 2 by default: Static sky + one dynamic. Will grow if needed. DynamicArray m_CachedCloudContexts = new DynamicArray(2); @@ -369,6 +372,8 @@ public void Build(HDRenderPipelineAsset hdAsset, RenderPipelineResources default m_BakeCloudTextureCS = hdrp.renderPipelineResources.shaders.bakeCloudTextureCS; m_BakeCloudTextureKernel = m_BakeCloudTextureCS.FindKernel("BakeCloudTexture"); + m_ComputeCloudShadowsCS = hdrp.renderPipelineResources.shaders.computeCloudShadowsCS; + m_ComputeCloudShadowsKernel = m_ComputeCloudShadowsCS.FindKernel("ComputeCloudShadows"); } void InitializeBlackCubemapArray() @@ -613,7 +618,7 @@ void BakeCloudTexture(SkyUpdateContext skyContext, Light sunLight) var renderingContext = m_CachedCloudContexts[skyContext.cachedCloudRenderingContextId].renderingContext; var layer = skyContext.cloudLayer; - Vector4 params1 = sunLight.transform.forward; + Vector4 params1 = sunLight == null ? Vector3.zero : sunLight.transform.forward; params1.w = (layer.upperHemisphereOnly.value ? 1.0f : -1.0f) / (float)m_CloudResolution; cmd.SetComputeVectorParam(m_BakeCloudTextureCS, "_Params1", params1); @@ -647,6 +652,30 @@ void BakeCloudTexture(SkyUpdateContext skyContext, Light sunLight) } } + void ComputeCloudShadows(SkyUpdateContext skyContext, Light sunLight) + { + var cmd = m_BuiltinParameters.commandBuffer; + using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.ComputeCloudShadows))) + { + var renderingContext = m_CachedCloudContexts[skyContext.cachedCloudRenderingContextId].renderingContext; + var layer = skyContext.cloudLayer; + + cmd.SetComputeVectorParam(m_ComputeCloudShadowsCS, "_SunDirection", sunLight.transform.forward); + cmd.SetComputeFloatParam(m_ComputeCloudShadowsCS, "_Resolution", 1.0f / (float)m_CloudShadowsResolution); + cmd.SetComputeTextureParam(m_ComputeCloudShadowsCS, m_ComputeCloudShadowsKernel, "_CloudTexture", renderingContext.cloudTextureRT); + cmd.SetComputeTextureParam(m_ComputeCloudShadowsCS, m_ComputeCloudShadowsKernel, m_CloudShadowsOutputParam, renderingContext.cloudShadowsRT); + + skyContext.cloudLayer.SetComputeParams(cmd, m_ComputeCloudShadowsCS, m_ComputeCloudShadowsKernel); + + const int groupSizeX = 8; + const int groupSizeY = 8; + int threadGroupX = (m_CloudShadowsResolution + (groupSizeX - 1)) / groupSizeX; + int threadGroupY = (m_CloudShadowsResolution + (groupSizeY - 1)) / groupSizeY; + + cmd.DispatchCompute(m_ComputeCloudShadowsCS, m_ComputeCloudShadowsKernel, threadGroupX, threadGroupY, 1); + } + } + // We do our own hash here because Unity does not provide correct hash for builtin types // Moreover, we don't want to test every single parameters of the light so we filter them here in this specific function. int GetSunLightHashCode(Light light) @@ -936,6 +965,7 @@ public void UpdateEnvironment( HDCamera hdCamera, m_BuiltinParameters.cloudLayer = skyContext.cloudLayer; m_BuiltinParameters.cloudTexture = null; + bool cloudShadows = false; if (skyContext.cloudLayer != null && skyContext.cloudLayer.opacity.value != 0.0f) { int cloudHash = ComputeCloudHash(skyContext.cloudLayer, sunLight, out int numLayers, out bool castShadows); @@ -946,6 +976,13 @@ public void UpdateEnvironment( HDCamera hdCamera, var cloudContext = m_CachedCloudContexts[skyContext.cachedCloudRenderingContextId].renderingContext; m_BuiltinParameters.cloudTexture = cloudContext.cloudTextureRT; + + if (castShadows && sunLight != null) + { + cloudShadows = true; + ComputeCloudShadows(skyContext, sunLight); + cmd.SetGlobalTexture("_CloudShadows", cloudContext.cloudShadowsRT); + } } else if (skyContext.cachedCloudRenderingContextId != -1) { @@ -953,6 +990,9 @@ public void UpdateEnvironment( HDCamera hdCamera, skyContext.cachedCloudRenderingContextId = -1; } + if (!cloudShadows) + cmd.SetGlobalTexture("_CloudShadows", Texture2D.blackTexture); + int skyHash = ComputeSkyHash(hdCamera, skyContext, sunLight, ambientMode, staticSky); bool forceUpdate = updateRequired; From ad465a9d65bc83297790833cc41005e533d6f1d9 Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Fri, 31 Jul 2020 15:13:35 +0200 Subject: [PATCH 07/10] Minor changes --- .../Editor/Sky/CloudLayer/CloudLayerEditor.cs | 2 +- .../RenderPipeline/RenderPipelineResources.cs | 3 - .../HDRenderPipelineResources.asset | 247 ++++++++++++------ .../Material/DefaultCloudLayerMaterial.mat | 33 --- .../DefaultCloudLayerMaterial.mat.meta | 8 - .../RenderPipelineResources/Shader.meta | 8 - .../Shader/DefaultCloudLayerShader.shader | 50 ---- .../DefaultCloudLayerShader.shader.meta | 10 - .../Texture/DefaultCloudLayer.asset | 53 ---- .../Texture/DefaultCloudLayer.asset.meta | 8 - ...edCloudTexture.png => DefaultCloudMap.png} | 0 ...ture.png.meta => DefaultCloudMap.png.meta} | 0 .../Runtime/Sky/CloudLayer/CloudLayer.cs | 14 +- .../Runtime/Sky/CloudLayer/CloudLayer.hlsl | 4 +- .../PhysicallyBasedSky.shader | 5 +- 15 files changed, 177 insertions(+), 268 deletions(-) delete mode 100644 com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Material/DefaultCloudLayerMaterial.mat delete mode 100644 com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Material/DefaultCloudLayerMaterial.mat.meta delete mode 100644 com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Shader.meta delete mode 100644 com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Shader/DefaultCloudLayerShader.shader delete mode 100644 com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Shader/DefaultCloudLayerShader.shader.meta delete mode 100644 com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/DefaultCloudLayer.asset delete mode 100644 com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/DefaultCloudLayer.asset.meta rename com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/{LayeredCloudTexture.png => DefaultCloudMap.png} (100%) rename com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/{LayeredCloudTexture.png.meta => DefaultCloudMap.png.meta} (100%) diff --git a/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs b/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs index 9bf35c83518..114f1a7096e 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs @@ -196,7 +196,7 @@ public override void OnInspectorGUI() EditorGUI.indentLevel++; PropertyField(m_Layers); EditorGUI.indentLevel--; - + PropertyField(m_Maps[0], "Map A"); bool cloudShadows = m_Maps[0].lighting.castShadows.value.boolValue; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPipelineResources.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPipelineResources.cs index 4624802458e..d771106dbd6 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPipelineResources.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPipelineResources.cs @@ -402,9 +402,6 @@ public sealed class TextureResources [Reload("Runtime/RenderPipelineResources/Texture/DefaultHDRISky.exr")] public Cubemap defaultHDRISky; - - [Reload("Runtime/RenderPipelineResources/Texture/DefaultCloudLayer.asset")] - public CustomRenderTexture defaultCloudLayer; } [Serializable, ReloadGroup] diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset index b15422a7e9a..1d4c1372b25 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/HDRenderPipelineResources.asset @@ -15,122 +15,193 @@ MonoBehaviour: m_Version: 4 shaders: defaultPS: {fileID: 4800000, guid: 6e4ae4064600d784cac1e41a9e6f2e59, type: 3} - debugDisplayLatlongPS: {fileID: 4800000, guid: c1d1d149a043a5349ba367da6c2051ba, type: 3} - debugViewMaterialGBufferPS: {fileID: 4800000, guid: 439949ea1bfa91b4ba0d04269fcde33d, type: 3} + debugDisplayLatlongPS: {fileID: 4800000, guid: c1d1d149a043a5349ba367da6c2051ba, + type: 3} + debugViewMaterialGBufferPS: {fileID: 4800000, guid: 439949ea1bfa91b4ba0d04269fcde33d, + type: 3} debugViewTilesPS: {fileID: 4800000, guid: c7c2bd17b06ceb4468e14081aaf1b96f, type: 3} debugFullScreenPS: {fileID: 4800000, guid: e874aca2df8300a488258738c31f85cf, type: 3} - debugColorPickerPS: {fileID: 4800000, guid: 8137b807709e178498f22ed710864bb0, type: 3} + debugColorPickerPS: {fileID: 4800000, guid: 8137b807709e178498f22ed710864bb0, + type: 3} debugExposurePS: {fileID: 4800000, guid: 0ef322534f047a34c96d29419d56d17a, type: 3} - debugLightVolumePS: {fileID: 4800000, guid: 8e706c0e71fcec34a8f5c9713e5e2943, type: 3} - debugLightVolumeCS: {fileID: 7200000, guid: f5d5d21faef5cf445ac2c5d8ff9c4184, type: 3} + debugLightVolumePS: {fileID: 4800000, guid: 8e706c0e71fcec34a8f5c9713e5e2943, + type: 3} + debugLightVolumeCS: {fileID: 7200000, guid: f5d5d21faef5cf445ac2c5d8ff9c4184, + type: 3} debugBlitQuad: {fileID: 4800000, guid: cf5ca5b6ef18b3f429ed707ee9ceac9f, type: 3} - debugViewVirtualTexturingBlit: {fileID: 4800000, guid: 55d195396b03b804eb78c92d468e3c8e, type: 3} + debugViewVirtualTexturingBlit: {fileID: 4800000, guid: 55d195396b03b804eb78c92d468e3c8e, + type: 3} deferredPS: {fileID: 4800000, guid: 00dd221e34a6ab349a1196b0f2fab693, type: 3} colorPyramidPS: {fileID: 4800000, guid: 2fcfb8d92f45e4549b3f0bad5d0654bf, type: 3} depthPyramidCS: {fileID: 7200000, guid: 64a553bb564274041906f78ffba955e4, type: 3} copyChannelCS: {fileID: 7200000, guid: a4d45eda75e8e474dbe24a31f741f3b4, type: 3} - screenSpaceReflectionsCS: {fileID: 7200000, guid: d1de9ac7d9016204da289affe9677942, type: 3} + screenSpaceReflectionsCS: {fileID: 7200000, guid: d1de9ac7d9016204da289affe9677942, + type: 3} applyDistortionPS: {fileID: 4800000, guid: 02ae56f4306413c4a96dcf005cde1971, type: 3} - clearDispatchIndirectCS: {fileID: 7200000, guid: fc1f553acb80a6446a32d33e403d0656, type: 3} + clearDispatchIndirectCS: {fileID: 7200000, guid: fc1f553acb80a6446a32d33e403d0656, + type: 3} clearLightListsCS: {fileID: 7200000, guid: 743eb3491795b9545955695d591195a1, type: 3} - buildDispatchIndirectCS: {fileID: 7200000, guid: 4eb1b418be7044c40bb5200496c50f14, type: 3} + buildDispatchIndirectCS: {fileID: 7200000, guid: 4eb1b418be7044c40bb5200496c50f14, + type: 3} buildScreenAABBCS: {fileID: 7200000, guid: 728dce960f8a9c44bbc3abb3b851d8f6, type: 3} - buildPerTileLightListCS: {fileID: 7200000, guid: 65af3444cbf4b3747a4dead7ee00cfee, type: 3} - buildPerBigTileLightListCS: {fileID: 7200000, guid: 5ee1f9d6e09abe045b2f5e0b784b9072, type: 3} - buildPerVoxelLightListCS: {fileID: 7200000, guid: 0bb1b7e0ddcd5c44baf3ddc7456eb196, type: 3} - lightListClusterClearAtomicIndexCS: {fileID: 7200000, guid: 1e3472a94b14a334a93230bbc700d7b2, type: 3} - buildMaterialFlagsCS: {fileID: 7200000, guid: fb3eda953cd6e634e877fb777be2cd08, type: 3} + buildPerTileLightListCS: {fileID: 7200000, guid: 65af3444cbf4b3747a4dead7ee00cfee, + type: 3} + buildPerBigTileLightListCS: {fileID: 7200000, guid: 5ee1f9d6e09abe045b2f5e0b784b9072, + type: 3} + buildPerVoxelLightListCS: {fileID: 7200000, guid: 0bb1b7e0ddcd5c44baf3ddc7456eb196, + type: 3} + lightListClusterClearAtomicIndexCS: {fileID: 7200000, guid: 1e3472a94b14a334a93230bbc700d7b2, + type: 3} + buildMaterialFlagsCS: {fileID: 7200000, guid: fb3eda953cd6e634e877fb777be2cd08, + type: 3} deferredCS: {fileID: 7200000, guid: 0b64f79746d2daf4198eaf6eab9af259, type: 3} contactShadowCS: {fileID: 7200000, guid: 3e6900e06dc185a4380af4dacb4db0a4, type: 3} - volumeVoxelizationCS: {fileID: 7200000, guid: c20b371db720da244b73830ec74a343a, type: 3} - volumetricLightingCS: {fileID: 7200000, guid: b4901a10df2d1e24282725e9fbc77c97, type: 3} - volumetricLightingFilteringCS: {fileID: 7200000, guid: ef9a910d0ec6ebb41ae3f5c7a69daf46, type: 3} + volumeVoxelizationCS: {fileID: 7200000, guid: c20b371db720da244b73830ec74a343a, + type: 3} + volumetricLightingCS: {fileID: 7200000, guid: b4901a10df2d1e24282725e9fbc77c97, + type: 3} + volumetricLightingFilteringCS: {fileID: 7200000, guid: ef9a910d0ec6ebb41ae3f5c7a69daf46, + type: 3} deferredTilePS: {fileID: 4800000, guid: dedaf4ea0d134ca4aad1d95a558c46e5, type: 3} - screenSpaceShadowPS: {fileID: 4800000, guid: bfa43a48695613b4ea19c58858ae1a61, type: 3} - probeVolumeAtlasBlitCS: {fileID: 7200000, guid: 07f429bf534edb44eb5a0e4b2c65b108, type: 3} - probeVolumeAtlasOctahedralDepthBlitCS: {fileID: 7200000, guid: f60c895d3a3061848844b36ccf9e44a9, type: 3} - probeVolumeAtlasOctahedralDepthConvolveCS: {fileID: 7200000, guid: 7ef71ce05401a4c4081039b475d3b9ee, type: 3} - debugDisplayProbeVolumePS: {fileID: 4800000, guid: e7c19cfee7a88394fbb53652b9644cc0, type: 3} - subsurfaceScatteringCS: {fileID: 7200000, guid: b06a7993621def248addd55d0fe931b1, type: 3} + screenSpaceShadowPS: {fileID: 4800000, guid: bfa43a48695613b4ea19c58858ae1a61, + type: 3} + probeVolumeAtlasBlitCS: {fileID: 7200000, guid: 07f429bf534edb44eb5a0e4b2c65b108, + type: 3} + probeVolumeAtlasOctahedralDepthBlitCS: {fileID: 7200000, guid: f60c895d3a3061848844b36ccf9e44a9, + type: 3} + probeVolumeAtlasOctahedralDepthConvolveCS: {fileID: 7200000, guid: 7ef71ce05401a4c4081039b475d3b9ee, + type: 3} + debugDisplayProbeVolumePS: {fileID: 4800000, guid: e7c19cfee7a88394fbb53652b9644cc0, + type: 3} + subsurfaceScatteringCS: {fileID: 7200000, guid: b06a7993621def248addd55d0fe931b1, + type: 3} combineLightingPS: {fileID: 4800000, guid: 2e37131331fbdca449b1a2bc47a639ca, type: 3} - cameraMotionVectorsPS: {fileID: 4800000, guid: 035941b63024d1943af48811c1db20d9, type: 3} - clearStencilBufferPS: {fileID: 4800000, guid: 8ea49ef16606acd489439e676ab84040, type: 3} - copyStencilBufferPS: {fileID: 4800000, guid: 3d1574f1cdfa0ce4995f9bc79ed7f8ec, type: 3} + cameraMotionVectorsPS: {fileID: 4800000, guid: 035941b63024d1943af48811c1db20d9, + type: 3} + clearStencilBufferPS: {fileID: 4800000, guid: 8ea49ef16606acd489439e676ab84040, + type: 3} + copyStencilBufferPS: {fileID: 4800000, guid: 3d1574f1cdfa0ce4995f9bc79ed7f8ec, + type: 3} copyDepthBufferPS: {fileID: 4800000, guid: 42dfcc8fe803ece4096c58630689982f, type: 3} blitPS: {fileID: 4800000, guid: 370f7a9cc4e362d488af024d371091e8, type: 3} downsampleDepthPS: {fileID: 4800000, guid: 67d6171b0acc6554aad48c845ec7e67f, type: 3} - upsampleTransparentPS: {fileID: 4800000, guid: 2ad7ce40f0dbaf64dadef1f58d8524d3, type: 3} + upsampleTransparentPS: {fileID: 4800000, guid: 2ad7ce40f0dbaf64dadef1f58d8524d3, + type: 3} resolveStencilCS: {fileID: 7200000, guid: 65b89cac5f286b043a31bf8041776ee7, type: 3} blitCubemapPS: {fileID: 4800000, guid: d05913e251bed7a4992c921c62e1b647, type: 3} - buildProbabilityTablesCS: {fileID: 7200000, guid: b9f26cf340afe9145a699753531b2a4c, type: 3} - computeGgxIblSampleDataCS: {fileID: 7200000, guid: 764a24bb47ef5ba4781d9ae82ca07445, type: 3} + buildProbabilityTablesCS: {fileID: 7200000, guid: b9f26cf340afe9145a699753531b2a4c, + type: 3} + computeGgxIblSampleDataCS: {fileID: 7200000, guid: 764a24bb47ef5ba4781d9ae82ca07445, + type: 3} GGXConvolvePS: {fileID: 4800000, guid: 123ed592ad5c2494b8aed301fd609e7b, type: 3} charlieConvolvePS: {fileID: 4800000, guid: 5685fd17e71045e4ca9fefca38a7c177, type: 3} - opaqueAtmosphericScatteringPS: {fileID: 4800000, guid: 32f724728cf19904291226f239ec16f0, type: 3} + opaqueAtmosphericScatteringPS: {fileID: 4800000, guid: 32f724728cf19904291226f239ec16f0, + type: 3} hdriSkyPS: {fileID: 4800000, guid: 9bd32a6ece529fd4f9408b8d7e00c10d, type: 3} - integrateHdriSkyPS: {fileID: 4800000, guid: 48db2705cf2856d4e893eb30a6892d1b, type: 3} + integrateHdriSkyPS: {fileID: 4800000, guid: 48db2705cf2856d4e893eb30a6892d1b, + type: 3} skyboxCubemapPS: {fileID: 103, guid: 0000000000000000f000000000000000, type: 0} gradientSkyPS: {fileID: 4800000, guid: 2b5d4f1b26f03dc4a873b093e0c4adb1, type: 3} - bakeCloudTextureCS: {fileID: 7200000, guid: ab3c4e1fdc13358468dc6ee4caf14fc2, type: 3} - computeCloudShadowsCS: {fileID: 7200000, guid: 09410d5c082f02848be25be02bbe8edf, type: 3} - ambientProbeConvolutionCS: {fileID: 7200000, guid: 6d048f7b1bd45e840b4e79ec92639fa8, type: 3} - groundIrradiancePrecomputationCS: {fileID: 7200000, guid: eb6ae6f326207ee4d987a3e5adddf63a, type: 3} - inScatteredRadiancePrecomputationCS: {fileID: 7200000, guid: 70c69d514688f8545855680760d77418, type: 3} - physicallyBasedSkyPS: {fileID: 4800000, guid: a06934a4863e778498be65d8f865b7a4, type: 3} - planarReflectionFilteringCS: {fileID: 7200000, guid: 9f3f8a01b8caaaa4595591dc96d43dd2, type: 3} - preIntegratedFGD_GGXDisneyDiffusePS: {fileID: 4800000, guid: 123f13d52852ef547b2962de4bd9eaad, type: 3} - preIntegratedFGD_CharlieFabricLambertPS: {fileID: 4800000, guid: 3b3bf235775cf8b4baae7f3306787ab0, type: 3} - preIntegratedFGD_WardPS: {fileID: 4800000, guid: d279c46a545b0af4f9f0c4fa82cd489e, type: 3} - preIntegratedFGD_CookTorrancePS: {fileID: 4800000, guid: a6402c19b020b4a4fb7073aaa2e26aba, type: 3} + bakeCloudTextureCS: {fileID: 7200000, guid: 5d4461b96f173b34792b6c8ae075651e, + type: 3} + computeCloudShadowsCS: {fileID: 7200000, guid: 09410d5c082f02848be25be02bbe8edf, + type: 3} + ambientProbeConvolutionCS: {fileID: 7200000, guid: 6d048f7b1bd45e840b4e79ec92639fa8, + type: 3} + groundIrradiancePrecomputationCS: {fileID: 7200000, guid: eb6ae6f326207ee4d987a3e5adddf63a, + type: 3} + inScatteredRadiancePrecomputationCS: {fileID: 7200000, guid: 70c69d514688f8545855680760d77418, + type: 3} + physicallyBasedSkyPS: {fileID: 4800000, guid: a06934a4863e778498be65d8f865b7a4, + type: 3} + planarReflectionFilteringCS: {fileID: 7200000, guid: 9f3f8a01b8caaaa4595591dc96d43dd2, + type: 3} + preIntegratedFGD_GGXDisneyDiffusePS: {fileID: 4800000, guid: 123f13d52852ef547b2962de4bd9eaad, + type: 3} + preIntegratedFGD_CharlieFabricLambertPS: {fileID: 4800000, guid: 3b3bf235775cf8b4baae7f3306787ab0, + type: 3} + preIntegratedFGD_WardPS: {fileID: 4800000, guid: d279c46a545b0af4f9f0c4fa82cd489e, + type: 3} + preIntegratedFGD_CookTorrancePS: {fileID: 4800000, guid: a6402c19b020b4a4fb7073aaa2e26aba, + type: 3} encodeBC6HCS: {fileID: 7200000, guid: aa922d239de60304f964e24488559eeb, type: 3} cubeToPanoPS: {fileID: 4800000, guid: 595434cc3b6405246b6cd3086d0b6f7d, type: 3} - blitCubeTextureFacePS: {fileID: 4800000, guid: d850d0a2481878d4bbf17e5126b04163, type: 3} - filterAreaLightCookiesPS: {fileID: 4800000, guid: c243aac96dda5fa40bed693ed5ba02c4, type: 3} - clearUIntTextureCS: {fileID: 7200000, guid: d067ad4b88af51c498875426894aef76, type: 3} + blitCubeTextureFacePS: {fileID: 4800000, guid: d850d0a2481878d4bbf17e5126b04163, + type: 3} + filterAreaLightCookiesPS: {fileID: 4800000, guid: c243aac96dda5fa40bed693ed5ba02c4, + type: 3} + clearUIntTextureCS: {fileID: 7200000, guid: d067ad4b88af51c498875426894aef76, + type: 3} customPassUtils: {fileID: 4800000, guid: 7e3722d0388000848acb25fd3cc8c088, type: 3} - customPassRenderersUtils: {fileID: 4800000, guid: cef5ba33ee5063d4c8b495d2292e394d, type: 3} + customPassRenderersUtils: {fileID: 4800000, guid: cef5ba33ee5063d4c8b495d2292e394d, + type: 3} xrMirrorViewPS: {fileID: 4800000, guid: e6255f98cf405eb45ab6f9006cf11e1f, type: 3} xrOcclusionMeshPS: {fileID: 4800000, guid: 46a45b32bb110604fb36216b63bcdb81, type: 3} shadowClearPS: {fileID: 4800000, guid: e3cab24f27741f44d8af1e94d006267c, type: 3} evsmBlurCS: {fileID: 7200000, guid: fb36979473602464fa32deacb9630c08, type: 3} - debugHDShadowMapPS: {fileID: 4800000, guid: 93d40cc9a6e13994f86f576a624efa18, type: 3} + debugHDShadowMapPS: {fileID: 4800000, guid: 93d40cc9a6e13994f86f576a624efa18, + type: 3} momentShadowsCS: {fileID: 7200000, guid: 4dea53e2ff15ed0448817c2aa4246e53, type: 3} - decalNormalBufferPS: {fileID: 4800000, guid: fd532bf1795188c4daaa66ea798b8b0a, type: 3} - decalClearPropertyMaskBufferCS: {fileID: 7200000, guid: 1076a08965d4a91479b72599724f7fd6, type: 3} + decalNormalBufferPS: {fileID: 4800000, guid: fd532bf1795188c4daaa66ea798b8b0a, + type: 3} + decalClearPropertyMaskBufferCS: {fileID: 7200000, guid: 1076a08965d4a91479b72599724f7fd6, + type: 3} GTAOCS: {fileID: 7200000, guid: 6710b06492bd58c4bb8aec0fdc1fced3, type: 3} - GTAOSpatialDenoiseCS: {fileID: 7200000, guid: 2cb33c21587d12b4388d7866ab6c65f6, type: 3} - GTAOTemporalDenoiseCS: {fileID: 7200000, guid: 31e0ca4c210f97c468037d11a5b832bb, type: 3} + GTAOSpatialDenoiseCS: {fileID: 7200000, guid: 2cb33c21587d12b4388d7866ab6c65f6, + type: 3} + GTAOTemporalDenoiseCS: {fileID: 7200000, guid: 31e0ca4c210f97c468037d11a5b832bb, + type: 3} GTAOCopyHistoryCS: {fileID: 7200000, guid: 7f43be57ffd12ff469d4fc175c00c4b4, type: 3} - GTAOBlurAndUpsample: {fileID: 7200000, guid: 9eb1abde882538a4ea46fa23e49ab9fa, type: 3} - screenSpaceGlobalIlluminationCS: {fileID: 7200000, guid: 96170a954eb538b40a5ff369552c3629, type: 3} + GTAOBlurAndUpsample: {fileID: 7200000, guid: 9eb1abde882538a4ea46fa23e49ab9fa, + type: 3} + screenSpaceGlobalIlluminationCS: {fileID: 7200000, guid: 96170a954eb538b40a5ff369552c3629, + type: 3} depthValuesPS: {fileID: 4800000, guid: 6e6a4a3dbb788234594aa74f2d6aeb6f, type: 3} colorResolvePS: {fileID: 4800000, guid: dd7047092f3c82b40b3a07868f9c4de2, type: 3} - resolveMotionVecPS: {fileID: 4800000, guid: ea18ca9826385e943979c46cf98968cc, type: 3} + resolveMotionVecPS: {fileID: 4800000, guid: ea18ca9826385e943979c46cf98968cc, + type: 3} copyAlphaCS: {fileID: 7200000, guid: c2c7eb6611725264187721ef9df0354b, type: 3} nanKillerCS: {fileID: 7200000, guid: 83982f199acf927499576a99abc9bea9, type: 3} exposureCS: {fileID: 7200000, guid: 976d7bce54fae534fb9ec67e9c18570c, type: 3} - histogramExposureCS: {fileID: 7200000, guid: 222da48299136f34b8e3fb75ae9f8ac7, type: 3} + histogramExposureCS: {fileID: 7200000, guid: 222da48299136f34b8e3fb75ae9f8ac7, + type: 3} applyExposureCS: {fileID: 7200000, guid: 1a6fea1dc099b984d8f2b27d504dc096, type: 3} - debugImageHistogramCS: {fileID: 7200000, guid: 52cc17ef5a5ffc443a5c142f9b745a85, type: 3} + debugImageHistogramCS: {fileID: 7200000, guid: 52cc17ef5a5ffc443a5c142f9b745a85, + type: 3} uberPostCS: {fileID: 7200000, guid: f1bf52f7c71bffd4f91e6cd90d12a4f7, type: 3} lutBuilder3DCS: {fileID: 7200000, guid: 37f2b1b0ecd6f1c439e4c1b4f2fdb524, type: 3} - depthOfFieldKernelCS: {fileID: 7200000, guid: 7869415cc3e4eaa4d82ac21a752a2780, type: 3} + depthOfFieldKernelCS: {fileID: 7200000, guid: 7869415cc3e4eaa4d82ac21a752a2780, + type: 3} depthOfFieldCoCCS: {fileID: 7200000, guid: 048b235b54fbfaa4d80ec85ea847d4f8, type: 3} - depthOfFieldCoCReprojectCS: {fileID: 7200000, guid: 4980decaa3878d6448569489f5fc7931, type: 3} - depthOfFieldDilateCS: {fileID: 7200000, guid: 1c93af4338c0c1b42b92464992eebc10, type: 3} + depthOfFieldCoCReprojectCS: {fileID: 7200000, guid: 4980decaa3878d6448569489f5fc7931, + type: 3} + depthOfFieldDilateCS: {fileID: 7200000, guid: 1c93af4338c0c1b42b92464992eebc10, + type: 3} depthOfFieldMipCS: {fileID: 7200000, guid: d3ef53de069ded64e8377cba6eb951fa, type: 3} - depthOfFieldMipSafeCS: {fileID: 7200000, guid: 2d24ee7b2c804d947a5c371c12ed46bd, type: 3} - depthOfFieldPrefilterCS: {fileID: 7200000, guid: f2b89d19910854346b792fe7177ce634, type: 3} - depthOfFieldTileMaxCS: {fileID: 7200000, guid: 84f84585ea8a7a849bea4a581adb93a7, type: 3} - depthOfFieldGatherCS: {fileID: 7200000, guid: 486be52dddc4e054fb10a7b9b78788c2, type: 3} - depthOfFieldCombineCS: {fileID: 7200000, guid: c8049ca85c4c7d047ba28f34d800c663, type: 3} - depthOfFieldPreCombineFarCS: {fileID: 7200000, guid: 3b4a2acd03d1ce2438d93c325d588735, type: 3} - depthOfFieldClearIndirectArgsCS: {fileID: 7200000, guid: 69905045e1d0a65458b205d6ab55502b, type: 3} - paniniProjectionCS: {fileID: 7200000, guid: 0ddbf72c8fbb6e44b983f470c8384ef6, type: 3} - motionBlurMotionVecPrepCS: {fileID: 7200000, guid: ed9438fa777911d48933402087203b15, type: 3} - motionBlurGenTileCS: {fileID: 7200000, guid: 336e1fdbb3a1b8647b06208415f87804, type: 3} - motionBlurMergeTileCS: {fileID: 7200000, guid: cd14ddf849edeed43b0e3ccf66023038, type: 3} - motionBlurNeighborhoodTileCS: {fileID: 7200000, guid: 5ea9865df3e53b448856785b88f8e7b9, type: 3} + depthOfFieldMipSafeCS: {fileID: 7200000, guid: 2d24ee7b2c804d947a5c371c12ed46bd, + type: 3} + depthOfFieldPrefilterCS: {fileID: 7200000, guid: f2b89d19910854346b792fe7177ce634, + type: 3} + depthOfFieldTileMaxCS: {fileID: 7200000, guid: 84f84585ea8a7a849bea4a581adb93a7, + type: 3} + depthOfFieldGatherCS: {fileID: 7200000, guid: 486be52dddc4e054fb10a7b9b78788c2, + type: 3} + depthOfFieldCombineCS: {fileID: 7200000, guid: c8049ca85c4c7d047ba28f34d800c663, + type: 3} + depthOfFieldPreCombineFarCS: {fileID: 7200000, guid: 3b4a2acd03d1ce2438d93c325d588735, + type: 3} + depthOfFieldClearIndirectArgsCS: {fileID: 7200000, guid: 69905045e1d0a65458b205d6ab55502b, + type: 3} + paniniProjectionCS: {fileID: 7200000, guid: 0ddbf72c8fbb6e44b983f470c8384ef6, + type: 3} + motionBlurMotionVecPrepCS: {fileID: 7200000, guid: ed9438fa777911d48933402087203b15, + type: 3} + motionBlurGenTileCS: {fileID: 7200000, guid: 336e1fdbb3a1b8647b06208415f87804, + type: 3} + motionBlurMergeTileCS: {fileID: 7200000, guid: cd14ddf849edeed43b0e3ccf66023038, + type: 3} + motionBlurNeighborhoodTileCS: {fileID: 7200000, guid: 5ea9865df3e53b448856785b88f8e7b9, + type: 3} motionBlurCS: {fileID: 7200000, guid: 2af5c49c7865edb4b823826970ec176a, type: 3} bloomPrefilterCS: {fileID: 7200000, guid: 243b24008041aaa4a91800690f63c684, type: 3} bloomBlurCS: {fileID: 7200000, guid: 133a68380d324de4ea8d3ff8657b02d8, type: 3} @@ -139,17 +210,21 @@ MonoBehaviour: finalPassPS: {fileID: 4800000, guid: 5ac9ef0c50282754b93c7692488e7ee7, type: 3} clearBlackPS: {fileID: 4800000, guid: 3330c1503ea8c6d4d9408df3f64227eb, type: 3} SMAAPS: {fileID: 4800000, guid: 9655f4aa89a469c49aceaceabf9bc77b, type: 3} - temporalAntialiasingPS: {fileID: 4800000, guid: 3dd9fd928fdb83743b1f27d15df22179, type: 3} - dofCircleOfConfusion: {fileID: 7200000, guid: 75332b7b315c80d4babe506820aa0bfd, type: 3} + temporalAntialiasingPS: {fileID: 4800000, guid: 3dd9fd928fdb83743b1f27d15df22179, + type: 3} + dofCircleOfConfusion: {fileID: 7200000, guid: 75332b7b315c80d4babe506820aa0bfd, + type: 3} dofGatherCS: {fileID: 7200000, guid: 1e6b16a7970a1494db74b1d3d007d1cc, type: 3} DoFCoCPyramidCS: {fileID: 7200000, guid: df41a69211c03fe479b63a8bed3bfbb4, type: 3} - contrastAdaptiveSharpenCS: {fileID: 7200000, guid: 560896aec2f412c48995be35551a4ac6, type: 3} + contrastAdaptiveSharpenCS: {fileID: 7200000, guid: 560896aec2f412c48995be35551a4ac6, + type: 3} accumulationCS: {fileID: 7200000, guid: ed80add7a217efa468d137d6f7c668f3, type: 3} alphaInjectionPS: {fileID: 4800000, guid: 4edd96259a5e8b44c90479928f0cd11e, type: 3} chromaKeyingPS: {fileID: 4800000, guid: 49feb6b111e82ec4eb6d3d08e4b6903e, type: 3} customClearPS: {fileID: 4800000, guid: 9cef3686fa32c8840947ed99b561195c, type: 3} ssGIDenoiserCS: {fileID: 7200000, guid: a435d803bc32d0845ba1a713b7a1c8b1, type: 3} - bilateralUpsampleCS: {fileID: 7200000, guid: 68e831c555284d741b985e05369f0e63, type: 3} + bilateralUpsampleCS: {fileID: 7200000, guid: 68e831c555284d741b985e05369f0e63, + type: 3} textures: debugFontTex: {fileID: 2800000, guid: a3ad2df0e49aaa341a3b3a80f93b3f66, type: 3} colorGradient: {fileID: 2800000, guid: 4ea52e665573c1644bf05dd9b11fd2a4, type: 3} @@ -220,15 +295,20 @@ MonoBehaviour: - {fileID: 2800000, guid: 7641a2b116fafd64d9c3d6459fdfe801, type: 3} - {fileID: 2800000, guid: c6a5e40e6746fef4fa486e8f620ee8d4, type: 3} - {fileID: 2800000, guid: fd4189357c6dfb94fa2d36afbce72086, type: 3} - owenScrambledRGBATex: {fileID: 2800000, guid: b0fe077c1ee7d80428f3d8dfa28a027d, type: 3} - owenScrambled256Tex: {fileID: 2800000, guid: 2a205358e67aa9e4a94a128ac9362f4e, type: 3} + owenScrambledRGBATex: {fileID: 2800000, guid: b0fe077c1ee7d80428f3d8dfa28a027d, + type: 3} + owenScrambled256Tex: {fileID: 2800000, guid: 2a205358e67aa9e4a94a128ac9362f4e, + type: 3} scramblingTex: {fileID: 2800000, guid: bf25cd6288e2c8d43854a61a8496a830, type: 3} rankingTile1SPP: {fileID: 2800000, guid: f2fe0251f704c4c478a8063775cffedb, type: 3} - scramblingTile1SPP: {fileID: 2800000, guid: 6185473f62ad3e74da4acac5d482917a, type: 3} + scramblingTile1SPP: {fileID: 2800000, guid: 6185473f62ad3e74da4acac5d482917a, + type: 3} rankingTile8SPP: {fileID: 2800000, guid: af4bd638a4b3eb14781e6441adcdfbb9, type: 3} - scramblingTile8SPP: {fileID: 2800000, guid: 152f8b933250a7b448fc2d4d301b9944, type: 3} + scramblingTile8SPP: {fileID: 2800000, guid: 152f8b933250a7b448fc2d4d301b9944, + type: 3} rankingTile256SPP: {fileID: 2800000, guid: 1e604a266c415cd46b36d97cd9220aa8, type: 3} - scramblingTile256SPP: {fileID: 2800000, guid: 882fb55d7b3e7c94598a318df9376e32, type: 3} + scramblingTile256SPP: {fileID: 2800000, guid: 882fb55d7b3e7c94598a318df9376e32, + type: 3} filmGrainTex: - {fileID: 2800000, guid: 284a1ac236869fa4eacf377d73c7dff8, type: 3} - {fileID: 2800000, guid: bd74961b009b93145a998ae93a5fc186, type: 3} @@ -243,8 +323,9 @@ MonoBehaviour: SMAASearchTex: {fileID: 2800000, guid: dc95d70472e232b438d0fd38651e7ec2, type: 3} SMAAAreaTex: {fileID: 2800000, guid: 92e0d85ab4eca874098e7fcf6f8f674e, type: 3} defaultHDRISky: {fileID: 8900000, guid: 8253d41e6e8b11a4cbe77a4f8f82934d, type: 3} - defaultCloudLayer: {fileID: 8600000, guid: da544156f6db72d42b0d827428ba4b8b, type: 2} assets: - defaultDiffusionProfile: {fileID: 11400000, guid: 2b7005ba3a4d8474b8cdc34141ad766e, type: 2} - emissiveCylinderMesh: {fileID: 2534964839176971238, guid: accb6d90f0d50fe4ca0f68159b4323de, type: 3} + defaultDiffusionProfile: {fileID: 11400000, guid: 2b7005ba3a4d8474b8cdc34141ad766e, + type: 2} + emissiveCylinderMesh: {fileID: 2534964839176971238, guid: accb6d90f0d50fe4ca0f68159b4323de, + type: 3} emissiveQuadMesh: {fileID: 4300000, guid: 1d5a8595286f94f4bb54171d49f473c3, type: 3} diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Material/DefaultCloudLayerMaterial.mat b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Material/DefaultCloudLayerMaterial.mat deleted file mode 100644 index 9fb12a3f45a..00000000000 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Material/DefaultCloudLayerMaterial.mat +++ /dev/null @@ -1,33 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!21 &2100000 -Material: - serializedVersion: 6 - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_Name: DefaultCloudLayerMaterial - m_Shader: {fileID: 4800000, guid: 7e7bad3fcd7c528419fe1c10e158b76c, type: 3} - m_ShaderKeywords: - m_LightmapFlags: 4 - m_EnableInstancingVariants: 0 - m_DoubleSidedGI: 0 - m_CustomRenderQueue: -1 - stringTagMap: {} - disabledShaderPasses: [] - m_SavedProperties: - serializedVersion: 3 - m_TexEnvs: - - _Tex: - m_Texture: {fileID: 2800000, guid: d5c1d2ec831566f4eb10f092da21fba1, type: 3} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - m_Floats: - - Opacity_A: 0.1 - - Opacity_B: 1 - - Opacity_G: 0.25 - - Opacity_R: 1 - - Rotate: 0 - m_Colors: [] - m_BuildTextureStacks: [] diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Material/DefaultCloudLayerMaterial.mat.meta b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Material/DefaultCloudLayerMaterial.mat.meta deleted file mode 100644 index f9deb296df3..00000000000 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Material/DefaultCloudLayerMaterial.mat.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 755965f3fe65ac244bb51842a1a136ad -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 0 - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Shader.meta b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Shader.meta deleted file mode 100644 index c5c93544b0d..00000000000 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Shader.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 54ee5b367ee513d44a1c6428334dfd62 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Shader/DefaultCloudLayerShader.shader b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Shader/DefaultCloudLayerShader.shader deleted file mode 100644 index 9d27c22d649..00000000000 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Shader/DefaultCloudLayerShader.shader +++ /dev/null @@ -1,50 +0,0 @@ -Shader "Hidden/DefaultCloudLayer" -{ - Properties - { - [NoScaleOffset] - _Tex("Cloud Texture", 2D) = "white" {} - - Opacity_R("Cumulus Opacity", Range(0,1)) = 1 - Opacity_G("Stratus Opacity", Range(0,1)) = 0.25 - Opacity_B("Cirrus Opacity", Range(0,1)) = 1 - Opacity_A("Wispy Opacity", Range(0,1)) = 0.1 - } - - SubShader - { - Lighting Off - Blend One Zero - - Pass - { - Name "Cloud Map" - - CGPROGRAM - - #include "UnityCustomRenderTexture.cginc" - #pragma vertex CustomRenderTextureVertexShader - #pragma fragment frag - #pragma target 3.0 - - sampler2D _Tex; - float Opacity_R; - float Opacity_G; - float Opacity_B; - float Opacity_A; - - float4 frag(v2f_customrendertexture IN) : COLOR - { - float2 UV = float2 (IN.localTexcoord.x, IN.localTexcoord.y); - float4 opacity = float4(Opacity_R, Opacity_G, Opacity_B, Opacity_A); - float4 clouds = tex2D(_Tex, UV) * opacity; - - return max(max(clouds.r, clouds.g), max(clouds.b, clouds.a)); - } - - ENDCG - } - } - Fallback Off - CustomEditor "Rendering.HighDefinition.DefaultCloudLayerGUI" -} diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Shader/DefaultCloudLayerShader.shader.meta b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Shader/DefaultCloudLayerShader.shader.meta deleted file mode 100644 index 7f96c9891ff..00000000000 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Shader/DefaultCloudLayerShader.shader.meta +++ /dev/null @@ -1,10 +0,0 @@ -fileFormatVersion: 2 -guid: 7e7bad3fcd7c528419fe1c10e158b76c -ShaderImporter: - externalObjects: {} - defaultTextures: [] - nonModifiableTextures: [] - preprocessorOverride: 0 - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/DefaultCloudLayer.asset b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/DefaultCloudLayer.asset deleted file mode 100644 index 90c07aa77cd..00000000000 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/DefaultCloudLayer.asset +++ /dev/null @@ -1,53 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!86 &8600000 -CustomRenderTexture: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_Name: DefaultCloudLayer - m_ImageContentsHash: - serializedVersion: 2 - Hash: 00000000000000000000000000000000 - m_ForcedFallbackFormat: 4 - m_DownscaleFallback: 0 - m_IsAlphaChannelOptional: 0 - serializedVersion: 3 - m_Width: 2048 - m_Height: 1024 - m_AntiAliasing: 1 - m_MipCount: -1 - m_DepthFormat: 0 - m_ColorFormat: 9 - m_MipMap: 0 - m_GenerateMips: 1 - m_SRGB: 0 - m_UseDynamicScale: 0 - m_BindMS: 0 - m_EnableCompatibleFormat: 1 - m_TextureSettings: - serializedVersion: 2 - m_FilterMode: 1 - m_Aniso: 0 - m_MipBias: 0 - m_WrapU: 0 - m_WrapV: 1 - m_WrapW: 0 - m_Dimension: 2 - m_VolumeDepth: 1 - m_Material: {fileID: 2100000, guid: 755965f3fe65ac244bb51842a1a136ad, type: 2} - m_InitSource: 0 - m_InitMaterial: {fileID: 0} - m_InitColor: {r: 1, g: 1, b: 1, a: 1} - m_InitTexture: {fileID: 0} - m_UpdateMode: 1 - m_InitializationMode: 1 - m_UpdateZoneSpace: 0 - m_CurrentUpdateZoneSpace: 0 - m_UpdateZones: [] - m_UpdatePeriod: 0 - m_ShaderPass: 0 - m_CubemapFaceMask: 4294967295 - m_DoubleBuffered: 0 - m_WrapUpdateZones: 0 diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/DefaultCloudLayer.asset.meta b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/DefaultCloudLayer.asset.meta deleted file mode 100644 index d173171109a..00000000000 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/DefaultCloudLayer.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: da544156f6db72d42b0d827428ba4b8b -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 0 - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/LayeredCloudTexture.png b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/DefaultCloudMap.png similarity index 100% rename from com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/LayeredCloudTexture.png rename to com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/DefaultCloudMap.png diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/LayeredCloudTexture.png.meta b/com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/DefaultCloudMap.png.meta similarity index 100% rename from com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/LayeredCloudTexture.png.meta rename to com.unity.render-pipelines.high-definition/Runtime/RenderPipelineResources/Texture/DefaultCloudMap.png.meta diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs index 5ec9ebfd5ec..bf70ff3008d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs @@ -66,14 +66,14 @@ public class CloudLayer : VolumeComponent public VolumeParameter mode = new VolumeParameter(); /// Choose the number of cloud layers. public VolumeParameter layers = new VolumeParameter(); - + /// Controls the opacity of the cloud shadows. [Tooltip("Controls the opacity of the cloud shadows.")] public ClampedFloatParameter shadowsOpacity = new ClampedFloatParameter(0.5f, 0.0f, 4.0f); /// Controls the scale of the cloud shadows. [Tooltip("Controls the scale of the cloud shadows.")] - public MinFloatParameter shadowsScale = new MinFloatParameter(500.0f, 0.0f); + public MinFloatParameter shadowsScale = new MinFloatParameter(500.0f, 0.0f); [Serializable] @@ -126,7 +126,7 @@ public class CloudLighting public ClampedIntParameter steps = new ClampedIntParameter(4, 1, 10); /// Thickness of the clouds. [Tooltip("Controls the thickness of the clouds.")] - public ClampedFloatParameter thickness = new ClampedFloatParameter(1, 0, 2); + public ClampedFloatParameter thickness = new ClampedFloatParameter(0.5f, 0, 2); /// Enable to cast shadows. [Tooltip("Enable or disable cloud shadows.")] @@ -171,7 +171,7 @@ public class CloudMap /// Opacity of the alpha layer. [Tooltip("Opacity of the alpha layer.")] public ClampedFloatParameter opacityA = new ClampedFloatParameter(0.0f, 0.0f, 1.0f); - + public CloudSettings settings = new CloudSettings(); public CloudLighting lighting = new CloudLighting(); @@ -230,7 +230,7 @@ internal bool SetComputeParams(ComputeShader cs, string mapKeyword, string motio } return false; } - + internal int GetBakingHashCode(ref bool castShadows) { int hash = 17; @@ -257,11 +257,11 @@ public class CloudCRT /// Texture used to render the clouds. [Tooltip("Specify the CustomRenderTexture HDRP uses to render the clouds (in LatLong layout).")] public TextureParameter cloudCRT = new TextureParameter(null); - + public CloudSettings settings = new CloudSettings(); public CloudLighting lighting = new CloudLighting(); - + internal int GetBakingHashCode(ref bool castShadows) { int hash = 17; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl index c4b63a99750..371c42e706d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl @@ -6,10 +6,10 @@ TEXTURE2D_ARRAY(_CloudTexture); SAMPLER(sampler_CloudTexture); - + TEXTURE2D(_CloudFlowmap1); SAMPLER(sampler_CloudFlowmap1); - + TEXTURE2D(_CloudFlowmap2); SAMPLER(sampler_CloudFlowmap2); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader b/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader index 9ed024f5138..36085be1a81 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader @@ -225,12 +225,13 @@ Shader "Hidden/HDRP/Sky/PbrSky" EvaluatePbrAtmosphere(_WorldSpaceCameraPos1, V, distAlongRay, renderSunDisk, skyColor, skyOpacity); } + skyColor += radiance * (1 - skyOpacity); + // Hacky way to boost the clouds to match other sky types float cloudIntensity = 200.0; skyColor = ApplyCloudLayer(-V, skyColor / cloudIntensity) * cloudIntensity; - skyColor += radiance * (1 - skyOpacity); - skyColor *= _IntensityMultiplier; + skyColor *= _IntensityMultiplier; return float4(skyColor, 1.0); } From 42ebf216dae68be018239c77dedd539332b1aa46 Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Tue, 4 Aug 2020 14:16:19 +0200 Subject: [PATCH 08/10] Bug fixes and documentation --- .../CHANGELOG.md | 1 + .../Documentation~/Creating-a-Custom-Sky.md | 8 ++- .../Images/Override-CloudLayer.png | 4 +- .../Documentation~/Override-Cloud-Layer.md | 49 ++++++++------ .../Material/DefaultCloudLayerGUI.cs | 30 --------- .../Material/DefaultCloudLayerGUI.cs.meta | 11 ---- .../Editor/Sky/CloudLayer/CloudLayerEditor.cs | 32 +++++----- .../Runtime/Debug/DebugDisplay.cs | 12 ++-- .../Runtime/Lighting/LightEvaluation.hlsl | 7 +- .../Runtime/Lighting/LightLoop/LightLoop.cs | 3 +- .../RenderPipeline/HDStringConstants.cs | 13 ++-- .../ShaderLibrary/ShaderVariablesGlobal.cs | 2 +- .../ShaderVariablesGlobal.cs.hlsl | 2 +- .../Sky/CloudLayer/BakeCloudTexture.compute | 35 ++++++---- .../Runtime/Sky/CloudLayer/CloudLayer.cs | 64 ++++++++++--------- .../CloudLayer/ComputeCloudShadows.compute | 13 ++-- .../Runtime/Sky/CloudRenderingContext.cs | 2 +- .../Runtime/Sky/HDRISky/HDRISky.shader | 13 +--- .../PhysicallyBasedSky.shader | 4 +- .../Runtime/Sky/SkyManager.cs | 56 ++++++++++------ 20 files changed, 182 insertions(+), 179 deletions(-) delete mode 100644 com.unity.render-pipelines.high-definition/Editor/RenderPipelineResources/Material/DefaultCloudLayerGUI.cs delete mode 100644 com.unity.render-pipelines.high-definition/Editor/RenderPipelineResources/Material/DefaultCloudLayerGUI.cs.meta diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 1f609362227..6692f996b80 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -165,6 +165,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added path tracing test scene for normal mapping. - Added missing API documentation. - Added an option to have only the metering mask displayed in the debug mode. +- Added lighting and shadows to the cloud layer ### Fixed - Fix when rescale probe all direction below zero (1219246) diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Creating-a-Custom-Sky.md b/com.unity.render-pipelines.high-definition/Documentation~/Creating-a-Custom-Sky.md index a585b578bed..6cc30ff7a1f 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Creating-a-Custom-Sky.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Creating-a-Custom-Sky.md @@ -59,7 +59,7 @@ public class NewSky : SkySettings } return hash; } - + public override int GetHashCode(Camera camera) { // Implement if your sky depends on the camera settings (like position for instance) @@ -168,7 +168,7 @@ class NewSkyRenderer : SkyRenderer m_PropertyBlock.SetMatrix(_PixelCoordToViewDirWS, builtinParams.pixelCoordToViewDirMatrix); if (SupportCloudLayer) - CloudLayer.Apply(builtinParams.cloudLayer, m_NewSkyMaterial); + CloudLayer.Apply(builtinParams, m_NewSkyMaterial); CoreUtils.DrawFullScreen(builtinParams.commandBuffer, m_NewSkyMaterial, m_PropertyBlock, passID); } @@ -177,7 +177,7 @@ class NewSkyRenderer : SkyRenderer ``` ### Important note: -If your sky renderer has to manage heavy data (like precomputed textures or similar things) then particular care has to be taken. Indeed, one instance of the renderer will exist per camera so by default if this data is a member of the renderer, it willl also be duplicated in memory. +If your sky renderer has to manage heavy data (like precomputed textures or similar things) then particular care has to be taken. Indeed, one instance of the renderer will exist per camera so by default if this data is a member of the renderer, it will also be duplicated in memory. Since each sky renderer can have very different needs, the responsbility to share this kind of data is the renderer's and need to be implemented by the user. @@ -200,6 +200,8 @@ Shader "Hidden/HDRP/Sky/NewSky" #pragma multi_compile_local _ USE_CLOUD_MAP #pragma multi_compile_local _ USE_CLOUD_MOTION + #pragma multi_compile_local _ USE_SECOND_CLOUD_MAP + #pragma multi_compile_local _ USE_SECOND_CLOUD_MOTION #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonLighting.hlsl" diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Images/Override-CloudLayer.png b/com.unity.render-pipelines.high-definition/Documentation~/Images/Override-CloudLayer.png index b729b6268c4..f7a79f2c5b0 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Images/Override-CloudLayer.png +++ b/com.unity.render-pipelines.high-definition/Documentation~/Images/Override-CloudLayer.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:58f1c0836b097b52457650cc996d13154eaea7ccf939d4cfc8175a66aa17c822 -size 12864 +oid sha256:bf4deba271d9dfe24d4f746d374cd62b85076ef6b307c57087a2b79cfded83e7 +size 35151 diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Override-Cloud-Layer.md b/com.unity.render-pipelines.high-definition/Documentation~/Override-Cloud-Layer.md index 1c1c61a9cdb..eebf62c32ae 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Override-Cloud-Layer.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Override-Cloud-Layer.md @@ -9,32 +9,28 @@ The **Cloud Layer** uses the [Volume](Volumes.md) framework, so to enable and mo 1. In the Scene or Hierarchy view, select a GameObject that contains a Volume component to view it in the Inspector. 2. In the Inspector, navigate to **Add Override > Sky** and click on **Cloud Layer**. -After you add a **Cloud Layer** override, you must enable it in the override itself. In the override, Check the **Enable** property. HDRP now renders **Cloud Layer** for any Camera this Volume affects. +To enable the **Cloud Layer** override, you must set the **Opacity** slider to a value higher than `0` and assign a Cloud Map. To assign a Cloud Map, you can refer to the [Cloud Map](#CloudMap) section to learn about the cloud map format or where to find a sample cloud map texture. - +The Cloud Layer will bake the cloud map to an intermediate texture, which is recomputed everytime a parameter changes. The resolution of the baked texture is determined by the **Cloud Texture Size** parameter in the HDRP asset. +Clouds shadows are also baked to a separate texture whose resolution is set by the **Cloud Shadows Size** parameter in the HDRP asset. -## Using the default Cloud Map + -HDRP includes an example Cloud Map texture named `DefaultCloudLayer`. -This example Cloud Map is a read-only **CustomRenderTexture**. This means that, if you want to modify any of its properties, you need to create a duplicate of it and modify that instead. To duplicate the example Cloud Map: +## About the Cloud Map -1. Duplicate the `DefaultCloudLayer` asset. -2. Duplicate the Material referenced by the DefaultCloudLayer asset. This Material is called `DefaultCloudLayerMaterial`. -3. In the Inspector for the new `DefaultCloudLayer`, assign the new `DefaultCloudLayerMaterial` to the **Material** property. +The Cloud Map is a 2D RGBA texture in LatLong layout (sometimes called Cylindrical or Equirectangular) where each channel contains a cloud opacity. For rendering, the 4 channels are mixed together using the **Opacities** parameters of the volume override. This allows to change the aspects of the clouds using a single texture and the volume framework. - +HDRP includes an example Cloud Map named `DefaultCloudMap`. This texture contains cumulus clouds in the red channel, stratus clouds in the green channel, cirrus clouds in the blue channel and wispy clouds in the alpha channel. -## Customizing the Cloud Map - -The Cloud Map is a 2D texture in LatLong layout (sometimes called Cylindrical or Equirectangular) that contains cloud opacity in the red channel. If **Upper Hemisphere Only** is checked, the map is interpreted as being the upper half of a LatLong texture. It means that it will only conver the sky above the horizon. ## Customizing the Flowmap -The Flowmap must have the same layout as the cloud map, and is also subject to the **Upper Hemisphere Only** property. -Only the red and green channel are used and they represent respectively horizontal and vertical displacement. For each of these channels, a value of `0.5` means no displacement, a value of `0` means a negative displacement and a value of `1` means a positive displacement. +You can assign a custom Flowmap to the **Cloud Layer** to have control over the cloud movement. +The Flowmap has the same layout as the Cloud Map, and is also subject to the **Upper Hemisphere Only** property. +Only the red and green channels are used and they represent respectively horizontal and vertical displacement. For each of these channels, a value of `0.5` means no displacement, a value of `0` means a negative displacement and a value of `1` means a positive displacement. ## Properties @@ -42,14 +38,27 @@ Only the red and green channel are used and they represent respectively horizont | Property | Description | | ----------------------------- | ------------------------------------------------------------ | -| **Enable** | Enables the cloud layer. | -| **Cloud Map* | Assign a Texture that HDRP uses to render the cloud layer. Refer to the section [Using the default Cloud Map](#DefaultCloudMap) or [Customizing the Cloud Map](#CustomizingCloudMap) for more details. | +| **Opacity** | This controls the global opacity of the cloud layer. | | **Upper Hemisphere Only** | Check the box to display the cloud layer above the horizon only. | +| **Layers** | Control the number of cloud layers. Each have its own set of parameters described in the table below. | +| **Shadows Opacity** | Controls the opacity of the clouds shadows. This property only appears if at least one cloud layer has **Cast Shadows** enabled. | +| **Shadows Tiling** | Controls the tiling of the cloud shadows. This property only appears if at least one cloud layer has **Cast Shadows** enabled. | + +| Map Property | Description | +| ----------------------------- | ------------------------------------------------------------ | +| **Cloud Map** | Assign a Texture that HDRP uses to render the cloud layer. Refer to the section [Cloud Map](#CloudMap) for more details. | +| - **Opacity R** | Opacity of the red layer. | +| - **Opacity G** | Opacity of the green layer. | +| - **Opacity B** | Opacity of the blue layer. | +| - **Opacity A** | Opacity of the alpha layer. | +| **Rotation** | Use the slider to set the angle to rotate the Cloud Layer, in degrees. | | **Tint** | Specifies a color that HDRP uses to tint the Cloud Layer. | | **Intensity Multiplier** | Set the multiplier by which HDRP multiplies the Cloud Layer color. | -| **Rotation** | Use the slider to set the angle to rotate the Cloud Layer, in degrees. | -| **Enable Distortion** | Enable or disable cloud motion using UV distortion. | -| - **Distortion Mode** | Use the drop-down to select the method that HDRP uses to calculate the cloud distortion.
• **Procedural**: HDRP distorts the clouds using a uniform wind direction.
• **Flowmap**: HDRP distorts the clouds with a user provided flowmap. | -| -- **Flowmap** | Assign a flowmap, in LatLong layout, that HDRP uses to distort UVs when rendering the clouds. Refer to the section [Customizing the Flowmap](#CustomizingFlowmap) for more details.
This property only appears when you select **Flowmap** from the **Distortion Mode** drop-down. | +| **Distortion** | Use the dropdown to choose the distortion mode for simulating cloud motion.
• **None**: No distortion.
• **Procedural**: HDRP distorts the clouds using a uniform wind direction.
• **Flowmap**: HDRP distorts the clouds using the provided flowmap. | | - **Scroll direction** | Use the slider to set the scrolling direction for the distortion. | | - **Scroll speed** | Modify the speed at which HDRP scrolls the distortion texture. | +| - **Flowmap** | Assign a flowmap that HDRP uses to distort UVs when rendering the clouds. Refer to the section [Customizing the Flowmap](#CustomizingFlowmap) for more details.
This property only appears when you select **Flowmap** from the **Distortion** drop-down. | +| **Lighting** | Use the dropdown to choose the cloud lighting mode.
• **None**: No lighting.
• **Raymarching**: HDRP lights the clouds using 2D raymarching with the main directionnal light. | +| - **Steps** | Use the slider to set the number of steps for the raymarching. | +| - **Thickness** | Set the thickness of the clouds. | +| **Cast Shadows** | Enable to have the clouds cast shadows for the main directionnal light. | diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipelineResources/Material/DefaultCloudLayerGUI.cs b/com.unity.render-pipelines.high-definition/Editor/RenderPipelineResources/Material/DefaultCloudLayerGUI.cs deleted file mode 100644 index ada9b7747b0..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipelineResources/Material/DefaultCloudLayerGUI.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.Rendering; -using UnityEngine.Experimental.Rendering; -using System; - -namespace UnityEditor.Rendering.HighDefinition -{ - /// - /// GUI for the default cloud layer material - /// - class DefaultCloudLayerGUI : ShaderGUI - { - override public void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) - { - materialEditor.SetDefaultGUIWidths(); - - for (var i = 0; i < props.Length; i++) - { - if ((props[i].flags & MaterialProperty.PropFlags.HideInInspector) != 0) - continue; - - float h = materialEditor.GetPropertyHeight(props[i], props[i].displayName); - Rect r = EditorGUILayout.GetControlRect(true, h, EditorStyles.layerMaskField); - - materialEditor.ShaderProperty(r, props[i], props[i].displayName); - } - } - } -} // namespace UnityEditor diff --git a/com.unity.render-pipelines.high-definition/Editor/RenderPipelineResources/Material/DefaultCloudLayerGUI.cs.meta b/com.unity.render-pipelines.high-definition/Editor/RenderPipelineResources/Material/DefaultCloudLayerGUI.cs.meta deleted file mode 100644 index ee1919ac7ea..00000000000 --- a/com.unity.render-pipelines.high-definition/Editor/RenderPipelineResources/Material/DefaultCloudLayerGUI.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 9ef3d0150aa5cca4f91de34d462d4b6d -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs b/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs index 114f1a7096e..5c4caf6289c 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs @@ -105,9 +105,9 @@ CloudCRTParameter UnpackCloudCRT(SerializedProperty serializedProperty) } SerializedDataParameter m_Opacity, m_UpperHemisphereOnly; - SerializedDataParameter m_Mode, m_Layers; - SerializedDataParameter m_ShadowsOpacity, m_ShadowsScale; - CloudMapParameter[] m_Maps; + SerializedDataParameter m_Mode, m_LayerCount; + SerializedDataParameter m_ShadowsOpacity, m_ShadowsTiling; + CloudMapParameter[] m_Layers; CloudCRTParameter m_Crt; public override void OnEnable() @@ -119,14 +119,14 @@ public override void OnEnable() m_Opacity = Unpack(o.Find(x => x.opacity)); m_UpperHemisphereOnly = Unpack(o.Find(x => x.upperHemisphereOnly)); m_Mode = Unpack(o.Find(x => x.mode)); - m_Layers = Unpack(o.Find(x => x.layers)); + m_LayerCount = Unpack(o.Find(x => x.layers)); m_ShadowsOpacity = Unpack(o.Find(x => x.shadowsOpacity)); - m_ShadowsScale = Unpack(o.Find(x => x.shadowsScale)); + m_ShadowsTiling = Unpack(o.Find(x => x.shadowsTiling)); - m_Maps = new CloudMapParameter[] { - UnpackCloudMap(o.Find(x => x.mapA)), - UnpackCloudMap(o.Find(x => x.mapB)) + m_Layers = new CloudMapParameter[] { + UnpackCloudMap(o.Find(x => x.layerA)), + UnpackCloudMap(o.Find(x => x.layerB)) }; m_Crt = UnpackCloudCRT(o.Find(x => x.crt)); @@ -194,16 +194,16 @@ public override void OnInspectorGUI() if (m_Mode.value.intValue == (int)CloudLayerMode.CloudMap) { EditorGUI.indentLevel++; - PropertyField(m_Layers); + PropertyField(m_LayerCount); EditorGUI.indentLevel--; - PropertyField(m_Maps[0], "Map A"); - bool cloudShadows = m_Maps[0].lighting.castShadows.value.boolValue; + PropertyField(m_Layers[0], "Layer A"); + bool cloudShadows = m_Layers[0].lighting.castShadows.value.boolValue; - if (m_Layers.value.intValue == (int)CloudMapMode.Double) + if (m_LayerCount.value.intValue == (int)CloudMapMode.Double) { - PropertyField(m_Maps[1], "Map B"); - cloudShadows |= m_Maps[1].lighting.castShadows.value.boolValue; + PropertyField(m_Layers[1], "Layer B"); + cloudShadows |= m_Layers[1].lighting.castShadows.value.boolValue; } if (cloudShadows) @@ -211,8 +211,8 @@ public override void OnInspectorGUI() EditorGUILayout.Space(); EditorGUILayout.LabelField("Cloud Shadows", EditorStyles.miniLabel); - PropertyField(m_ShadowsOpacity, new GUIContent("Opacity")); - PropertyField(m_ShadowsScale, new GUIContent("Scale")); + PropertyField(m_ShadowsOpacity); + PropertyField(m_ShadowsTiling); } } else if (m_Mode.value.intValue == (int)CloudLayerMode.RenderTexture) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs index 2d02e049975..48df9bdfa7d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs @@ -1455,14 +1455,14 @@ DebugUI.Widget makeWidget(string name, VolumeParameter param) // Build rows - recursively handles nested parameters var rows = new List(); - void AddParameterRows(Type type) + void AddParameterRows(Type type, string prefix = null) { - void AddRow(FieldInfo f) + void AddRow(FieldInfo f, string prefix) { - var fieldName = f.Name; + var fieldName = prefix + f.Name; var attr = (DisplayInfoAttribute[])f.GetCustomAttributes(typeof(DisplayInfoAttribute), true); if (attr.Length != 0) - fieldName = attr[0].name; + fieldName = prefix + attr[0].name; #if UNITY_EDITOR // Would be nice to have the equivalent for the runtime debug. else @@ -1496,9 +1496,9 @@ void AddRow(FieldInfo f) { var fieldType = field.FieldType; if (fieldType.IsSubclassOf(typeof(VolumeParameter))) - AddRow(field); + AddRow(field, prefix ?? ""); else if (!fieldType.IsArray && fieldType.IsClass) - AddParameterRows(fieldType); + AddParameterRows(fieldType, prefix ?? (field.Name + " ")); } } AddParameterRows(selectedType); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl index 79b66fa9f50..e9c6f563ad5 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl @@ -293,13 +293,14 @@ SHADOW_TYPE EvaluateShadow_Directional( LightLoopContext lightLoopContext, Posit #endif // Cloud shadows - float3x3 lightToWorld = float3x3(light.right, light.up, light.forward); + float3x3 lightToWorld = float3x3(light.right, light.up, light.forward); float3 lightToSample = posInput.positionWS - light.positionRWS; - float3 positionLS = mul(lightToSample, transpose(lightToWorld)); + float3 positionLS = mul(lightToSample, transpose(lightToWorld)); float2 uv = positionLS.xy / _CloudShadowScale; float cloudShadow = SAMPLE_TEXTURE2D_LOD(_CloudShadows, sampler_CloudShadows, uv, 0).r; - shadow = saturate(lerp(shadow, _CloudShadowOpacity, cloudShadow)); + //shadow = saturate(lerp(shadow, _CloudShadowOpacity, cloudShadow)); + shadow = min(shadow, cloudShadow); return shadow; #else // LIGHT_EVALUATION_NO_SHADOWS diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs index 1b8d3c6e353..4a0818faa3e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs @@ -3609,8 +3609,7 @@ unsafe void UpdateShaderVariablesGlobalLightLoop(ref ShaderVariablesGlobal cb, H // Misc cb._EnableSSRefraction = hdCamera.frameSettings.IsEnabled(FrameSettingsField.Refraction) ? 1u : 0u; - cb._CloudShadowOpacity = hdCamera.lightingSky.cloudLayer == null ? 1.0f : 1.0f - hdCamera.lightingSky.cloudLayer.shadowsOpacity.value; - cb._CloudShadowScale = hdCamera.lightingSky.cloudLayer == null ? 1.0f : hdCamera.lightingSky.cloudLayer.shadowsScale.value; + cb._CloudShadowScale = hdCamera.lightingSky.cloudLayer == null ? 1.0f : hdCamera.lightingSky.cloudLayer.shadowsTiling.value; } void PushLightDataGlobalParams(CommandBuffer cmd) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs index 1914f95ebeb..e61303d7f60 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs @@ -402,10 +402,15 @@ static class HDShaderIDs public static readonly int _Flowmap = Shader.PropertyToID("_Flowmap"); public static readonly int _FlowmapParam = Shader.PropertyToID("_FlowmapParam"); - public static readonly int _CloudMap = Shader.PropertyToID("_CloudMap"); - public static readonly int _CloudFlowmap = Shader.PropertyToID("_CloudFlowmap"); - public static readonly int _CloudParam = Shader.PropertyToID("_CloudParam"); - public static readonly int _CloudParam2 = Shader.PropertyToID("_CloudParam2"); + public static readonly int _CloudMapA = Shader.PropertyToID("_CloudMapA"); + public static readonly int _CloudMapB = Shader.PropertyToID("_CloudMapB"); + public static readonly int _CloudTexture = Shader.PropertyToID("_CloudTexture"); + public static readonly int _CloudParams1 = Shader.PropertyToID("_CloudParams1"); + public static readonly int _CloudParams2 = Shader.PropertyToID("_CloudParams2"); + public static readonly int _CloudFlowmap1 = Shader.PropertyToID("_CloudFlowmap1"); + public static readonly int _CloudFlowmap2 = Shader.PropertyToID("_CloudFlowmap2"); + public static readonly int _CloudShadows = Shader.PropertyToID("_CloudShadows"); + public static readonly int _CloudShadowOpacity = Shader.PropertyToID("_CloudShadowOpacity"); public static readonly int _Size = Shader.PropertyToID("_Size"); public static readonly int _Source = Shader.PropertyToID("_Source"); diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs index eb0fa045937..fd6a979d486 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs @@ -191,7 +191,7 @@ unsafe struct ShaderVariablesGlobal public float _MicroShadowOpacity; public uint _EnableProbeVolumes; public uint _ProbeVolumeCount; - public float _CloudShadowOpacity; + public float _Pad7; public Vector4 _CookieAtlasSize; public Vector4 _CookieAtlasData; diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl index 176f4b8881b..20230412a75 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesGlobal.cs.hlsl @@ -104,7 +104,7 @@ GLOBAL_CBUFFER_START(ShaderVariablesGlobal, b0) float _MicroShadowOpacity; uint _EnableProbeVolumes; uint _ProbeVolumeCount; - float _CloudShadowOpacity; + float _Pad7; float4 _CookieAtlasSize; float4 _CookieAtlasData; float4 _PlanarAtlasData; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/BakeCloudTexture.compute b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/BakeCloudTexture.compute index 7e131c841bc..67bcd7dab36 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/BakeCloudTexture.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/BakeCloudTexture.compute @@ -25,18 +25,18 @@ SAMPLER(sampler_CloudMapB); RW_TEXTURE2D_ARRAY(float2, _CloudTextureOutput); CBUFFER_START(cb0) -float4 _Params1; +float4 _Params; +float4 _Params1[NUM_LAYERS]; float4 _Params2[NUM_LAYERS]; -float4 _Params3[NUM_LAYERS]; CBUFFER_END -#define _SunDirection _Params1.xyz -#define _CloudUpperHemisphere (_Params1.w > 0) -#define _Resolution abs(_Params1.w) -#define _Opacities _Params2[LAYER] -#define _CloudRotation _Params3[LAYER].x -#define _LightingSteps _Params3[LAYER].y -#define _Thickness _Params3[LAYER].z +#define _SunDirection _Params.xyz +#define _CloudUpperHemisphere (_Params.w > 0) +#define _Resolution abs(_Params.w) +#define _Opacities _Params1[LAYER] +#define _CloudRotation _Params2[LAYER].x +#define _LightingSteps _Params2[LAYER].y +#define _Thickness _Params2[LAYER].z float3 InverseLatLong(float2 uv, bool upperHemisphereOnly) @@ -60,6 +60,14 @@ float SampleCloudMap(TEXTURE2D(_CloudMap), SAMPLER(sampler_CloudMap), float2 uv, return max(max(clouds.r, clouds.g), max(clouds.b, clouds.a)); } +float3 RotationUp(float3 p, float2 cos_sin) +{ + float3 rotDirX = float3(cos_sin.x, 0, -cos_sin.y); + float3 rotDirY = float3(cos_sin.y, 0, cos_sin.x); + + return float3(dot(rotDirX, p), p.y, dot(rotDirY, p)); +} + float2 ComputeCloudLighting(TEXTURE2D(_CloudMap), SAMPLER(sampler_CloudMap), float2 uv, uint3 dispatchThreadId) { float opacity = SampleCloudMap(_CloudMap, sampler_CloudMap, uv, _Opacities); @@ -69,8 +77,10 @@ float2 ComputeCloudLighting(TEXTURE2D(_CloudMap), SAMPLER(sampler_CloudMap), flo if (numSteps != 0 && opacity != 0.0) { float3 sun = -_SunDirection; + sun = RotationUp(sun, float2(cos(_CloudRotation*PI*2.0), sin(_CloudRotation*PI*2.0))); + float3 dir = InverseLatLong(uv, _CloudUpperHemisphere); - float3 marchStep = normalize(sun - dir) * 0.01; + float3 marchStep = normalize(sun - dir) * 0.03 / numSteps; float density = opacity; int i = 0; @@ -84,8 +94,9 @@ float2 ComputeCloudLighting(TEXTURE2D(_CloudMap), SAMPLER(sampler_CloudMap), flo density *= 3.0 / _LightingSteps; float angle = Smoothstep01(max(dot(sun, dir) - 0.7, 0.0)); + float height = max(0.1 - dir.y, 0.0) * abs(sun.y - dir.y); - finalColor.x = exp(-density * _Thickness * (1.0-angle/0.7)); + finalColor.x = exp(-density * _Thickness * (1.0-angle/0.7) * (1.0-height/0.1)); } return finalColor; @@ -95,11 +106,11 @@ float2 ComputeCloudLighting(TEXTURE2D(_CloudMap), SAMPLER(sampler_CloudMap), flo void KERNEL_NAME(uint3 dispatchThreadId : SV_DispatchThreadID) { float2 uv = float2(dispatchThreadId.x * _Resolution, dispatchThreadId.y * _Resolution * 2.0f); - uv.x = frac(uv.x + _CloudRotation); float2 cloudLayerColor = LAYER == 0 ? ComputeCloudLighting(_CloudMapA, sampler_CloudMapA, uv, dispatchThreadId) : ComputeCloudLighting(_CloudMapB, sampler_CloudMapB, uv, dispatchThreadId); + dispatchThreadId.x = frac(uv.x + _CloudRotation) / _Resolution; _CloudTextureOutput[dispatchThreadId] = cloudLayerColor; } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs index bf70ff3008d..da35d4f5e4e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs @@ -55,8 +55,8 @@ public enum CloudLightingMode [VolumeComponentMenu("Sky/Cloud Layer (Preview)")] public class CloudLayer : VolumeComponent { - /// Enable fog. - [Tooltip("Check to have a cloud layer in the sky.")] + /// Controls the global opacity of the cloud layer. + [Tooltip("Controls the global opacity of the cloud layer.")] public ClampedFloatParameter opacity = new ClampedFloatParameter(0.0f, 0.0f, 1.0f); /// Enable to cover only the upper part of the sky. [Tooltip("Check this box if the cloud layer covers only the upper part of the sky.")] @@ -70,10 +70,10 @@ public class CloudLayer : VolumeComponent /// Controls the opacity of the cloud shadows. [Tooltip("Controls the opacity of the cloud shadows.")] - public ClampedFloatParameter shadowsOpacity = new ClampedFloatParameter(0.5f, 0.0f, 4.0f); - /// Controls the scale of the cloud shadows. - [Tooltip("Controls the scale of the cloud shadows.")] - public MinFloatParameter shadowsScale = new MinFloatParameter(500.0f, 0.0f); + public ClampedFloatParameter shadowsOpacity = new ClampedFloatParameter(1.0f, 0.0f, 1.0f); + /// Controls the tiling of the cloud shadows. + [Tooltip("Controls the tiling of the cloud shadows.")] + public MinFloatParameter shadowsTiling = new MinFloatParameter(500.0f, 0.0f); [Serializable] @@ -181,7 +181,7 @@ public class CloudMap internal (Vector4, Vector4) GetBakingParameters() { Vector4 parameters = new Vector4( - settings.rotation.value / 360.0f, + -settings.rotation.value / 360.0f, lighting.NumSteps, lighting.thickness.value, 0 @@ -245,6 +245,11 @@ internal int GetBakingHashCode(ref bool castShadows) hash = hash * 23 + settings.rotation.GetHashCode(); hash = hash * 23 + lighting.GetBakingHashCode(ref castShadows); +#if UNITY_EDITOR + // In the editor, we want to rebake the texture if the texture content is modified + if (cloudMap.value != null) + hash = hash * 23 + cloudMap.value.imageContentsHash.GetHashCode(); +#endif } return hash; @@ -277,8 +282,8 @@ internal int GetBakingHashCode(ref bool castShadows) } } - public CloudMap mapA = new CloudMap(); - public CloudMap mapB = new CloudMap(); + public CloudMap layerA = new CloudMap(); + public CloudMap layerB = new CloudMap(); public CloudCRT crt = new CloudCRT(); private float lastTime = 0.0f; @@ -308,26 +313,26 @@ public static void Apply(BuiltinSkyParameters builtinParams, Material skyMateria if (layer.mode.value == CloudLayerMode.CloudMap) { float dt = (Time.time - layer.lastTime) * 0.01f; - layer.mapA.settings.scrollFactor += layer.mapA.settings.scrollSpeed.value * dt; - layer.mapB.settings.scrollFactor += layer.mapB.settings.scrollSpeed.value * dt; + layer.layerA.settings.scrollFactor += layer.layerA.settings.scrollSpeed.value * dt; + layer.layerB.settings.scrollFactor += layer.layerB.settings.scrollSpeed.value * dt; layer.lastTime = Time.time; - var paramsA = layer.mapA.settings.GetRenderingParameters(); - var paramsB = layer.mapB.settings.GetRenderingParameters(); + var paramsA = layer.layerA.settings.GetRenderingParameters(); + var paramsB = layer.layerB.settings.GetRenderingParameters(); paramsA.Item1.w = layer.opacity.value; paramsB.Item1.w = layer.upperHemisphereOnly.value ? 1 : 0; - skyMaterial.SetTexture("_CloudTexture", builtinParams.cloudTexture); - skyMaterial.SetVectorArray("_CloudParams1", new Vector4[]{ paramsA.Item1, paramsB.Item1 }); - skyMaterial.SetVectorArray("_CloudParams2", new Vector4[]{ paramsA.Item2, paramsB.Item2 }); + skyMaterial.SetTexture(HDShaderIDs._CloudTexture, builtinParams.cloudTexture); + skyMaterial.SetVectorArray(HDShaderIDs._CloudParams1, new Vector4[]{ paramsA.Item1, paramsB.Item1 }); + skyMaterial.SetVectorArray(HDShaderIDs._CloudParams2, new Vector4[]{ paramsA.Item2, paramsB.Item2 }); - if (layer.mapA.Apply(skyMaterial, "USE_CLOUD_MAP", "USE_CLOUD_MOTION")) - skyMaterial.SetTexture("_CloudFlowmap1", layer.mapA.settings.flowmap.value); + if (layer.layerA.Apply(skyMaterial, "USE_CLOUD_MAP", "USE_CLOUD_MOTION")) + skyMaterial.SetTexture(HDShaderIDs._CloudFlowmap1, layer.layerA.settings.flowmap.value); if (layer.layers.value == CloudMapMode.Double) { - if (layer.mapB.Apply(skyMaterial, "USE_SECOND_CLOUD_MAP", "USE_SECOND_CLOUD_MOTION")) - skyMaterial.SetTexture("_CloudFlowmap2", layer.mapB.settings.flowmap.value); + if (layer.layerB.Apply(skyMaterial, "USE_SECOND_CLOUD_MAP", "USE_SECOND_CLOUD_MOTION")) + skyMaterial.SetTexture(HDShaderIDs._CloudFlowmap2, layer.layerB.settings.flowmap.value); } else { @@ -339,20 +344,20 @@ public static void Apply(BuiltinSkyParameters builtinParams, Material skyMateria internal void SetComputeParams(CommandBuffer cmd, ComputeShader cs, int kernel) { - var paramsA = mapA.settings.GetRenderingParameters(); - var paramsB = mapB.settings.GetRenderingParameters(); + var paramsA = layerA.settings.GetRenderingParameters(); + var paramsB = layerB.settings.GetRenderingParameters(); paramsA.Item1.w = opacity.value; paramsB.Item1.w = upperHemisphereOnly.value ? 1 : 0; - cmd.SetComputeVectorArrayParam(cs, "_CloudParams1", new Vector4[]{ paramsA.Item1, paramsB.Item1 }); + cmd.SetComputeVectorArrayParam(cs, HDShaderIDs._CloudParams1, new Vector4[]{ paramsA.Item1, paramsB.Item1 }); - if (mapA.SetComputeParams(cs, "USE_CLOUD_MAP", "USE_CLOUD_MOTION")) - cmd.SetComputeTextureParam(cs, kernel, "_CloudFlowmap1", mapA.settings.flowmap.value); + if (layerA.SetComputeParams(cs, "USE_CLOUD_MAP", "USE_CLOUD_MOTION")) + cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._CloudFlowmap1, layerA.settings.flowmap.value); if (layers.value == CloudMapMode.Double) { - if (mapB.SetComputeParams(cs, "USE_SECOND_CLOUD_MAP", "USE_SECOND_CLOUD_MOTION")) - cmd.SetComputeTextureParam(cs, kernel, "_CloudFlowmap2", mapB.settings.flowmap.value); + if (layerB.SetComputeParams(cs, "USE_SECOND_CLOUD_MAP", "USE_SECOND_CLOUD_MOTION")) + cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._CloudFlowmap2, layerB.settings.flowmap.value); } else { @@ -367,16 +372,17 @@ internal int GetBakingHashCode(out int numLayers, out bool castShadows) castShadows = false; numLayers = 1; + unchecked { hash = hash * 23 + mode.GetHashCode(); if (mode.value == CloudLayerMode.CloudMap) { hash = hash * 23 + layers.GetHashCode(); - hash = hash * 23 + mapA.GetBakingHashCode(ref castShadows); + hash = hash * 23 + layerA.GetBakingHashCode(ref castShadows); if (layers.value == CloudMapMode.Double) { - hash = hash * 23 + mapB.GetBakingHashCode(ref castShadows); + hash = hash * 23 + layerB.GetBakingHashCode(ref castShadows); numLayers = 2; } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/ComputeCloudShadows.compute b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/ComputeCloudShadows.compute index a05678865c1..46e5004b51c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/ComputeCloudShadows.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/ComputeCloudShadows.compute @@ -14,15 +14,18 @@ RW_TEXTURE2D(float, _CloudShadowsOutput); -float3 _SunDirection; -float _Resolution; +float4 _Params; +float _CloudShadowOpacity; + +#define _SunDirection _Params.xyz +#define _Resolution _Params.w static float3 tangent; static float3 bitangent; float ComputeCloudShadow(float2 uv) { - const float width = 0.1; + const float width = 0.15; float3 dir = -_SunDirection + uv.x * width * tangent + uv.y * width * bitangent; return GetCloudOpacity(dir); @@ -34,7 +37,7 @@ void KERNEL_NAME(uint2 dispatchThreadId : SV_DispatchThreadID) tangent = normalize(cross(-_SunDirection, float3(0.0, 1.0, 0.0))); bitangent = cross(tangent, -_SunDirection); - float2 uv = float2(dispatchThreadId.x * _Resolution, dispatchThreadId.y * _Resolution) * 2.0 - 1.0; + float2 uv = float2(dispatchThreadId.x * _Resolution, 1.0 - dispatchThreadId.y * _Resolution) * 2.0 - 1.0; float shadow = ComputeCloudShadow(uv); // Blend with the other borders to make the texture tileable @@ -54,5 +57,5 @@ void KERNEL_NAME(uint2 dispatchThreadId : SV_DispatchThreadID) shadow = lerp(shadow, shadow2, weights.y); } - _CloudShadowsOutput[dispatchThreadId] = shadow; + _CloudShadowsOutput[dispatchThreadId] = exp(-shadow * _CloudShadowOpacity); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs index 62c9fef1856..92fcfcf2346 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudRenderingContext.cs @@ -20,7 +20,7 @@ public CloudRenderingContext(int resolution, int numLayers, bool supportShadows, filterMode: FilterMode.Bilinear, name: "Cloud Texture"); if (supportShadows) - cloudShadowsRT = RTHandles.Alloc(shadowResolution, shadowResolution, colorFormat: GraphicsFormat.R8_SNorm, + cloudShadowsRT = RTHandles.Alloc(shadowResolution, shadowResolution, colorFormat: GraphicsFormat.R16_SNorm, dimension: TextureDimension.Tex2D, enableRandomWrite: true, useMipMap: false, filterMode: FilterMode.Bilinear, name: "Cloud Shadows"); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader index 44c64cc932b..b071f96909f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader @@ -188,7 +188,7 @@ Shader "Hidden/HDRP/Sky/HDRISky" return IsHit(sdf, dir.y); } - float3 GetDistordedSkyColor(float3 dir) + float3 GetSkyColor(float3 dir) { #if SKY_MOTION if (dir.y >= 0 || !_UpperHemisphere) @@ -222,19 +222,12 @@ Shader "Hidden/HDRP/Sky/HDRISky" return SAMPLE_TEXTURECUBE_LOD(_Cubemap, sampler_Cubemap, dir, 0).rgb; } - float3 GetSkyColor(float3 dir) - { - float3 sky = GetDistordedSkyColor(dir); - return ApplyCloudLayer(dir, sky); - } - float4 GetColorWithRotation(float3 dir, float exposure, float2 cos_sin) { - dir = RotationUp(dir, cos_sin); + float3 skyColor = GetSkyColor(RotationUp(dir, cos_sin)); + skyColor = ApplyCloudLayer(dir, skyColor)*_Intensity*exposure; - float3 skyColor = GetSkyColor(dir)*_Intensity*exposure; skyColor = ClampToFloat16Max(skyColor); - return float4(skyColor, 1.0); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader b/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader index 36085be1a81..ddc2440d572 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader @@ -228,8 +228,8 @@ Shader "Hidden/HDRP/Sky/PbrSky" skyColor += radiance * (1 - skyOpacity); // Hacky way to boost the clouds to match other sky types - float cloudIntensity = 200.0; - skyColor = ApplyCloudLayer(-V, skyColor / cloudIntensity) * cloudIntensity; + float maxLuminance = (78.0f / (100.0f * 0.65)) * pow(2.0f, -13.5); + skyColor = ApplyCloudLayer(-V, skyColor * maxLuminance) / maxLuminance; skyColor *= _IntensityMultiplier; return float4(skyColor, 1.0); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs index 865da7f4de8..2eb43f50bda 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs @@ -39,6 +39,10 @@ public enum CloudResolution CloudResolution1024x512 = 1024, /// Size 2048x1024 CloudResolution2048x1024 = 2048, + /// Size 4096x2048 + CloudResolution4096x2048 = 4096, + /// Size 8192x4096 + CloudResolution8192x4096 = 8192, } /// @@ -55,6 +59,10 @@ public enum CloudShadowsResolution CloudShadowsResolution256 = 256, /// Size 512 CloudShadowsResolution512 = 512, + /// Size 1024 + CloudShadowsResolution1024 = 1024, + /// Size 2048 + CloudShadowsResolution2048 = 2048, } /// @@ -115,7 +123,6 @@ struct CachedCloudContext public void Reset() { - // We keep around the rendering context to avoid useless allocation if they get reused. hash = 0; refCount = 0; } @@ -621,26 +628,26 @@ void BakeCloudTexture(SkyUpdateContext skyContext, Light sunLight) Vector4 params1 = sunLight == null ? Vector3.zero : sunLight.transform.forward; params1.w = (layer.upperHemisphereOnly.value ? 1.0f : -1.0f) / (float)m_CloudResolution; - cmd.SetComputeVectorParam(m_BakeCloudTextureCS, "_Params1", params1); + cmd.SetComputeVectorParam(m_BakeCloudTextureCS, HDShaderIDs._Params, params1); cmd.SetComputeTextureParam(m_BakeCloudTextureCS, m_BakeCloudTextureKernel, m_CloudTextureOutputParam, renderingContext.cloudTextureRT); - cmd.SetComputeTextureParam(m_BakeCloudTextureCS, m_BakeCloudTextureKernel, "_CloudMapA", layer.mapA.cloudMap.value); - var paramsA = layer.mapA.GetBakingParameters(); + cmd.SetComputeTextureParam(m_BakeCloudTextureCS, m_BakeCloudTextureKernel, HDShaderIDs._CloudMapA, layer.layerA.cloudMap.value); + var paramsA = layer.layerA.GetBakingParameters(); if (renderingContext.numLayers == 1) { m_BakeCloudTextureCS.DisableKeyword("CLOUD_LAYER_DOUBLE_MODE"); - cmd.SetComputeVectorParam(m_BakeCloudTextureCS, "_Params2", paramsA.Item1); - cmd.SetComputeVectorParam(m_BakeCloudTextureCS, "_Params3", paramsA.Item2); + cmd.SetComputeVectorParam(m_BakeCloudTextureCS, HDShaderIDs._Params1, paramsA.Item1); + cmd.SetComputeVectorParam(m_BakeCloudTextureCS, HDShaderIDs._Params2, paramsA.Item2); } else { - cmd.SetComputeTextureParam(m_BakeCloudTextureCS, m_BakeCloudTextureKernel, "_CloudMapB", layer.mapB.cloudMap.value); - var paramsB = layer.mapB.GetBakingParameters(); + cmd.SetComputeTextureParam(m_BakeCloudTextureCS, m_BakeCloudTextureKernel, HDShaderIDs._CloudMapB, layer.layerB.cloudMap.value); + var paramsB = layer.layerB.GetBakingParameters(); m_BakeCloudTextureCS.EnableKeyword("CLOUD_LAYER_DOUBLE_MODE"); - cmd.SetComputeVectorArrayParam(m_BakeCloudTextureCS, "_Params2", new Vector4[] { paramsA.Item1, paramsB.Item1 }); - cmd.SetComputeVectorArrayParam(m_BakeCloudTextureCS, "_Params3", new Vector4[] { paramsA.Item2, paramsB.Item2 }); + cmd.SetComputeVectorArrayParam(m_BakeCloudTextureCS, HDShaderIDs._Params1, new Vector4[] { paramsA.Item1, paramsB.Item1 }); + cmd.SetComputeVectorArrayParam(m_BakeCloudTextureCS, HDShaderIDs._Params2, new Vector4[] { paramsA.Item2, paramsB.Item2 }); } const int groupSizeX = 8; @@ -660,9 +667,12 @@ void ComputeCloudShadows(SkyUpdateContext skyContext, Light sunLight) var renderingContext = m_CachedCloudContexts[skyContext.cachedCloudRenderingContextId].renderingContext; var layer = skyContext.cloudLayer; - cmd.SetComputeVectorParam(m_ComputeCloudShadowsCS, "_SunDirection", sunLight.transform.forward); - cmd.SetComputeFloatParam(m_ComputeCloudShadowsCS, "_Resolution", 1.0f / (float)m_CloudShadowsResolution); - cmd.SetComputeTextureParam(m_ComputeCloudShadowsCS, m_ComputeCloudShadowsKernel, "_CloudTexture", renderingContext.cloudTextureRT); + Vector4 _Params = sunLight.transform.forward; + _Params.w = 1.0f / (float)m_CloudShadowsResolution; + + cmd.SetComputeVectorParam(m_ComputeCloudShadowsCS, HDShaderIDs._Params, _Params); + cmd.SetComputeFloatParam(m_ComputeCloudShadowsCS, HDShaderIDs._CloudShadowOpacity, 10.0f*layer.shadowsOpacity.value); + cmd.SetComputeTextureParam(m_ComputeCloudShadowsCS, m_ComputeCloudShadowsKernel, HDShaderIDs._CloudTexture, renderingContext.cloudTextureRT); cmd.SetComputeTextureParam(m_ComputeCloudShadowsCS, m_ComputeCloudShadowsKernel, m_CloudShadowsOutputParam, renderingContext.cloudShadowsRT); skyContext.cloudLayer.SetComputeParams(cmd, m_ComputeCloudShadowsCS, m_ComputeCloudShadowsKernel); @@ -962,8 +972,6 @@ public void UpdateEnvironment( HDCamera hdCamera, m_BuiltinParameters.debugSettings = null; // We don't want any debug when updating the environment. m_BuiltinParameters.frameIndex = frameIndex; m_BuiltinParameters.skySettings = skyContext.skySettings; - m_BuiltinParameters.cloudLayer = skyContext.cloudLayer; - m_BuiltinParameters.cloudTexture = null; bool cloudShadows = false; if (skyContext.cloudLayer != null && skyContext.cloudLayer.opacity.value != 0.0f) @@ -975,23 +983,29 @@ public void UpdateEnvironment( HDCamera hdCamera, BakeCloudTexture(skyContext, sunLight); var cloudContext = m_CachedCloudContexts[skyContext.cachedCloudRenderingContextId].renderingContext; + m_BuiltinParameters.cloudLayer = skyContext.cloudLayer; m_BuiltinParameters.cloudTexture = cloudContext.cloudTextureRT; if (castShadows && sunLight != null) { cloudShadows = true; ComputeCloudShadows(skyContext, sunLight); - cmd.SetGlobalTexture("_CloudShadows", cloudContext.cloudShadowsRT); + cmd.SetGlobalTexture(HDShaderIDs._CloudShadows, cloudContext.cloudShadowsRT); } } - else if (skyContext.cachedCloudRenderingContextId != -1) + else { - ReleaseCachedCloudContext(skyContext.cachedCloudRenderingContextId); - skyContext.cachedCloudRenderingContextId = -1; + if (skyContext.cachedCloudRenderingContextId != -1) + { + ReleaseCachedCloudContext(skyContext.cachedCloudRenderingContextId); + skyContext.cachedCloudRenderingContextId = -1; + } + m_BuiltinParameters.cloudLayer = null; + m_BuiltinParameters.cloudTexture = null; } if (!cloudShadows) - cmd.SetGlobalTexture("_CloudShadows", Texture2D.blackTexture); + cmd.SetGlobalTexture(HDShaderIDs._CloudShadows, Texture2D.whiteTexture); int skyHash = ComputeSkyHash(hdCamera, skyContext, sunLight, ambientMode, staticSky); bool forceUpdate = updateRequired; @@ -1115,7 +1129,7 @@ internal void UpdateBuiltinParameters(SkyUpdateContext skyContext, HDCamera hdCa m_BuiltinParameters.frameIndex = frameIndex; m_BuiltinParameters.skySettings = skyContext.skySettings; - if (skyContext.cloudLayer != null) + if (skyContext.cloudLayer != null && skyContext.cloudLayer.opacity.value != 0.0f) { int cloudHash = ComputeCloudHash(skyContext.cloudLayer, sunLight, out int numLayers, out bool castShadows); AcquireCloudRenderingContext(skyContext, cloudHash, numLayers, castShadows); From c3c33052f6871a7e2fcd12130259a866d2c390c4 Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Wed, 5 Aug 2020 12:58:32 +0200 Subject: [PATCH 09/10] Change exposure mode. Update test scene --- .../Scenes/5x_SkyAndFog/5010_CloudLayer.unity | 374 +++++++++++++++++- .../Scene Settings Profile.asset | 339 ++++++++++++++-- .../5x_SkyAndFog/5010_CloudLayer/clouds.png | 3 - .../5010_CloudLayer/clouds.png.meta | 108 ----- .../Vulkan/None/5010_CloudLayer.png | 4 +- .../OSXEditor/Metal/None/5010_CloudLayer.png | 4 +- .../Direct3D11/None/5010_CloudLayer.png | 4 +- .../Direct3D12/None/5010_CloudLayer.png | 4 +- .../Vulkan/None/5010_CloudLayer.png | 4 +- .../Direct3D11/None/5010_CloudLayer.png | 4 +- .../Documentation~/Override-Cloud-Layer.md | 6 +- .../Editor/Sky/CloudLayer/CloudLayerEditor.cs | 187 +++------ .../Runtime/Debug/DebugDisplay.cs | 6 +- .../Runtime/Lighting/LightEvaluation.hlsl | 12 +- .../LightLoop/ShaderVariablesLightLoop.hlsl | 1 - .../Runtime/Sky/CloudLayer/CloudLayer.cs | 246 ++++-------- .../Runtime/Sky/CloudLayer/CloudLayer.hlsl | 3 +- .../CloudLayer/ComputeCloudShadows.compute | 20 +- .../Sky/GradientSky/GradientSky.shader | 4 +- .../Runtime/Sky/HDRISky/HDRISky.shader | 4 +- .../PhysicallyBasedSky.shader | 6 +- .../Runtime/Sky/SkyManager.cs | 34 +- 22 files changed, 875 insertions(+), 502 deletions(-) delete mode 100644 TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/5x_SkyAndFog/5010_CloudLayer/clouds.png delete mode 100644 TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/5x_SkyAndFog/5010_CloudLayer/clouds.png.meta diff --git a/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/5x_SkyAndFog/5010_CloudLayer.unity b/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/5x_SkyAndFog/5010_CloudLayer.unity index 4f4276a9bae..0fa493100cf 100644 --- a/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/5x_SkyAndFog/5010_CloudLayer.unity +++ b/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/5x_SkyAndFog/5010_CloudLayer.unity @@ -123,6 +123,51 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +--- !u!1 &440300291 +GameObject: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 440300293} + - component: {fileID: 440300292} + m_Layer: 0 + m_Name: StaticLightingSky + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &440300292 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 440300291} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 441482e8936e35048a1dffac814e3ef8, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Profile: {fileID: 0} + m_StaticLightingSkyUniqueID: 0 +--- !u!4 &440300293 +Transform: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 440300291} + 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!1001 &452585676 PrefabInstance: m_ObjectHideFlags: 0 @@ -132,31 +177,31 @@ PrefabInstance: m_Modifications: - target: {fileID: 4209882255362944, guid: c07ace9ab142ca9469fa377877c2f1e7, type: 3} propertyPath: m_LocalPosition.x - value: -0.44 + value: 0.38555184 objectReference: {fileID: 0} - target: {fileID: 4209882255362944, guid: c07ace9ab142ca9469fa377877c2f1e7, type: 3} propertyPath: m_LocalPosition.y - value: 0.28999972 + value: 0.7531727 objectReference: {fileID: 0} - target: {fileID: 4209882255362944, guid: c07ace9ab142ca9469fa377877c2f1e7, type: 3} propertyPath: m_LocalPosition.z - value: -13.38 + value: -4.727645 objectReference: {fileID: 0} - target: {fileID: 4209882255362944, guid: c07ace9ab142ca9469fa377877c2f1e7, type: 3} propertyPath: m_LocalRotation.x - value: -0.15503997 + value: -0.081274085 objectReference: {fileID: 0} - target: {fileID: 4209882255362944, guid: c07ace9ab142ca9469fa377877c2f1e7, type: 3} propertyPath: m_LocalRotation.y - value: -0 + value: 0.02695976 objectReference: {fileID: 0} - target: {fileID: 4209882255362944, guid: c07ace9ab142ca9469fa377877c2f1e7, type: 3} propertyPath: m_LocalRotation.z - value: -0 + value: 0.0021992126 objectReference: {fileID: 0} - target: {fileID: 4209882255362944, guid: c07ace9ab142ca9469fa377877c2f1e7, type: 3} propertyPath: m_LocalRotation.w - value: 0.98790824 + value: 0.99632466 objectReference: {fileID: 0} - target: {fileID: 4209882255362944, guid: c07ace9ab142ca9469fa377877c2f1e7, type: 3} propertyPath: m_RootOrder @@ -164,7 +209,11 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 4209882255362944, guid: c07ace9ab142ca9469fa377877c2f1e7, type: 3} propertyPath: m_LocalEulerAnglesHint.x - value: -17.838 + value: -9.327 + objectReference: {fileID: 0} + - target: {fileID: 4209882255362944, guid: c07ace9ab142ca9469fa377877c2f1e7, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 3.1 objectReference: {fileID: 0} - target: {fileID: 20109210616973140, guid: c07ace9ab142ca9469fa377877c2f1e7, type: 3} @@ -273,7 +322,7 @@ LightingSettings: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_Name: Settings.lighting - serializedVersion: 2 + serializedVersion: 3 m_GIWorkflowMode: 1 m_EnableBakedLightmaps: 1 m_EnableRealtimeLightmaps: 1 @@ -312,7 +361,7 @@ LightingSettings: m_PVREnvironmentReferencePointCount: 2048 m_LightProbeSampleCountMultiplier: 4 m_PVRBounces: 2 - m_PVRRussianRouletteStartBounce: 2 + m_PVRMinBounces: 1 m_PVREnvironmentMIS: 1 m_PVRFilteringMode: 1 m_PVRDenoiserTypeDirect: 1 @@ -327,3 +376,308 @@ LightingSettings: m_PVRFilteringAtrousPositionSigmaDirect: 0.5 m_PVRFilteringAtrousPositionSigmaIndirect: 2 m_PVRFilteringAtrousPositionSigmaAO: 1 +--- !u!1 &1211733623 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1211733626} + - component: {fileID: 1211733625} + - component: {fileID: 1211733624} + m_Layer: 0 + m_Name: Directional Light + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1211733624 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1211733623} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7a68c43fe1f2a47cfa234b5eeaa98012, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Version: 11 + m_ObsoleteShadowResolutionTier: 1 + m_ObsoleteUseShadowQualitySettings: 0 + m_ObsoleteCustomShadowResolution: 512 + m_ObsoleteContactShadows: 0 + m_PointlightHDType: 0 + m_SpotLightShape: 0 + m_AreaLightShape: 0 + m_Intensity: 100000 + m_EnableSpotReflector: 0 + m_LuxAtDistance: 1 + m_InnerSpotPercent: 0 + m_SpotIESCutoffPercent: 100 + m_LightDimmer: 1 + m_VolumetricDimmer: 1 + m_LightUnit: 2 + m_FadeDistance: 10000 + m_AffectDiffuse: 1 + m_AffectSpecular: 1 + m_NonLightmappedOnly: 0 + m_ShapeWidth: 0.5 + m_ShapeHeight: 0.5 + m_AspectRatio: 1 + m_ShapeRadius: 0.025 + m_SoftnessScale: 1 + m_UseCustomSpotLightShadowCone: 0 + m_CustomSpotLightShadowCone: 30 + m_MaxSmoothness: 0.99 + m_ApplyRangeAttenuation: 1 + m_DisplayAreaLightEmissiveMesh: 0 + m_AreaLightCookie: {fileID: 0} + m_IESPoint: {fileID: 0} + m_IESSpot: {fileID: 0} + m_AreaLightShadowCone: 120 + m_UseScreenSpaceShadows: 0 + m_InteractsWithSky: 1 + m_AngularDiameter: 0.5 + m_FlareSize: 2 + m_FlareTint: {r: 1, g: 1, b: 1, a: 1} + m_FlareFalloff: 4 + m_SurfaceTexture: {fileID: 0} + m_SurfaceTint: {r: 1, g: 1, b: 1, a: 1} + m_Distance: 1.5e+11 + m_UseRayTracedShadows: 0 + m_NumRayTracingSamples: 4 + m_FilterTracedShadow: 1 + m_FilterSizeTraced: 16 + m_SunLightConeAngle: 0.5 + m_LightShadowRadius: 0.5 + m_SemiTransparentShadow: 0 + m_ColorShadow: 1 + m_DistanceBasedFiltering: 0 + m_EvsmExponent: 15 + m_EvsmLightLeakBias: 0 + m_EvsmVarianceBias: 0.00001 + m_EvsmBlurPasses: 0 + m_LightlayersMask: 1 + m_LinkShadowLayers: 1 + m_ShadowNearPlane: 0.1 + m_BlockerSampleCount: 24 + m_FilterSampleCount: 16 + m_MinFilterSize: 0.1 + m_KernelSize: 5 + m_LightAngle: 1 + m_MaxDepthBias: 0.001 + m_ShadowResolution: + m_Override: 512 + m_UseOverride: 1 + m_Level: 0 + m_ShadowDimmer: 1 + m_VolumetricShadowDimmer: 1 + m_ShadowFadeDistance: 10000 + m_UseContactShadow: + m_Override: 0 + m_UseOverride: 1 + m_Level: 0 + m_RayTracedContactShadow: 0 + m_ShadowTint: {r: 0, g: 0, b: 0, a: 1} + m_PenumbraTint: 0 + m_NormalBias: 0.75 + m_SlopeBias: 0.5 + m_ShadowUpdateMode: 0 + m_BarnDoorAngle: 90 + m_BarnDoorLength: 0.05 + m_preserveCachedShadow: 0 + m_ShadowCascadeRatios: + - 0.05 + - 0.2 + - 0.3 + m_ShadowCascadeBorders: + - 0.2 + - 0.2 + - 0.2 + - 0.2 + m_ShadowAlgorithm: 0 + m_ShadowVariant: 0 + m_ShadowPrecision: 0 + useOldInspector: 0 + useVolumetric: 1 + featuresFoldout: 1 + showAdditionalSettings: 0 + m_AreaLightEmissiveMeshShadowCastingMode: 0 + m_AreaLightEmissiveMeshMotionVectorGenerationMode: 0 + m_AreaLightEmissiveMeshLayer: -1 +--- !u!108 &1211733625 +Light: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1211733623} + m_Enabled: 1 + serializedVersion: 10 + m_Type: 1 + m_Shape: 0 + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_Intensity: 100000 + m_Range: 10 + m_SpotAngle: 30 + m_InnerSpotAngle: 21.80208 + m_CookieSize: 10 + m_Shadows: + m_Type: 0 + m_Resolution: -1 + m_CustomResolution: -1 + m_Strength: 1 + m_Bias: 0.05 + m_NormalBias: 0.4 + m_NearPlane: 0.2 + m_CullingMatrixOverride: + e00: 1 + e01: 0 + e02: 0 + e03: 0 + e10: 0 + e11: 1 + e12: 0 + e13: 0 + e20: 0 + e21: 0 + e22: 1 + e23: 0 + e30: 0 + e31: 0 + e32: 0 + e33: 1 + m_UseCullingMatrixOverride: 0 + m_Cookie: {fileID: 0} + m_DrawHalo: 0 + m_Flare: {fileID: 0} + m_RenderMode: 0 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingLayerMask: 1 + m_Lightmapping: 4 + m_LightShadowCasterMode: 2 + m_AreaSize: {x: 0.5, y: 0.5} + m_BounceIntensity: 1 + m_ColorTemperature: 6570 + m_UseColorTemperature: 0 + m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} + m_UseBoundingSphereOverride: 0 + m_UseViewFrustumForShadowCasterCull: 1 + m_ShadowRadius: 0 + m_ShadowAngle: 0 +--- !u!4 &1211733626 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1211733623} + m_LocalRotation: {x: 0.06376937, y: -0.9690352, z: 0.11848511, w: 0.20704007} + m_LocalPosition: {x: 0, y: 2, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 4 + m_LocalEulerAnglesHint: {x: 14.835, y: -156.455, z: -4.422} +--- !u!1 &1996547904 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1996547908} + - component: {fileID: 1996547907} + - component: {fileID: 1996547906} + - component: {fileID: 1996547905} + m_Layer: 0 + m_Name: Cube + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!65 &1996547905 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1996547904} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 1, y: 1, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!23 &1996547906 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1996547904} + m_Enabled: 1 + m_CastShadows: 1 + m_ReceiveShadows: 1 + m_DynamicOccludee: 1 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 257 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 73c176f402d2c2f4d929aa5da7585d17, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + 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 + m_AdditionalVertexStreams: {fileID: 0} +--- !u!33 &1996547907 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1996547904} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!4 &1996547908 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1996547904} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 100, y: 0.5, z: 100} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/5x_SkyAndFog/5010_CloudLayer/Scene Settings Profile.asset b/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/5x_SkyAndFog/5010_CloudLayer/Scene Settings Profile.asset index 583f7bba85c..b50efad1d7b 100644 --- a/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/5x_SkyAndFog/5010_CloudLayer/Scene Settings Profile.asset +++ b/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/5x_SkyAndFog/5010_CloudLayer/Scene Settings Profile.asset @@ -1,5 +1,162 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: +--- !u!114 &-8349613636572047543 +MonoBehaviour: + m_ObjectHideFlags: 3 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2d08ce26990eb1a4a9177b860541e702, type: 3} + m_Name: Exposure + m_EditorClassIdentifier: + active: 1 + m_AdvancedMode: 0 + mode: + m_OverrideState: 0 + m_Value: 0 + meteringMode: + m_OverrideState: 0 + m_Value: 2 + luminanceSource: + m_OverrideState: 0 + m_Value: 1 + fixedExposure: + m_OverrideState: 1 + m_Value: 13.5 + compensation: + m_OverrideState: 0 + m_Value: 0 + limitMin: + m_OverrideState: 0 + m_Value: -10 + limitMax: + m_OverrideState: 0 + m_Value: 20 + curveMap: + m_OverrideState: 0 + m_Value: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: -10 + value: -10 + inSlope: 0 + outSlope: 1 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 20 + value: 20 + inSlope: 1 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + limitMinCurveMap: + m_OverrideState: 0 + m_Value: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: -10 + value: -12 + inSlope: 0 + outSlope: 1 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 20 + value: 18 + inSlope: 1 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + limitMaxCurveMap: + m_OverrideState: 0 + m_Value: + serializedVersion: 2 + m_Curve: + - serializedVersion: 3 + time: -10 + value: -8 + inSlope: 0 + outSlope: 1 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + - serializedVersion: 3 + time: 20 + value: 22 + inSlope: 1 + outSlope: 0 + tangentMode: 0 + weightedMode: 0 + inWeight: 0 + outWeight: 0 + m_PreInfinity: 2 + m_PostInfinity: 2 + m_RotationOrder: 4 + adaptationMode: + m_OverrideState: 0 + m_Value: 1 + adaptationSpeedDarkToLight: + m_OverrideState: 0 + m_Value: 3 + min: 0.001 + adaptationSpeedLightToDark: + m_OverrideState: 0 + m_Value: 1 + min: 0.001 + weightTextureMask: + m_OverrideState: 0 + m_Value: {fileID: 0} + histogramPercentages: + m_OverrideState: 0 + m_Value: {x: 40, y: 90} + min: 0 + max: 100 + histogramUseCurveRemapping: + m_OverrideState: 0 + m_Value: 0 + targetMidGray: + m_OverrideState: 0 + m_Value: 0 + centerAroundExposureTarget: + m_OverrideState: 0 + m_Value: 0 + proceduralCenter: + m_OverrideState: 0 + m_Value: {x: 0.5, y: 0.5} + proceduralRadii: + m_OverrideState: 0 + m_Value: {x: 0.3, y: 0.3} + maskMinIntensity: + m_OverrideState: 0 + m_Value: -30 + maskMaxIntensity: + m_OverrideState: 0 + m_Value: 30 + proceduralSoftness: + m_OverrideState: 0 + m_Value: 0.5 + min: 0 --- !u!114 &-3155368813038754222 MonoBehaviour: m_ObjectHideFlags: 3 @@ -15,16 +172,16 @@ MonoBehaviour: active: 1 m_AdvancedMode: 0 rotation: - m_OverrideState: 0 - m_Value: 0 + m_OverrideState: 1 + m_Value: 178 min: 0 max: 360 skyIntensityMode: m_OverrideState: 0 m_Value: 0 exposure: - m_OverrideState: 0 - m_Value: 0 + m_OverrideState: 1 + m_Value: 13.5 multiplier: m_OverrideState: 0 m_Value: 1 @@ -136,43 +293,164 @@ MonoBehaviour: m_EditorClassIdentifier: active: 1 m_AdvancedMode: 0 - enabled: + opacity: m_OverrideState: 1 m_Value: 1 - cloudMap: - m_OverrideState: 1 - m_Value: {fileID: 2800000, guid: 556e9bc309995094c87d3c02677f230d, type: 3} + min: 0 + max: 1 upperHemisphereOnly: m_OverrideState: 0 m_Value: 1 - tint: - m_OverrideState: 1 - m_Value: {r: 0.5647059, g: 0.5764706, b: 0.5568628, a: 1} - hdr: 0 - showAlpha: 1 - showEyeDropper: 1 - intensityMultiplier: - m_OverrideState: 1 - m_Value: 1.02 - min: 0 - enableDistortion: + layers: m_OverrideState: 0 m_Value: 0 - procedural: + shadowsOpacity: m_OverrideState: 0 m_Value: 1 - flowmap: - m_OverrideState: 0 - m_Value: {fileID: 0} - scrollDirection: - m_OverrideState: 0 - m_Value: 0 min: 0 - max: 360 - scrollSpeed: - m_OverrideState: 0 - m_Value: 2 + max: 1 + shadowsTiling: + m_OverrideState: 1 + m_Value: 50 min: 0 + layerA: + cloudMap: + m_OverrideState: 1 + m_Value: {fileID: 2800000, guid: d5c1d2ec831566f4eb10f092da21fba1, type: 3} + opacityR: + m_OverrideState: 1 + m_Value: 1 + min: 0 + max: 1 + opacityG: + m_OverrideState: 0 + m_Value: 0 + min: 0 + max: 1 + opacityB: + m_OverrideState: 1 + m_Value: 1 + min: 0 + max: 1 + opacityA: + m_OverrideState: 0 + m_Value: 0 + min: 0 + max: 1 + rotation: + m_OverrideState: 1 + m_Value: 136 + min: 0 + max: 360 + tint: + m_OverrideState: 1 + m_Value: {r: 0.43529412, g: 0.31764707, b: 0.13725491, a: 1} + hdr: 0 + showAlpha: 1 + showEyeDropper: 1 + exposure: + m_OverrideState: 1 + m_Value: 16 + distortionMode: + m_OverrideState: 0 + m_Value: 0 + scrollDirection: + m_OverrideState: 0 + m_Value: 0 + min: 0 + max: 360 + scrollSpeed: + m_OverrideState: 0 + m_Value: 1 + min: 0 + flowmap: + m_OverrideState: 0 + m_Value: {fileID: 0} + lightingMode: + m_OverrideState: 1 + m_Value: 1 + steps: + m_OverrideState: 1 + m_Value: 10 + min: 1 + max: 10 + thickness: + m_OverrideState: 1 + m_Value: 1.3 + min: 0 + max: 2 + castShadows: + m_OverrideState: 1 + m_Value: 1 + layerB: + cloudMap: + m_OverrideState: 0 + m_Value: {fileID: 0} + opacityR: + m_OverrideState: 0 + m_Value: 1 + min: 0 + max: 1 + opacityG: + m_OverrideState: 0 + m_Value: 0 + min: 0 + max: 1 + opacityB: + m_OverrideState: 0 + m_Value: 0 + min: 0 + max: 1 + opacityA: + m_OverrideState: 0 + m_Value: 0 + min: 0 + max: 1 + rotation: + m_OverrideState: 0 + m_Value: 0 + min: 0 + max: 360 + tint: + m_OverrideState: 0 + m_Value: {r: 1, g: 1, b: 1, a: 1} + hdr: 0 + showAlpha: 1 + showEyeDropper: 1 + exposure: + m_OverrideState: 0 + m_Value: 0 + distortionMode: + m_OverrideState: 0 + m_Value: 0 + scrollDirection: + m_OverrideState: 0 + m_Value: 0 + min: 0 + max: 360 + scrollSpeed: + m_OverrideState: 0 + m_Value: 1 + min: 0 + flowmap: + m_OverrideState: 0 + m_Value: {fileID: 0} + lightingMode: + m_OverrideState: 0 + m_Value: 0 + steps: + m_OverrideState: 0 + m_Value: 4 + min: 1 + max: 10 + thickness: + m_OverrideState: 0 + m_Value: 0.5 + min: 0 + max: 2 + castShadows: + m_OverrideState: 0 + m_Value: 0 --- !u!114 &11400000 MonoBehaviour: m_ObjectHideFlags: 0 @@ -186,6 +464,7 @@ MonoBehaviour: m_Name: Scene Settings Profile m_EditorClassIdentifier: components: + - {fileID: -8349613636572047543} - {fileID: 3479482973930658046} - {fileID: -3155368813038754222} - {fileID: -1065974624950405951} diff --git a/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/5x_SkyAndFog/5010_CloudLayer/clouds.png b/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/5x_SkyAndFog/5010_CloudLayer/clouds.png deleted file mode 100644 index d0b9985b2c1..00000000000 --- a/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/5x_SkyAndFog/5010_CloudLayer/clouds.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:b5f4f77e643c755598e9c59f45839fe3818aead9859d098461708d10dcc5cf74 -size 744889 diff --git a/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/5x_SkyAndFog/5010_CloudLayer/clouds.png.meta b/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/5x_SkyAndFog/5010_CloudLayer/clouds.png.meta deleted file mode 100644 index 5983659864a..00000000000 --- a/TestProjects/HDRP_Tests/Assets/GraphicTests/Scenes/5x_SkyAndFog/5010_CloudLayer/clouds.png.meta +++ /dev/null @@ -1,108 +0,0 @@ -fileFormatVersion: 2 -guid: 556e9bc309995094c87d3c02677f230d -TextureImporter: - internalIDToNameTable: [] - externalObjects: {} - serializedVersion: 11 - mipmaps: - mipMapMode: 0 - enableMipMap: 0 - sRGBTexture: 0 - linearTexture: 0 - fadeOut: 0 - borderMipMap: 0 - mipMapsPreserveCoverage: 0 - alphaTestReferenceValue: 0.5 - mipMapFadeDistanceStart: 1 - mipMapFadeDistanceEnd: 3 - bumpmap: - convertToNormalMap: 0 - externalNormalMap: 0 - heightScale: 0.25 - normalMapFilter: 0 - isReadable: 0 - streamingMipmaps: 0 - streamingMipmapsPriority: 0 - vTOnly: 0 - grayScaleToAlpha: 0 - generateCubemap: 6 - cubemapConvolution: 0 - seamlessCubemap: 0 - textureFormat: 1 - maxTextureSize: 2048 - textureSettings: - serializedVersion: 2 - filterMode: -1 - aniso: -1 - mipBias: -100 - wrapU: -1 - wrapV: -1 - wrapW: -1 - nPOTScale: 1 - lightmap: 0 - compressionQuality: 50 - spriteMode: 0 - spriteExtrude: 1 - spriteMeshType: 1 - alignment: 0 - spritePivot: {x: 0.5, y: 0.5} - spritePixelsToUnits: 100 - spriteBorder: {x: 0, y: 0, z: 0, w: 0} - spriteGenerateFallbackPhysicsShape: 1 - alphaUsage: 2 - alphaIsTransparency: 1 - spriteTessellationDetail: -1 - textureType: 0 - textureShape: 1 - singleChannelComponent: 0 - flipbookRows: 1 - flipbookColumns: 1 - maxTextureSizeSet: 0 - compressionQualitySet: 0 - textureFormatSet: 0 - ignorePngGamma: 0 - applyGammaDecoding: 0 - platformSettings: - - serializedVersion: 3 - buildTarget: DefaultTexturePlatform - maxTextureSize: 2048 - resizeAlgorithm: 0 - textureFormat: -1 - textureCompression: 1 - compressionQuality: 50 - crunchedCompression: 0 - allowsAlphaSplitting: 0 - overridden: 0 - androidETC2FallbackOverride: 0 - forceMaximumCompressionQuality_BC6H_BC7: 0 - - serializedVersion: 3 - buildTarget: Standalone - maxTextureSize: 2048 - resizeAlgorithm: 0 - textureFormat: -1 - textureCompression: 1 - compressionQuality: 50 - crunchedCompression: 0 - allowsAlphaSplitting: 0 - overridden: 0 - androidETC2FallbackOverride: 0 - forceMaximumCompressionQuality_BC6H_BC7: 0 - spriteSheet: - serializedVersion: 2 - sprites: [] - outline: [] - physicsShape: [] - bones: [] - spriteID: - internalID: 0 - vertices: [] - indices: - edges: [] - weights: [] - secondaryTextures: [] - spritePackingTag: - pSDRemoveMatte: 0 - pSDShowRemoveMatteOption: 0 - userData: - assetBundleName: - assetBundleVariant: diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/LinuxEditor/Vulkan/None/5010_CloudLayer.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/LinuxEditor/Vulkan/None/5010_CloudLayer.png index 524f5b419d8..69ff7bc20dc 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/LinuxEditor/Vulkan/None/5010_CloudLayer.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/LinuxEditor/Vulkan/None/5010_CloudLayer.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:727618937f30f812f35c3a26ec7b4935d78788a1e46d952a4b86e1bccefcdda9 -size 194309 +oid sha256:302824154ca54cc13c47db63fde1017fa26bdd539faf99aa1aa17131cdd9803b +size 207902 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/5010_CloudLayer.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/5010_CloudLayer.png index b6905fbd255..69ff7bc20dc 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/5010_CloudLayer.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/5010_CloudLayer.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8c141c8eaec873e0ce1f0289dd16035d05f5e43c0127256e26465944ea36995e -size 166413 +oid sha256:302824154ca54cc13c47db63fde1017fa26bdd539faf99aa1aa17131cdd9803b +size 207902 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/5010_CloudLayer.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/5010_CloudLayer.png index b6905fbd255..69ff7bc20dc 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/5010_CloudLayer.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D11/None/5010_CloudLayer.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8c141c8eaec873e0ce1f0289dd16035d05f5e43c0127256e26465944ea36995e -size 166413 +oid sha256:302824154ca54cc13c47db63fde1017fa26bdd539faf99aa1aa17131cdd9803b +size 207902 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5010_CloudLayer.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5010_CloudLayer.png index b6905fbd255..69ff7bc20dc 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5010_CloudLayer.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Direct3D12/None/5010_CloudLayer.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8c141c8eaec873e0ce1f0289dd16035d05f5e43c0127256e26465944ea36995e -size 166413 +oid sha256:302824154ca54cc13c47db63fde1017fa26bdd539faf99aa1aa17131cdd9803b +size 207902 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/5010_CloudLayer.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/5010_CloudLayer.png index b6905fbd255..69ff7bc20dc 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/5010_CloudLayer.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsEditor/Vulkan/None/5010_CloudLayer.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8c141c8eaec873e0ce1f0289dd16035d05f5e43c0127256e26465944ea36995e -size 166413 +oid sha256:302824154ca54cc13c47db63fde1017fa26bdd539faf99aa1aa17131cdd9803b +size 207902 diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsPlayer/Direct3D11/None/5010_CloudLayer.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsPlayer/Direct3D11/None/5010_CloudLayer.png index b6905fbd255..69ff7bc20dc 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsPlayer/Direct3D11/None/5010_CloudLayer.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/WindowsPlayer/Direct3D11/None/5010_CloudLayer.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:8c141c8eaec873e0ce1f0289dd16035d05f5e43c0127256e26465944ea36995e -size 166413 +oid sha256:302824154ca54cc13c47db63fde1017fa26bdd539faf99aa1aa17131cdd9803b +size 207902 diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Override-Cloud-Layer.md b/com.unity.render-pipelines.high-definition/Documentation~/Override-Cloud-Layer.md index eebf62c32ae..bafc4689782 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Override-Cloud-Layer.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Override-Cloud-Layer.md @@ -53,12 +53,12 @@ Only the red and green channels are used and they represent respectively horizon | - **Opacity A** | Opacity of the alpha layer. | | **Rotation** | Use the slider to set the angle to rotate the Cloud Layer, in degrees. | | **Tint** | Specifies a color that HDRP uses to tint the Cloud Layer. | -| **Intensity Multiplier** | Set the multiplier by which HDRP multiplies the Cloud Layer color. | -| **Distortion** | Use the dropdown to choose the distortion mode for simulating cloud motion.
• **None**: No distortion.
• **Procedural**: HDRP distorts the clouds using a uniform wind direction.
• **Flowmap**: HDRP distorts the clouds using the provided flowmap. | +| **Exposure** | Set the amount of light per unit area that HDRP applies to the cloud layer. | +| **Distortion Mode** | Use the dropdown to choose the distortion mode for simulating cloud motion.
• **None**: No distortion.
• **Procedural**: HDRP distorts the clouds using a uniform wind direction.
• **Flowmap**: HDRP distorts the clouds using the provided flowmap. | | - **Scroll direction** | Use the slider to set the scrolling direction for the distortion. | | - **Scroll speed** | Modify the speed at which HDRP scrolls the distortion texture. | | - **Flowmap** | Assign a flowmap that HDRP uses to distort UVs when rendering the clouds. Refer to the section [Customizing the Flowmap](#CustomizingFlowmap) for more details.
This property only appears when you select **Flowmap** from the **Distortion** drop-down. | -| **Lighting** | Use the dropdown to choose the cloud lighting mode.
• **None**: No lighting.
• **Raymarching**: HDRP lights the clouds using 2D raymarching with the main directionnal light. | +| **Lighting Mode** | Use the dropdown to choose the cloud lighting mode.
• **None**: No lighting.
• **Raymarching**: HDRP lights the clouds using 2D raymarching with the main directionnal light. | | - **Steps** | Use the slider to set the number of steps for the raymarching. | | - **Thickness** | Set the thickness of the clouds. | | **Cast Shadows** | Enable to have the clouds cast shadows for the main directionnal light. | diff --git a/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs b/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs index 5c4caf6289c..c8dacf74c14 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Sky/CloudLayer/CloudLayerEditor.cs @@ -10,67 +10,25 @@ namespace UnityEditor.Rendering.HighDefinition [VolumeComponentEditor(typeof(CloudLayer))] class CloudLayerEditor : VolumeComponentEditor { - struct CloudSettingsParameter + struct CloudMapParameter { + public SerializedDataParameter cloudMap; + public SerializedDataParameter[] opacities; + public SerializedDataParameter rotation; public SerializedDataParameter tint; - public SerializedDataParameter intensityMultiplier; + public SerializedDataParameter exposure; + public SerializedDataParameter distortion; public SerializedDataParameter scrollDirection; public SerializedDataParameter scrollSpeed; public SerializedDataParameter flowmap; - } - struct CloudLightingParameter - { - public SerializedDataParameter mode; + public SerializedDataParameter lighting; public SerializedDataParameter steps; public SerializedDataParameter thickness; - public SerializedDataParameter castShadows; - } - - struct CloudMapParameter - { - public SerializedDataParameter cloudMap; - public SerializedDataParameter[] opacities; - public CloudSettingsParameter settings; - public CloudLightingParameter lighting; - } - - struct CloudCRTParameter - { - public SerializedDataParameter cloudCRT; - public CloudSettingsParameter settings; - public CloudLightingParameter lighting; - } - - CloudSettingsParameter UnpackCloudSettings(SerializedProperty serializedProperty) - { - var p = new RelativePropertyFetcher(serializedProperty); - - return new CloudSettingsParameter - { - rotation = Unpack(p.Find(x => x.rotation)), - tint = Unpack(p.Find(x => x.tint)), - intensityMultiplier = Unpack(p.Find(x => x.intensityMultiplier)), - distortion = Unpack(p.Find(x => x.distortion)), - scrollDirection = Unpack(p.Find(x => x.scrollDirection)), - scrollSpeed = Unpack(p.Find(x => x.scrollSpeed)), - flowmap = Unpack(p.Find(x => x.flowmap)), - }; - } - - CloudLightingParameter UnpackCloudLighting(SerializedProperty serializedProperty) - { - var p = new RelativePropertyFetcher(serializedProperty); - return new CloudLightingParameter - { - mode = Unpack(p.Find(x => x.lighting)), - steps = Unpack(p.Find(x => x.steps)), - thickness = Unpack(p.Find(x => x.thickness)), - castShadows = Unpack(p.Find(x => x.castShadows)), - }; + public SerializedDataParameter castShadows; } CloudMapParameter UnpackCloudMap(SerializedProperty serializedProperty) @@ -87,28 +45,25 @@ CloudMapParameter UnpackCloudMap(SerializedProperty serializedProperty) Unpack(p.Find(x => x.opacityB)), Unpack(p.Find(x => x.opacityA)) }, - settings = UnpackCloudSettings(p.Find(x => x.settings)), - lighting = UnpackCloudLighting(p.Find(x => x.lighting)), - }; - } - CloudCRTParameter UnpackCloudCRT(SerializedProperty serializedProperty) - { - var p = new RelativePropertyFetcher(serializedProperty); + rotation = Unpack(p.Find(x => x.rotation)), + tint = Unpack(p.Find(x => x.tint)), + exposure = Unpack(p.Find(x => x.exposure)), + distortion = Unpack(p.Find(x => x.distortionMode)), + scrollDirection = Unpack(p.Find(x => x.scrollDirection)), + scrollSpeed = Unpack(p.Find(x => x.scrollSpeed)), + flowmap = Unpack(p.Find(x => x.flowmap)), - return new CloudCRTParameter - { - cloudCRT = Unpack(p.Find(x => x.cloudCRT)), - settings = UnpackCloudSettings(p.Find(x => x.settings)), - lighting = UnpackCloudLighting(p.Find(x => x.lighting)) + lighting = Unpack(p.Find(x => x.lightingMode)), + steps = Unpack(p.Find(x => x.steps)), + thickness = Unpack(p.Find(x => x.thickness)), + castShadows = Unpack(p.Find(x => x.castShadows)), }; } - SerializedDataParameter m_Opacity, m_UpperHemisphereOnly; - SerializedDataParameter m_Mode, m_LayerCount; + SerializedDataParameter m_Opacity, m_UpperHemisphereOnly, m_LayerCount; SerializedDataParameter m_ShadowsOpacity, m_ShadowsTiling; CloudMapParameter[] m_Layers; - CloudCRTParameter m_Crt; public override void OnEnable() { @@ -118,7 +73,6 @@ public override void OnEnable() m_Opacity = Unpack(o.Find(x => x.opacity)); m_UpperHemisphereOnly = Unpack(o.Find(x => x.upperHemisphereOnly)); - m_Mode = Unpack(o.Find(x => x.mode)); m_LayerCount = Unpack(o.Find(x => x.layers)); m_ShadowsOpacity = Unpack(o.Find(x => x.shadowsOpacity)); @@ -128,101 +82,72 @@ public override void OnEnable() UnpackCloudMap(o.Find(x => x.layerA)), UnpackCloudMap(o.Find(x => x.layerB)) }; - - m_Crt = UnpackCloudCRT(o.Find(x => x.crt)); } + void PropertyField(CloudMapParameter map, string label) + { + EditorGUILayout.Space(); + EditorGUILayout.LabelField(label, EditorStyles.miniLabel); + PropertyField(map.cloudMap); + EditorGUI.indentLevel++; + for (int i = 0; i < 4; i++) + PropertyField(map.opacities[i]); + EditorGUI.indentLevel--; - void PropertyField(CloudSettingsParameter settings) - { - PropertyField(settings.rotation); - PropertyField(settings.tint); - PropertyField(settings.intensityMultiplier); + PropertyField(map.rotation); + PropertyField(map.tint); + PropertyField(map.exposure); - PropertyField(settings.distortion); - if (settings.distortion.value.intValue != (int)CloudDistortionMode.None) + PropertyField(map.distortion); + if (map.distortion.value.intValue != (int)CloudDistortionMode.None) { EditorGUI.indentLevel++; - PropertyField(settings.scrollDirection); - PropertyField(settings.scrollSpeed); - if (settings.distortion.value.intValue == (int)CloudDistortionMode.Flowmap) + PropertyField(map.scrollDirection); + PropertyField(map.scrollSpeed); + if (map.distortion.value.intValue == (int)CloudDistortionMode.Flowmap) { - PropertyField(settings.flowmap); + PropertyField(map.flowmap); } EditorGUI.indentLevel--; } - } - void PropertyField(CloudLightingParameter lighting, string label) - { EditorGUILayout.Space(); - EditorGUILayout.LabelField(label, EditorStyles.miniLabel); + EditorGUILayout.LabelField(label + " Lighting", EditorStyles.miniLabel); - PropertyField(lighting.mode); - if (lighting.mode.value.intValue == (int)CloudLightingMode.Raymarching) + PropertyField(map.lighting); + if (map.lighting.value.intValue == (int)CloudLightingMode.Raymarching) { EditorGUI.indentLevel++; - PropertyField(lighting.steps); - PropertyField(lighting.thickness); + PropertyField(map.steps); + PropertyField(map.thickness); EditorGUI.indentLevel--; } - PropertyField(lighting.castShadows); - } - - void PropertyField(CloudMapParameter map, string label) - { - EditorGUILayout.Space(); - EditorGUILayout.LabelField(label, EditorStyles.miniLabel); - - PropertyField(map.cloudMap); - EditorGUI.indentLevel++; - for (int i = 0; i < 4; i++) - PropertyField(map.opacities[i]); - EditorGUI.indentLevel--; - - PropertyField(map.settings); - PropertyField(map.lighting, label + " Lighting"); + PropertyField(map.castShadows); } public override void OnInspectorGUI() { PropertyField(m_Opacity); PropertyField(m_UpperHemisphereOnly); + PropertyField(m_LayerCount); - PropertyField(m_Mode); - if (m_Mode.value.intValue == (int)CloudLayerMode.CloudMap) - { - EditorGUI.indentLevel++; - PropertyField(m_LayerCount); - EditorGUI.indentLevel--; - - PropertyField(m_Layers[0], "Layer A"); - bool cloudShadows = m_Layers[0].lighting.castShadows.value.boolValue; - - if (m_LayerCount.value.intValue == (int)CloudMapMode.Double) - { - PropertyField(m_Layers[1], "Layer B"); - cloudShadows |= m_Layers[1].lighting.castShadows.value.boolValue; - } + PropertyField(m_Layers[0], "Layer A"); + bool cloudShadows = m_Layers[0].castShadows.value.boolValue; - if (cloudShadows) - { - EditorGUILayout.Space(); - EditorGUILayout.LabelField("Cloud Shadows", EditorStyles.miniLabel); - - PropertyField(m_ShadowsOpacity); - PropertyField(m_ShadowsTiling); - } + if (m_LayerCount.value.intValue == (int)CloudMapMode.Double) + { + PropertyField(m_Layers[1], "Layer B"); + cloudShadows |= m_Layers[1].castShadows.value.boolValue; } - else if (m_Mode.value.intValue == (int)CloudLayerMode.RenderTexture) + + if (cloudShadows) { EditorGUILayout.Space(); - EditorGUILayout.LabelField("Custom Render Texture", EditorStyles.miniLabel); + EditorGUILayout.LabelField("Cloud Shadows", EditorStyles.miniLabel); - PropertyField(m_Crt.cloudCRT); - PropertyField(m_Crt.settings); - PropertyField(m_Crt.lighting, "Lighting"); + PropertyField(m_ShadowsOpacity); + PropertyField(m_ShadowsTiling); } } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs index 48df9bdfa7d..dcbe7df9539 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs @@ -1455,7 +1455,7 @@ DebugUI.Widget makeWidget(string name, VolumeParameter param) // Build rows - recursively handles nested parameters var rows = new List(); - void AddParameterRows(Type type, string prefix = null) + void AddParameterRows(Type type, string baseName = null) { void AddRow(FieldInfo f, string prefix) { @@ -1496,9 +1496,9 @@ void AddRow(FieldInfo f, string prefix) { var fieldType = field.FieldType; if (fieldType.IsSubclassOf(typeof(VolumeParameter))) - AddRow(field, prefix ?? ""); + AddRow(field, baseName ?? ""); else if (!fieldType.IsArray && fieldType.IsClass) - AddParameterRows(fieldType, prefix ?? (field.Name + " ")); + AddParameterRows(fieldType, baseName ?? (field.Name + " ")); } } AddParameterRows(selectedType); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl index e9c6f563ad5..2c20b0941bf 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightEvaluation.hlsl @@ -293,14 +293,10 @@ SHADOW_TYPE EvaluateShadow_Directional( LightLoopContext lightLoopContext, Posit #endif // Cloud shadows - float3x3 lightToWorld = float3x3(light.right, light.up, light.forward); - float3 lightToSample = posInput.positionWS - light.positionRWS; - float3 positionLS = mul(lightToSample, transpose(lightToWorld)); - - float2 uv = positionLS.xy / _CloudShadowScale; - float cloudShadow = SAMPLE_TEXTURE2D_LOD(_CloudShadows, sampler_CloudShadows, uv, 0).r; - //shadow = saturate(lerp(shadow, _CloudShadowOpacity, cloudShadow)); - shadow = min(shadow, cloudShadow); + float3 lightToSample = posInput.positionWS - light.positionRWS; + float2 posLS = float2(dot(lightToSample, normalize(light.right)), dot(lightToSample, normalize(light.up))); + + shadow *= SAMPLE_TEXTURE2D_LOD(_CloudShadows, s_linear_repeat_sampler, posLS / _CloudShadowScale, 0).r; return shadow; #else // LIGHT_EVALUATION_NO_SHADOWS diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/ShaderVariablesLightLoop.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/ShaderVariablesLightLoop.hlsl index 5e889c306ae..634d0f3c6c8 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/ShaderVariablesLightLoop.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/ShaderVariablesLightLoop.hlsl @@ -20,7 +20,6 @@ TEXTURE2D(_CookieAtlas); // Used by the main directional light TEXTURE2D(_CloudShadows); -SAMPLER(sampler_CloudShadows); // Use texture array for reflection (or LatLong 2D array for mobile) TEXTURECUBE_ARRAY_ABSTRACT(_EnvCubemapTextures); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs index da35d4f5e4e..c0ddd041ed2 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs @@ -2,17 +2,6 @@ namespace UnityEngine.Rendering.HighDefinition { - /// - /// Cloud Layer Mode. - /// - public enum CloudLayerMode - { - /// Cloud Map mode. - CloudMap, - /// CustomRenderTexture mode. - RenderTexture, - } - /// /// Cloud Map Mode. /// @@ -61,9 +50,6 @@ public class CloudLayer : VolumeComponent /// Enable to cover only the upper part of the sky. [Tooltip("Check this box if the cloud layer covers only the upper part of the sky.")] public BoolParameter upperHemisphereOnly = new BoolParameter(true); - /// Select the cloud layer mode. - [Tooltip("Choose the cloud layer mode;")] - public VolumeParameter mode = new VolumeParameter(); /// Choose the number of cloud layers. public VolumeParameter layers = new VolumeParameter(); @@ -75,23 +61,38 @@ public class CloudLayer : VolumeComponent [Tooltip("Controls the tiling of the cloud shadows.")] public MinFloatParameter shadowsTiling = new MinFloatParameter(500.0f, 0.0f); - [Serializable] - public class CloudSettings + public class CloudMap { + /// Texture used to render the clouds. + [Tooltip("Specify the texture HDRP uses to render the clouds (in LatLong layout).")] + public TextureParameter cloudMap = new TextureParameter(null); + /// Opacity of the red layer. + [Tooltip("Opacity of the red layer.")] + public ClampedFloatParameter opacityR = new ClampedFloatParameter(1.0f, 0.0f, 1.0f); + /// Opacity of the green layer. + [Tooltip("Opacity of the green layer.")] + public ClampedFloatParameter opacityG = new ClampedFloatParameter(0.0f, 0.0f, 1.0f); + /// Opacity of the blue layer. + [Tooltip("Opacity of the blue layer.")] + public ClampedFloatParameter opacityB = new ClampedFloatParameter(0.0f, 0.0f, 1.0f); + /// Opacity of the alpha layer. + [Tooltip("Opacity of the alpha layer.")] + public ClampedFloatParameter opacityA = new ClampedFloatParameter(0.0f, 0.0f, 1.0f); + /// Rotation of the clouds. [Tooltip("Sets the rotation of the clouds.")] public ClampedFloatParameter rotation = new ClampedFloatParameter(0.0f, 0.0f, 360.0f); /// Color multiplier of the clouds. [Tooltip("Specifies the color that HDRP uses to tint the clouds.")] public ColorParameter tint = new ColorParameter(Color.white); - /// Intensity multipler of the clouds. - [Tooltip("Sets the intensity multiplier for the clouds.")] - public MinFloatParameter intensityMultiplier = new MinFloatParameter(10.0f, 0.0f); + /// Exposure of the clouds. + [Tooltip("Sets the exposure of the clouds in EV.")] + public FloatParameter exposure = new FloatParameter(0.0f); /// Distortion mode. [Tooltip("Distortion mode.")] - public VolumeParameter distortion = new VolumeParameter(); + public VolumeParameter distortionMode = new VolumeParameter(); /// Direction of the distortion. [Tooltip("Sets the rotation of the distortion (in degrees).")] public ClampedFloatParameter scrollDirection = new ClampedFloatParameter(0.0f, 0.0f, 360.0f); @@ -102,99 +103,51 @@ public class CloudSettings [Tooltip("Specify the flowmap HDRP uses for cloud distortion (in LatLong layout).")] public TextureParameter flowmap = new TextureParameter(null); - internal float scrollFactor = 0.0f; - - - internal (Vector4, Vector4) GetRenderingParameters() - { - float dir = -Mathf.Deg2Rad * scrollDirection.value; - var params1 = new Vector4(Mathf.Cos(dir), Mathf.Sin(dir), scrollFactor, 0); - Vector4 params2 = tint.value; - params2.w = intensityMultiplier.value; - return (params1, params2); - } - } - - [Serializable] - public class CloudLighting - { - /// Distortion mode. - [Tooltip("Distortion mode.")] - public VolumeParameter lighting = new VolumeParameter(); + /// Lighting mode. + [Tooltip("Lighting mode.")] + public VolumeParameter lightingMode = new VolumeParameter(); /// Number of raymarching steps. [Tooltip("Number of raymarching steps.")] - public ClampedIntParameter steps = new ClampedIntParameter(4, 1, 10); + public ClampedIntParameter steps = new ClampedIntParameter(4, 1, 10); /// Thickness of the clouds. [Tooltip("Controls the thickness of the clouds.")] - public ClampedFloatParameter thickness = new ClampedFloatParameter(0.5f, 0, 2); + public ClampedFloatParameter thickness = new ClampedFloatParameter(0.5f, 0, 2); /// Enable to cast shadows. [Tooltip("Enable or disable cloud shadows.")] public BoolParameter castShadows = new BoolParameter(false); - internal int NumSteps => (lighting == CloudLightingMode.Raymarching) ? steps.value : 0; - - - internal int GetBakingHashCode(ref bool cloudShadows) - { - int hash = 17; - - unchecked - { - hash = hash * 23 + lighting.GetHashCode(); - hash = hash * 23 + steps.GetHashCode(); - hash = hash * 23 + thickness.GetHashCode(); - hash = hash * 23 + castShadows.GetHashCode(); - } - - cloudShadows |= castShadows.value; - return hash; - } - } - - [Serializable] - public class CloudMap - { - /// Texture used to render the clouds. - [Tooltip("Specify the texture HDRP uses to render the clouds (in LatLong layout).")] - public TextureParameter cloudMap = new TextureParameter(null); - - /// Opacity of the red layer. - [Tooltip("Opacity of the red layer.")] - public ClampedFloatParameter opacityR = new ClampedFloatParameter(1.0f, 0.0f, 1.0f); - /// Opacity of the green layer. - [Tooltip("Opacity of the green layer.")] - public ClampedFloatParameter opacityG = new ClampedFloatParameter(0.0f, 0.0f, 1.0f); - /// Opacity of the blue layer. - [Tooltip("Opacity of the blue layer.")] - public ClampedFloatParameter opacityB = new ClampedFloatParameter(0.0f, 0.0f, 1.0f); - /// Opacity of the alpha layer. - [Tooltip("Opacity of the alpha layer.")] - public ClampedFloatParameter opacityA = new ClampedFloatParameter(0.0f, 0.0f, 1.0f); - - public CloudSettings settings = new CloudSettings(); - public CloudLighting lighting = new CloudLighting(); + internal float scrollFactor = 0.0f; + internal int NumSteps => (lightingMode == CloudLightingMode.Raymarching) ? steps.value : 0; internal Vector4 Opacities => new Vector4(opacityR.value, opacityG.value, opacityB.value, opacityA.value); internal (Vector4, Vector4) GetBakingParameters() { Vector4 parameters = new Vector4( - -settings.rotation.value / 360.0f, - lighting.NumSteps, - lighting.thickness.value, + -rotation.value / 360.0f, + NumSteps, + thickness.value, 0 ); return (Opacities, parameters); } + internal (Vector4, Vector4) GetRenderingParameters() + { + float dir = -Mathf.Deg2Rad * scrollDirection.value; + var params1 = new Vector4(Mathf.Cos(dir), Mathf.Sin(dir), scrollFactor, 0); + Vector4 params2 = tint.value * ColorUtils.ConvertEV100ToExposure(-exposure.value); + return (params1, params2); + } + internal bool Apply(Material skyMaterial, string mapKeyword, string motionKeyword) { - if (settings.distortion.value != CloudDistortionMode.None) + if (distortionMode.value != CloudDistortionMode.None) { skyMaterial.EnableKeyword(motionKeyword); - if (settings.distortion.value == CloudDistortionMode.Flowmap) + if (distortionMode.value == CloudDistortionMode.Flowmap) { skyMaterial.EnableKeyword(mapKeyword); return true; @@ -212,10 +165,10 @@ internal bool Apply(Material skyMaterial, string mapKeyword, string motionKeywor internal bool SetComputeParams(ComputeShader cs, string mapKeyword, string motionKeyword) { - if (settings.distortion.value != CloudDistortionMode.None) + if (distortionMode.value != CloudDistortionMode.None) { cs.EnableKeyword(motionKeyword); - if (settings.distortion.value == CloudDistortionMode.Flowmap) + if (distortionMode.value == CloudDistortionMode.Flowmap) { cs.EnableKeyword(mapKeyword); return true; @@ -231,7 +184,7 @@ internal bool SetComputeParams(ComputeShader cs, string mapKeyword, string motio return false; } - internal int GetBakingHashCode(ref bool castShadows) + internal int GetBakingHashCode(ref bool cloudShadows) { int hash = 17; @@ -243,8 +196,13 @@ internal int GetBakingHashCode(ref bool castShadows) hash = hash * 23 + opacityB.GetHashCode(); hash = hash * 23 + opacityA.GetHashCode(); - hash = hash * 23 + settings.rotation.GetHashCode(); - hash = hash * 23 + lighting.GetBakingHashCode(ref castShadows); + hash = hash * 23 + rotation.GetHashCode(); + + hash = hash * 23 + lightingMode.GetHashCode(); + hash = hash * 23 + steps.GetHashCode(); + hash = hash * 23 + thickness.GetHashCode(); + hash = hash * 23 + castShadows.GetHashCode(); + #if UNITY_EDITOR // In the editor, we want to rebake the texture if the texture content is modified if (cloudMap.value != null) @@ -252,41 +210,16 @@ internal int GetBakingHashCode(ref bool castShadows) #endif } - return hash; - } - } - - [Serializable] - public class CloudCRT - { - /// Texture used to render the clouds. - [Tooltip("Specify the CustomRenderTexture HDRP uses to render the clouds (in LatLong layout).")] - public TextureParameter cloudCRT = new TextureParameter(null); - - public CloudSettings settings = new CloudSettings(); - public CloudLighting lighting = new CloudLighting(); - - - internal int GetBakingHashCode(ref bool castShadows) - { - int hash = 17; - - unchecked - { - hash = hash * 23 + cloudCRT.GetHashCode(); - hash = hash * 23 + settings.rotation.GetHashCode(); - hash = hash * 23 + lighting.GetBakingHashCode(ref castShadows); - } - + cloudShadows |= castShadows.value; return hash; } } public CloudMap layerA = new CloudMap(); public CloudMap layerB = new CloudMap(); - public CloudCRT crt = new CloudCRT(); private float lastTime = 0.0f; + static internal Vector4[] vectorArray = new Vector4[2]; CloudLayer() @@ -310,54 +243,53 @@ public static void Apply(BuiltinSkyParameters builtinParams, Material skyMateria return; } - if (layer.mode.value == CloudLayerMode.CloudMap) - { - float dt = (Time.time - layer.lastTime) * 0.01f; - layer.layerA.settings.scrollFactor += layer.layerA.settings.scrollSpeed.value * dt; - layer.layerB.settings.scrollFactor += layer.layerB.settings.scrollSpeed.value * dt; - layer.lastTime = Time.time; + float dt = (Time.time - layer.lastTime) * 0.01f; + layer.layerA.scrollFactor += layer.layerA.scrollSpeed.value * dt; + layer.layerB.scrollFactor += layer.layerB.scrollSpeed.value * dt; + layer.lastTime = Time.time; - var paramsA = layer.layerA.settings.GetRenderingParameters(); - var paramsB = layer.layerB.settings.GetRenderingParameters(); - paramsA.Item1.w = layer.opacity.value; - paramsB.Item1.w = layer.upperHemisphereOnly.value ? 1 : 0; + var paramsA = layer.layerA.GetRenderingParameters(); + var paramsB = layer.layerB.GetRenderingParameters(); + paramsA.Item1.w = layer.opacity.value; + paramsB.Item1.w = layer.upperHemisphereOnly.value ? 1 : 0; - skyMaterial.SetTexture(HDShaderIDs._CloudTexture, builtinParams.cloudTexture); - skyMaterial.SetVectorArray(HDShaderIDs._CloudParams1, new Vector4[]{ paramsA.Item1, paramsB.Item1 }); - skyMaterial.SetVectorArray(HDShaderIDs._CloudParams2, new Vector4[]{ paramsA.Item2, paramsB.Item2 }); + skyMaterial.SetTexture(HDShaderIDs._CloudTexture, builtinParams.cloudTexture); + vectorArray[0] = paramsA.Item1; vectorArray[1] = paramsB.Item1; + skyMaterial.SetVectorArray(HDShaderIDs._CloudParams1, vectorArray); + vectorArray[0] = paramsA.Item2; vectorArray[1] = paramsB.Item2; + skyMaterial.SetVectorArray(HDShaderIDs._CloudParams2, vectorArray); - if (layer.layerA.Apply(skyMaterial, "USE_CLOUD_MAP", "USE_CLOUD_MOTION")) - skyMaterial.SetTexture(HDShaderIDs._CloudFlowmap1, layer.layerA.settings.flowmap.value); + if (layer.layerA.Apply(skyMaterial, "USE_CLOUD_MAP", "USE_CLOUD_MOTION")) + skyMaterial.SetTexture(HDShaderIDs._CloudFlowmap1, layer.layerA.flowmap.value); - if (layer.layers.value == CloudMapMode.Double) - { - if (layer.layerB.Apply(skyMaterial, "USE_SECOND_CLOUD_MAP", "USE_SECOND_CLOUD_MOTION")) - skyMaterial.SetTexture(HDShaderIDs._CloudFlowmap2, layer.layerB.settings.flowmap.value); - } - else - { - skyMaterial.DisableKeyword("USE_SECOND_CLOUD_MAP"); - skyMaterial.DisableKeyword("USE_SECOND_CLOUD_MOTION"); - } + if (layer.layers.value == CloudMapMode.Double) + { + if (layer.layerB.Apply(skyMaterial, "USE_SECOND_CLOUD_MAP", "USE_SECOND_CLOUD_MOTION")) + skyMaterial.SetTexture(HDShaderIDs._CloudFlowmap2, layer.layerB.flowmap.value); + } + else + { + skyMaterial.DisableKeyword("USE_SECOND_CLOUD_MAP"); + skyMaterial.DisableKeyword("USE_SECOND_CLOUD_MOTION"); } } internal void SetComputeParams(CommandBuffer cmd, ComputeShader cs, int kernel) { - var paramsA = layerA.settings.GetRenderingParameters(); - var paramsB = layerB.settings.GetRenderingParameters(); + var paramsA = layerA.GetRenderingParameters(); + var paramsB = layerB.GetRenderingParameters(); paramsA.Item1.w = opacity.value; paramsB.Item1.w = upperHemisphereOnly.value ? 1 : 0; cmd.SetComputeVectorArrayParam(cs, HDShaderIDs._CloudParams1, new Vector4[]{ paramsA.Item1, paramsB.Item1 }); if (layerA.SetComputeParams(cs, "USE_CLOUD_MAP", "USE_CLOUD_MOTION")) - cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._CloudFlowmap1, layerA.settings.flowmap.value); + cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._CloudFlowmap1, layerA.flowmap.value); if (layers.value == CloudMapMode.Double) { if (layerB.SetComputeParams(cs, "USE_SECOND_CLOUD_MAP", "USE_SECOND_CLOUD_MOTION")) - cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._CloudFlowmap2, layerB.settings.flowmap.value); + cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._CloudFlowmap2, layerB.flowmap.value); } else { @@ -375,19 +307,13 @@ internal int GetBakingHashCode(out int numLayers, out bool castShadows) unchecked { - hash = hash * 23 + mode.GetHashCode(); - if (mode.value == CloudLayerMode.CloudMap) + hash = hash * 23 + layers.GetHashCode(); + hash = hash * 23 + layerA.GetBakingHashCode(ref castShadows); + if (layers.value == CloudMapMode.Double) { - hash = hash * 23 + layers.GetHashCode(); - hash = hash * 23 + layerA.GetBakingHashCode(ref castShadows); - if (layers.value == CloudMapMode.Double) - { - hash = hash * 23 + layerB.GetBakingHashCode(ref castShadows); - numLayers = 2; - } + hash = hash * 23 + layerB.GetBakingHashCode(ref castShadows); + numLayers = 2; } - else - hash = hash * 23 + crt.GetBakingHashCode(ref castShadows); } return hash; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl index 371c42e706d..3dd7d46a69d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.hlsl @@ -23,7 +23,6 @@ float4 _CloudParams2[2]; // TODO: Those 2 params can be premultiplied #define _CloudTint(l) _CloudParams2[l].xyz -#define _CloudIntensity(l) _CloudParams2[l].w struct CloudLayerData { @@ -118,7 +117,7 @@ float4 GetCloudLayerColor(float3 dir, int index) else color = SampleCloudMap(dir, layer.index); - return float4(color.x * _CloudIntensity(layer.index) * _CloudTint(layer.index), color.y * _CloudOpacity); + return float4(color.x * _CloudTint(layer.index), color.y * _CloudOpacity); } float GetCloudOpacity(float3 dir) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/ComputeCloudShadows.compute b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/ComputeCloudShadows.compute index 46e5004b51c..017d43fe690 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/ComputeCloudShadows.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/ComputeCloudShadows.compute @@ -15,28 +15,26 @@ RW_TEXTURE2D(float, _CloudShadowsOutput); float4 _Params; -float _CloudShadowOpacity; +float4 _Params1; +float4 _Params2; -#define _SunDirection _Params.xyz -#define _Resolution _Params.w - -static float3 tangent; -static float3 bitangent; +#define _SunForward _Params.xyz +#define _SunRight _Params1.xyz +#define _SunUp _Params2.xyz +#define _Resolution _Params.w +#define _CloudShadowOpacity _Params1.w float ComputeCloudShadow(float2 uv) { const float width = 0.15; - float3 dir = -_SunDirection + uv.x * width * tangent + uv.y * width * bitangent; + float3 dir = -_SunForward + uv.x * width * _SunRight + uv.y * width * _SunUp; - return GetCloudOpacity(dir); + return GetCloudOpacity(normalize(dir)); } [numthreads(8, 8, 1)] void KERNEL_NAME(uint2 dispatchThreadId : SV_DispatchThreadID) { - tangent = normalize(cross(-_SunDirection, float3(0.0, 1.0, 0.0))); - bitangent = cross(tangent, -_SunDirection); - float2 uv = float2(dispatchThreadId.x * _Resolution, 1.0 - dispatchThreadId.y * _Resolution) * 2.0 - 1.0; float shadow = ComputeCloudShadow(uv); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/GradientSky/GradientSky.shader b/com.unity.render-pipelines.high-definition/Runtime/Sky/GradientSky/GradientSky.shader index 35cd14b639a..0af54e90202 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/GradientSky/GradientSky.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/GradientSky/GradientSky.shader @@ -54,9 +54,9 @@ Shader "Hidden/HDRP/Sky/GradientSky" float topLerpFactor = saturate(-verticalGradient); float bottomLerpFactor = saturate(verticalGradient); float3 color = lerp(_GradientMiddle.xyz, _GradientBottom.xyz, bottomLerpFactor); - color = lerp(color, _GradientTop.xyz, topLerpFactor); + color = lerp(color, _GradientTop.xyz, topLerpFactor) * _SkyIntensity; color = ApplyCloudLayer(-viewDirWS, color); - return float4(color * _SkyIntensity, 1.0); + return float4(color, 1.0); } float4 FragBaking(Varyings input) : SV_Target diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader index b071f96909f..500f5d00545 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/HDRISky/HDRISky.shader @@ -224,8 +224,8 @@ Shader "Hidden/HDRP/Sky/HDRISky" float4 GetColorWithRotation(float3 dir, float exposure, float2 cos_sin) { - float3 skyColor = GetSkyColor(RotationUp(dir, cos_sin)); - skyColor = ApplyCloudLayer(dir, skyColor)*_Intensity*exposure; + float3 skyColor = GetSkyColor(RotationUp(dir, cos_sin))*_Intensity; + skyColor = ApplyCloudLayer(dir, skyColor)*exposure; skyColor = ClampToFloat16Max(skyColor); return float4(skyColor, 1.0); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader b/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader index ddc2440d572..5859879d57a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/PhysicallyBasedSky/PhysicallyBasedSky.shader @@ -226,12 +226,10 @@ Shader "Hidden/HDRP/Sky/PbrSky" } skyColor += radiance * (1 - skyOpacity); + skyColor *= _IntensityMultiplier; - // Hacky way to boost the clouds to match other sky types - float maxLuminance = (78.0f / (100.0f * 0.65)) * pow(2.0f, -13.5); - skyColor = ApplyCloudLayer(-V, skyColor * maxLuminance) / maxLuminance; + skyColor = ApplyCloudLayer(-V, skyColor); - skyColor *= _IntensityMultiplier; return float4(skyColor, 1.0); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs index 2eb43f50bda..d3da81f3c36 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs @@ -667,11 +667,16 @@ void ComputeCloudShadows(SkyUpdateContext skyContext, Light sunLight) var renderingContext = m_CachedCloudContexts[skyContext.cachedCloudRenderingContextId].renderingContext; var layer = skyContext.cloudLayer; - Vector4 _Params = sunLight.transform.forward; + Vector4 _Params = sunLight.transform.forward; + Vector4 _Params1 = sunLight.transform.right; + Vector4 _Params2 = sunLight.transform.up; _Params.w = 1.0f / (float)m_CloudShadowsResolution; + _Params1.w = 10.0f * layer.shadowsOpacity.value; cmd.SetComputeVectorParam(m_ComputeCloudShadowsCS, HDShaderIDs._Params, _Params); - cmd.SetComputeFloatParam(m_ComputeCloudShadowsCS, HDShaderIDs._CloudShadowOpacity, 10.0f*layer.shadowsOpacity.value); + cmd.SetComputeVectorParam(m_ComputeCloudShadowsCS, HDShaderIDs._Params1, _Params1); + cmd.SetComputeVectorParam(m_ComputeCloudShadowsCS, HDShaderIDs._Params2, _Params2); + cmd.SetComputeTextureParam(m_ComputeCloudShadowsCS, m_ComputeCloudShadowsKernel, HDShaderIDs._CloudTexture, renderingContext.cloudTextureRT); cmd.SetComputeTextureParam(m_ComputeCloudShadowsCS, m_ComputeCloudShadowsKernel, m_CloudShadowsOutputParam, renderingContext.cloudShadowsRT); @@ -973,7 +978,6 @@ public void UpdateEnvironment( HDCamera hdCamera, m_BuiltinParameters.frameIndex = frameIndex; m_BuiltinParameters.skySettings = skyContext.skySettings; - bool cloudShadows = false; if (skyContext.cloudLayer != null && skyContext.cloudLayer.opacity.value != 0.0f) { int cloudHash = ComputeCloudHash(skyContext.cloudLayer, sunLight, out int numLayers, out bool castShadows); @@ -982,16 +986,13 @@ public void UpdateEnvironment( HDCamera hdCamera, if (AcquireCloudRenderingContext(skyContext, cloudHash, numLayers, castShadows)) BakeCloudTexture(skyContext, sunLight); + if (castShadows && sunLight != null) + ComputeCloudShadows(skyContext, sunLight); + var cloudContext = m_CachedCloudContexts[skyContext.cachedCloudRenderingContextId].renderingContext; m_BuiltinParameters.cloudLayer = skyContext.cloudLayer; m_BuiltinParameters.cloudTexture = cloudContext.cloudTextureRT; - if (castShadows && sunLight != null) - { - cloudShadows = true; - ComputeCloudShadows(skyContext, sunLight); - cmd.SetGlobalTexture(HDShaderIDs._CloudShadows, cloudContext.cloudShadowsRT); - } } else { @@ -1004,9 +1005,6 @@ public void UpdateEnvironment( HDCamera hdCamera, m_BuiltinParameters.cloudTexture = null; } - if (!cloudShadows) - cmd.SetGlobalTexture(HDShaderIDs._CloudShadows, Texture2D.whiteTexture); - int skyHash = ComputeSkyHash(hdCamera, skyContext, sunLight, ambientMode, staticSky); bool forceUpdate = updateRequired; @@ -1129,6 +1127,7 @@ internal void UpdateBuiltinParameters(SkyUpdateContext skyContext, HDCamera hdCa m_BuiltinParameters.frameIndex = frameIndex; m_BuiltinParameters.skySettings = skyContext.skySettings; + bool cloudShadows = false; if (skyContext.cloudLayer != null && skyContext.cloudLayer.opacity.value != 0.0f) { int cloudHash = ComputeCloudHash(skyContext.cloudLayer, sunLight, out int numLayers, out bool castShadows); @@ -1136,12 +1135,21 @@ internal void UpdateBuiltinParameters(SkyUpdateContext skyContext, HDCamera hdCa var cloudContext = m_CachedCloudContexts[skyContext.cachedCloudRenderingContextId].renderingContext; m_BuiltinParameters.cloudLayer = skyContext.cloudLayer; m_BuiltinParameters.cloudTexture = cloudContext.cloudTextureRT; + + if (castShadows && sunLight != null) + { + cloudShadows = true; + cmd.SetGlobalTexture(HDShaderIDs._CloudShadows, cloudContext.cloudShadowsRT); + } } else { m_BuiltinParameters.cloudLayer = null; m_BuiltinParameters.cloudTexture = null; } + + if (!cloudShadows) + cmd.SetGlobalTexture(HDShaderIDs._CloudShadows, Texture2D.whiteTexture); } public void PreRenderSky(HDCamera hdCamera, Light sunLight, RTHandle colorBuffer, RTHandle normalBuffer, RTHandle depthBuffer, DebugDisplaySettings debugSettings, int frameIndex, CommandBuffer cmd) @@ -1172,6 +1180,8 @@ public void PreRenderSky(HDCamera hdCamera, Light sunLight, RTHandle colorBuffer } skyContext.skyRenderer.PreRenderSky(m_BuiltinParameters, false, hdCamera.camera.cameraType != CameraType.Reflection || skyContext.skySettings.includeSunInBaking.value); } + else + cmd.SetGlobalTexture(HDShaderIDs._CloudShadows, Texture2D.whiteTexture); } public void RenderSky(HDCamera hdCamera, Light sunLight, RTHandle colorBuffer, RTHandle depthBuffer, DebugDisplaySettings debugSettings, int frameIndex, CommandBuffer cmd) From f938d1af8dc3763b24df5b449b1a8d7555327dce Mon Sep 17 00:00:00 2001 From: Adrien de Tocqueville Date: Thu, 6 Aug 2020 13:01:54 +0200 Subject: [PATCH 10/10] GC Alloc --- .../OSXEditor/Metal/None/5010_CloudLayer.png | 4 ++-- .../Documentation~/Images/Override-CloudLayer.png | 4 ++-- .../Sky/CloudLayer/BakeCloudTexture.compute | 2 -- .../Runtime/Sky/CloudLayer/CloudLayer.cs | 14 ++++++++++---- .../Runtime/Sky/SkyManager.cs | 7 +++++-- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/5010_CloudLayer.png b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/5010_CloudLayer.png index 69ff7bc20dc..1237839afe7 100644 --- a/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/5010_CloudLayer.png +++ b/TestProjects/HDRP_Tests/Assets/ReferenceImages/Linear/OSXEditor/Metal/None/5010_CloudLayer.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:302824154ca54cc13c47db63fde1017fa26bdd539faf99aa1aa17131cdd9803b -size 207902 +oid sha256:12fa2bb58ba190f866bfcbe4489fcc58c4f5b02d0631fd251b1bbc1289181533 +size 207722 diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Images/Override-CloudLayer.png b/com.unity.render-pipelines.high-definition/Documentation~/Images/Override-CloudLayer.png index f7a79f2c5b0..f4e758d9bc5 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Images/Override-CloudLayer.png +++ b/com.unity.render-pipelines.high-definition/Documentation~/Images/Override-CloudLayer.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bf4deba271d9dfe24d4f746d374cd62b85076ef6b307c57087a2b79cfded83e7 -size 35151 +oid sha256:e1221ab3ecdcf1e2a53879d7fcbf1460d03037d37e233e4b29d9433dd0ef8b58 +size 36067 diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/BakeCloudTexture.compute b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/BakeCloudTexture.compute index 67bcd7dab36..f879246a0f8 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/BakeCloudTexture.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/BakeCloudTexture.compute @@ -24,11 +24,9 @@ SAMPLER(sampler_CloudMapB); RW_TEXTURE2D_ARRAY(float2, _CloudTextureOutput); -CBUFFER_START(cb0) float4 _Params; float4 _Params1[NUM_LAYERS]; float4 _Params2[NUM_LAYERS]; -CBUFFER_END #define _SunDirection _Params.xyz #define _CloudUpperHemisphere (_Params.w > 0) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs index c0ddd041ed2..0ae303b620c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/CloudLayer/CloudLayer.cs @@ -61,6 +61,10 @@ public class CloudLayer : VolumeComponent [Tooltip("Controls the tiling of the cloud shadows.")] public MinFloatParameter shadowsTiling = new MinFloatParameter(500.0f, 0.0f); + /// + /// Cloud Map Volume Parameters. + /// This groups parameters for one cloud map layer. + /// [Serializable] public class CloudMap { @@ -215,7 +219,9 @@ internal int GetBakingHashCode(ref bool cloudShadows) } } + /// Layer A. public CloudMap layerA = new CloudMap(); + /// Layer B. public CloudMap layerB = new CloudMap(); private float lastTime = 0.0f; @@ -229,8 +235,8 @@ internal int GetBakingHashCode(ref bool cloudShadows) } /// Sets keywords and parameters on a sky material to render the cloud layer. - /// The cloud layer to apply. - /// The sky material to change. + /// The builtin sky parameters. + /// The sky material. public static void Apply(BuiltinSkyParameters builtinParams, Material skyMaterial) { var layer = builtinParams.cloudLayer; @@ -281,7 +287,8 @@ internal void SetComputeParams(CommandBuffer cmd, ComputeShader cs, int kernel) paramsA.Item1.w = opacity.value; paramsB.Item1.w = upperHemisphereOnly.value ? 1 : 0; - cmd.SetComputeVectorArrayParam(cs, HDShaderIDs._CloudParams1, new Vector4[]{ paramsA.Item1, paramsB.Item1 }); + vectorArray[0] = paramsA.Item1; vectorArray[1] = paramsB.Item1; + cmd.SetComputeVectorArrayParam(cs, HDShaderIDs._CloudParams1, vectorArray); if (layerA.SetComputeParams(cs, "USE_CLOUD_MAP", "USE_CLOUD_MOTION")) cmd.SetComputeTextureParam(cs, kernel, HDShaderIDs._CloudFlowmap1, layerA.flowmap.value); @@ -304,7 +311,6 @@ internal int GetBakingHashCode(out int numLayers, out bool castShadows) castShadows = false; numLayers = 1; - unchecked { hash = hash * 23 + layers.GetHashCode(); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs index d3da81f3c36..a3c9d1a30e1 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs @@ -228,6 +228,7 @@ class SkyManager ComputeShader m_ComputeCloudShadowsCS; int m_ComputeCloudShadowsKernel; readonly int m_CloudShadowsOutputParam = Shader.PropertyToID("_CloudShadowsOutput"); + Vector4[] m_VectorArray = new Vector4[2]; // 2 by default: Static sky + one dynamic. Will grow if needed. DynamicArray m_CachedCloudContexts = new DynamicArray(2); @@ -646,8 +647,10 @@ void BakeCloudTexture(SkyUpdateContext skyContext, Light sunLight) var paramsB = layer.layerB.GetBakingParameters(); m_BakeCloudTextureCS.EnableKeyword("CLOUD_LAYER_DOUBLE_MODE"); - cmd.SetComputeVectorArrayParam(m_BakeCloudTextureCS, HDShaderIDs._Params1, new Vector4[] { paramsA.Item1, paramsB.Item1 }); - cmd.SetComputeVectorArrayParam(m_BakeCloudTextureCS, HDShaderIDs._Params2, new Vector4[] { paramsA.Item2, paramsB.Item2 }); + m_VectorArray[0] = paramsA.Item1; m_VectorArray[1] = paramsB.Item1; + cmd.SetComputeVectorArrayParam(m_BakeCloudTextureCS, HDShaderIDs._Params1, m_VectorArray); + m_VectorArray[0] = paramsA.Item2; m_VectorArray[1] = paramsB.Item2; + cmd.SetComputeVectorArrayParam(m_BakeCloudTextureCS, HDShaderIDs._Params2, m_VectorArray); } const int groupSizeX = 8;