浏览代码

HDRenderLoop: Update Debug view mode for new parameters

+ Automatic update of inspector
+ create Debug Paramters function to call for builtin data, varyings and
surfaceData
/main
Sebastien Lagarde 8 年前
当前提交
bb06ff58
共有 17 个文件被更改,包括 981 次插入129 次删除
  1. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset
  2. 50
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  3. 45
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoopInspector.cs
  4. 43
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugCommon.hlsl
  5. 65
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lit.shader
  6. 30
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LitTemplate.hlsl
  7. 35
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.hlsl
  8. 90
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.hlsl
  9. 3
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl
  10. 4
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Unlit.shader
  11. 1
      Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl
  12. 15
      ProjectSettings/GraphicsSettings.asset
  13. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LitUI.cs.meta
  14. 8
      Assets/TestScenes/FPTL/Materials/FwdMat.mat.meta
  15. 695
      ScriptableRenderLoop.sdf
  16. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lit.cs.meta
  17. 0
      /Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LitUI.cs

2
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset


m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 558064ecdbf6b6742892d699acb39aed, type: 3}
m_Name: HDRenderLoop
m_Name:
m_EditorClassIdentifier:

50
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


public enum MaterialDebugMode
{
None = 0,
DiffuseColor = 1,
Normal = 2,
Depth = 3,
AmbientOcclusion = 4,
SpecularColor = 5,
SpecularOcclustion = 6,
Smoothness = 7,
MaterialId = 8,
UV0 = 9,
Tangent = 10,
Bitangent = 11
Depth = 1,
TexCoord0 = 2,
VertexNormalWS = 3,
VertexTangentWS = 4,
VertexBitangentWS = 5,
BakeDiffuseLighting = 100,
EmissiveColor = 101,
EmissiveIntensity = 102,
Velocity = 103,
Distortion = 104,
DistortionBlur = 105,
BaseColor = 1001,
SpecularOcclusion = 1002,
NormalWS = 1003,
PerceptualSmoothness = 1004,
MaterialId = 1005,
AmbientOcclusion = 1006,
TangentWS = 1007,
Anisotropy = 1008,
Metalic = 1009,
Specular = 1010,
SubSurfaceRadius = 1011,
Thickness = 1012,
SubSurfaceProfile = 1013,
CoatNormalWS = 1014,
CoatPerceptualSmoothness = 1015,
SpecularColor = 1016,
}
public enum GBufferDebugMode

{
ClearComputeBuffers();
// See Lit.hlsl for details
gbufferManager.SetBufferDescription(0, "_CameraGBufferTexture0", RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB); // Store diffuse color => sRGB
gbufferManager.SetBufferDescription(1, "_CameraGBufferTexture1", RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
gbufferManager.SetBufferDescription(2, "_CameraGBufferTexture2", RenderTextureFormat.ARGB2101010, RenderTextureReadWrite.Linear); // Store normal => higher precision
gbufferManager.SetBufferDescription(0, "_CameraGBufferTexture0", RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
gbufferManager.SetBufferDescription(1, "_CameraGBufferTexture1", RenderTextureFormat.ARGB2101010, RenderTextureReadWrite.Linear);
gbufferManager.SetBufferDescription(2, "_CameraGBufferTexture2", RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
gbufferManager.SetBufferDescription(3, "_CameraGBufferTexture3", RenderTextureFormat.RGB111110Float, RenderTextureReadWrite.Linear);
s_CameraColorBuffer = Shader.PropertyToID("_CameraColorTexture");

renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
Shader.SetGlobalInt("g_MaterialDebugMode", (int)debugParameters.materialDebugMode);
Shader.SetGlobalInt("_MaterialDebugMode", (int)debugParameters.materialDebugMode);
RenderOpaqueRenderList(cull, camera, renderLoop, "Debug");
RenderTransparentRenderList(cull, camera, renderLoop, "Debug");

45
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoopInspector.cs


public readonly GUIContent enableTonemap = new GUIContent("Enable Tonemap");
public readonly GUIContent exposure = new GUIContent("Exposure");
public readonly GUIContent[] materialDebugStrings = { new GUIContent("None"),
new GUIContent("Diffuse Color"),
new GUIContent("Normal"),
new GUIContent("Depth"),
new GUIContent("Ambient Occlusion"),
new GUIContent("Specular Color"),
new GUIContent("Specular Occlusion"),
new GUIContent("Smoothness"),
new GUIContent("MaterialId"),
new GUIContent("UV0"),
new GUIContent("Tangent"),
new GUIContent("Bitangent")
};
public readonly int[] materialDebugValues = { (int)HDRenderLoop.MaterialDebugMode.None,
(int)HDRenderLoop.MaterialDebugMode.DiffuseColor,
(int)HDRenderLoop.MaterialDebugMode.Normal,
(int)HDRenderLoop.MaterialDebugMode.Depth,
(int)HDRenderLoop.MaterialDebugMode.AmbientOcclusion,
(int)HDRenderLoop.MaterialDebugMode.SpecularColor,
(int)HDRenderLoop.MaterialDebugMode.SpecularOcclustion,
(int)HDRenderLoop.MaterialDebugMode.Smoothness,
(int)HDRenderLoop.MaterialDebugMode.MaterialId,
(int)HDRenderLoop.MaterialDebugMode.UV0,
(int)HDRenderLoop.MaterialDebugMode.Tangent,
(int)HDRenderLoop.MaterialDebugMode.Bitangent
};
public GUIContent[] materialDebugStrings = null;
public int[] materialDebugValues = null;
public readonly GUIContent[] gBufferDebugStrings = { new GUIContent("None"),
new GUIContent("Diffuse Color"),
new GUIContent("Normal"),

EditorGUILayout.LabelField(styles.debugParameters);
EditorGUI.indentLevel++;
EditorGUI.BeginChangeCheck();
if (styles.materialDebugStrings == null)
{
String[] names = Enum.GetNames(typeof(HDRenderLoop.MaterialDebugMode));
styles.materialDebugStrings = new GUIContent[names.Length];
styles.materialDebugValues = new int[names.Length];
int index = 0;
foreach (var value in Enum.GetValues(typeof(HDRenderLoop.MaterialDebugMode)))
{
styles.materialDebugStrings[index] = new GUIContent(names[index]);
styles.materialDebugValues[index] = (int)value;
index++;
}
}
debugParameters.gBufferDebugMode = (HDRenderLoop.GBufferDebugMode)EditorGUILayout.IntPopup(styles.gBufferDebugMode, (int)debugParameters.gBufferDebugMode, styles.gBufferDebugStrings, styles.gBufferDebugValues);
debugParameters.materialDebugMode = (HDRenderLoop.MaterialDebugMode)EditorGUILayout.IntPopup(styles.materialDebugMode, (int)debugParameters.materialDebugMode, styles.materialDebugStrings, styles.materialDebugValues);

43
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugCommon.hlsl


// List of material debug modes. Keep in sync with HDRenderLoop.MaterialDebugMode
#define MaterialDebugNone 0,
#define MaterialDebugDiffuseColor 1
#define MaterialDebugNormal 2
#define MaterialDebugDepth 3
#define MaterialDebugAO 4
#define MaterialDebugSpecularColor 5
#define MaterialDebugSpecularOcclusion 6
#define MaterialDebugSmoothness 7
#define MaterialDebugMaterialId 8
#define MaterialDebugUV0 9
#define MaterialDebugTangent 10
#define MaterialDebugBitangent 11
#define MaterialDebugNone 0
#define MaterialDebugDepth 1
#define MaterialDebugTexCoord0 2
#define MaterialDebugVertexNormalWS 3
#define MaterialDebugVertexTangentWS 4
#define MaterialDebugVertexBitangentWS 5
#define MaterialDebugBakeDiffuseLighting 100
#define MaterialDebugEmissiveColor 101
#define MaterialDebugEmissiveIntensity 102
#define MaterialDebugVelocity 103
#define MaterialDebugDistortion 104
#define MaterialDebugDistortionBlur 105
#define MaterialDebugBaseColor 1001
#define MaterialDebugSpecularOcclusion 1002
#define MaterialDebugNormalWS 1003
#define MaterialDebugPerceptualSmoothness 1004
#define MaterialDebugMaterialId 1005
#define MaterialDebugAmbientOcclusion 1006
#define MaterialDebugTangentWS 1007
#define MaterialDebugAnisotropy 1008
#define MaterialDebugMetalic 1009
#define MaterialDebugSpecular 1010
#define MaterialDebugSubSurfaceRadius 1011
#define MaterialDebugThickness 1012
#define MaterialDebugSubSurfaceProfile 1013
#define MaterialDebugCoatNormalWS 1014
#define MaterialDebugCoatPerceptualSmoothness 1015
#define MaterialDebugSpecularColor 1016
// List of GBuffer debug modes. Keep in sync with HDRenderLoop.GBufferDebugMode
#define GBufferDebugNone 0

65
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lit.shader


Cull[_CullMode]
HLSLPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
int g_MaterialDebugMode;
#include "Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl"
#include "Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugCommon.hlsl"
int _MaterialDebugMode;
#if SHADER_STAGE_FRAGMENT

float3 result = float3(1.0, 1.0, 0.0);
bool outputIsLinear = false;
if(g_MaterialDebugMode == MaterialDebugDiffuseColor)
{
result = surfaceData.baseColor;
}
else if (g_MaterialDebugMode == MaterialDebugNormal)
{
result = surfaceData.normalWS * 0.5 + 0.5;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugDepth)
{
float linearDepth = frac(LinearEyeDepth(input.positionHS.z, _ZBufferParams) * 0.1);
result = linearDepth.xxx;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugAO)
{
result = surfaceData.ambientOcclusion.xxx;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugSpecularColor)
{
result = surfaceData.metalic.xxx;
}
else if (g_MaterialDebugMode == MaterialDebugSpecularOcclusion)
{
result = surfaceData.specularOcclusion.xxx;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugSmoothness)
{
result = surfaceData.perceptualSmoothness.xxx;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugMaterialId)
{
result = surfaceData.materialId.xxx;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugUV0)
{
result = float3(input.texCoord0, 0.0);
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugTangent)
{
result = input.tangentToWorld[0].xyz * 0.5 + 0.5;
outputIsLinear = true;
}
else if (g_MaterialDebugMode == MaterialDebugBitangent)
{
result = input.tangentToWorld[1].xyz * 0.5 + 0.5;
outputIsLinear = true;
}
GetVaryingsDataDebug(_MaterialDebugMode, input, result, outputIsLinear);
GetSurfaceDataDebug(_MaterialDebugMode, surfaceData, result, outputIsLinear);
GetBuiltinDataDebug(_MaterialDebugMode, builtinData, result, outputIsLinear);
// TEMP!
// For now, the final blit in the backbuffer performs an sRGB write
// So in the meantime we apply the inverse transform to linear data to compensate.
if(outputIsLinear)

30
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LitTemplate.hlsl


builtinData.distortionBlur = 0.0;
}
void GetVaryingsDataDebug(uint paramId, Varyings input, inout float3 result, inout float outputIsLinear)
{
if (paramId == MaterialDebugDepth)
{
float linearDepth = frac(LinearEyeDepth(input.positionHS.z, _ZBufferParams) * 0.1);
result = linearDepth.xxx;
outputIsLinear = true;
}
else if (paramId == MaterialDebugTexCoord0)
{
result = float3(input.texCoord0, 0.0);
outputIsLinear = true;
}
else if (paramId == MaterialDebugVertexNormalWS)
{
result = input.tangentToWorld[2].xyz * 0.5 + 0.5;
outputIsLinear = true;
}
else if (paramId == MaterialDebugVertexTangentWS)
{
result = input.tangentToWorld[0].xyz * 0.5 + 0.5;
outputIsLinear = true;
}
else if (paramId == MaterialDebugVertexBitangentWS)
{
result = input.tangentToWorld[1].xyz * 0.5 + 0.5;
outputIsLinear = true;
}
}
#endif // #if SHADER_STAGE_FRAGMENT

35
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.hlsl


float distortionBlur; // Define the color buffer mipmap level to use
};
void GetBuiltinDataDebug(uint paramId, BuiltinData builtinData, inout float3 result, inout float outputIsLinear)
{
if (paramId == MaterialDebugBakeDiffuseLighting)
{
// TODO: require a remap
result = builtinData.bakeDiffuseLighting;
outputIsLinear = true;
}
else if (paramId == MaterialDebugEmissiveColor)
{
result = builtinData.emissiveColor;
outputIsLinear = true;
}
else if (paramId == MaterialDebugEmissiveIntensity)
{
// TODO: require a reamp
result = builtinData.emissiveIntensity.xxx;
outputIsLinear = true;
}
else if (paramId == MaterialDebugVelocity)
{
result = float3(builtinData.velocity, 0.0);
outputIsLinear = true;
}
else if (paramId == MaterialDebugDistortion)
{
result = float3(builtinData.distortion, 0.0);
outputIsLinear = true;
}
else if (paramId == MaterialDebugDistortionBlur)
{
result = builtinData.distortionBlur.xxx;
outputIsLinear = true;
}
}
#endif // UNITY_BUILTIN_DATA_INCLUDED

90
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.hlsl


#define GBUFFER_MATERIAL_COUNT 3
// Encode SurfaceData (BSDF parameters) into GBuffer
// Must be in sync with RT declared in HDRenderLoop.cs ::Rebuild
void EncodeIntoGBuffer( SurfaceData surfaceData,
out float4 outGBuffer0,
out float4 outGBuffer1,

}
return bsdfData;
}
//-----------------------------------------------------------------------------
// Debug method (use to display values)
//-----------------------------------------------------------------------------
void GetSurfaceDataDebug(uint paramId, SurfaceData surfaceData, inout float3 result, inout float outputIsLinear)
{
if (paramId == MaterialDebugBaseColor)
{
result = surfaceData.baseColor;
}
else if (paramId == MaterialDebugSpecularOcclusion)
{
result = surfaceData.specularOcclusion.xxx;
outputIsLinear = true;
}
else if (paramId == MaterialDebugNormalWS)
{
result = surfaceData.normalWS * 0.5 + 0.5;
outputIsLinear = true;
}
else if (paramId == MaterialDebugPerceptualSmoothness)
{
result = surfaceData.perceptualSmoothness.xxx;
outputIsLinear = true;
}
else if (paramId == MaterialDebugMaterialId)
{
// TODO: it is an enum display solid color instead
result = surfaceData.materialId.xxx;
outputIsLinear = true;
}
else if (paramId == MaterialDebugAmbientOcclusion)
{
result = surfaceData.ambientOcclusion.xxx;
outputIsLinear = true;
}
else if (paramId == MaterialDebugTangentWS)
{
result = surfaceData.tangentWS * 0.5 + 0.5;
outputIsLinear = true;
}
else if (paramId == MaterialDebugAnisotropy)
{
result = surfaceData.anisotropy.xxx;
outputIsLinear = true;
}
else if (paramId == MaterialDebugMetalic)
{
result = surfaceData.metalic.xxx;
outputIsLinear = true;
}
else if (paramId == MaterialDebugSpecular)
{
// TODO: may require a reamp
result = surfaceData.specular.xxx;
outputIsLinear = true;
}
else if (paramId == MaterialDebugSubSurfaceRadius)
{
result = surfaceData.subSurfaceRadius.xxx;
outputIsLinear = true;
}
else if (paramId == MaterialDebugThickness)
{
result = surfaceData.thickness.xxx;
outputIsLinear = true;
}
else if (paramId == MaterialDebugSubSurfaceProfile)
{
// TODO: require solid color
result = surfaceData.subSurfaceProfile.xxx;
outputIsLinear = true;
}
else if (paramId == MaterialDebugCoatNormalWS)
{
result = surfaceData.coatNormalWS * 0.5 + 0.5;
outputIsLinear = true;
}
else if (paramId == MaterialDebugCoatPerceptualSmoothness)
{
result = surfaceData.coatPerceptualSmoothness.xxx;
outputIsLinear = true;
}
else if (paramId == MaterialDebugSpecularColor)
{
result = surfaceData.specularColor;
}
}
//-----------------------------------------------------------------------------

3
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl


#include "Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl"
#include "Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Shaderconfig.cs"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderConfig.cs"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugCommon.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LightDefinition.cs.hlsl"
//-----------------------------------------------------------------------------

4
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Unlit.shader


float4 _Color;
sampler2D _ColorMap;
float4 _EmissiveColor;
float3 _EmissiveColor;
sampler2D _EmissiveColorMap;
float _EmissiveIntensity;

void GetSurfaceAndBuiltinData(Varyings input, out SurfaceData surfaceData, out BuiltinData builtinData)
{
surfaceData.color = tex2D(_ColorMap, input.texCoord0).rgb * _Color.rgb;
float alpha = tex2D(_ColorMap, input.texCoord0).a * _Color.rgb;
float alpha = tex2D(_ColorMap, input.texCoord0).a * _Color.a;
#ifdef _ALPHATEST_ON
clip(alpha - _AlphaCutoff);

1
Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl


float D_GGX(float NdotH, float roughness)
{
roughness = max(roughness, UNITY_MIN_ROUGHNESS);
float a2 = roughness * roughness;
float f = (NdotH * a2 - NdotH) * NdotH + 1.0;
return INV_PI * a2 / (f * f);

15
ProjectSettings/GraphicsSettings.asset


--- !u!30 &1
GraphicsSettings:
m_ObjectHideFlags: 0
serializedVersion: 9
serializedVersion: 10
m_Deferred:
m_Mode: 0
m_Shader: {fileID: 0}

- {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 10782, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 4800000, guid: 36c23fe83f8e7a54d8fb168fa6cf2a3d, type: 3}
- {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0}

useHDR: 0
hdrMode: 0
useHDR: 0
hdrMode: 0
useHDR: 0
hdrMode: 0
m_DefaultRenderingPath: 1
m_DefaultMobileRenderingPath: 1
m_TierSettings:

m_Settings:
standardShaderQuality: 2
renderingPath: 1
hdrMode: 0
useHDR: 0
useDetailNormalMap: 1
useCascadedShadowMaps: 1
useDitherMaskForAlphaBlendedShadows: 1

m_Settings:
standardShaderQuality: 2
renderingPath: 1
hdrMode: 0
useHDR: 0
useDetailNormalMap: 1
useCascadedShadowMaps: 1
useDitherMaskForAlphaBlendedShadows: 1

m_Settings:
standardShaderQuality: 2
renderingPath: 1
hdrMode: 0
useHDR: 0
useDetailNormalMap: 1
useCascadedShadowMaps: 1
useDitherMaskForAlphaBlendedShadows: 1

12
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LitUI.cs.meta


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

8
Assets/TestScenes/FPTL/Materials/FwdMat.mat.meta


fileFormatVersion: 2
guid: 24e6a15bf9d2c0944b380d860a738528
timeCreated: 1475863528
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

695
ScriptableRenderLoop.sdf
文件差异内容过多而无法显示
查看文件

12
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lit.cs.meta


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

/Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lit.cs → /Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LitUI.cs

正在加载...
取消
保存