浏览代码

HDRenderLoop: Update shader generation code for debug with last change

/main
sebastienlagarde 8 年前
当前提交
0067d748
共有 8 个文件被更改,包括 119 次插入99 次删除
  1. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset
  2. 7
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.cs
  3. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.cs.hlsl
  4. 8
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/BuiltinData.hlsl
  5. 19
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.cs
  6. 58
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.cs.hlsl
  7. 88
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.hlsl
  8. 28
      Assets/ShaderGenerator/ShaderTypeGeneration.cs

2
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.asset


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

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


[GenerateHLSL(PackingRules.Exact, true, 100)]
public struct BuiltinData
{
[SurfaceDataAttributes("Opacity")]
public float opacity;
// These are lighting data.

[SurfaceDataAttributes("Bake Diffuse Lighting")]
[SurfaceDataAttributes("Emissive Color")]
[SurfaceDataAttributes("Emissive Intensity")]
[SurfaceDataAttributes("Velocity")]
[SurfaceDataAttributes("Distortion")]
[SurfaceDataAttributes("Distortion Blur")]
public float distortionBlur; // Define the color buffer mipmap level to use
};
}

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


// 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_BAKE_DIFFUSE_LIGHTING (101)
#define DEBUGVIEW_BUILTIN_BUILTINDATA_EMISSIVE_COLOR (102)
#define DEBUGVIEW_BUILTIN_BUILTINDATA_EMISSIVE_INTENSITY (103)
#define DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTIONBLUR (106)
#define DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTION_BLUR (106)
// Generated from UnityEngine.ScriptableRenderLoop.Builtin.BuiltinData
// PackingRules = Exact

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


case DEBUGVIEW_BUILTIN_BUILTINDATA_OPACITY:
result = builtinData.opacity.xxx;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_BAKEDIFFUSELIGHTING:
case DEBUGVIEW_BUILTIN_BUILTINDATA_BAKE_DIFFUSE_LIGHTING:
case DEBUGVIEW_BUILTIN_BUILTINDATA_EMISSIVECOLOR:
case DEBUGVIEW_BUILTIN_BUILTINDATA_EMISSIVE_COLOR:
case DEBUGVIEW_BUILTIN_BUILTINDATA_EMISSIVEINTENSITY:
case DEBUGVIEW_BUILTIN_BUILTINDATA_EMISSIVE_INTENSITY:
result = builtinData.emissiveIntensity.xxx;
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_VELOCITY:

result = float3(builtinData.distortion, 0.0);
break;
case DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTIONBLUR:
case DEBUGVIEW_BUILTIN_BUILTINDATA_DISTORTION_BLUR:
result = builtinData.distortionBlur.xxx;
break;
}

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


{
namespace Lit
{
[GenerateHLSL(PackingRules.Exact)]
public enum MaterialId
{
LitStandard = 0,
LitSSS = 1,
LitClearCoat = 2,
LitSpecular = 3
};
//-----------------------------------------------------------------------------
// SurfaceData
//-----------------------------------------------------------------------------

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")]

// fold into fresnel0
};
}
}
}

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


//
//
// UnityEngine.ScriptableRenderLoop.Lit.MaterialId: static fields
//
#define MATERIALID_LIT_STANDARD (0)
#define MATERIALID_LIT_SSS (1)
#define MATERIALID_LIT_CLEAR_COAT (2)
#define MATERIALID_LIT_SPECULAR (3)
//
#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_BASE_COLOR (1000)
#define DEBUGVIEW_LIT_SURFACEDATA_SPECULAR_OCCLUSION (1001)
#define DEBUGVIEW_LIT_SURFACEDATA_NORMAL_WS (1002)
#define DEBUGVIEW_LIT_SURFACEDATA_PERCEPTUAL_SMOOTHNESS (1003)
#define DEBUGVIEW_LIT_SURFACEDATA_MATERIAL_ID (1004)
#define DEBUGVIEW_LIT_SURFACEDATA_AMBIENT_OCCLUSION (1005)
#define DEBUGVIEW_LIT_SURFACEDATA_TANGENT_WS (1006)
#define DEBUGVIEW_LIT_SURFACEDATA_SUBSURFACERADIUS (1010)
#define DEBUGVIEW_LIT_SURFACEDATA_SUB_SURFACE_RADIUS (1010)
#define DEBUGVIEW_LIT_SURFACEDATA_SUBSURFACEPROFILE (1012)
#define DEBUGVIEW_LIT_SURFACEDATA_COATNORMALWS (1013)
#define DEBUGVIEW_LIT_SURFACEDATA_COATPERCEPTUALSMOOTHNESS (1014)
#define DEBUGVIEW_LIT_SURFACEDATA_SPECULARCOLOR (1015)
#define DEBUGVIEW_LIT_SURFACEDATA_SUB_SURFACE_PROFILE (1012)
#define DEBUGVIEW_LIT_SURFACEDATA_COAT_NORMAL_WS (1013)
#define DEBUGVIEW_LIT_SURFACEDATA_COAT_PERCEPTUAL_SMOOTHNESS (1014)
#define DEBUGVIEW_LIT_SURFACEDATA_SPECULAR_COLOR (1015)
#define DEBUGVIEW_LIT_BSDFDATA_DIFFUSECOLOR (1030)
#define DEBUGVIEW_LIT_BSDFDATA_DIFFUSE_COLOR (1030)
#define DEBUGVIEW_LIT_BSDFDATA_SPECULAROCCLUSION (1032)
#define DEBUGVIEW_LIT_BSDFDATA_NORMALWS (1033)
#define DEBUGVIEW_LIT_BSDFDATA_PERCEPTUALROUGHNESS (1034)
#define DEBUGVIEW_LIT_BSDFDATA_SPECULAR_OCCLUSION (1032)
#define DEBUGVIEW_LIT_BSDFDATA_NORMAL_WS (1033)
#define DEBUGVIEW_LIT_BSDFDATA_PERCEPTUAL_ROUGHNESS (1034)
#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_MATERIAL_ID (1036)
#define DEBUGVIEW_LIT_BSDFDATA_TANGENT_WS (1037)
#define DEBUGVIEW_LIT_BSDFDATA_BITANGENT_WS (1038)
#define DEBUGVIEW_LIT_BSDFDATA_ROUGHNESS_T (1039)
#define DEBUGVIEW_LIT_BSDFDATA_ROUGHNESS_B (1040)
#define DEBUGVIEW_LIT_BSDFDATA_SUB_SURFACE_RADIUS (1041)
#define DEBUGVIEW_LIT_BSDFDATA_SUBSURFACEPROFILE (1043)
#define DEBUGVIEW_LIT_BSDFDATA_COATNORMALWS (1044)
#define DEBUGVIEW_LIT_BSDFDATA_COATROUGHNESS (1045)
#define DEBUGVIEW_LIT_BSDFDATA_SUB_SURFACE_PROFILE (1043)
#define DEBUGVIEW_LIT_BSDFDATA_COAT_NORMAL_WS (1044)
#define DEBUGVIEW_LIT_BSDFDATA_COAT_ROUGHNESS (1045)
// Generated from UnityEngine.ScriptableRenderLoop.Lit.SurfaceData
// PackingRules = Exact

88
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!
#define LIT_STANDARD 0
#define LIT_SSS 1
#define LIT_CLEARCOAT 2
#define LIT_SPECULAR 3
// SurfaceData is define in Lit.cs which generate Lit.cs.hlsl
#include "Lit.cs.hlsl"

bsdfData.roughness = PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness);
bsdfData.materialId = surfaceData.materialId;
if (bsdfData.materialId == LIT_STANDARD)
if (bsdfData.materialId == MATERIALID_LIT_STANDARD)
{
bsdfData.diffuseColor = surfaceData.baseColor * (1.0 - surfaceData.metalic);
bsdfData.fresnel0 = lerp(float3(surfaceData.specular, surfaceData.specular, surfaceData.specular), surfaceData.baseColor, surfaceData.metalic);

ConvertAnisotropyToRoughness(bsdfData.roughness, surfaceData.anisotropy, bsdfData.roughnessT, bsdfData.roughnessB);
}
else if (bsdfData.materialId == LIT_SSS)
else if (bsdfData.materialId == MATERIALID_LIT_SSS)
{
bsdfData.diffuseColor = surfaceData.baseColor;
bsdfData.fresnel0 = 0.028; // TODO take from subSurfaceProfile

else if (bsdfData.materialId == LIT_CLEARCOAT)
else if (bsdfData.materialId == MATERIALID_LIT_CLEAR_COAT)
{
bsdfData.diffuseColor = surfaceData.baseColor * (1.0 - surfaceData.metalic);
bsdfData.fresnel0 = lerp(float3(surfaceData.specular, surfaceData.specular, surfaceData.specular), surfaceData.baseColor, surfaceData.metalic);

else if (bsdfData.materialId == LIT_SPECULAR)
else if (bsdfData.materialId == MATERIALID_LIT_SPECULAR)
{
bsdfData.diffuseColor = surfaceData.baseColor;
bsdfData.fresnel0 = surfaceData.specularColor;

{
float3 diffuseColor;
if (surfaceData.materialId == LIT_STANDARD)
if (surfaceData.materialId == MATERIALID_LIT_STANDARD)
else if (surfaceData.materialId == LIT_SSS)
else if (surfaceData.materialId == MATERIALID_LIT_SSS)
else if (surfaceData.materialId == LIT_CLEARCOAT)
else if (surfaceData.materialId == MATERIALID_LIT_CLEAR_COAT)
else if (surfaceData.materialId == LIT_SPECULAR)
else if (surfaceData.materialId == MATERIALID_LIT_SPECULAR)
{
diffuseColor = surfaceData.baseColor;
}

outGBuffer1 = float4(octNormalWS * 0.5 + 0.5, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness), PackMaterialId(surfaceData.materialId));
// RT2 - 8:8:8:8
if (surfaceData.materialId == LIT_STANDARD)
if (surfaceData.materialId == MATERIALID_LIT_STANDARD)
{
// Encode tangent on 16bit with oct compression
float2 octTangentWS = PackNormalOctEncode(surfaceData.tangentWS);

else if (surfaceData.materialId == LIT_SSS)
else if (surfaceData.materialId == MATERIALID_LIT_SSS)
else if (surfaceData.materialId == LIT_CLEARCOAT)
else if (surfaceData.materialId == MATERIALID_LIT_CLEAR_COAT)
{
// Encode coat normal on 16bit with oct compression
float2 octCoatNormalWS = PackNormalOctEncode(surfaceData.coatNormalWS);

else if (surfaceData.materialId == LIT_SPECULAR)
else if (surfaceData.materialId == MATERIALID_LIT_SPECULAR)
{
outGBuffer2 = float4(surfaceData.specularColor, 0.0);
}

bsdfData.roughness = PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness);
bsdfData.materialId = UnpackMaterialId(inGBuffer1.a);
if (bsdfData.materialId == LIT_STANDARD)
if (bsdfData.materialId == MATERIALID_LIT_STANDARD)
{
float metalic = inGBuffer2.a;
// TODO extract spec

bsdfData.bitangentWS = cross(bsdfData.normalWS, bsdfData.tangentWS);
ConvertAnisotropyToRoughness(bsdfData.roughness, anisotropy, bsdfData.roughnessT, bsdfData.roughnessB);
}
else if (bsdfData.materialId == LIT_SSS)
else if (bsdfData.materialId == MATERIALID_LIT_SSS)
{
bsdfData.diffuseColor = baseColor;
bsdfData.fresnel0 = 0.028; // TODO take from subSurfaceProfile

else if (bsdfData.materialId == LIT_CLEARCOAT)
else if (bsdfData.materialId == MATERIALID_LIT_CLEAR_COAT)
{
float metalic = inGBuffer2.a;
// TODO extract spec

bsdfData.coatNormalWS = UnpackNormalOctEncode(float2(inGBuffer2.rg * 2.0 - 1.0));
bsdfData.coatRoughness = inGBuffer2.b;
}
else if (bsdfData.materialId == LIT_SPECULAR)
else if (bsdfData.materialId == MATERIALID_LIT_SPECULAR)
{
bsdfData.diffuseColor = baseColor;
bsdfData.fresnel0 = inGBuffer2.rgb;

{
switch (paramId)
{
case DEBUGVIEW_LIT_SURFACEDATA_BASECOLOR:
case DEBUGVIEW_LIT_SURFACEDATA_BASE_COLOR:
case DEBUGVIEW_LIT_SURFACEDATA_SPECULAROCCLUSION:
case DEBUGVIEW_LIT_SURFACEDATA_SPECULAR_OCCLUSION:
case DEBUGVIEW_LIT_SURFACEDATA_NORMALWS:
case DEBUGVIEW_LIT_SURFACEDATA_NORMAL_WS:
case DEBUGVIEW_LIT_SURFACEDATA_PERCEPTUALSMOOTHNESS:
case DEBUGVIEW_LIT_SURFACEDATA_PERCEPTUAL_SMOOTHNESS:
case DEBUGVIEW_LIT_SURFACEDATA_MATERIALID:
case DEBUGVIEW_LIT_SURFACEDATA_MATERIAL_ID:
case DEBUGVIEW_LIT_SURFACEDATA_AMBIENTOCCLUSION:
case DEBUGVIEW_LIT_SURFACEDATA_AMBIENT_OCCLUSION:
case DEBUGVIEW_LIT_SURFACEDATA_TANGENTWS:
case DEBUGVIEW_LIT_SURFACEDATA_TANGENT_WS:
result = surfaceData.tangentWS * 0.5 + 0.5;
break;
case DEBUGVIEW_LIT_SURFACEDATA_ANISOTROPY:

case DEBUGVIEW_LIT_SURFACEDATA_SPECULAR:
result = surfaceData.specular.xxx;
break;
case DEBUGVIEW_LIT_SURFACEDATA_SUBSURFACERADIUS:
case DEBUGVIEW_LIT_SURFACEDATA_SUB_SURFACE_RADIUS:
case DEBUGVIEW_LIT_SURFACEDATA_SUBSURFACEPROFILE:
case DEBUGVIEW_LIT_SURFACEDATA_SUB_SURFACE_PROFILE:
case DEBUGVIEW_LIT_SURFACEDATA_COATNORMALWS:
case DEBUGVIEW_LIT_SURFACEDATA_COAT_NORMAL_WS:
case DEBUGVIEW_LIT_SURFACEDATA_COATPERCEPTUALSMOOTHNESS:
case DEBUGVIEW_LIT_SURFACEDATA_COAT_PERCEPTUAL_SMOOTHNESS:
case DEBUGVIEW_LIT_SURFACEDATA_SPECULARCOLOR:
case DEBUGVIEW_LIT_SURFACEDATA_SPECULAR_COLOR:
result = surfaceData.specularColor; needLinearToSRGB = true;
break;
}

{
switch (paramId)
{
case DEBUGVIEW_LIT_BSDFDATA_DIFFUSECOLOR:
case DEBUGVIEW_LIT_BSDFDATA_DIFFUSE_COLOR:
case DEBUGVIEW_LIT_BSDFDATA_SPECULAROCCLUSION:
case DEBUGVIEW_LIT_BSDFDATA_SPECULAR_OCCLUSION:
case DEBUGVIEW_LIT_BSDFDATA_NORMALWS:
case DEBUGVIEW_LIT_BSDFDATA_NORMAL_WS:
case DEBUGVIEW_LIT_BSDFDATA_PERCEPTUALROUGHNESS:
case DEBUGVIEW_LIT_BSDFDATA_PERCEPTUAL_ROUGHNESS:
case DEBUGVIEW_LIT_BSDFDATA_MATERIALID:
case DEBUGVIEW_LIT_BSDFDATA_MATERIAL_ID:
case DEBUGVIEW_LIT_BSDFDATA_TANGENTWS:
case DEBUGVIEW_LIT_BSDFDATA_TANGENT_WS:
case DEBUGVIEW_LIT_BSDFDATA_BITANGENTWS:
case DEBUGVIEW_LIT_BSDFDATA_BITANGENT_WS:
case DEBUGVIEW_LIT_BSDFDATA_ROUGHNESST:
case DEBUGVIEW_LIT_BSDFDATA_ROUGHNESS_T:
case DEBUGVIEW_LIT_BSDFDATA_ROUGHNESSB:
case DEBUGVIEW_LIT_BSDFDATA_ROUGHNESS_B:
case DEBUGVIEW_LIT_BSDFDATA_SUBSURFACERADIUS:
case DEBUGVIEW_LIT_BSDFDATA_SUB_SURFACE_RADIUS:
case DEBUGVIEW_LIT_BSDFDATA_SUBSURFACEPROFILE:
case DEBUGVIEW_LIT_BSDFDATA_SUB_SURFACE_PROFILE:
case DEBUGVIEW_LIT_BSDFDATA_COATNORMALWS:
case DEBUGVIEW_LIT_BSDFDATA_COAT_NORMAL_WS:
case DEBUGVIEW_LIT_BSDFDATA_COATROUGHNESS:
case DEBUGVIEW_LIT_BSDFDATA_COAT_ROUGHNESS:
result = bsdfData.coatRoughness.xxx;
break;
}

28
Assets/ShaderGenerator/ShaderTypeGeneration.cs


return EmitDefines() + EmitTypeDecl() + EmitAccessors();
}
// This function is a helper to follow unity convertion
// when converting fooBar ro FOO_BAR
string InsertUnderscore(string name)
{
for (int i = 1; i < name.Length; i++)
{
if (char.IsLower(name[i - 1]) && char.IsUpper(name[i]))
{
// case switch, insert underscore
name = name.Insert(i, "_");
}
}
return name;
}
public bool Generate()
{
statics = new Dictionary<string, string>();

if (!field.IsSpecialName)
{
string name = field.Name;
for (int i = 1; i < name.Length; i++)
{
if (char.IsLower(name[i - 1]) && char.IsUpper(name[i]))
{
// case switch, insert underscore
name = name.Insert(i, "_");
}
}
name = InsertUnderscore(name);
statics[(type.Name + "_" + name).ToUpper()] = field.GetRawConstantValue().ToString();
}
}

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++);
string name = InsertUnderscore(field.Name);
statics[("DEBUGVIEW_" + subNamespace + "_" + type.Name + "_" + name).ToUpper()] = Convert.ToString(attr.debugCounterStart + debugCounter++);
}
if (field.FieldType.IsPrimitive)

正在加载...
取消
保存