浏览代码

HDRenderLoop: Move FragInput is now global to share code + reorganise debug attributes

/main
sebastienlagarde 8 年前
当前提交
996cc98f
共有 21 个文件被更改,包括 162 次插入142 次删除
  1. 6
      Assets/ScriptableRenderLoop/HDRenderLoop/Debug/Resources/DebugViewMaterialGBuffer.shader
  2. 11
      Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs
  3. 19
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
  4. 3
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/LayeredLit/LayeredLit.shader
  5. 5
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.shader
  6. 22
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitData.hlsl
  7. 16
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/Unlit.shader
  8. 11
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/UnlitData.hlsl
  9. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/ShaderPass/ShaderPassDebugViewMaterial.hlsl
  10. 31
      Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs
  11. 27
      Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs.hlsl
  12. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs.hlsl.meta
  13. 12
      Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs.meta
  14. 60
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Attributes.hlsl
  15. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Attributes.hlsl.meta
  16. 15
      Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.hlsl
  17. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.hlsl.meta
  18. 28
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitDebugPass.hlsl
  19. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitDebugPass.hlsl.meta
  20. 0
      /Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/UnlitSharePass.hlsl
  21. 0
      /Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/UnlitSharePass.hlsl.meta

6
Assets/ScriptableRenderLoop/HDRenderLoop/Debug/Resources/DebugViewMaterialGBuffer.shader


#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Material/Material.hlsl"

float3 result = float3(-666.0, 0.0, 0.0);
bool needLinearToSRGB = false;
if (_DebugViewMaterial == DEBUGVIEW_GBUFFER_DEPTH)
if (_DebugViewMaterial == DEBUGVIEWGBUFFER_DEPTH)
else if (_DebugViewMaterial == DEBUGVIEW_GBUFFER_BAKEDIFFUSELIGHTING)
else if (_DebugViewMaterial == DEBUGVIEWGBUFFER_BAKE_DIFFUSE_LIGHTING)
{
result = bakeDiffuseLighting;
}

11
Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopInspector.cs


string GetSubNameSpaceName(Type type)
{
var attributes = type.GetCustomAttributes(true);
return type.Namespace.Substring(type.Namespace.LastIndexOf((".")) + 1) + "/";
}

}
var fields = type.GetFields();
var subNamespace = GetSubNameSpaceName(type);
var localIndex = 0;
foreach (var field in fields)

if (!styles.isDebugViewMaterialInit)
{
var varyingNames = Enum.GetNames(typeof(HDRenderLoop.DebugViewVaryingMode));
var gbufferNames = Enum.GetNames(typeof(HDRenderLoop.DebugViewGbufferMode));
var varyingNames = Enum.GetNames(typeof(Attributes.DebugViewVarying));
var gbufferNames = Enum.GetNames(typeof(Attributes.DebugViewGbuffer));
// +1 for the zero case
var num = 1 + varyingNames.Length

styles.debugViewMaterialValues[0] = 0;
index++;
FillWithPropertiesEnum(typeof(HDRenderLoop.DebugViewVaryingMode), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, "Attributes/", false, ref index);
FillWithPropertiesEnum(typeof(Attributes.DebugViewVarying), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, GetSubNameSpaceName(typeof(Attributes.DebugViewVarying)), false, ref index);
FillWithProperties(typeof(Builtin.BuiltinData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, GetSubNameSpaceName(typeof(Lit.SurfaceData)), ref index);
FillWithProperties(typeof(Lit.SurfaceData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, GetSubNameSpaceName(typeof(Lit.SurfaceData)), ref index);
FillWithProperties(typeof(Builtin.BuiltinData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, false, GetSubNameSpaceName(typeof(Unlit.SurfaceData)), ref index);

FillWithPropertiesEnum(typeof(HDRenderLoop.DebugViewGbufferMode), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, "", true, ref index);
FillWithPropertiesEnum(typeof(Attributes.DebugViewGbuffer), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, "", true, ref index);
FillWithProperties(typeof(Lit.BSDFData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, true, "", ref index);
FillWithProperties(typeof(Unlit.BSDFData), styles.debugViewMaterialStrings, styles.debugViewMaterialValues, true, "", ref index);

19
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs


{
private const string k_HDRenderLoopPath = "Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset";
// Must be in sync with DebugViewMaterial.hlsl
public enum DebugViewVaryingMode
{
TexCoord0 = 1,
TexCoord1 = 2,
TexCoord2 = 3,
VertexTangentWS = 4,
VertexBitangentWS = 5,
VertexNormalWS = 6,
VertexColor = 7,
}
// Must be in sync with DebugViewMaterial.hlsl
public enum DebugViewGbufferMode
{
Depth = 10,
BakeDiffuseLighting = 11,
}
public class SkyParameters
{
public Cubemap skyHDRI;

3
Assets/ScriptableRenderLoop/HDRenderLoop/Material/LayeredLit/LayeredLit.shader


#include "common.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Material/Attributes.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.hlsl"
//-------------------------------------------------------------------------------------
// variable declaration

#include "../../Material/Material.hlsl"
#include "../Lit/LitData.hlsl"
#include "../Lit/LitSharePass.hlsl"
#include "../Lit/LitDebugPass.hlsl"
#include "../../ShaderPass/ShaderPassDebugViewMaterial.hlsl"

5
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.shader


#include "common.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderPass/ShaderPass.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Material/Attributes.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderPass/ShaderPass.cs.hlsl"
//-------------------------------------------------------------------------------------
// variable declaration

#include "../../Material/Material.hlsl"
#include "LitData.hlsl"
#include "LitSharePass.hlsl"
#include "LitDebugPass.hlsl"
#include "../../ShaderPass/ShaderPassDebugViewMaterial.hlsl"

22
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitData.hlsl


//-------------------------------------------------------------------------------------
// FragInput
// This structure gather all possible varying/interpolator for this shader.
//-------------------------------------------------------------------------------------
struct FragInput
{
float4 unPositionSS; // This is the position return by VPOS (That is name positionCS in PackedVarying), only xy is use
float3 positionWS;
float2 texCoord0;
float2 texCoord1;
float2 texCoord2;
float3 tangentToWorld[3];
// For velocity
// Note: Z component is not use
float4 positionCS; // This is the clip spae position. Warning, do not confuse with the value of positionCS in PackedVarying which is VPOS and store in unPositionSS
float4 previousPositionCS;
// For two sided lighting
bool isFrontFace;
};
//-------------------------------------------------------------------------------------
// Fill SurfaceData/Builtin data function

16
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/Unlit.shader


#include "common.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderConfig.cs.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/ShaderVariables.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Material/Attributes.hlsl"
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.hlsl"
//-------------------------------------------------------------------------------------
// variable declaration

#define SHADERPASS SHADERPASS_DEBUG_VIEW_MATERIAL
#include "../../Material/Material.hlsl"
#include "UnlitData.hlsl"
#include "UnlitShare.hlsl"
void GetVaryingsDataDebug(uint paramId, FragInput input, inout float3 result, inout bool needLinearToSRGB)
{
switch (paramId)
{
case DEBUGVIEW_VARYING_TEXCOORD0:
result = float3(input.texCoord0 * 0.5 + 0.5, 0.0);
break;
}
}
#include "UnlitSharePass.hlsl"
#include "../../ShaderPass/ShaderPassDebugViewMaterial.hlsl"

#define SHADERPASS SHADERPASS_FORWARD_UNLIT
#include "../../Material/Material.hlsl"
#include "UnlitData.hlsl"
#include "UnlitShare.hlsl"
#include "UnlitSharePass.hlsl"
#include "../../ShaderPass/ShaderPassForwardUnlit.hlsl"

11
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/UnlitData.hlsl


//-------------------------------------------------------------------------------------
// FragInput
// This structure gather all possible varying/interpolator for this shader.
//-------------------------------------------------------------------------------------
struct FragInput
{
float4 unPositionSS;
float2 texCoord0;
float2 texCoord1;
};
//-------------------------------------------------------------------------------------
// Fill SurfaceData/Builtin data function

2
Assets/ScriptableRenderLoop/HDRenderLoop/ShaderPass/ShaderPassDebugViewMaterial.hlsl


BSDFData bsdfData = ConvertSurfaceDataToBSDFData(surfaceData);
float3 result = float3(1.0, 1.0, 0.0);
float3 result = float3(1.0, 0.0, 1.0);
bool needLinearToSRGB = false;
GetVaryingsDataDebug(_DebugViewMaterial, input, result, needLinearToSRGB);

31
Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs


using UnityEngine;
namespace UnityEngine.Experimental.ScriptableRenderLoop
{
namespace Attributes
{
// 0 is reserved!
[GenerateHLSL]
public enum DebugViewVarying
{
Texcoord0 = 1,
Texcoord1,
Texcoord2,
Texcoord3,
VertexTangentWS,
VertexBitangentWS,
VertexNormalWS,
VertexColor,
VertexColorAlpha,
};
// Number must be contiguous
[GenerateHLSL]
public enum DebugViewGbuffer
{
Depth = DebugViewVarying.VertexColor + 1,
BakeDiffuseLighting,
}
}
} // namespace UnityEngine.Experimental.ScriptableRenderLoop

27
Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs.hlsl


//
// This file was automatically generated from Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs. Please don't edit by hand.
//
#ifndef DEBUGVIEWMATERIAL_CS_HLSL
#define DEBUGVIEWMATERIAL_CS_HLSL
//
// UnityEngine.Experimental.ScriptableRenderLoop.Attributes.DebugViewVarying: static fields
//
#define DEBUGVIEWVARYING_TEXCOORD0 (1)
#define DEBUGVIEWVARYING_TEXCOORD1 (2)
#define DEBUGVIEWVARYING_TEXCOORD2 (3)
#define DEBUGVIEWVARYING_TEXCOORD3 (4)
#define DEBUGVIEWVARYING_VERTEX_TANGENT_WS (5)
#define DEBUGVIEWVARYING_VERTEX_BITANGENT_WS (6)
#define DEBUGVIEWVARYING_VERTEX_NORMAL_WS (7)
#define DEBUGVIEWVARYING_VERTEX_COLOR (8)
#define DEBUGVIEWVARYING_VERTEX_COLOR_ALPHA (9)
//
// UnityEngine.Experimental.ScriptableRenderLoop.Attributes.DebugViewGbuffer: static fields
//
#define DEBUGVIEWGBUFFER_DEPTH (9)
#define DEBUGVIEWGBUFFER_BAKE_DIFFUSE_LIGHTING (10)
#endif

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


fileFormatVersion: 2
guid: 972a0c56f0332c84f95914786d1f2f4b
timeCreated: 1479292942
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

12
Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs.meta


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

60
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Attributes.hlsl


//-------------------------------------------------------------------------------------
// FragInput
// This structure gather all possible varying/interpolator for this shader.
//-------------------------------------------------------------------------------------
#include "Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.cs.hlsl"
struct FragInput
{
float4 unPositionSS; // This is the position return by VPOS (That is name positionCS in PackedVarying), only xy is use
float3 positionWS;
float2 texCoord0;
float2 texCoord1;
float2 texCoord2;
float2 texCoord3;
float3 tangentToWorld[3];
float4 vertexColor;
// For velocity
// Note: Z component is not use
float4 positionCS; // This is the clip spae position. Warning, do not confuse with the value of positionCS in PackedVarying which is VPOS and store in unPositionSS
float4 previousPositionCS;
// For two sided lighting
bool isFrontFace;
};
void GetVaryingsDataDebug(uint paramId, FragInput input, inout float3 result, inout bool needLinearToSRGB)
{
switch (paramId)
{
case DEBUGVIEWVARYING_TEXCOORD0:
result = float3(input.texCoord0 * 0.5 + 0.5, 0.0);
break;
case DEBUGVIEWVARYING_TEXCOORD1:
result = float3(input.texCoord1 * 0.5 + 0.5, 0.0);
break;
case DEBUGVIEWVARYING_TEXCOORD2:
result = float3(input.texCoord2 * 0.5 + 0.5, 0.0);
break;
case DEBUGVIEWVARYING_TEXCOORD3:
result = float3(input.texCoord3 * 0.5 + 0.5, 0.0);
break;
case DEBUGVIEWVARYING_VERTEX_TANGENT_WS:
result = input.tangentToWorld[0].xyz * 0.5 + 0.5;
break;
case DEBUGVIEWVARYING_VERTEX_BITANGENT_WS:
result = input.tangentToWorld[1].xyz * 0.5 + 0.5;
break;
case DEBUGVIEWVARYING_VERTEX_NORMAL_WS:
result = input.tangentToWorld[2].xyz * 0.5 + 0.5;
break;
case DEBUGVIEWVARYING_VERTEX_COLOR:
result = input.vertexColor.rgb; needLinearToSRGB = true;
break;
case DEBUGVIEWVARYING_VERTEX_COLOR_ALPHA:
result = input.vertexColor.aaa;
break;
}
}

9
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Attributes.hlsl.meta


fileFormatVersion: 2
guid: 6d56e29698894b440905cc5d63814ef9
timeCreated: 1479292899
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

15
Assets/ScriptableRenderLoop/HDRenderLoop/Debug/DebugViewMaterial.hlsl


// CAUTION: 0 is a reserved numbers meaning there is no debug view mode
// All number below folow each others!
// Must be in sync with DebugViewVaryingMode
#define DEBUGVIEW_VARYING_TEXCOORD0 1
#define DEBUGVIEW_VARYING_TEXCOORD1 2
#define DEBUGVIEW_VARYING_TEXCOORD2 3
#define DEBUGVIEW_VARYING_VERTEXTANGENTWS 4
#define DEBUGVIEW_VARYING_VERTEXBITANGENTWS 5
#define DEBUGVIEW_VARYING_VERTEXNORMALWS 6
#define DEBUGVIEW_VARYING_VERTEXCOLOR 7
// These define are sepcific to GBuffer
#define DEBUGVIEW_GBUFFER_DEPTH 10
#define DEBUGVIEW_GBUFFER_BAKEDIFFUSELIGHTING 11

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


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

28
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitDebugPass.hlsl


#ifndef SHADERPASS
#error Undefine_SHADERPASS
#endif
void GetVaryingsDataDebug(uint paramId, FragInput input, inout float3 result, inout bool needLinearToSRGB)
{
switch (paramId)
{
case DEBUGVIEW_VARYING_TEXCOORD0:
result = float3(input.texCoord0 * 0.5 + 0.5, 0.0);
break;
case DEBUGVIEW_VARYING_TEXCOORD1:
result = float3(input.texCoord1 * 0.5 + 0.5, 0.0);
break;
case DEBUGVIEW_VARYING_TEXCOORD2:
result = float3(input.texCoord2 * 0.5 + 0.5, 0.0);
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;
case DEBUGVIEW_VARYING_VERTEXNORMALWS:
result = input.tangentToWorld[2].xyz * 0.5 + 0.5;
break;
}
}

9
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/LitDebugPass.hlsl.meta


fileFormatVersion: 2
guid: afea19c25b5e93847af6262c2c00401f
timeCreated: 1478601047
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

/Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/UnlitShare.hlsl → /Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/UnlitSharePass.hlsl

/Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/UnlitShare.hlsl.meta → /Assets/ScriptableRenderLoop/HDRenderLoop/Material/Unlit/UnlitSharePass.hlsl.meta

正在加载...
取消
保存