浏览代码

HDRenderloop: Update Parameters of lit material and update GBuffer layout + add aniso function

/main
sebastienlagarde 8 年前
当前提交
6d8ef108
共有 21 个文件被更改,包括 862 次插入403 次删除
  1. 6
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Lit.shader
  2. 221
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/Material/Lit.hlsl
  3. 56
      Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl
  4. 25
      Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl
  5. 3
      Assets/TestScenes/HDTest/HDRenderLoopTest.unity
  6. 5
      Assets/TestScenes/HDTest/Leaf/GroundLeaf/Materials/GroundLeaf_Albedo.mat
  7. 14
      Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Blue_Alpha.mat
  8. 14
      Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Gray.mat
  9. 14
      Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Green.mat
  10. 14
      Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Red.mat
  11. 14
      Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Terrain.mat
  12. 13
      Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test-alpha.mat
  13. 10
      Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test-transparent.mat
  14. 9
      Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test-twosidedLighting.mat
  15. 8
      Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test.mat
  16. 284
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LitTemplate.hlsl
  17. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LitTemplate.hlsl.meta
  18. 239
      Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/CubeTransparent.mat
  19. 8
      Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/CubeTransparent.mat.meta
  20. 9
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateLit.hlsl.meta
  21. 290
      Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateLit.hlsl

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


#pragma shader_feature _HEIGHTMAP
#pragma shader_feature _HEIGHTMAP_AS_DISPLACEMENT
#include "TemplateLit.hlsl"
#include "LitTemplate.hlsl"
ENDHLSL

if(g_MaterialDebugMode == MaterialDebugDiffuseColor)
{
result = surfaceData.diffuseColor;
result = surfaceData.baseColor;
}
else if (g_MaterialDebugMode == MaterialDebugNormal)
{

}
else if (g_MaterialDebugMode == MaterialDebugSpecularColor)
{
result = surfaceData.specularColor;
result = surfaceData.metalic.xxx;
}
else if (g_MaterialDebugMode == MaterialDebugSpecularOcclusion)
{

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


// SurfaceData and BSDFData
//-----------------------------------------------------------------------------
#define LIT_STANDARD 0
#define LIT_SSS 1
#define LIT_CLEARCOAT 2
#define LIT_SPECULAR 3
float3 diffuseColor;
float ambientOcclusion;
float3 specularColor;
float3 baseColor;
float specularOcclusion;
float3 normalWS;

// MaterialID SSS - When enable, we only need one channel for specColor, so one is free to store information.
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 thickness;
// int subSurfaceProfile;
float thickness;
int subSurfaceProfile;
// MaterialID Clear coat
// float coatCoverage;
// float coatRoughness;
// Clearcoat
float3 coatNormalWS;
float coatPerceptualSmoothness;
// SpecColor
float3 specularColor;
float matData0;
float3 fresnel0;
float3 fresnel0;
//float matData1;
float roughness;
float roughness;
// 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
};
//-----------------------------------------------------------------------------

BSDFData ConvertSurfaceDataToBSDFData(SurfaceData input)
BSDFData ConvertSurfaceDataToBSDFData(SurfaceData surfaceData)
BSDFData output;
BSDFData bsdfData;
output.diffuseColor = input.diffuseColor;
output.matData0 = input.subSurfaceRadius; // TEMP
bsdfData.specularOcclusion = surfaceData.specularOcclusion;
bsdfData.normalWS = surfaceData.normalWS;
bsdfData.perceptualRoughness = PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness);
bsdfData.roughness = PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness);
bsdfData.materialId = surfaceData.materialId;
output.fresnel0 = input.specularColor;
output.specularOcclusion = input.specularOcclusion;
//output.matData1 = input.matData1;
if (bsdfData.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);
output.normalWS = input.normalWS;
output.perceptualRoughness = PerceptualSmoothnessToPerceptualRoughness(input.perceptualSmoothness);
output.materialId = input.materialId;
output.roughness = PerceptualRoughnessToRoughness(output.perceptualRoughness);
return output;
bsdfData.tangentWS = surfaceData.tangentWS;
bsdfData.bitangentWS = cross(surfaceData.normalWS, surfaceData.tangentWS);
ConvertAnisotropyToRoughness(bsdfData.roughness, surfaceData.anisotropy, bsdfData.roughnessT, bsdfData.roughnessB);
}
else if (bsdfData.materialId == LIT_SSS)
{
bsdfData.diffuseColor = surfaceData.baseColor;
bsdfData.fresnel0 = 0.028; // TODO take from subSurfaceProfile
bsdfData.subSurfaceRadius = surfaceData.subSurfaceRadius;
bsdfData.thickness = surfaceData.thickness;
}
else if (bsdfData.materialId == LIT_CLEARCOAT)
{
bsdfData.diffuseColor = surfaceData.baseColor * (1.0 - surfaceData.metalic);
bsdfData.fresnel0 = lerp(float3(surfaceData.specular, surfaceData.specular, surfaceData.specular), surfaceData.baseColor, surfaceData.metalic);
bsdfData.coatNormalWS = surfaceData.coatNormalWS;
bsdfData.coatRoughness = PerceptualSmoothnessToRoughness(surfaceData.coatPerceptualSmoothness);
}
else if (bsdfData.materialId == LIT_SPECULAR)
{
bsdfData.diffuseColor = surfaceData.baseColor;
bsdfData.fresnel0 = surfaceData.specularColor;
}
return bsdfData;
}
//-----------------------------------------------------------------------------

float3 GetBakedDiffuseLigthing(SurfaceData surfaceData, BuiltinData builtinData)
{
return builtinData.bakeDiffuseLighting * surfaceData.ambientOcclusion * surfaceData.diffuseColor + builtinData.emissiveColor * builtinData.emissiveIntensity;
float3 diffuseColor;
if (surfaceData.materialId == LIT_STANDARD)
{
diffuseColor = surfaceData.baseColor * (1.0 - surfaceData.metalic);
}
else if (surfaceData.materialId == LIT_SSS)
{
diffuseColor = surfaceData.baseColor;
}
else if (surfaceData.materialId == LIT_CLEARCOAT)
{
diffuseColor = surfaceData.baseColor * (1.0 - surfaceData.metalic);
}
else if (surfaceData.materialId == LIT_SPECULAR)
{
diffuseColor = surfaceData.baseColor;
}
return builtinData.bakeDiffuseLighting * surfaceData.ambientOcclusion * diffuseColor + builtinData.emissiveColor * builtinData.emissiveIntensity;
}
//-----------------------------------------------------------------------------

out float4 outGBuffer2)
{
// RT0 - 8:8:8:8 sRGB
outGBuffer0 = float4(surfaceData.diffuseColor, surfaceData.subSurfaceRadius);
// RT1 - 8:8:8:8:
outGBuffer1 = float4(surfaceData.specularColor, surfaceData.specularOcclusion /*, surfaceData.matData1 */);
outGBuffer0 = float4(surfaceData.baseColor, surfaceData.specularOcclusion);
// RT2 - 10:10:10:2
// RT1 - 10:10:10:2
float2 octNormal = PackNormalOctEncode(surfaceData.normalWS);
float2 octNormalWS = PackNormalOctEncode(surfaceData.normalWS);
outGBuffer2 = float4(octNormal * 0.5 + 0.5, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness), PackMaterialId(surfaceData.materialId));
// TODO: Store 2 bit of flag into perceptualSmoothness (one for SSR, other is free (deferred planar reflection ID ? / MatID extension ?)
outGBuffer1 = float4(octNormalWS * 0.5 + 0.5, PerceptualSmoothnessToPerceptualRoughness(surfaceData.perceptualSmoothness), PackMaterialId(surfaceData.materialId));
// RT2 - 8:8:8:8
if (surfaceData.materialId == LIT_STANDARD)
{
// Encode tangent on 16bit with oct compression
float2 octTangentWS = PackNormalOctEncode(surfaceData.tangentWS);
// TODO: store metal and specular together, specular should be an enum (fixed value)
outGBuffer2 = float4(octTangentWS * 0.5 + 0.5, surfaceData.anisotropy, surfaceData.metalic);
}
else if (surfaceData.materialId == LIT_SSS)
{
outGBuffer2 = float4(surfaceData.subSurfaceRadius, surfaceData.thickness, 0.0, 0.0);
}
else if (surfaceData.materialId == LIT_CLEARCOAT)
{
// Encode coat normal on 16bit with oct compression
float2 octCoatNormalWS = PackNormalOctEncode(surfaceData.coatNormalWS);
// TODO: store metal and specular together, specular should be an enum (fixed value)
outGBuffer2 = float4(octCoatNormalWS * 0.5 + 0.5, PerceptualSmoothnessToRoughness(surfaceData.coatPerceptualSmoothness), surfaceData.metalic);
}
else if (surfaceData.materialId == LIT_SPECULAR)
{
outGBuffer2 = float4(surfaceData.specularColor, 0.0);
}
}
BSDFData DecodeFromGBuffer( float4 inGBuffer0,

BSDFData bsdfData;
bsdfData.diffuseColor = inGBuffer0.rgb;
bsdfData.matData0 = inGBuffer0.a;
float3 baseColor = inGBuffer0.rgb;
bsdfData.specularOcclusion = inGBuffer0.a;
bsdfData.fresnel0 = inGBuffer1.rgb;
bsdfData.specularOcclusion = inGBuffer1.a;
// bsdfData.matData1 = ?;
bsdfData.normalWS = UnpackNormalOctEncode(float2(inGBuffer1.r * 2.0 - 1.0, inGBuffer1.g * 2.0 - 1.0));
bsdfData.perceptualRoughness = inGBuffer1.b;
bsdfData.roughness = PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness);
bsdfData.materialId = UnpackMaterialId(inGBuffer1.a);
bsdfData.normalWS = UnpackNormalOctEncode(float2(inGBuffer2.r * 2.0 - 1.0, inGBuffer2.g * 2 - 1));
bsdfData.perceptualRoughness = inGBuffer2.b;
bsdfData.materialId = UnpackMaterialId(inGBuffer2.a);
if (bsdfData.materialId == LIT_STANDARD)
{
float metalic = inGBuffer2.a;
// TODO extract spec
float specular = 0.04;
float anisotropy = inGBuffer2.b;
bsdfData.diffuseColor = baseColor * (1.0 - metalic);
bsdfData.fresnel0 = lerp(float3(specular, specular, specular), baseColor, metalic);
bsdfData.tangentWS = UnpackNormalOctEncode(float2(inGBuffer2.rg * 2.0 - 1.0));
bsdfData.bitangentWS = cross(bsdfData.normalWS, bsdfData.tangentWS);
ConvertAnisotropyToRoughness(bsdfData.roughness, anisotropy, bsdfData.roughnessT, bsdfData.roughnessB);
}
else if (bsdfData.materialId == LIT_SSS)
{
bsdfData.diffuseColor = baseColor;
bsdfData.fresnel0 = 0.028; // TODO take from subSurfaceProfile
bsdfData.subSurfaceRadius = inGBuffer2.r;
bsdfData.thickness = inGBuffer2.g;
}
else if (bsdfData.materialId == LIT_CLEARCOAT)
{
float metalic = inGBuffer2.a;
// TODO extract spec
float specular = 0.04;
bsdfData.roughness = PerceptualRoughnessToRoughness(bsdfData.perceptualRoughness);
bsdfData.diffuseColor = baseColor * (1.0 - metalic);
bsdfData.fresnel0 = lerp(float3(specular, specular, specular), baseColor, metalic);
bsdfData.coatNormalWS = UnpackNormalOctEncode(float2(inGBuffer2.rg * 2.0 - 1.0));
bsdfData.coatRoughness = inGBuffer2.b;
}
else if (bsdfData.materialId == LIT_SPECULAR)
{
bsdfData.diffuseColor = baseColor;
bsdfData.fresnel0 = inGBuffer2.rgb;
}
return bsdfData;
}

56
Assets/ScriptableRenderLoop/ShaderLibrary/BSDF.hlsl


// Specular BRDF
//-----------------------------------------------------------------------------
// With analytical light (not image based light) we clamp the minimun roughness to avoid numerical instability.
// With analytical light (not image based light) we clamp the minimun roughness in the NDF to avoid numerical instability.
#define UNITY_MIN_ROUGHNESS 0.002
float D_GGX(float NdotH, float roughness)

return INV_PI * a2 / (f * f);
}
// roughnessT -> roughness in tangent direction
// roughnessB -> roughness in bitangent direction
float D_GGXAniso(float NdotH, float TdotH, float BdotH, float roughnessT, float roughnessB)
{
// TODO: Do the clamp on the artists parameter
float f = TdotH * TdotH / (roughnessT * roughnessT) + BdotH * BdotH / (roughnessB * roughnessB) + NdotH * NdotH;
return INV_PI / (roughnessT * roughnessB * f * f);
}
// Ref: http://jcgt.org/published/0003/02/03/paper.pdf
float V_SmithJointGGX(float NdotL, float NdotV, float roughness)
{

// G = 1 / (1 + lambda_v + lambda_l);
// Reorder code to be more optimal
half a = roughness;
half a2 = a * a;
float a = roughness;
float a2 = a * a;
half lambdaV = NdotL * sqrt((-NdotV * a2 + NdotV) * NdotV + a2);
half lambdaL = NdotV * sqrt((-NdotL * a2 + NdotL) * NdotL + a2);
float lambdaV = NdotL * sqrt((-NdotV * a2 + NdotV) * NdotV + a2);
float lambdaL = NdotV * sqrt((-NdotL * a2 + NdotL) * NdotL + a2);
half a = roughness;
half lambdaV = NdotL * (NdotV * (1 - a) + a);
half lambdaL = NdotV * (NdotL * (1 - a) + a);
float a = roughness;
float lambdaV = NdotL * (NdotV * (1 - a) + a);
float lambdaL = NdotV * (NdotL * (1 - a) + a);
// Ref: https://cedec.cesa.or.jp/2015/session/ENG/14698.html The Rendering Materials of Far Cry 4
// TODO: Check with Eric Heitz
// roughnessT -> roughness in tangent direction
// roughnessB -> roughness in bitangent direction
float D_GGXAniso(float TdotH, float BdotH, float NdotH, float roughnessT, float roughnessB)
{
roughnessT = max(roughnessT, UNITY_MIN_ROUGHNESS);
roughnessB = max(roughnessB, UNITY_MIN_ROUGHNESS);
float V_SmithJointGGX(float3 L, float3 V, float roughnessT, float roughnessB)
float f = TdotH * TdotH / (roughnessT * roughnessT) + BdotH * BdotH / (roughnessB * roughnessB) + NdotH * NdotH;
return INV_PI / (roughnessT * roughnessB * f * f);
}
// Ref: https://cedec.cesa.or.jp/2015/session/ENG/14698.html The Rendering Materials of Far Cry 4
float V_SmithJointGGXAniso(float TdotV, float BdotV, float NdotV, float TdotL, float BdotL, float NdotL, float roughnessT, float roughnessB)
half aX = roughnessT;
half aX2 = aX * aX;
half aY = roughnessB;
half aY2 = aY * aY;
float aT = roughnessT;
float aT2 = aT * aT;
float aB = roughnessB;
float aB2 = aB * aB;
half lambdaV = L.z * sqrt(aX2 * V.x * V.x + aY2 * V.y * V.y + V.z * V.z);
half lambdaL = V.z * sqrt(aX2 * L.x * L.x + aY2 * L.y * L.y + L.z * L.z);
float lambdaV = NdotL * sqrt(aT2 * TdotV * TdotV + aB2 * BdotV * BdotV + NdotV * NdotV);
float lambdaL = NdotV * sqrt(aT2 * TdotL * TdotL + aB2 * BdotL * BdotL + NdotL * NdotL);
return 0.5f / (lambdaV + lambdaL);
return 0.5 / (lambdaV + lambdaL);
// TODO: Optimize, lambdaV could be precomputed at the beginning of the loop and reuse for all lights.
//-----------------------------------------------------------------------------
// Diffuse BRDF - diffuseColor is expected to be multiply by the caller

25
Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl


return attenuation;
}
//-----------------------------------------------------------------------------
// Helper function for anisotropy
//-----------------------------------------------------------------------------
// Ref: http://blog.selfshadow.com/publications/s2012-shading-course/burley/s2012_pbs_disney_brdf_notes_v3.pdf (in addenda)
// Convert anisotropic ratio (0->no isotropic; 1->full anisotropy in tangent direction) to roughness
void ConvertAnisotropyToRoughness(float roughness, float anisotropy, out float roughnessT, out float roughnessB)
{
float anisoAspect = sqrt(1.0 - 0.9 * anisotropy);
roughnessT = roughness * anisoAspect;
roughnessB = roughness / anisoAspect;
}
// Ref: http://www.nvidia.com/object/real-time-ycocg-dxt-compression.html
// Fake anisotropic by distorting the normal as suggested by:
// Donald Revie - Implementing Fur Using Deferred Shading (GPU Pro 2)
// anisotropic ratio (0->no isotropic; 1->full anisotropy in tangent direction)
float3 GetAnisotropicModifiedNormal(float3 normalWS, float3 tangentWS, float3 viewVector, float anisotropy)
{
float3 anisoTangentWS = cross(-viewVector, tangentWS);
float3 anisoNormalWS = cross(anisoTangentWS, tangentWS);
return normalize(lerp(normalWS, anisoNormalWS, anisotropy));
}
#endif // UNITY_COMMON_LIGHTING_INCLUDED

3
Assets/TestScenes/HDTest/HDRenderLoopTest.unity


objectReference: {fileID: 0}
- target: {fileID: 485392, guid: e641a36bceddbf24a89656e94dafb3e5, type: 2}
propertyPath: m_RootOrder
value: 13
value: 14
objectReference: {fileID: 0}
- target: {fileID: 115764, guid: e641a36bceddbf24a89656e94dafb3e5, type: 2}
propertyPath: m_Name

m_Name:
m_EditorClassIdentifier:
m_RenderLoop: {fileID: 11400000, guid: 2400b74f5ce370c4481e5dc417d03703, type: 2}
m_AssetVersion: 0
--- !u!1001 &1828950732
Prefab:
m_ObjectHideFlags: 0

5
Assets/TestScenes/HDTest/Leaf/GroundLeaf/Materials/GroundLeaf_Albedo.mat


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: GroundLeaf_Albedo
m_Shader: {fileID: 4800000, guid: e1a84346ee54f9f4993c2f05c59805a0, type: 3}
m_Shader: {fileID: 4800000, guid: e7e3743f30ad81a4ba2d0528f52d026b, type: 3}
m_ShaderKeywords: _ALPHACUTOFFENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONONLY_OFF
_DOUBLESIDED_LIGHTING_FLIP _EMISSION _MASKMAP _METALLICGLOSSMAP _NORMALMAP _NORMALMAP_TANGENT_SPACE
m_LightmapFlags: 1

second: 1
- first:
name: _MaterialId
second: 0
- first:
name: _Metalic
second: 0
- first:
name: _Metallic

14
Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Blue_Alpha.mat


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Blue_Alpha
m_Shader: {fileID: 4800000, guid: e1a84346ee54f9f4993c2f05c59805a0, type: 3}
m_ShaderKeywords: _ALPHACUTOFFENABLE_OFF _DOUBLESIDED_LIGHTING_MIRROR _EMISSION
_NORMALMAP_TANGENT_SPACE
m_Shader: {fileID: 4800000, guid: e7e3743f30ad81a4ba2d0528f52d026b, type: 3}
m_ShaderKeywords: _ALPHACUTOFFENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONONLY_OFF
_DOUBLESIDED_LIGHTING_MIRROR _EMISSION _NORMALMAP_TANGENT_SPACE
m_CustomRenderQueue: 3000
stringTagMap:
RenderType: Transparent
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:

second: 0
- first:
name: _MaterialId
second: 0
- first:
name: _Metalic
second: 0
- first:
name: _Metallic

14
Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Gray.mat


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Gray
m_Shader: {fileID: 4800000, guid: e1a84346ee54f9f4993c2f05c59805a0, type: 3}
m_ShaderKeywords: _EMISSION _NORMALMAP_TANGENT_SPACE
m_Shader: {fileID: 4800000, guid: e7e3743f30ad81a4ba2d0528f52d026b, type: 3}
m_ShaderKeywords: _ALPHACUTOFFENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONONLY_OFF
_EMISSION _NORMALMAP_TANGENT_SPACE
m_LightmapFlags: 1
m_CustomRenderQueue: -1
stringTagMap: {}

name: _DetailNormalMapScale
second: 1
- first:
name: _DistortionDepthTest
second: 0
- first:
name: _DistortionOnly
second: 0
- first:
name: _DoubleSided
second: 1
- first:

second: 0
- first:
name: _MaterialId
second: 0
- first:
name: _Metalic
second: 0
- first:
name: _Metallic

14
Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Green.mat


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Green
m_Shader: {fileID: 4800000, guid: e1a84346ee54f9f4993c2f05c59805a0, type: 3}
m_ShaderKeywords: _EMISSION _NORMALMAP_TANGENT_SPACE
m_Shader: {fileID: 4800000, guid: e7e3743f30ad81a4ba2d0528f52d026b, type: 3}
m_ShaderKeywords: _ALPHACUTOFFENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONONLY_OFF
_EMISSION _NORMALMAP_TANGENT_SPACE
m_LightmapFlags: 1
m_CustomRenderQueue: -1
stringTagMap: {}

name: _DetailNormalMapScale
second: 1
- first:
name: _DistortionDepthTest
second: 0
- first:
name: _DistortionOnly
second: 0
- first:
name: _DoubleSided
second: 1
- first:

second: 0
- first:
name: _MaterialId
second: 0
- first:
name: _Metalic
second: 0
- first:
name: _Metallic

14
Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Red.mat


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Red
m_Shader: {fileID: 4800000, guid: e1a84346ee54f9f4993c2f05c59805a0, type: 3}
m_ShaderKeywords: _EMISSION _NORMALMAP_TANGENT_SPACE
m_Shader: {fileID: 4800000, guid: e7e3743f30ad81a4ba2d0528f52d026b, type: 3}
m_ShaderKeywords: _ALPHACUTOFFENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONONLY_OFF
_EMISSION _NORMALMAP_TANGENT_SPACE
m_LightmapFlags: 1
m_CustomRenderQueue: -1
stringTagMap: {}

name: _DetailNormalMapScale
second: 1
- first:
name: _DistortionDepthTest
second: 0
- first:
name: _DistortionOnly
second: 0
- first:
name: _DoubleSided
second: 1
- first:

second: 0
- first:
name: _MaterialId
second: 0
- first:
name: _Metalic
second: 0
- first:
name: _Metallic

14
Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/Terrain.mat


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: Terrain
m_Shader: {fileID: 4800000, guid: e1a84346ee54f9f4993c2f05c59805a0, type: 3}
m_ShaderKeywords: _EMISSION _NORMALMAP_TANGENT_SPACE
m_Shader: {fileID: 4800000, guid: e7e3743f30ad81a4ba2d0528f52d026b, type: 3}
m_ShaderKeywords: _ALPHACUTOFFENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONONLY_OFF
_EMISSION _NORMALMAP_TANGENT_SPACE
m_LightmapFlags: 1
m_CustomRenderQueue: -1
stringTagMap: {}

name: _DetailNormalMapScale
second: 1
- first:
name: _DistortionDepthTest
second: 0
- first:
name: _DistortionOnly
second: 0
- first:
name: _DoubleSidedMode
second: 0
- first:

second: 1
- first:
name: _MaterialId
second: 0
- first:
name: _Metalic
second: 0
- first:
name: _Metallic

13
Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test-alpha.mat


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: test-alpha
m_Shader: {fileID: 4800000, guid: e1a84346ee54f9f4993c2f05c59805a0, type: 3}
m_ShaderKeywords: _ALPHATEST_ON _EMISSION _NORMALMAP _NORMALMAP_TANGENT_SPACE
m_Shader: {fileID: 4800000, guid: e7e3743f30ad81a4ba2d0528f52d026b, type: 3}
m_ShaderKeywords: _ALPHATEST_ON _DISTORTIONDEPTHTEST_OFF _DISTORTIONONLY_OFF _EMISSION
_NORMALMAP _NORMALMAP_TANGENT_SPACE
m_CustomRenderQueue: 2450
stringTagMap:
RenderType: TransparentCutout
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:

second: 0
- first:
name: _MaterialId
second: 0
- first:
name: _Metalic
second: 0
- first:
name: _Metallic

10
Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test-transparent.mat


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: test-transparent
m_Shader: {fileID: 4800000, guid: e1a84346ee54f9f4993c2f05c59805a0, type: 3}
m_ShaderKeywords: _ALPHACUTOFFENABLE_OFF _EMISSION _NORMALMAP _NORMALMAP_TANGENT_SPACE
m_Shader: {fileID: 4800000, guid: e7e3743f30ad81a4ba2d0528f52d026b, type: 3}
m_ShaderKeywords: _ALPHACUTOFFENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONONLY_OFF
_EMISSION _NORMALMAP _NORMALMAP_TANGENT_SPACE
m_LightmapFlags: 1
m_CustomRenderQueue: 3000
stringTagMap:

second: 0
- first:
name: _CullMode
second: 0
second: 2
- first:
name: _Cutoff
second: 0.5

second: 0
- first:
name: _MaterialId
second: 0
- first:
name: _Metalic
second: 0
- first:
name: _Metallic

9
Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test-twosidedLighting.mat


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: test-twosidedLighting
m_Shader: {fileID: 4800000, guid: e1a84346ee54f9f4993c2f05c59805a0, type: 3}
m_ShaderKeywords: _ALPHACUTOFFENABLE_OFF _DOUBLESIDED_LIGHTING_FLIP _EMISSION _NORMALMAP
_NORMALMAP_TANGENT_SPACE
m_Shader: {fileID: 4800000, guid: e7e3743f30ad81a4ba2d0528f52d026b, type: 3}
m_ShaderKeywords: _ALPHACUTOFFENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONONLY_OFF
_DOUBLESIDED_LIGHTING_FLIP _EMISSION _NORMALMAP _NORMALMAP_TANGENT_SPACE
m_LightmapFlags: 1
m_CustomRenderQueue: -1
stringTagMap: {}

second: 0
- first:
name: _MaterialId
second: 0
- first:
name: _Metalic
second: 0
- first:
name: _Metallic

8
Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/test.mat


m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: test
m_Shader: {fileID: 4800000, guid: e1a84346ee54f9f4993c2f05c59805a0, type: 3}
m_ShaderKeywords: _ALPHACUTOFFENABLE_OFF _EMISSION _NORMALMAP _NORMALMAP_TANGENT_SPACE
m_Shader: {fileID: 4800000, guid: e7e3743f30ad81a4ba2d0528f52d026b, type: 3}
m_ShaderKeywords: _ALPHACUTOFFENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONONLY_OFF
_EMISSION _NORMALMAP _NORMALMAP_TANGENT_SPACE
m_LightmapFlags: 1
m_CustomRenderQueue: -1
stringTagMap: {}

second: 0
- first:
name: _MaterialId
second: 0
- first:
name: _Metalic
second: 0
- first:
name: _Metallic

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


// GENERATED BY SHADER GRAPH
// Question for shader graph: how to handle dynamic parameter data like matData0 that can change name
// No guard header!
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "Lighting/Lighting.hlsl" // This include Material.hlsl
#include "ShaderVariables.hlsl"
// This files is generated by the ShaderGraph or written by hand
// Note for ShaderGraph:
// ShaderGraph should generate the vertex shader output to add the variable that may be required
// For example if we require view vector in shader graph, the output must contain positionWS and we calcualte the view vector with it.
// Still some input are mandatory depends on the type of loop. positionWS is mandatory in this current framework. So the ShaderGraph should always generate it.
//-------------------------------------------------------------------------------------
// variable declaration
//-------------------------------------------------------------------------------------
// Set of users variables
float4 _BaseColor;
sampler2D _BaseColorMap;
float _Metalic;
float _Smoothness;
sampler2D _MaskMap;
sampler2D _SpecularOcclusionMap;
sampler2D _NormalMap;
sampler2D _Heightmap;
float _HeightScale;
float _HeightBias;
sampler2D _DiffuseLightingMap;
float4 _EmissiveColor;
sampler2D _EmissiveColorMap;
float _EmissiveIntensity;
float _SubSurfaceRadius;
sampler2D _SubSurfaceRadiusMap;
// float _Thickness;
// sampler2D _ThicknessMap;
// float _CoatCoverage;
// sampler2D _CoatCoverageMap;
// float _CoatRoughness;
// sampler2D _CoatRoughnessMap;
float _AlphaCutoff;
//-------------------------------------------------------------------------------------
// Lighting architecture
//-------------------------------------------------------------------------------------
// TODO: Check if we will have different Varyings based on different pass, not sure about that...
// Forward
struct Attributes
{
float3 positionOS : POSITION;
float3 normalOS : NORMAL;
float2 uv0 : TEXCOORD0;
float4 tangentOS : TANGENT;
};
struct Varyings
{
float4 positionHS;
float3 positionWS;
float2 texCoord0;
float4 tangentToWorld[3]; // [3x3:tangentToWorld | 1x3:viewDirForParallax]
#ifdef SHADER_STAGE_FRAGMENT
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
FRONT_FACE_TYPE cullFace;
#endif
#endif
};
struct PackedVaryings
{
float4 positionHS : SV_Position;
float4 interpolators[5] : TEXCOORD0;
#ifdef SHADER_STAGE_FRAGMENT
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMATIC;
#endif
#endif
};
// Function to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions
PackedVaryings PackVaryings(Varyings input)
{
PackedVaryings output;
output.positionHS = input.positionHS;
output.interpolators[0].xyz = input.positionWS.xyz;
output.interpolators[0].w = input.texCoord0.x;
output.interpolators[1] = input.tangentToWorld[0];
output.interpolators[2] = input.tangentToWorld[1];
output.interpolators[3] = input.tangentToWorld[2];
output.interpolators[4].x = input.texCoord0.y;
output.interpolators[4].yzw = float3(0.0, 0.0, 0.0);
return output;
}
Varyings UnpackVaryings(PackedVaryings input)
{
Varyings output;
output.positionHS = input.positionHS;
output.positionWS.xyz = input.interpolators[0].xyz;
output.texCoord0.x = input.interpolators[0].w;
output.texCoord0.y = input.interpolators[4].x;
output.tangentToWorld[0] = input.interpolators[1];
output.tangentToWorld[1] = input.interpolators[2];
output.tangentToWorld[2] = input.interpolators[3];
#ifdef SHADER_STAGE_FRAGMENT
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
output.cullFace = input.cullFace;
#endif
#endif
return output;
}
// TODO: Here we will also have all the vertex deformation (GPU skinning, vertex animation, morph target...) or we will need to generate a compute shaders instead (better! but require work to deal with unpacking like fp16)
PackedVaryings VertDefault(Attributes input)
{
Varyings output;
output.positionWS = TransformObjectToWorld(input.positionOS);
// TODO deal with camera center rendering and instancing (This is the reason why we always perform tow steps transform to clip space + instancing matrix)
output.positionHS = TransformWorldToHClip(output.positionWS);
float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
output.texCoord0 = input.uv0;
float4 tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
float3x3 tangentToWorld = CreateTangentToWorld(normalWS, tangentWS.xyz, tangentWS.w);
output.tangentToWorld[0].xyz = tangentToWorld[0];
output.tangentToWorld[1].xyz = tangentToWorld[1];
output.tangentToWorld[2].xyz = tangentToWorld[2];
output.tangentToWorld[0].w = 0;
output.tangentToWorld[1].w = 0;
output.tangentToWorld[2].w = 0;
return PackVaryings(output);
}
//-------------------------------------------------------------------------------------
// Fill SurfaceData/Lighting data function
//-------------------------------------------------------------------------------------
float3 TransformTangentToWorld(float3 normalTS, float4 tangentToWorld[3])
{
// TODO check: do we need to normalize ?
return normalize(mul(normalTS, float3x3(tangentToWorld[0].xyz, tangentToWorld[1].xyz, tangentToWorld[2].xyz)));
}
#if SHADER_STAGE_FRAGMENT
void GetSurfaceAndBuiltinData(Varyings input, out SurfaceData surfaceData, out BuiltinData builtinData)
{
surfaceData.baseColor = tex2D(_BaseColorMap, input.texCoord0).rgb * _BaseColor.rgb;
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
float alpha = _BaseColor.a;
#else
float alpha = tex2D(_BaseColorMap, input.texCoord0).a * _BaseColor.a;
#endif
#ifdef _ALPHATEST_ON
clip(alpha - _AlphaCutoff);
#endif
builtinData.opacity = alpha;
#ifdef _SPECULAROCCLUSIONMAP
// TODO: Do something. For now just take alpha channel
surfaceData.specularOcclusion = tex2D(_SpecularOcclusionMap, input.texCoord0).a;
#else
// Horizon Occlusion for Normal Mapped Reflections: http://marmosetco.tumblr.com/post/81245981087
//surfaceData.specularOcclusion = saturate(1.0 + horizonFade * dot(r, input.tangentToWorld[2].xyz);
// smooth it
//surfaceData.specularOcclusion *= surfaceData.specularOcclusion;
surfaceData.specularOcclusion = 1.0;
#endif
// TODO: think about using BC5
float3 vertexNormalWS = input.tangentToWorld[2].xyz;
#ifdef _NORMALMAP
#ifdef _NORMALMAP_TANGENT_SPACE
float3 normalTS = UnpackNormalDXT5nm(tex2D(_NormalMap, input.texCoord0));
surfaceData.normalWS = TransformTangentToWorld(normalTS, input.tangentToWorld);
#else // Object space (TODO: We need to apply the world rotation here!)
surfaceData.normalWS = tex2D(_NormalMap, input.texCoord0).rgb;
#endif
#else
surfaceData.normalWS = vertexNormalWS;
#endif
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
#ifdef _DOUBLESIDED_LIGHTING_FLIP
float3 oppositeNormalWS = -surfaceData.normalWS;
#else
// Mirror the normal with the plane define by vertex normal
float3 oppositeNormalWS = reflect(surfaceData.normalWS, vertexNormalWS);
#endif
// TODO : Test if GetOdddNegativeScale() is necessary here in case of normal map, as GetOdddNegativeScale is take into account in CreateTangentToWorld();
surfaceData.normalWS = IS_FRONT_VFACE(input.cullFace, GetOdddNegativeScale() >= 0.0 ? surfaceData.normalWS : oppositeNormalWS, -GetOdddNegativeScale() >= 0.0 ? surfaceData.normalWS : oppositeNormalWS);
#endif
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
surfaceData.perceptualSmoothness = tex2D(_BaseColorMap, input.texCoord0).a;
#elif defined(_MASKMAP)
surfaceData.perceptualSmoothness = tex2D(_MaskMap, input.texCoord0).a;
#else
surfaceData.perceptualSmoothness = 1.0;
#endif
surfaceData.perceptualSmoothness *= _Smoothness;
surfaceData.materialId = 0;
// MaskMap is Metalic, Ambient Occlusion, (Optional) - emissive Mask, Optional - Smoothness (in alpha)
#ifdef _MASKMAP
surfaceData.metalic = tex2D(_MaskMap, input.texCoord0).r;
surfaceData.ambientOcclusion = tex2D(_MaskMap, input.texCoord0).g;
#else
surfaceData.metalic = 1.0;
surfaceData.ambientOcclusion = 1.0;
#endif
surfaceData.metalic *= _Metalic;
surfaceData.tangentWS = float3(1.0, 0.0, 0.0);
surfaceData.anisotropy = 0;
surfaceData.specular = 0.04;
surfaceData.subSurfaceRadius = 1.0;
surfaceData.thickness = 0.0;
surfaceData.subSurfaceProfile = 0;
surfaceData.coatNormalWS = float3(1.0, 0.0, 0.0);
surfaceData.coatPerceptualSmoothness = 1.0;
surfaceData.specularColor = float3(0.0, 0.0, 0.0);
// Builtin Data
// TODO: Sample lightmap/lightprobe/volume proxy
// This should also handle projective lightmap
// Note that data input above can be use to sample into lightmap (like normal)
builtinData.bakeDiffuseLighting = tex2D(_DiffuseLightingMap, input.texCoord0).rgb;
// If we chose an emissive color, we have a dedicated texture for it and don't use MaskMap
#ifdef _EMISSIVE_COLOR
#ifdef _EMISSIVE_COLOR_MAP
builtinData.emissiveColor = tex2D(_EmissiveColorMap, input.texCoord0).rgb * _EmissiveColor;
#else
builtinData.emissiveColor = _EmissiveColor;
#endif
#elif defined(_MASKMAP) // If we have a MaskMap, use emissive slot as a mask on baseColor
builtinData.emissiveColor = surfaceData.baseColor * tex2D(_MaskMap, input.texCoord0).bbb;
#else
builtinData.emissiveColor = float3(0.0, 0.0, 0.0);
#endif
builtinData.emissiveIntensity = _EmissiveIntensity;
builtinData.velocity = float2(0.0, 0.0);
builtinData.distortion = float2(0.0, 0.0);
builtinData.distortionBlur = 0.0;
}
#endif // #if SHADER_STAGE_FRAGMENT

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/LitTemplate.hlsl.meta


fileFormatVersion: 2
guid: dda3abfe43d26f84c9255796cfad662a
timeCreated: 1475859326
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

239
Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/CubeTransparent.mat


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: CubeTransparent
m_Shader: {fileID: 4800000, guid: e7e3743f30ad81a4ba2d0528f52d026b, type: 3}
m_ShaderKeywords: _ALPHACUTOFFENABLE_OFF _DISTORTIONDEPTHTEST_OFF _DISTORTIONONLY_OFF
_EMISSION _NORMALMAP_TANGENT_SPACE
m_LightmapFlags: 1
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
- first:
name: _BaseColorMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _BumpMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DetailAlbedoMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DetailMask
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DetailNormalMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DiffuseLightingMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _EmissionMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _EmissiveColorMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _HeightMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _MainTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _MaskMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _MetallicGlossMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _NormalMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _OcclusionMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _ParallaxMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _SpecularOcclusionMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _SubSurfaceRadiusMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- first:
name: _AlphaCutoff
second: 0.5
- first:
name: _AlphaCutoffEnable
second: 0
- first:
name: _BlendMode
second: 0
- first:
name: _BumpScale
second: 1
- first:
name: _CullMode
second: 0
- first:
name: _Cutoff
second: 0.5
- first:
name: _DetailNormalMapScale
second: 1
- first:
name: _DistortionDepthTest
second: 0
- first:
name: _DistortionOnly
second: 0
- first:
name: _DoubleSidedMode
second: 0
- first:
name: _DstBlend
second: 10
- first:
name: _EmissiveColorMode
second: 1
- first:
name: _EmissiveIntensity
second: 0
- first:
name: _GlossMapScale
second: 1
- first:
name: _Glossiness
second: 0.5
- first:
name: _GlossyReflections
second: 1
- first:
name: _HeightBias
second: 0
- first:
name: _HeightMapMode
second: 0
- first:
name: _HeightScale
second: 1
- first:
name: _MaterialId
second: 0
- first:
name: _Metalic
second: 0
- first:
name: _Metallic
second: 0
- first:
name: _Mettalic
second: 0
- first:
name: _Mode
second: 0
- first:
name: _NormalMapSpace
second: 0
- first:
name: _OcclusionStrength
second: 1
- first:
name: _Parallax
second: 0.02
- first:
name: _Smoothness
second: 0.5
- first:
name: _SmoothnessTextureChannel
second: 0
- first:
name: _SpecularHighlights
second: 1
- first:
name: _SrcBlend
second: 5
- first:
name: _SubSurfaceRadius
second: 0
- first:
name: _SurfaceType
second: 1
- first:
name: _UVSec
second: 0
- first:
name: _ZWrite
second: 0
m_Colors:
- first:
name: _BaseColor
second: {r: 0.9117647, g: 0.1273789, b: 0.1273789, a: 0.566}
- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
- first:
name: _EmissionColor
second: {r: 0, g: 0, b: 0, a: 1}
- first:
name: _EmissiveColor
second: {r: 0, g: 0, b: 0, a: 1}

8
Assets/TestScenes/HDTest/Material/HDRenderLoopMaterials/CubeTransparent.mat.meta


fileFormatVersion: 2
guid: 53db393fa1a97b244b8f7e9d8f0bbdba
timeCreated: 1475760437
licenseType: Pro
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateLit.hlsl.meta


fileFormatVersion: 2
guid: f69e98902bfd77a48ab69e05b54c09a5
timeCreated: 1475845771
licenseType: Pro
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

290
Assets/ScriptableRenderLoop/HDRenderLoop/Shaders/TemplateLit.hlsl


// GENERATED BY SHADER GRAPH
// Question for shader graph: how to handle dynamic parameter data like matData0 that can change name
// No guard header!
#define UNITY_MATERIAL_LIT // Need to be define before including Material.hlsl
#include "Lighting/Lighting.hlsl" // This include Material.hlsl
#include "ShaderVariables.hlsl"
// This files is generated by the ShaderGraph or written by hand
// Note for ShaderGraph:
// ShaderGraph should generate the vertex shader output to add the variable that may be required
// For example if we require view vector in shader graph, the output must contain positionWS and we calcualte the view vector with it.
// Still some input are mandatory depends on the type of loop. positionWS is mandatory in this current framework. So the ShaderGraph should always generate it.
//-------------------------------------------------------------------------------------
// variable declaration
//-------------------------------------------------------------------------------------
// Set of users variables
float4 _BaseColor;
sampler2D _BaseColorMap;
float _Metalic;
float _Smoothness;
sampler2D _MaskMap;
sampler2D _SpecularOcclusionMap;
sampler2D _NormalMap;
sampler2D _Heightmap;
float _HeightScale;
float _HeightBias;
sampler2D _DiffuseLightingMap;
float4 _EmissiveColor;
sampler2D _EmissiveColorMap;
float _EmissiveIntensity;
float _SubSurfaceRadius;
sampler2D _SubSurfaceRadiusMap;
// float _Thickness;
// sampler2D _ThicknessMap;
// float _CoatCoverage;
// sampler2D _CoatCoverageMap;
// float _CoatRoughness;
// sampler2D _CoatRoughnessMap;
float _AlphaCutoff;
//-------------------------------------------------------------------------------------
// Lighting architecture
//-------------------------------------------------------------------------------------
// TODO: Check if we will have different Varyings based on different pass, not sure about that...
// Forward
struct Attributes
{
float3 positionOS : POSITION;
float3 normalOS : NORMAL;
float2 uv0 : TEXCOORD0;
float4 tangentOS : TANGENT;
};
struct Varyings
{
float4 positionHS;
float3 positionWS;
float2 texCoord0;
float4 tangentToWorld[3]; // [3x3:tangentToWorld | 1x3:viewDirForParallax]
#ifdef SHADER_STAGE_FRAGMENT
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
FRONT_FACE_TYPE cullFace;
#endif
#endif
};
struct PackedVaryings
{
float4 positionHS : SV_Position;
float4 interpolators[5] : TEXCOORD0;
#ifdef SHADER_STAGE_FRAGMENT
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMATIC;
#endif
#endif
};
// Function to pack data to use as few interpolator as possible, the ShaderGraph should generate these functions
PackedVaryings PackVaryings(Varyings input)
{
PackedVaryings output;
output.positionHS = input.positionHS;
output.interpolators[0].xyz = input.positionWS.xyz;
output.interpolators[0].w = input.texCoord0.x;
output.interpolators[1] = input.tangentToWorld[0];
output.interpolators[2] = input.tangentToWorld[1];
output.interpolators[3] = input.tangentToWorld[2];
output.interpolators[4].x = input.texCoord0.y;
output.interpolators[4].yzw = float3(0.0, 0.0, 0.0);
return output;
}
Varyings UnpackVaryings(PackedVaryings input)
{
Varyings output;
output.positionHS = input.positionHS;
output.positionWS.xyz = input.interpolators[0].xyz;
output.texCoord0.x = input.interpolators[0].w;
output.texCoord0.y = input.interpolators[4].x;
output.tangentToWorld[0] = input.interpolators[1];
output.tangentToWorld[1] = input.interpolators[2];
output.tangentToWorld[2] = input.interpolators[3];
#ifdef SHADER_STAGE_FRAGMENT
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
output.cullFace = input.cullFace;
#endif
#endif
return output;
}
// TODO: Here we will also have all the vertex deformation (GPU skinning, vertex animation, morph target...) or we will need to generate a compute shaders instead (better! but require work to deal with unpacking like fp16)
PackedVaryings VertDefault(Attributes input)
{
Varyings output;
output.positionWS = TransformObjectToWorld(input.positionOS);
// TODO deal with camera center rendering and instancing (This is the reason why we always perform tow steps transform to clip space + instancing matrix)
output.positionHS = TransformWorldToHClip(output.positionWS);
float3 normalWS = TransformObjectToWorldNormal(input.normalOS);
output.texCoord0 = input.uv0;
float4 tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
float3x3 tangentToWorld = CreateTangentToWorld(normalWS, tangentWS.xyz, tangentWS.w);
output.tangentToWorld[0].xyz = tangentToWorld[0];
output.tangentToWorld[1].xyz = tangentToWorld[1];
output.tangentToWorld[2].xyz = tangentToWorld[2];
output.tangentToWorld[0].w = 0;
output.tangentToWorld[1].w = 0;
output.tangentToWorld[2].w = 0;
return PackVaryings(output);
}
//-------------------------------------------------------------------------------------
// Fill SurfaceData/Lighting data function
//-------------------------------------------------------------------------------------
float3 TransformTangentToWorld(float3 normalTS, float4 tangentToWorld[3])
{
// TODO check: do we need to normalize ?
return normalize(mul(normalTS, float3x3(tangentToWorld[0].xyz, tangentToWorld[1].xyz, tangentToWorld[2].xyz)));
}
#if SHADER_STAGE_FRAGMENT
void GetSurfaceAndBuiltinData(Varyings input, out SurfaceData surfaceData, out BuiltinData builtinData)
{
float3 baseColor = tex2D(_BaseColorMap, input.texCoord0).rgb * _BaseColor.rgb;
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
float alpha = _BaseColor.a;
#else
float alpha = tex2D(_BaseColorMap, input.texCoord0).a * _BaseColor.a;
#endif
#ifdef _ALPHATEST_ON
clip(alpha - _AlphaCutoff);
#endif
builtinData.opacity = alpha;
// MaskMap is Metalic, Ambient Occlusion, (Optional) - emissive Mask, Optional - Smoothness (in alpha)
#ifdef _MASKMAP
float metalic = tex2D(_MaskMap, input.texCoord0).r;
surfaceData.ambientOcclusion = tex2D(_MaskMap, input.texCoord0).g;
#else
float metalic = 1.0;
surfaceData.ambientOcclusion = 1.0;
#endif
metalic *= _Metalic;
surfaceData.diffuseColor = baseColor * (1.0 - metalic);
float f0_dieletric = 0.04;
surfaceData.specularColor = lerp(float3(f0_dieletric, f0_dieletric, f0_dieletric), baseColor, metalic);
#ifdef _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
surfaceData.perceptualSmoothness = tex2D(_BaseColorMap, input.texCoord0).a;
#elif defined(_MASKMAP)
surfaceData.perceptualSmoothness = tex2D(_MaskMap, input.texCoord0).a;
#else
surfaceData.perceptualSmoothness = 1.0;
#endif
surfaceData.perceptualSmoothness *= _Smoothness;
#ifdef _SPECULAROCCLUSIONMAP
// TODO: Do something. For now just take alpha channel
surfaceData.specularOcclusion = tex2D(_SpecularOcclusionMap, input.texCoord0).a;
#else
// Horizon Occlusion for Normal Mapped Reflections: http://marmosetco.tumblr.com/post/81245981087
//surfaceData.specularOcclusion = saturate(1.0 + horizonFade * dot(r, input.tangentToWorld[2].xyz);
// smooth it
//surfaceData.specularOcclusion *= surfaceData.specularOcclusion;
surfaceData.specularOcclusion = 1.0;
#endif
// TODO: think about using BC5
float3 vertexNormalWS = input.tangentToWorld[2].xyz;
#ifdef _NORMALMAP
#ifdef _NORMALMAP_TANGENT_SPACE
float3 normalTS = UnpackNormalDXT5nm(tex2D(_NormalMap, input.texCoord0));
surfaceData.normalWS = TransformTangentToWorld(normalTS, input.tangentToWorld);
#else // Object space (TODO: We need to apply the world rotation here!)
surfaceData.normalWS = tex2D(_NormalMap, input.texCoord0).rgb;
#endif
#else
surfaceData.normalWS = vertexNormalWS;
#endif
#if defined(_DOUBLESIDED_LIGHTING_FLIP) || defined(_DOUBLESIDED_LIGHTING_MIRROR)
#ifdef _DOUBLESIDED_LIGHTING_FLIP
float3 oppositeNormalWS = -surfaceData.normalWS;
#else
// Mirror the normal with the plane define by vertex normal
float3 oppositeNormalWS = reflect(surfaceData.normalWS, vertexNormalWS);
#endif
// TODO : Test if GetOdddNegativeScale() is necessary here in case of normal map, as GetOdddNegativeScale is take into account in CreateTangentToWorld();
surfaceData.normalWS = IS_FRONT_VFACE(input.cullFace, GetOdddNegativeScale() >= 0.0 ? surfaceData.normalWS : oppositeNormalWS, -GetOdddNegativeScale() >= 0.0 ? surfaceData.normalWS : oppositeNormalWS);
#endif
surfaceData.materialId = 0;
surfaceData.subSurfaceRadius = 1.0; // tex2D(_SubSurfaceRadiusMap, input.texCoord0).r * _SubSurfaceRadius;
// TODO
/*
float _SubSurfaceRadius;
sampler2D _SubSurfaceRadiusMap;
float _Thickness;
sampler2D _ThicknessMap;
float _CoatCoverage;
sampler2D _CoatCoverageMap;
float _CoatRoughness;
sampler2D _CoatRoughnessMap;
*/
// Builtin Data
// TODO: Sample lightmap/lightprobe/volume proxy
// This should also handle projective lightmap
// Note that data input above can be use to sample into lightmap (like normal)
builtinData.bakeDiffuseLighting = tex2D(_DiffuseLightingMap, input.texCoord0).rgb;
// If we chose an emissive color, we have a dedicated texture for it and don't use MaskMap
#ifdef _EMISSIVE_COLOR
#ifdef _EMISSIVE_COLOR_MAP
builtinData.emissiveColor = tex2D(_EmissiveColorMap, input.texCoord0).rgb * _EmissiveColor;
#else
builtinData.emissiveColor = _EmissiveColor;
#endif
#elif defined(_MASKMAP) // If we have a MaskMap, use emissive slot as a mask on baseColor
builtinData.emissiveColor = baseColor * tex2D(_MaskMap, input.texCoord0).bbb;
#else
builtinData.emissiveColor = float3(0.0, 0.0, 0.0);
#endif
builtinData.emissiveIntensity = _EmissiveIntensity;
builtinData.velocity = float2(0.0, 0.0);
builtinData.distortion = float2(0.0, 0.0);
builtinData.distortionBlur = 0.0;
}
#endif // #if SHADER_STAGE_FRAGMENT
正在加载...
取消
保存