浏览代码

Merge pull request #727 from Unity-Technologies/Branch_SkyLightingOverride

List of available skies is now generated from reflection information.
/feature-ReflectionProbeFit
GitHub 7 年前
当前提交
5426acfa
共有 8 个文件被更改,包括 150 次插入47 次删除
  1. 13
      ScriptableRenderPipeline/Core/CoreRP/Editor/Volume/VolumeComponentEditor.cs
  2. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDRenderPipelineMenuItems.cs
  3. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/HDRISky/HDRISky.cs
  4. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/ProceduralSky/ProceduralSky.cs
  5. 65
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/SkyManager.cs
  6. 22
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/SkySettings.cs
  7. 26
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/VisualEnvironment.cs
  8. 65
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Sky/VisualEnvironmentEditor.cs

13
ScriptableRenderPipeline/Core/CoreRP/Editor/Volume/VolumeComponentEditor.cs


using (new EditorGUILayout.HorizontalScope())
{
// Override checkbox
var overrideRect = GUILayoutUtility.GetRect(17f, 17f, GUILayout.ExpandWidth(false));
overrideRect.yMin += 4f;
overrideRect.xMin += EditorGUI.indentLevel * 15f;
DrawOverrideCheckbox(overrideRect, property.overrideState);
DrawOverrideCheckbox(property);
// Property
using (new EditorGUI.DisabledScope(!property.overrideState.boolValue))

}
}
void DrawOverrideCheckbox(Rect rect, SerializedProperty property)
protected void DrawOverrideCheckbox(SerializedDataParameter property)
var overrideRect = GUILayoutUtility.GetRect(17f, 17f, GUILayout.ExpandWidth(false));
overrideRect.yMin += 4f;
overrideRect.xMin += EditorGUI.indentLevel * 15f;
property.boolValue = GUI.Toggle(rect, property.boolValue, CoreEditorUtils.GetContent("|Override this setting for this volume."), CoreEditorStyles.smallTickbox);
property.overrideState.boolValue = GUI.Toggle(overrideRect, property.overrideState.boolValue, CoreEditorUtils.GetContent("|Override this setting for this volume."), CoreEditorStyles.smallTickbox);
GUI.color = oldColor;
}
}

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/HDRenderPipelineMenuItems.cs


volume.isGlobal = true;
volume.Add<HDShadowSettings>(true);
var visualEnv = volume.Add<VisualEnvironment>(true);
visualEnv.skyType.value = SkyType.ProceduralSky;
visualEnv.skyType.value = SkySettings.GetUniqueID<ProceduralSky>();
visualEnv.fogType.value = FogType.Exponential;
volume.Add<ProceduralSky>(true);
volume.Add<ExponentialFog>(true);

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


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[DisallowMultipleComponent]
[SkyUniqueID((int)SkyType.HDRISky)]
public class HDRISky : SkySettings
{
[Tooltip("Cubemap used to render the sky.")]

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


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[DisallowMultipleComponent]
[SkyUniqueID((int)SkyType.ProceduralSky)]
public class ProceduralSky : SkySettings
{
public ClampedFloatParameter sunSize = new ClampedFloatParameter(0.04f, 0.0f, 1.0f);

65
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/SkyManager.cs


using UnityEngine.Rendering;
using System;
using System;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{

VolumeStack m_LightingOverrideVolumeStack;
LayerMask m_LightingOverrideLayerMask = -1;
static Dictionary<int, Type> m_SkyTypesDict = null;
public static Dictionary<int, Type> skyTypesDict { get { if (m_SkyTypesDict == null) UpdateSkyTypes(); return m_SkyTypesDict; } }
SkySettings result;
switch (visualEnv.skyType.value)
int skyID = visualEnv.skyType;
Type skyType;
if(m_SkyTypesDict.TryGetValue(skyID, out skyType))
{
return (SkySettings)stack.GetComponent(skyType);
}
else
{
return null;
}
}
static void UpdateSkyTypes()
{
if(m_SkyTypesDict == null)
case SkyType.HDRISky:
m_SkyTypesDict = new Dictionary<int, Type>();
var skyTypes = CoreUtils.GetAllAssemblyTypes().Where(t => t.IsSubclassOf(typeof(SkySettings)) && !t.IsAbstract);
foreach(Type skyType in skyTypes)
{
var uniqueIDs = skyType.GetCustomAttributes(typeof(SkyUniqueID), false);
if(uniqueIDs.Length == 0)
result = stack.GetComponent<HDRISky>();
break;
Debug.LogWarningFormat("Missing attribute SkyUniqueID on class {0}. Class won't be registered as an available sky.", skyType);
case SkyType.ProceduralSky:
else
result = stack.GetComponent<ProceduralSky>();
break;
int uniqueID = ((SkyUniqueID)uniqueIDs[0]).uniqueID;
if(uniqueID == 0)
{
Debug.LogWarningFormat("0 is a reserved SkyUniqueID and is used in class {0}. Class won't be registered as an available sky.", skyType);
continue;
}
Type value;
if(m_SkyTypesDict.TryGetValue(uniqueID, out value))
{
Debug.LogWarningFormat("SkyUniqueID {0} used in class {1} is already used in class {2}. Class won't be registered as an available sky.", uniqueID, skyType, value);
continue;
}
m_SkyTypesDict.Add(uniqueID, skyType);
default:
result = null;
break;
}
return result;
}
void UpdateCurrentSkySettings(HDCamera camera)

m_NeedUpdateRealtimeEnv = false;
}
UpdateSkyTypes();
UpdateCurrentSkySettings(camera);
m_NeedUpdateBakingSky = m_BakingSkyRenderingContext.UpdateEnvironment(m_BakingSky, camera, sunLight, m_UpdateRequired, cmd);

22
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/SkySettings.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[Serializable]
public sealed class SkyResolutionParameter : VolumeParameter<SkyResolution>
// This class is used to associate a unique ID to a sky class.
// This is needed to be able to automatically register sky classes and avoid collisions and refactoring class names causing data compatibility issues.
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public sealed class SkyUniqueID : Attribute
public SkyResolutionParameter(SkyResolution val, bool overrideState = false)
: base(val, overrideState)
{
public readonly int uniqueID;
public SkyUniqueID(int uniqueID)
{
this.uniqueID = uniqueID;
}
}

}
public static int GetUniqueID<T>()
{
var uniqueIDs = typeof(T).GetCustomAttributes(typeof(SkyUniqueID), false);
if (uniqueIDs.Length == 0)
return -1;
else
return ((SkyUniqueID)uniqueIDs[0]).uniqueID;
}
public abstract SkyRenderer CreateRenderer();
}

26
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Sky/VisualEnvironment.cs


namespace UnityEngine.Experimental.Rendering.HDPipeline
{
// This enum is just here to centralize UniqueID values for skies provided with HDRP
public enum SkyType
{
HDRISky = 1,
ProceduralSky = 2
}
public SkyTypeParameter skyType = new SkyTypeParameter(SkyType.None);
public IntParameter skyType = new IntParameter(0);
public FogTypeParameter fogType = new FogTypeParameter(FogType.None);
public void PushFogShaderParameters(CommandBuffer cmd, FrameSettings frameSettings)

break;
}
}
}
}
// TODO instead of hardcoding this, we need to generate the information from the existing sky currently implemented.
public enum SkyType
{
None,
HDRISky,
ProceduralSky
}
[Serializable]
public sealed class SkyTypeParameter : VolumeParameter<SkyType>
{
public SkyTypeParameter(SkyType value, bool overrideState = false)
: base(value, overrideState)
{
}
}
}

65
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Sky/VisualEnvironmentEditor.cs


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEditor.Experimental.Rendering;
namespace UnityEditor.Experimental.Rendering.HDPipeline
{
[VolumeComponentEditor(typeof(VisualEnvironment))]
public class VisualEnvironmentEditor : VolumeComponentEditor
{
SerializedDataParameter m_SkyType;
SerializedDataParameter m_FogType;
List<GUIContent> m_SkyClassNames = null;
List<int> m_SkyUniqueIDs = null;
public override void OnEnable()
{
base.OnEnable();
var o = new PropertyFetcher<VisualEnvironment>(serializedObject);
m_SkyType = Unpack(o.Find(x => x.skyType));
m_FogType = Unpack(o.Find(x => x.fogType));
}
void UpdateSkyIntPopupData()
{
if(m_SkyClassNames == null)
{
m_SkyClassNames = new List<GUIContent>();
m_SkyUniqueIDs = new List<int>();
// Add special "None" case.
m_SkyClassNames.Add(new GUIContent("None"));
m_SkyUniqueIDs.Add(0);
var skyTypesDict = SkyManager.skyTypesDict;
foreach (KeyValuePair<int, Type> kvp in skyTypesDict)
{
m_SkyClassNames.Add(new GUIContent(kvp.Value.Name.ToString()));
m_SkyUniqueIDs.Add(kvp.Key);
}
}
}
public override void OnInspectorGUI()
{
UpdateSkyIntPopupData();
using (new EditorGUILayout.HorizontalScope())
{
DrawOverrideCheckbox(m_SkyType);
using (new EditorGUI.DisabledScope(!m_SkyType.overrideState.boolValue))
{
EditorGUILayout.IntPopup(m_SkyType.value, m_SkyClassNames.ToArray(), m_SkyUniqueIDs.ToArray(), new GUIContent("Sky Type"));
}
}
PropertyField(m_FogType);
}
}
}
正在加载...
取消
保存