浏览代码
HDRenderLoop: Add automatic support for material propery debug
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 次删除
-
155Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
-
120Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoopInspector.cs
-
17Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lit.shader
-
50Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LitTemplate.hlsl
-
80Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.hlsl
-
265Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.hlsl
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Material.hlsl
-
2Assets/ShaderGenerator/CSharpToHLSL.cs
-
39Assets/ShaderGenerator/ShaderTypeGeneration.cs
-
14Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterial.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterial.hlsl.meta
-
100Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterialGBuffer.shader
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugViewMaterialGBuffer.shader.meta
-
38Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.cs
-
29Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.cs.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.cs.hlsl.meta
-
12Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.cs.meta
-
113Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.cs
-
89Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.cs.hlsl
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.cs.hlsl.meta
-
12Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.cs.meta
-
34Assets/ScriptableRenderLoop/ShaderLibrary/Debug.hlsl
-
9Assets/ScriptableRenderLoop/ShaderLibrary/Debug.hlsl.meta
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugCommon.hlsl.meta
-
9Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/GBufferDebug.shader.meta
-
116Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/GBufferDebug.shader
-
44Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Debug/DebugCommon.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 |
|||
|
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 9048292f91ac48d479ce668c5aabf122 |
|||
timeCreated: 1476053153 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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 |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 439949ea1bfa91b4ba0d04269fcde33d |
|||
timeCreated: 1476053153 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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
|
|||
}; |
|||
} |
|||
} |
|
|||
// |
|||
// 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; |
|||
}; |
|||
|
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: 8683f17295ce92e48b6000424f8ba166 |
|||
timeCreated: 1476011766 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 4e7ffefa010d39847ba8fc54d4aa8e46 |
|||
timeCreated: 1476011696 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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
|
|||
}; |
|||
} |
|||
} |
|
|||
// |
|||
// 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; |
|||
}; |
|||
|
|||
|
|
|||
fileFormatVersion: 2 |
|||
guid: ee69429b3df477b4391cbf8b40b46a23 |
|||
timeCreated: 1476010259 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: c35b94e21bc30c948928a1131e79bd2e |
|||
timeCreated: 1476007916 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
#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 |
|
|||
fileFormatVersion: 2 |
|||
guid: 90f3145f58b7eb44cb4252ac2a3ab258 |
|||
timeCreated: 1476051069 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 3babddf8b47eecd48ac0a07efc211c0c |
|||
timeCreated: 1475754031 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: beffb29605949f0429be0427db7a9993 |
|||
timeCreated: 1475748193 |
|||
licenseType: Pro |
|||
ShaderImporter: |
|||
defaultTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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 |
|||
} |
|
|||
|
|||
// 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 |
撰写
预览
正在加载...
取消
保存
Reference in new issue