浏览代码

HDRenderLoop: Add automatic support for material propery debug

- Modify shader generator to automatically generate define from struct
- Add attribute to be able to control display name and enum start value
- Refactor the whole debugging code for debug view material properties
- Rename a few thing
/main
Sebastien Lagarde 8 年前
当前提交
de43ba96
共有 27 个文件被更改,包括 833 次插入561 次删除
  1. 155
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  2. 120
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoopInspector.cs
  3. 17
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lit.shader
  4. 50
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LitTemplate.hlsl
  5. 80
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.hlsl
  6. 265
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.hlsl
  7. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl
  8. 2
      Assets/ShaderGenerator/CSharpToHLSL.cs
  9. 39
      Assets/ShaderGenerator/ShaderTypeGeneration.cs
  10. 14
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterial.hlsl
  11. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterial.hlsl.meta
  12. 100
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterialGBuffer.shader
  13. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterialGBuffer.shader.meta
  14. 38
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.cs
  15. 29
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.cs.hlsl
  16. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.cs.hlsl.meta
  17. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.cs.meta
  18. 113
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.cs
  19. 89
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.cs.hlsl
  20. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.cs.hlsl.meta
  21. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.cs.meta
  22. 34
      Assets/ScriptableRenderLoop/ShaderLibrary/Debug.hlsl
  23. 9
      Assets/ScriptableRenderLoop/ShaderLibrary/Debug.hlsl.meta
  24. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugCommon.hlsl.meta
  25. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/GBufferDebug.shader.meta
  26. 116
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/GBufferDebug.shader
  27. 44
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugCommon.hlsl

155
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


{
private static string m_HDRenderLoopPath = "Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset";
// Debugging
public enum MaterialDebugMode
// Must be in sync with DebugViewMaterial.hlsl
public enum DebugViewVaryingMode
None = 0,
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
// Must be in sync with DebugViewMaterial.hlsl
public enum DebugViewGbufferMode
None = 0,
DiffuseColor = 1,
Normal = 2,
Depth = 3,
BakedDiffuse = 4,
SpecularColor = 5,
SpecularOcclustion = 6,
Smoothness = 7,
MaterialId = 8,
Depth = 6,
BakeDiffuseLighting = 7,
public MaterialDebugMode materialDebugMode = MaterialDebugMode.None;
public GBufferDebugMode gBufferDebugMode = GBufferDebugMode.None;
public int debugViewMaterial = 0;
// Rendering debugging
public bool displayOpaqueObjects = true;

Material m_FinalPassMaterial;
// Debug
Material m_GBufferDebugMaterial;
Material m_DebugViewMaterialGBuffer;
GBufferManager gbufferManager = new GBufferManager();

m_FinalPassMaterial = CreateEngineMaterial("Hidden/Unity/FinalPass");
// Debug
m_GBufferDebugMaterial = CreateEngineMaterial("Hidden/Unity/GBufferDebug");
m_DebugViewMaterialGBuffer = CreateEngineMaterial("Hidden/Unity/DebugViewMaterialGBuffer");
// m_ShadowPass = new ShadowRenderPass (m_ShadowSettings);
}

RenderOpaqueRenderList(cull, camera, renderLoop, "GBuffer");
}
void RenderMaterialDebug(CullResults cull, Camera camera, RenderLoop renderLoop)
void RenderDebugViewMaterial(CullResults cull, Camera camera, RenderLoop renderLoop)
// setup GBuffer for rendering
var cmd = new CommandBuffer();
cmd.name = "Material Debug Pass";
cmd.GetTemporaryRT(s_CameraColorBuffer, camera.pixelWidth, camera.pixelHeight, 0, FilterMode.Point, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
cmd.GetTemporaryRT(s_CameraDepthBuffer, camera.pixelWidth, camera.pixelHeight, 24, FilterMode.Point, RenderTextureFormat.Depth);
cmd.SetRenderTarget(new RenderTargetIdentifier(s_CameraColorBuffer), new RenderTargetIdentifier(s_CameraDepthBuffer));
cmd.ClearRenderTarget(true, true, new Color(0, 0, 0, 0));
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
// Render Opaque forward
{
var cmd = new CommandBuffer();
cmd.name = "DebugView Material Mode Pass";
cmd.SetRenderTarget(new RenderTargetIdentifier(s_CameraColorBuffer), new RenderTargetIdentifier(s_CameraDepthBuffer));
cmd.ClearRenderTarget(true, true, new Color(0, 0, 0, 0));
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
Shader.SetGlobalInt("_DebugViewMaterial", (int)debugParameters.debugViewMaterial);
Shader.SetGlobalInt("_MaterialDebugMode", (int)debugParameters.materialDebugMode);
RenderOpaqueRenderList(cull, camera, renderLoop, "DebugView");
}
RenderOpaqueRenderList(cull, camera, renderLoop, "Debug");
RenderTransparentRenderList(cull, camera, renderLoop, "Debug");
// Render GBUffer opaque
{
Vector4 screenSize = ComputeScreenSize(camera);
m_DebugViewMaterialGBuffer.SetVector("_ScreenSize", screenSize);
m_DebugViewMaterialGBuffer.SetFloat("_DebugViewMaterial", (float)debugParameters.debugViewMaterial);
cmd = new CommandBuffer();
cmd.name = "Blit Material Debug";
cmd.Blit(s_CameraColorBuffer, BuiltinRenderTextureType.CameraTarget);
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
// gbufferManager.BindBuffers(m_DeferredMaterial);
// TODO: Bind depth textures
var cmd = new CommandBuffer();
cmd.name = "GBuffer Debug Pass";
cmd.Blit(null, new RenderTargetIdentifier(s_CameraColorBuffer), m_DebugViewMaterialGBuffer, 0);
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
void RenderGBufferDebug(Camera camera, RenderLoop renderLoop)
{
Matrix4x4 invViewProj = GetViewProjectionMatrix(camera).inverse;
m_GBufferDebugMaterial.SetMatrix("_InvViewProjMatrix", invViewProj);
}
Vector4 screenSize = ComputeScreenSize(camera);
m_GBufferDebugMaterial.SetVector("_ScreenSize", screenSize);
m_GBufferDebugMaterial.SetFloat("_DebugMode", (float)debugParameters.gBufferDebugMode);
// Render forward transparent
{
RenderTransparentRenderList(cull, camera, renderLoop, "DebugView");
}
// gbufferManager.BindBuffers(m_DeferredMaterial);
// TODO: Bind depth textures
var cmd = new CommandBuffer();
cmd.name = "GBuffer Debug Pass";
cmd.Blit(null, BuiltinRenderTextureType.CameraTarget, m_GBufferDebugMaterial, 0);
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
// Last blit
{
var cmd = new CommandBuffer();
cmd.name = "Blit DebugView Material Debug";
cmd.Blit(s_CameraColorBuffer, BuiltinRenderTextureType.CameraTarget);
renderLoop.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
}
Matrix4x4 GetViewProjectionMatrix(Camera camera)

void RenderForward(CullResults cullResults, Camera camera, RenderLoop renderLoop)
{
// setup GBuffer for rendering
var cmd = new CommandBuffer();
cmd.name = "Forward Pass";
cmd.SetRenderTarget(new RenderTargetIdentifier(s_CameraColorBuffer), new RenderTargetIdentifier(s_CameraDepthBuffer));

renderLoop.SetupCameraProperties (camera);
//UpdateLightConstants(cullResults.culledLights /*, ref shadows */);
bool needDebugRendering = debugParameters.materialDebugMode != MaterialDebugMode.None || debugParameters.gBufferDebugMode != GBufferDebugMode.None;
//UpdateLightConstants(cullResults.culledLights /*, ref shadows */);
if (!needDebugRendering)
{
UpdatePunctualLights(cullResults.culledLights);
UpdatePunctualLights(cullResults.culledLights);
InitAndClearBuffer(camera, renderLoop);
InitAndClearBuffer(camera, renderLoop);
RenderGBuffer(cullResults, camera, renderLoop);
RenderGBuffer(cullResults, camera, renderLoop);
if (debugParameters.debugViewMaterial != 0)
{
RenderDebugViewMaterial(cullResults, camera, renderLoop);
}
else
{
}
else
{
if(debugParameters.materialDebugMode != MaterialDebugMode.None)
{
RenderMaterialDebug(cullResults, camera, renderLoop);
}
else if (debugParameters.gBufferDebugMode != GBufferDebugMode.None)
{
InitAndClearBuffer(camera, renderLoop);
RenderGBuffer(cullResults, camera, renderLoop);
RenderGBufferDebug(camera, renderLoop);
}
}
renderLoop.Submit ();

120
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoopInspector.cs


using System.Collections;
using UnityEngine.Rendering;
using System.Collections.Generic;
using System.Reflection;
using System;
using UnityEditor;

private class Styles
{
public readonly GUIContent debugParameters = new GUIContent("Debug Parameters");
public readonly GUIContent materialDebugMode = new GUIContent("Material Debug Mode", "Display various properties of Materials.");
public readonly GUIContent gBufferDebugMode = new GUIContent("GBuffer Debug Mode", "Display various properties of contained in the GBuffer.");
public readonly GUIContent debugViewMaterial = new GUIContent("DebugView Material", "Display various properties of Materials.");
public readonly GUIContent displayOpaqueObjects = new GUIContent("Display Opaque Objects", "Toggle opaque objects rendering on and off.");
public readonly GUIContent displayTransparentObjects = new GUIContent("Display Transparent Objects", "Toggle transparent objects rendering on and off.");

public GUIContent[] materialDebugStrings = null;
public int[] materialDebugValues = null;
public readonly GUIContent[] gBufferDebugStrings = { new GUIContent("None"),
new GUIContent("Diffuse Color"),
new GUIContent("Normal"),
new GUIContent("Depth"),
new GUIContent("Baked Diffuse"),
new GUIContent("Specular Color"),
new GUIContent("Specular Occlusion"),
new GUIContent("Smoothness"),
new GUIContent("MaterialId")
};
public readonly int[] gBufferDebugValues = { (int)HDRenderLoop.GBufferDebugMode.None,
(int)HDRenderLoop.GBufferDebugMode.DiffuseColor,
(int)HDRenderLoop.GBufferDebugMode.Normal,
(int)HDRenderLoop.GBufferDebugMode.Depth,
(int)HDRenderLoop.GBufferDebugMode.BakedDiffuse,
(int)HDRenderLoop.GBufferDebugMode.SpecularColor,
(int)HDRenderLoop.GBufferDebugMode.SpecularOcclustion,
(int)HDRenderLoop.GBufferDebugMode.Smoothness,
(int)HDRenderLoop.GBufferDebugMode.MaterialId
};
public bool isDebugViewMaterialInit = false;
public GUIContent[] debugViewMaterialStrings = null;
public int[] debugViewMaterialValues = null;
}
private static Styles s_Styles = null;

public override void OnInspectorGUI()
void FillWithProperties(Type type, GUIContent[] debugViewMaterialStrings, int[] debugViewMaterialValues, bool isBSDFData, ref int index)
{
object[] attributes = type.GetCustomAttributes(true);
// Get attribute to get the start number of the value for the enum
GenerateHLSL attr = attributes[0] as GenerateHLSL;
FieldInfo[] fields = type.GetFields();
string subNamespace = type.Namespace.Substring(type.Namespace.LastIndexOf((".")) + 1);
int localIndex = 0;
foreach (var field in fields)
{
string name = field.Name;
// Check if the display name have been override by the users
if (Attribute.IsDefined(field, typeof(SurfaceDataAttributes)))
{
var propertyAttr = (SurfaceDataAttributes[])field.GetCustomAttributes(typeof(SurfaceDataAttributes), false);
if (propertyAttr[0].displayName != "")
{
name = propertyAttr[0].displayName;
}
}
name = (isBSDFData ? "Engine/" : "") + subNamespace + "/" + name;
debugViewMaterialStrings[index] = new GUIContent(name);
debugViewMaterialValues[index] = attr.debugCounterStart + (int)localIndex;
index++;
localIndex++;
}
}
void FillWithPropertiesEnum(Type type, GUIContent[] debugViewMaterialStrings, int[] debugViewMaterialValues, bool isBSDFData, ref int index)
{
String[] names = Enum.GetNames(type);
int localIndex = 0;
foreach (var value in Enum.GetValues(type))
{
string name = (isBSDFData ? "Engine/" : "") + names[localIndex];
debugViewMaterialStrings[index] = new GUIContent(name);
debugViewMaterialValues[index] = (int)value;
index++;
localIndex++;
}
}
public override void OnInspectorGUI()
{
HDRenderLoop renderLoop = target as HDRenderLoop;
if(renderLoop)

EditorGUI.indentLevel++;
EditorGUI.BeginChangeCheck();
if (styles.materialDebugStrings == null)
if (!styles.isDebugViewMaterialInit)
String[] names = Enum.GetNames(typeof(HDRenderLoop.MaterialDebugMode));
String[] varyingNames = Enum.GetNames(typeof(HDRenderLoop.DebugViewVaryingMode));
String[] GBufferNames = Enum.GetNames(typeof(HDRenderLoop.DebugViewGbufferMode));
// +1 for the zero case
int num = 1 + varyingNames.Length
+ GBufferNames.Length
+ typeof(Builtin.BuiltinData).GetFields().Length
+ typeof(Lit.SurfaceData).GetFields().Length
+ typeof(Lit.BSDFData).GetFields().Length;
styles.materialDebugStrings = new GUIContent[names.Length];
styles.materialDebugValues = new int[names.Length];
styles.debugViewMaterialStrings = new GUIContent[num];
styles.debugViewMaterialValues = new int[num];
foreach (var value in Enum.GetValues(typeof(HDRenderLoop.MaterialDebugMode)))
{
styles.materialDebugStrings[index] = new GUIContent(names[index]);
styles.materialDebugValues[index] = (int)value;
index++;
}
// 0 is a reserved number
styles.debugViewMaterialStrings[0] = new GUIContent("None");
styles.debugViewMaterialValues[0] = 0;
index++;
FillWithPropertiesEnum(typeof(HDRenderLoop.DebugViewVaryingMode), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, ref index);
FillWithProperties(typeof(Builtin.BuiltinData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, ref index);
FillWithProperties(typeof(Lit.SurfaceData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, ref index);
// Engine
FillWithPropertiesEnum(typeof(HDRenderLoop.DebugViewGbufferMode), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, true, ref index);
FillWithProperties(typeof(Lit.BSDFData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, true, ref index);
styles.isDebugViewMaterialInit = true;
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);
debugParameters.debugViewMaterial = EditorGUILayout.IntPopup(styles.debugViewMaterial, (int)debugParameters.debugViewMaterial, styles.debugViewMaterialStrings, styles.debugViewMaterialValues);
EditorGUILayout.Space();
debugParameters.enableTonemap = EditorGUILayout.Toggle(styles.enableTonemap, debugParameters.enableTonemap);

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


Pass
{
Name "Debug"
Tags { "LightMode" = "Debug" }
Tags { "LightMode" = "DebugView" }
Cull[_CullMode]

#include "Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl"
int _MaterialDebugMode;
int _DebugViewMaterial;
#if SHADER_STAGE_FRAGMENT

BuiltinData builtinData;
GetSurfaceAndBuiltinData(input, surfaceData, builtinData);
BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData);
bool outputIsLinear = false;
bool needLinearToSRGB = false;
GetVaryingsDataDebug(_MaterialDebugMode, input, result, outputIsLinear);
GetSurfaceDataDebug(_MaterialDebugMode, surfaceData, result, outputIsLinear);
GetBuiltinDataDebug(_MaterialDebugMode, builtinData, result, outputIsLinear);
GetVaryingsDataDebug(_DebugViewMaterial, input, result, needLinearToSRGB);
GetBuiltinDataDebug(_DebugViewMaterial, builtinData, result, needLinearToSRGB);
GetSurfaceDataDebug(_DebugViewMaterial, surfaceData, result, needLinearToSRGB);
GetBSDFDataDebug(_DebugViewMaterial, bsdfData, result, needLinearToSRGB); // TODO: This required to initialize all field from BSDFData...
if(outputIsLinear)
if (!needLinearToSRGB)
result = SRGBToLinear(max(0, result));
return float4(result, 0.0);

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


#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "Lighting/Lighting.hlsl" // This include Material.hlsl
#include "ShaderVariables.hlsl"
#include "Debug/DebugViewMaterial.hlsl"
// This files is generated by the ShaderGraph or written by hand

builtinData.distortionBlur = 0.0;
}
void GetVaryingsDataDebug(uint paramId, Varyings input, inout float3 result, inout float outputIsLinear)
void GetVaryingsDataDebug(uint paramId, Varyings input, inout float3 result, inout bool needLinearToSRGB)
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;
}
switch (paramId)
{
case DEBUGVIEW_VARYING_DEPTH:
// TODO: provide a customize parameter (like a slider)
float linearDepth = frac(LinearEyeDepth(input.positionHS.z, _ZBufferParams) * 0.1);
result = linearDepth.xxx;
break;
case DEBUGVIEW_VARYING_TEXCOORD0:
// TODO: require a remap
result = float3(input.texCoord0, 0.0);
break;
case DEBUGVIEW_VARYING_VERTEXNORMALWS:
result = input.tangentToWorld[2].xyz * 0.5 + 0.5;
break;
case DEBUGVIEW_VARYING_VERTEXTANGENTWS:
result = input.tangentToWorld[0].xyz * 0.5 + 0.5;
break;
case DEBUGVIEW_VARYING_VERTEXBITANGENTWS:
result = input.tangentToWorld[1].xyz * 0.5 + 0.5;
break;
}
}
#endif // #if SHADER_STAGE_FRAGMENT

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


// Note: These parameters can be store in GBuffer if the writer wants
//-----------------------------------------------------------------------------
struct BuiltinData
{
float opacity;
// These are lighting data.
// We would prefer to split lighting and material information but for performance reasons,
// those lighting information are fill
// at the same time than material information.
float3 bakeDiffuseLighting; // This is the result of sampling lightmap/lightprobe/proxyvolume
float3 emissiveColor;
float emissiveIntensity;
// These is required for motion blur and temporalAA
float2 velocity;
// Distortion
float2 distortion;
float distortionBlur; // Define the color buffer mipmap level to use
};
#include "BuiltinData.cs.hlsl"
void GetBuiltinDataDebug(uint paramId, BuiltinData builtinData, inout float3 result, inout float outputIsLinear)
void GetBuiltinDataDebug(uint paramId, BuiltinData builtinData, inout float3 result, inout bool needLinearToSRGB)
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;
}
switch (paramId)
{
case DEBUGVIEW_BUILTIN_BUILTINDATA_OPACITY:
result = builtinData.opacity.xxx;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_BAKEDIFFUSELIGHTING:
// TODO: require a remap
result = builtinData.bakeDiffuseLighting;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_EMISSIVECOLOR:
result = builtinData.emissiveColor; needLinearToSRGB = true;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_EMISSIVEINTENSITY:
result = builtinData.emissiveIntensity.xxx;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_VELOCITY:
result = float3(builtinData.velocity, 0.0);
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTION:
result = float3(builtinData.distortion, 0.0);
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTIONBLUR:
result = builtinData.distortionBlur.xxx;
break;
}
}
#endif // UNITY_BUILTIN_DATA_INCLUDED

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


// SurfaceData and BSDFData
//-----------------------------------------------------------------------------
// TODO: THis is suppose to be genenerated from enum on C# side, but haven't written the code yet!
// Main structure that store the user data (i.e user input of master node in material graph)
struct SurfaceData
{
float3 baseColor;
float specularOcclusion;
float3 normalWS;
float perceptualSmoothness;
float materialId;
float ambientOcclusion;
// MaterialId dependent attribute
// standard
float3 tangentWS;
float anisotropy; // anisotropic ratio(0->no isotropic; 1->full anisotropy in tangent direction)
float metalic;
float specular; // 0.02, 0.04, 0.16, 0.2
// SSS
float subSurfaceRadius;
float thickness;
int subSurfaceProfile;
// Clearcoat
float3 coatNormalWS;
float coatPerceptualSmoothness;
// SpecColor
float3 specularColor;
};
struct BSDFData
{
float3 diffuseColor;
float3 fresnel0;
float specularOcclusion;
float3 normalWS;
float perceptualRoughness;
float roughness;
float materialId;
// MaterialId dependent attribute
// standard
float3 tangentWS;
float3 bitangentWS;
float roughnessT;
float roughnessB;
// fold into fresnel0
// SSS
float subSurfaceRadius;
float thickness;
int subSurfaceProfile;
// Clearcoat
float3 coatNormalWS;
float coatRoughness;
// SpecColor
// fold into fresnel0
};
// SurfaceData is define in Lit.cs which generate Lit.cs.hlsl
#include "Lit.cs.hlsl"
//-----------------------------------------------------------------------------
// conversion function for forward

{
BSDFData bsdfData;
BSDFData bsdfData = (BSDFData)0;
bsdfData.specularOcclusion = surfaceData.specularOcclusion;
bsdfData.normalWS = surfaceData.normalWS;

float4 inGBuffer1,
float4 inGBuffer2)
{
BSDFData bsdfData;
BSDFData bsdfData = (BSDFData)0;
float3 baseColor = inGBuffer0.rgb;
bsdfData.specularOcclusion = inGBuffer0.a;

// Debug method (use to display values)
//-----------------------------------------------------------------------------
void GetSurfaceDataDebug(uint paramId, SurfaceData surfaceData, inout float3 result, inout float outputIsLinear)
void GetSurfaceDataDebug(uint paramId, SurfaceData surfaceData, inout float3 result, inout bool needLinearToSRGB)
{
switch (paramId)
{
case DEBUGVIEW_LIT_SURFACEDATA_BASECOLOR:
result = surfaceData.baseColor; needLinearToSRGB = true;
break;
case DEBUGVIEW_LIT_SURFACEDATA_SPECULAROCCLUSION:
result = surfaceData.specularOcclusion.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_NORMALWS:
result = surfaceData.normalWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_SURFACEDATA_PERCEPTUALSMOOTHNESS:
result = surfaceData.perceptualSmoothness.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_MATERIALID:
result = GetIndexColor(surfaceData.materialId);
break;
case DEBUGVIEW_LIT_SURFACEDATA_AMBIENTOCCLUSION:
result = surfaceData.ambientOcclusion.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_TANGENTWS:
result = surfaceData.tangentWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_SURFACEDATA_ANISOTROPY:
result = surfaceData.anisotropy.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_METALIC:
result = surfaceData.metalic.xxx;
break;
// TODO: Remap here!
case DEBUGVIEW_LIT_SURFACEDATA_SPECULAR:
result = surfaceData.specular.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_SUBSURFACERADIUS:
result = surfaceData.subSurfaceRadius.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_THICKNESS:
result = surfaceData.thickness.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_SUBSURFACEPROFILE:
result = GetIndexColor(surfaceData.subSurfaceProfile);
break;
case DEBUGVIEW_LIT_SURFACEDATA_COATNORMALWS:
result = surfaceData.coatNormalWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_SURFACEDATA_COATPERCEPTUALSMOOTHNESS:
result = surfaceData.coatPerceptualSmoothness.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_SPECULARCOLOR:
result = surfaceData.specularColor; needLinearToSRGB = true;
break;
}
}
void GetBSDFDataDebug(uint paramId, BSDFData bsdfData, inout float3 result, inout bool needLinearToSRGB)
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;
}
switch (paramId)
{
case DEBUGVIEW_LIT_BSDFDATA_DIFFUSECOLOR:
result = bsdfData.diffuseColor; needLinearToSRGB = true;
break;
case DEBUGVIEW_LIT_BSDFDATA_FRESNEL0:
result = bsdfData.fresnel0;
break;
case DEBUGVIEW_LIT_BSDFDATA_SPECULAROCCLUSION:
result = bsdfData.specularOcclusion.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_NORMALWS:
result = bsdfData.normalWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_BSDFDATA_PERCEPTUALROUGHNESS:
result = bsdfData.perceptualRoughness.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_ROUGHNESS:
result = bsdfData.roughness.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_MATERIALID:
result = GetIndexColor(bsdfData.materialId);
break;
case DEBUGVIEW_LIT_BSDFDATA_TANGENTWS:
result = bsdfData.tangentWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_BSDFDATA_BITANGENTWS:
result = bsdfData.bitangentWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_BSDFDATA_ROUGHNESST:
result = bsdfData.roughnessT.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_ROUGHNESSB:
result = bsdfData.roughnessB.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_SUBSURFACERADIUS:
result = bsdfData.subSurfaceRadius.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_THICKNESS:
result = bsdfData.thickness.xxx;
break;
case DEBUGVIEW_LIT_BSDFDATA_SUBSURFACEPROFILE:
result = GetIndexColor(bsdfData.subSurfaceProfile);
break;
case DEBUGVIEW_LIT_BSDFDATA_COATNORMALWS:
result = bsdfData.coatNormalWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_BSDFDATA_COATROUGHNESS:
result = bsdfData.coatRoughness.xxx;
break;
}
}
//-----------------------------------------------------------------------------

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


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

2
Assets/ShaderGenerator/CSharpToHLSL.cs


foreach (var gen in it.Value)
{
if (gen.hasFields)
if (gen.hasFields && !gen.IsSimple())
{
writer.Write(gen.EmitAccessors() + "\n");
}

39
Assets/ShaderGenerator/ShaderTypeGeneration.cs


public class GenerateHLSL : System.Attribute
{
public PackingRules packingRules;
public GenerateHLSL(PackingRules rules = PackingRules.Exact)
public bool simple;
public int debugCounterStart;
public GenerateHLSL(PackingRules rules = PackingRules.Exact, bool simple = false, int debugCounterStart = 1)
}
this.simple = simple;
this.debugCounterStart = debugCounterStart;
}
internal class ShaderTypeGenerator
[AttributeUsage(AttributeTargets.Field)]
public class SurfaceDataAttributes : System.Attribute
{
public string displayName;
public SurfaceDataAttributes(string displayName = "")
{
this.displayName = displayName;
}
}
internal class ShaderTypeGenerator
}
debugCounter = 0;
}
enum PrimitiveType
{

continue;
}
if (attr.simple)
{
string subNamespace = type.Namespace.Substring(type.Namespace.LastIndexOf((".")) + 1);
statics["DEBUGVIEW_" + subNamespace.ToUpper() + "_" + type.Name.ToUpper() + "_" + field.Name.ToUpper()] = Convert.ToString(attr.debugCounterStart + debugCounter++);
}
if (field.FieldType.IsPrimitive)
{
if (field.FieldType == typeof(float))

else if (field.FieldType == typeof(Vector4))
EmitPrimitiveType(PrimitiveType.Float, 4, field.Name, "", shaderFields);
else if (field.FieldType == typeof(Matrix4x4))
EmitMatrixType(PrimitiveType.Float, 4, 4, field.Name, "", shaderFields);
else if (!ExtractComplex(field, shaderFields))
EmitMatrixType(PrimitiveType.Float, 4, 4, field.Name, "", shaderFields);
else if (!ExtractComplex(field, shaderFields))
{
// Error reporting done in ExtractComplex()
return false;

get { return statics.Count > 0; }
}
public bool IsSimple()
{
return attr.simple;
}
public int debugCounter;
public List<string> errors = null;
Dictionary<string, string> statics;

14
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterial.hlsl


// CAUTION: 0 is a reserved numbers meaning there is no debug view mode
// Must be in sync with DebugViewVaryingMode
#define DEBUGVIEW_VARYING_DEPTH 1
#define DEBUGVIEW_VARYING_TEXCOORD0 2
#define DEBUGVIEW_VARYING_VERTEXNORMALWS 3
#define DEBUGVIEW_VARYING_VERTEXTANGENTWS 4
#define DEBUGVIEW_VARYING_VERTEXBITANGENTWS 5
// These define are sepcific to GBuffer
#define DEBUGVIEW_GBUFFER_DEPTH 6
#define DEBUGVIEW_GBUFFER_BAKEDIFFUSELIGHTING 7

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterial.hlsl.meta


fileFormatVersion: 2
guid: 9048292f91ac48d479ce668c5aabf122
timeCreated: 1476053153
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

100
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterialGBuffer.shader


Shader "Hidden/Unity/DebugViewMaterialGBuffer"
{
SubShader
{
Pass
{
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha // We will lerp only the values that are valid
HLSLPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
#pragma vertex VertDeferred
#pragma fragment FragDeferred
// CAUTION: In case deferred lighting need to support various lighting model statically, we will require to do multicompile with different define like UNITY_MATERIAL_LIT
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Lighting.hlsl" // This include Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterial.hlsl"
#include "Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl"
DECLARE_GBUFFER_TEXTURE(_CameraGBufferTexture);
DECLARE_GBUFFER_BAKE_LIGHTING(_CameraGBufferTexture);
Texture2D _CameraDepthTexture;
float4 _ScreenSize;
int _DebugViewMaterial;
struct Attributes
{
float3 positionOS : POSITION;
};
struct Varyings
{
float4 positionHS : SV_POSITION;
};
Varyings VertDeferred(Attributes input)
{
// TODO: implement SV_vertexID full screen quad
Varyings output;
float3 positionWS = TransformObjectToWorld(input.positionOS);
output.positionHS = TransformWorldToHClip(positionWS);
return output;
}
float4 FragDeferred(Varyings input) : SV_Target
{
Coordinate coord = GetCoordinate(input.positionHS.xy, _ScreenSize.zw);
float depth = _CameraDepthTexture.Load(uint3(coord.unPositionSS, 0)).x;
FETCH_GBUFFER(gbuffer, _CameraGBufferTexture, coord.unPositionSS);
BSDFData bsdfData = DECODE_FROM_GBUFFER(gbuffer);
// Init to not expected value
float3 result = float3(-666.0, 0.0, 0.0);
bool needLinearToSRGB = false;
if (_DebugViewMaterial == DEBUGVIEW_GBUFFER_DEPTH)
{
float linearDepth = frac(LinearEyeDepth(depth, _ZBufferParams) * 0.1);
result = linearDepth.xxx;
}
else if (_DebugViewMaterial == DEBUGVIEW_GBUFFER_BAKEDIFFUSELIGHTING)
{
FETCH_BAKE_LIGHTING_GBUFFER(gbuffer, _CameraGBufferTexture, coord.unPositionSS);
result = DECODE_BAKE_LIGHTING_FROM_GBUFFER(gbuffer);
}
GetBSDFDataDebug(_DebugViewMaterial, bsdfData, result, needLinearToSRGB);
// f we haven't touch result, we don't blend it. This allow to have the GBuffer debug pass working with the regular forward debug pass.
// The forward debug pass will write its value and then the deferred will overwrite only touched texels.
if (result.x == -666.0)
{
return float4(0.0, 0.0, 0.0, 0.0);
}
else
{
// 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 (!needLinearToSRGB)
result = SRGBToLinear(max(0, result));
return float4(result, 1.0);
}
}
ENDHLSL
}
}
Fallback Off
}

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterialGBuffer.shader.meta


fileFormatVersion: 2
guid: 439949ea1bfa91b4ba0d04269fcde33d
timeCreated: 1476053153
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

38
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.cs


using UnityEngine;
//-----------------------------------------------------------------------------
// structure definition
//-----------------------------------------------------------------------------
namespace UnityEngine.ScriptableRenderLoop
{
namespace Builtin
{
//-----------------------------------------------------------------------------
// BuiltinData
// This structure include common data that should be present in all material
// and are independent from the BSDF parametrization.
// Note: These parameters can be store in GBuffer if the writer wants
//-----------------------------------------------------------------------------
[GenerateHLSL(PackingRules.Exact, true, 100)]
public struct BuiltinData
{
public float opacity;
// These are lighting data.
// We would prefer to split lighting and material information but for performance reasons,
// those lighting information are fill
// at the same time than material information.
public Vector3 bakeDiffuseLighting; // This is the result of sampling lightmap/lightprobe/proxyvolume
public Vector3 emissiveColor;
public float emissiveIntensity;
// These is required for motion blur and temporalAA
public Vector2 velocity;
// Distortion
public Vector2 distortion;
public float distortionBlur; // Define the color buffer mipmap level to use
};
}
}

29
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.cs.hlsl


//
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.cs. Please don't edit by hand.
//
//
// UnityEngine.ScriptableRenderLoop.Builtin.BuiltinData: static fields
//
#define DEBUGVIEW_BUILTIN_BUILTINDATA_OPACITY (100)
#define DEBUGVIEW_BUILTIN_BUILTINDATA_BAKEDIFFUSELIGHTING (101)
#define DEBUGVIEW_BUILTIN_BUILTINDATA_EMISSIVECOLOR (102)
#define DEBUGVIEW_BUILTIN_BUILTINDATA_EMISSIVEINTENSITY (103)
#define DEBUGVIEW_BUILTIN_BUILTINDATA_VELOCITY (104)
#define DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTION (105)
#define DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTIONBLUR (106)
// Generated from UnityEngine.ScriptableRenderLoop.Builtin.BuiltinData
// PackingRules = Exact
struct BuiltinData
{
float opacity;
float3 bakeDiffuseLighting;
float3 emissiveColor;
float emissiveIntensity;
float2 velocity;
float2 distortion;
float distortionBlur;
};

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.cs.hlsl.meta


fileFormatVersion: 2
guid: 8683f17295ce92e48b6000424f8ba166
timeCreated: 1476011766
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

12
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.cs.meta


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

113
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.cs


using UnityEngine;
//-----------------------------------------------------------------------------
// structure definition
//-----------------------------------------------------------------------------
namespace UnityEngine.ScriptableRenderLoop
{
namespace Lit
{
//-----------------------------------------------------------------------------
// SurfaceData
//-----------------------------------------------------------------------------
// Main structure that store the user data (i.e user input of master node in material graph)
[GenerateHLSL(PackingRules.Exact, true, 1000)]
public struct SurfaceData
{
public enum MaterialId
{
LIT_STANDARD = 0,
LIT_SSS = 1,
LIT_CLEARCOAT = 2,
LIT_SPECULAR = 3
};
[SurfaceDataAttributes("Base Color")]
public Vector3 baseColor;
[SurfaceDataAttributes("Specular Occlusion")]
public float specularOcclusion;
[SurfaceDataAttributes("Normal")]
public Vector3 normalWS;
[SurfaceDataAttributes("Smoothness")]
public float perceptualSmoothness;
[SurfaceDataAttributes("Material ID")]
public MaterialId materialId;
[SurfaceDataAttributes("Ambient Occlusion")]
public float ambientOcclusion;
// MaterialId dependent attribute
// standard
[SurfaceDataAttributes("Tangent")]
public Vector3 tangentWS;
[SurfaceDataAttributes("Anisotropy")]
public float anisotropy; // anisotropic ratio(0->no isotropic; 1->full anisotropy in tangent direction)
[SurfaceDataAttributes("Metalic")]
public float metalic;
[SurfaceDataAttributes("Specular")]
public float specular; // 0.02, 0.04, 0.16, 0.2
// SSS
[SurfaceDataAttributes("SubSurface Radius")]
public float subSurfaceRadius;
[SurfaceDataAttributes("Thickness")]
public float thickness;
[SurfaceDataAttributes("SubSurface Profile")]
public int subSurfaceProfile;
// Clearcoat
[SurfaceDataAttributes("Coat Normal")]
public Vector3 coatNormalWS;
[SurfaceDataAttributes("Coat Smoothness")]
public float coatPerceptualSmoothness;
// SpecColor
[SurfaceDataAttributes("Specular Color")]
public Vector3 specularColor;
};
//-----------------------------------------------------------------------------
// BSDFData
//-----------------------------------------------------------------------------
[GenerateHLSL(PackingRules.Exact, true, 1030)]
public struct BSDFData
{
public Vector3 diffuseColor;
public Vector3 fresnel0;
public float specularOcclusion;
public Vector3 normalWS;
public float perceptualRoughness;
public float roughness;
public float materialId;
// MaterialId dependent attribute
// standard
public Vector3 tangentWS;
public Vector3 bitangentWS;
public float roughnessT;
public float roughnessB;
// fold into fresnel0
// SSS
public float subSurfaceRadius;
public float thickness;
public int subSurfaceProfile;
// Clearcoat
public Vector3 coatNormalWS;
public float coatRoughness;
// SpecColor
// fold into fresnel0
};
}
}

89
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.cs.hlsl


//
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.cs. Please don't edit by hand.
//
//
// UnityEngine.ScriptableRenderLoop.Lit.SurfaceData: static fields
//
#define DEBUGVIEW_LIT_SURFACEDATA_BASECOLOR (1000)
#define DEBUGVIEW_LIT_SURFACEDATA_SPECULAROCCLUSION (1001)
#define DEBUGVIEW_LIT_SURFACEDATA_NORMALWS (1002)
#define DEBUGVIEW_LIT_SURFACEDATA_PERCEPTUALSMOOTHNESS (1003)
#define DEBUGVIEW_LIT_SURFACEDATA_MATERIALID (1004)
#define DEBUGVIEW_LIT_SURFACEDATA_AMBIENTOCCLUSION (1005)
#define DEBUGVIEW_LIT_SURFACEDATA_TANGENTWS (1006)
#define DEBUGVIEW_LIT_SURFACEDATA_ANISOTROPY (1007)
#define DEBUGVIEW_LIT_SURFACEDATA_METALIC (1008)
#define DEBUGVIEW_LIT_SURFACEDATA_SPECULAR (1009)
#define DEBUGVIEW_LIT_SURFACEDATA_SUBSURFACERADIUS (1010)
#define DEBUGVIEW_LIT_SURFACEDATA_THICKNESS (1011)
#define DEBUGVIEW_LIT_SURFACEDATA_SUBSURFACEPROFILE (1012)
#define DEBUGVIEW_LIT_SURFACEDATA_COATNORMALWS (1013)
#define DEBUGVIEW_LIT_SURFACEDATA_COATPERCEPTUALSMOOTHNESS (1014)
#define DEBUGVIEW_LIT_SURFACEDATA_SPECULARCOLOR (1015)
//
// UnityEngine.ScriptableRenderLoop.Lit.BSDFData: static fields
//
#define DEBUGVIEW_LIT_BSDFDATA_DIFFUSECOLOR (1030)
#define DEBUGVIEW_LIT_BSDFDATA_FRESNEL0 (1031)
#define DEBUGVIEW_LIT_BSDFDATA_SPECULAROCCLUSION (1032)
#define DEBUGVIEW_LIT_BSDFDATA_NORMALWS (1033)
#define DEBUGVIEW_LIT_BSDFDATA_PERCEPTUALROUGHNESS (1034)
#define DEBUGVIEW_LIT_BSDFDATA_ROUGHNESS (1035)
#define DEBUGVIEW_LIT_BSDFDATA_MATERIALID (1036)
#define DEBUGVIEW_LIT_BSDFDATA_TANGENTWS (1037)
#define DEBUGVIEW_LIT_BSDFDATA_BITANGENTWS (1038)
#define DEBUGVIEW_LIT_BSDFDATA_ROUGHNESST (1039)
#define DEBUGVIEW_LIT_BSDFDATA_ROUGHNESSB (1040)
#define DEBUGVIEW_LIT_BSDFDATA_SUBSURFACERADIUS (1041)
#define DEBUGVIEW_LIT_BSDFDATA_THICKNESS (1042)
#define DEBUGVIEW_LIT_BSDFDATA_SUBSURFACEPROFILE (1043)
#define DEBUGVIEW_LIT_BSDFDATA_COATNORMALWS (1044)
#define DEBUGVIEW_LIT_BSDFDATA_COATROUGHNESS (1045)
// Generated from UnityEngine.ScriptableRenderLoop.Lit.SurfaceData
// PackingRules = Exact
struct SurfaceData
{
float3 baseColor;
float specularOcclusion;
float3 normalWS;
float perceptualSmoothness;
int materialId;
float ambientOcclusion;
float3 tangentWS;
float anisotropy;
float metalic;
float specular;
float subSurfaceRadius;
float thickness;
int subSurfaceProfile;
float3 coatNormalWS;
float coatPerceptualSmoothness;
float3 specularColor;
};
// Generated from UnityEngine.ScriptableRenderLoop.Lit.BSDFData
// PackingRules = Exact
struct BSDFData
{
float3 diffuseColor;
float3 fresnel0;
float specularOcclusion;
float3 normalWS;
float perceptualRoughness;
float roughness;
float materialId;
float3 tangentWS;
float3 bitangentWS;
float roughnessT;
float roughnessB;
float subSurfaceRadius;
float thickness;
int subSurfaceProfile;
float3 coatNormalWS;
float coatRoughness;
};

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.cs.hlsl.meta


fileFormatVersion: 2
guid: ee69429b3df477b4391cbf8b40b46a23
timeCreated: 1476010259
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

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


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

34
Assets/ScriptableRenderLoop/ShaderLibrary/Debug.hlsl


#ifndef UNITY_DEBUG_INCLUDED
#define UNITY_DEBUG_INCLUDED
// Given an enum (represented by an int here), return a color.
// Use for DebugView of enum
float3 GetIndexColor(int index)
{
float3 outColor = float3(1.0, 0.0, 0.0);
if (index == 0)
outColor = float3(1.0, 0.5, 0.5);
else if (index == 1)
outColor = float3(0.5, 1.0, 0.5);
else if (index == 2)
outColor = float3(0.5, 0.5, 1.0);
else if (index == 3)
outColor = float3(1.0, 1.0, 0.5);
else if (index == 4)
outColor = float3(1.0, 0.5, 1.0);
else if (index == 5)
outColor = float3(0.5, 1.0, 1.0);
else if (index == 6)
outColor = float3(0.25, 0.75, 1.0);
else if (index == 7)
outColor = float3(1.0, 0.75, 0.25);
else if (index == 8)
outColor = float3(0.75, 1.0, 0.25);
else if (index == 9)
outColor = float3(0.75, 0.25, 1.0);
return outColor;
}
#endif // UNITY_DEBUG_INCLUDED

9
Assets/ScriptableRenderLoop/ShaderLibrary/Debug.hlsl.meta


fileFormatVersion: 2
guid: 90f3145f58b7eb44cb4252ac2a3ab258
timeCreated: 1476051069
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugCommon.hlsl.meta


fileFormatVersion: 2
guid: 3babddf8b47eecd48ac0a07efc211c0c
timeCreated: 1475754031
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/GBufferDebug.shader.meta


fileFormatVersion: 2
guid: beffb29605949f0429be0427db7a9993
timeCreated: 1475748193
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

116
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/GBufferDebug.shader


Shader "Hidden/Unity/GBufferDebug"
{
SubShader
{
Pass
{
ZWrite Off
Blend One Zero
HLSLPROGRAM
#pragma target 5.0
#pragma only_renderers d3d11 // TEMP: unitl we go futher in dev
#pragma vertex VertDeferred
#pragma fragment FragDeferred
// CAUTION: In case deferred lighting need to support various lighting model statically, we will require to do multicompile with different define like UNITY_MATERIAL_DISNEYGXX
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lighting/Lighting.hlsl" // This include Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugCommon.hlsl"
#include "Assets/ScriptableRenderLoop/ShaderLibrary/Color.hlsl"
DECLARE_GBUFFER_TEXTURE(_CameraGBufferTexture);
DECLARE_GBUFFER_BAKE_LIGHTING(_CameraGBufferTexture);
Texture2D _CameraDepthTexture;
float4 _ScreenSize;
float _DebugMode;
float4x4 _InvViewProjMatrix;
struct Attributes
{
float3 positionOS : POSITION;
};
struct Varyings
{
float4 positionHS : SV_POSITION;
};
Varyings VertDeferred(Attributes input)
{
// TODO: implement SV_vertexID full screen quad
// Lights are draw as one fullscreen quad
Varyings output;
float3 positionWS = TransformObjectToWorld(input.positionOS);
output.positionHS = TransformWorldToHClip(positionWS);
return output;
}
float4 FragDeferred(Varyings input) : SV_Target
{
Coordinate coord = GetCoordinate(input.positionHS.xy, _ScreenSize.zw);
float depth = _CameraDepthTexture.Load(uint3(coord.unPositionSS, 0)).x;
FETCH_GBUFFER(gbuffer, _CameraGBufferTexture, coord.unPositionSS);
BSDFData bsdfData = DECODE_FROM_GBUFFER(gbuffer);
float3 result = float3(1.0, 1.0, 0.0);
bool outputIsLinear = false;
if (_DebugMode == GBufferDebugDiffuseColor)
{
result = bsdfData.diffuseColor;
}
else if (_DebugMode == GBufferDebugNormal)
{
result = bsdfData.normalWS * 0.5 + 0.5;
outputIsLinear = true;
}
else if (_DebugMode == GBufferDebugDepth)
{
float linearDepth = frac(LinearEyeDepth(depth, _ZBufferParams) * 0.1);
result = linearDepth.xxx;
outputIsLinear = true;
}
else if (_DebugMode == GBufferDebugBakedDiffuse)
{
FETCH_BAKE_LIGHTING_GBUFFER(gbuffer, _CameraGBufferTexture, coord.unPositionSS);
result = DECODE_BAKE_LIGHTING_FROM_GBUFFER(gbuffer);
outputIsLinear = true;
}
else if (_DebugMode == GBufferDebugSpecularColor)
{
result = bsdfData.fresnel0;
}
else if (_DebugMode == GBufferDebugSpecularOcclustion)
{
result = bsdfData.specularOcclusion.xxx;
outputIsLinear = true;
}
else if (_DebugMode == GBufferDebugSmoothness)
{
result = (1.0 - bsdfData.perceptualRoughness).xxx;
outputIsLinear = true;
}
else if (_DebugMode == GBufferDebugMaterialId)
{
result = bsdfData.materialId.xxx;
outputIsLinear = true;
}
if (outputIsLinear)
result = SRGBToLinear(max(0, result));
return float4(result, 1.0);
}
ENDHLSL
}
}
Fallback Off
}

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


// List of material debug modes. Keep in sync with HDRenderLoop.MaterialDebugMode
#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
#define GBufferDebugDiffuseColor 1
#define GBufferDebugNormal 2
#define GBufferDebugDepth 3
#define GBufferDebugBakedDiffuse 4
#define GBufferDebugSpecularColor 5
#define GBufferDebugSpecularOcclustion 6
#define GBufferDebugSmoothness 7
#define GBufferDebugMaterialId 8
正在加载...
取消
保存