浏览代码

Merge branch 'master'

/RenderPassXR_Sandbox
Evgenii Golubev 8 年前
当前提交
414344b8
共有 11 个文件被更改,包括 121 次插入159 次删除
  1. 26
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemUI.cs
  2. 41
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuManager.cs
  3. 101
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuState.cs
  4. 36
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanel.cs
  5. 30
      Assets/ScriptableRenderPipeline/Core/Debugging/Editor/DebugMenuEditor.cs
  6. 1
      Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateColor.cs
  7. 14
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
  8. 1
      Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawSssProfile.shader
  9. 4
      Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawTransmittanceGraph.shader
  10. 18
      Assets/ScriptableRenderPipeline/ShaderLibrary/CommonMaterial.hlsl
  11. 8
      ProjectSettings/EditorBuildSettings.asset

26
Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemUI.cs


string finalValue = new string(valueWithMaxDecimals.ToCharArray(), 0, index + 1);
// Add leading zeros until we reach where the current order is being edited.
if(m_CurrentIncrementIndex > 0)
if (m_CurrentIncrementIndex > 0)
if(incrementValue > currentValue)
if (incrementValue > currentValue)
{
float compareValue = currentValue + 1.0f; // Start at 1.0f because we know that we are going to increment by 10 or more
while (incrementValue > compareValue)

}
// When selecting which decimal/order you want to edit, we show brackets around the figure to show the user.
if(m_SelectIncrementMode)
if (m_SelectIncrementMode)
if(m_CurrentIncrementIndex >= 0) // Skip separator
if (m_CurrentIncrementIndex >= 0) // Skip separator
bracketIndex -= 1;
finalValue = finalValue.Insert(bracketIndex, "[");

if(isNegative)
if (isNegative)
finalValue = finalValue.Insert(0, "-");
m_Value.GetComponent<UI.Text>().text = finalValue;

public override void OnIncrement()
{
if(!m_SelectIncrementMode)
if (!m_SelectIncrementMode)
{
m_DebugItem.SetValue((float)m_DebugItem.GetValue() + Mathf.Pow(10.0f, (float)m_CurrentIncrementIndex));
}

{
m_CurrentIncrementIndex += 1; // * 10 (10^m_CurrentIncrementIndex)
}
Update();
Update();
}
}

string finalValue = string.Format("{0}", value);
// Add leading zeros until we reach where the current order is being edited.
if(m_CurrentIncrementIndex > 0)
if (m_CurrentIncrementIndex > 0)
if(incrementValue > value)
if (incrementValue > value)
{
int compareValue = System.Math.Max(value, 1);
while (incrementValue > compareValue)

}
// When selecting which decimal/order you want to edit, we show brackets around the figure to show the user.
if(m_SelectIncrementMode)
if (m_SelectIncrementMode)
{
int bracketIndex = finalValue.Length - 1 - m_CurrentIncrementIndex;

if(isNegative)
if (isNegative)
finalValue = finalValue.Insert(0, "-");
m_Value.GetComponent<UI.Text>().text = finalValue;

private int FindIndexForValue(int value)
{
for(int i = 0 ; i < m_Values.Length ; ++i)
for (int i = 0; i < m_Values.Length; ++i)
{
if (m_Values[i] == value)
return i;

public override void Update()
{
if(m_CurrentValueIndex != -1)
if (m_CurrentValueIndex != -1)
{
m_Value.GetComponent<UI.Text>().text = m_ValueNames[m_CurrentValueIndex].text;
}

41
Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuManager.cs


public class DebugMenuManager
{
private static DebugMenuManager s_Instance = null;
private static string s_MenuStateAssetPath = "Assets/DebugMenuState.asset";
private DebugMenuState m_DebugMenuState = null;
static public DebugMenuManager instance
{

{
s_Instance = new DebugMenuManager();
s_Instance.Initialize();
}
return s_Instance;

List<DebugPanel> m_DebugPanels = new List<DebugPanel>();
DebugPanel m_PersistentDebugPanel = null;
DebugMenuUI m_DebugMenuUI = null;
bool m_UpdateFromItemStateRequired = false;
public int panelCount { get { return m_DebugPanels.Count; } }
public DebugMenuUI menuUI { get { return m_DebugMenuUI; } }

}
}
private void Initialize()
{
#if UNITY_EDITOR
m_DebugMenuState = UnityEditor.AssetDatabase.LoadAssetAtPath<DebugMenuState>(s_MenuStateAssetPath);
if (m_DebugMenuState == null)
{
m_DebugMenuState = ScriptableObject.CreateInstance<DebugMenuState>();
UnityEditor.AssetDatabase.CreateAsset(m_DebugMenuState, s_MenuStateAssetPath);
}
#endif
}
public void RequireUpdateFromDebugItemState()
{
m_UpdateFromItemStateRequired = true;
}
// debug state will be null at runtime.
public DebugItemState FindDebugItemState(string itemName, string menuName)
{
return (m_DebugMenuState != null) ? m_DebugMenuState.FindDebugItemState(itemName, menuName) : null;
}
public void AddDebugItemState(DebugItemState state)
{
if(m_DebugMenuState != null)
m_DebugMenuState.AddDebugItemState(state);
}
public DebugPanel GetDebugPanel(int index)
{
if (index < m_DebugPanels.Count)

public void Update()
{
m_DebugMenuUI.Update();
if(m_UpdateFromItemStateRequired)
{
m_UpdateFromItemStateRequired = false;
m_DebugMenuState.UpdateAllDebugItems();
}
}
private void AddDebugPanel(DebugPanel panel)

101
Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuState.cs


public string panelName = "";
public string itemName = "";
protected DebugItem m_DebugItem = null;
public bool isValid { get { return m_DebugItem != null; } }
public void Initialize(string itemName, string panelName)
public void Initialize(DebugItem item)
this.panelName = panelName;
this.itemName = itemName;
this.panelName = item.panelName;
this.itemName = item.name;
m_DebugItem = item;
}
}

public override void SetValue(object value)
{
#if UNITY_EDITOR
UnityEditor.Undo.RecordObject(this, "DebugMenu State Update");
UnityEditor.EditorUtility.SetDirty(this);
#endif
DebugMenuManager dmm = DebugMenuManager.instance;
DebugPanel menu = dmm.GetDebugPanel(panelName);
if (menu != null)
if(m_DebugItem == null)
DebugItem item = menu.GetDebugItem(itemName);
if (item != null)
if (itemName != "" && panelName != "")
item.SetValue(value, false);
DebugMenuManager dmm = DebugMenuManager.instance;
DebugPanel menu = dmm.GetDebugPanel(panelName);
if (menu != null)
{
m_DebugItem = menu.GetDebugItem(itemName);
}
m_DebugItem.SetValue(value, false);
}
}

UnityEditor.Undo.undoRedoPerformed += OnUndoRedoPerformed;
#endif
// We need to delay the actual update because at this point, some menus might not be created yet (depending on call order) so we can't update their values.
DebugMenuManager.instance.RequireUpdateFromDebugItemState();
// Populate item states
DebugMenuManager dmm = DebugMenuManager.instance;
for (int panelIdx = 0 ; panelIdx < dmm.panelCount ; ++panelIdx)
{
DebugPanel panel = dmm.GetDebugPanel(panelIdx);
for(int itemIdx = 0 ; itemIdx < panel.itemCount ; ++itemIdx)
{
DebugItem item = panel.GetDebugItem(itemIdx);
DebugItemState debugItemState = FindDebugItemState(item);
if (debugItemState == null)
{
debugItemState = item.handler.CreateDebugItemState();
debugItemState.hideFlags = HideFlags.DontSave;
debugItemState.Initialize(item);
debugItemState.SetValue(item.GetValue());
AddDebugItemState(debugItemState);
}
}
}
UpdateAllDebugItems();
}
public void OnDisable()

#endif
// We check consistency in OnDisable instead of OnEnable because we compare the serialized state to the currently running debug menu so we need to make sure that all debug menu are properly created (which is not the case in OnEnable depending on call order)
CheckConsistency();
public void OnDestroy()
{
foreach(var item in m_ItemStateList)
{
Object.DestroyImmediate(item);
}
}
#if UNITY_EDITOR
#if UNITY_EDITOR
}
void CheckConsistency()
{
// Remove all objects that may have been removed from the debug menu since last serialization
DebugMenuManager dmm = DebugMenuManager.instance;
List<DebugItemState> tempList = new List<DebugItemState>();
foreach(var itemState in m_ItemStateList)
{
DebugItem item = null;
DebugPanel menu = dmm.GetDebugPanel(itemState.panelName);
if(menu != null)
{
item = menu.GetDebugItem(itemState.itemName);
}
// Item no longer exist, clean up its state from the asset.
if (item == null)
{
tempList.Add(itemState);
}
}
foreach(var itemState in tempList)
{
m_ItemStateList.Remove(itemState);
Object.DestroyImmediate(itemState, true);
}
#if UNITY_EDITOR
UnityEditor.AssetDatabase.AddObjectToAsset(state, this);
#endif
public DebugItemState FindDebugItemState(string itemName, string menuName)
public DebugItemState FindDebugItemState(DebugItem item)
return m_ItemStateList.Find(x => x.itemName == itemName && x.panelName == menuName);
return m_ItemStateList.Find(x => x.itemName == item.name && x.panelName == item.panelName);
}
public void UpdateAllDebugItems()

}
}
}
}
}

36
Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanel.cs


{
public class DebugItem
{
static public event Action<DebugItem> OnItemDirty;
public string panelName { get { return m_PanelName; } }
public DebugItem(string name, Type type, Func<object> getter, Action<object> setter, bool dynamicDisplay = false, DebugItemHandler handler = null)
public DebugItem(string name, string panelName, Type type, Func<object> getter, Action<object> setter, bool dynamicDisplay = false, DebugItemHandler handler = null)
m_PanelName = panelName;
m_Handler = handler;
m_DynamicDisplay = dynamicDisplay;
}

{
m_Setter(value);
m_Handler.ClampValues(m_Getter, m_Setter);
// Update state for serialization/undo
if(record && m_State != null)
m_State.SetValue(m_Getter());
if (record && OnItemDirty != null)
OnItemDirty(this);
}
public void SetDebugItemState(DebugItemState state)
{
m_State = state;
}
Func<object> m_Getter;

string m_PanelName;
DebugItemState m_State = null;
}
public class DebugPanel

m_DebugPanelUI.RebuildGUI();
}
public void AddDebugItem<ItemType>(string name, Func<object> getter, Action<object> setter, bool dynamicDisplay = false, DebugItemHandler handler = null)
public void AddDebugItem<ItemType>(string itemName, Func<object> getter, Action<object> setter, bool dynamicDisplay = false, DebugItemHandler handler = null)
DebugItem newItem = new DebugItem(name, typeof(ItemType), getter, setter, dynamicDisplay, handler);
DebugItem newItem = new DebugItem(itemName, m_Name, typeof(ItemType), getter, setter, dynamicDisplay, handler);
DebugMenuManager dmm = DebugMenuManager.instance;
DebugItemState itemState = dmm.FindDebugItemState(name, m_Name);
if(itemState == null)
{
itemState = handler.CreateDebugItemState();
itemState.Initialize(name, m_Name);
itemState.SetValue(getter());
dmm.AddDebugItemState(itemState);
}
newItem.SetDebugItemState(itemState);
}
}

30
Assets/ScriptableRenderPipeline/Core/Debugging/Editor/DebugMenuEditor.cs


// This is the class that handles rendering the debug menu in the editor (as opposed to the runtime version in the player)
public class DebugMenuEditor : EditorWindow
{
[SerializeField]
private DebugMenuState m_DebugMenuState;
[MenuItem("HDRenderPipeline/Debug Menu")]
static void DisplayDebugMenu()

DebugMenuManager m_DebugMenu = null;
DebugMenuEditor()
void OnEnable()
m_DebugMenu = DebugMenuManager.instance;
DebugItem.OnItemDirty += DebugItem_OnDirty;
if(m_DebugMenuState == null)
{
m_DebugMenuState = ScriptableObject.CreateInstance<DebugMenuState>();
m_DebugMenuState.hideFlags = HideFlags.DontSave;
}
void OnEnable()
void OnDisable()
m_DebugMenu = DebugMenuManager.instance;
DebugItem.OnItemDirty -= DebugItem_OnDirty;
}
void OnDestroy()
{
Object.DestroyImmediate(m_DebugMenuState);
}
void DebugItem_OnDirty(DebugItem item)
{
DebugItemState debugItemState = m_DebugMenuState.FindDebugItemState(item);
UnityEditor.Undo.RecordObject(debugItemState, "DebugMenu State Update");
debugItemState.SetValue(item.GetValue());
EditorUtility.SetDirty(m_DebugMenuState);
}
void OnGUI()

1
Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateColor.cs


{
}
}

14
Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl


#endif
}
// Computes the fraction of light passing through the object.
// Evaluate Int{0, inf}{2 * Pi * r * R(sqrt(r^2 + d^2))}, where R is the diffusion profile.
// Ref: Approximate Reflectance Profiles for Efficient Subsurface Scattering by Pixar (BSSRDF only).
float3 ComputeTransmittance(float3 S, float3 volumeAlbedo, float thickness, float radiusScale)
{
// Thickness and SSS radius are decoupled for artists.
// In theory, we should modify the thickness by the inverse of the radius scale of the profile.
// thickness /= radiusScale;
float3 expOneThird = exp(((-1.0 / 3.0) * thickness) * S);
return 0.25 * (expOneThird + 3 * expOneThird * expOneThird * expOneThird) * volumeAlbedo;
}
void FillMaterialIdStandardData(float3 baseColor, float specular, float metallic, float roughness, float3 normalWS, float3 tangentWS, float anisotropy, inout BSDFData bsdfData)
{
bsdfData.diffuseColor = baseColor * (1.0 - metallic);

1
Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawSssProfile.shader


//-------------------------------------------------------------------------------------
#include "../../../ShaderLibrary/Common.hlsl"
#include "../../../ShaderLibrary/Color.hlsl"
#include "../../ShaderVariables.hlsl"
//-------------------------------------------------------------------------------------

4
Assets/ScriptableRenderPipeline/HDRenderPipeline/SceneSettings/Resources/DrawTransmittanceGraph.shader


// Include
//-------------------------------------------------------------------------------------
#include "../../../ShaderLibrary/CommonMaterial.hlsl"
#include "../../../ShaderLibrary/Color.hlsl"
#define UNITY_MATERIAL_LIT // Needs to be defined before including Material.hlsl
#include "../../Material/Material.hlsl"
//-------------------------------------------------------------------------------------
// Inputs & outputs

18
Assets/ScriptableRenderPipeline/ShaderLibrary/CommonMaterial.hlsl


return float3(oneMinusT, oneMinusT, oneMinusT) + b * t;
}
// ----------------------------------------------------------------------------
// SSS/Transmittance
// ----------------------------------------------------------------------------
// Computes the fraction of light passing through the object.
// Evaluate Int{0, inf}{2 * Pi * r * R(sqrt(r^2 + d^2))}, where R is the diffusion profile.
// Ref: Approximate Reflectance Profiles for Efficient Subsurface Scattering by Pixar (BSSRDF only).
float3 ComputeTransmittance(float3 S, float3 volumeAlbedo, float thickness, float radiusScale)
{
// Thickness and SSS radius are decoupled for artists.
// In theory, we should modify the thickness by the inverse of the radius scale of the profile.
// thickness /= radiusScale;
float3 expOneThird = exp(((-1.0 / 3.0) * thickness) * S);
return 0.25 * (expOneThird + 3 * expOneThird * expOneThird * expOneThird) * volumeAlbedo;
}
// MACRO from Legacy Untiy
// Transforms 2D UV by scale/bias property
#define TRANSFORM_TEX(tex, name) ((tex.xy) * name##_ST.xy + name##_ST.zw)

8
ProjectSettings/EditorBuildSettings.asset


m_ObjectHideFlags: 0
serializedVersion: 2
m_Scenes:
- enabled: 0
- enabled: 1
- enabled: 1
path: Assets/TestScenes/HDTest/NewBatcherBench1.unity
guid: efeef759b5144ef4fa1cfc182ddbaea5
- enabled: 0
path: Assets/TestScenes/HDTest/NewBatcherBench2.unity
guid: 1816611d7c1a9bc41bbe1ae56076f699
正在加载...
取消
保存