ATOM-14688 Disable Individual Layers

Added flags for enabling StandardMultilayerPBR layers 2 and 3. This makes it easy to create a two-layer material, or to flip layers off and on for debugging.
This commit is contained in:
Chris Santora
2021-05-11 17:25:53 -07:00
parent 9faf35b529
commit 275bb1bfec
7 changed files with 114 additions and 22 deletions
@@ -295,6 +295,28 @@
}
],
"blend": [
{
"id": "enableLayer2",
"displayName": "Enable Layer 2",
"description": "Whether to enable layer 2.",
"type": "Bool",
"defaultValue": false,
"connection": {
"type": "ShaderOption",
"id": "o_layer2_enabled"
}
},
{
"id": "enableLayer3",
"displayName": "Enable Layer 3",
"description": "Whether to enable layer 3.",
"type": "Bool",
"defaultValue": false,
"connection": {
"type": "ShaderOption",
"id": "o_layer3_enabled"
}
},
{
"id": "blendSource",
"displayName": "Blend Source",
@@ -95,6 +95,9 @@ ShaderResourceGroup MaterialSrg : SRG_PerMaterial
// ------ Shader Options ----------------------------------------
option bool o_layer2_enabled;
option bool o_layer3_enabled;
enum class DebugDrawMode { None, BlendSource, DepthMaps };
option DebugDrawMode o_debugDrawMode;
@@ -146,14 +149,27 @@ float3 GetBlendSourceValues(float2 uv)
{
float3 blendSourceValues = float3(0,0,0);
switch(GetFinalBlendMaskSource())
if(o_layer2_enabled || o_layer3_enabled)
{
case BlendMaskSource::TextureMap:
blendSourceValues = MaterialSrg::m_blendMaskTexture.Sample(MaterialSrg::m_sampler, uv).rgb;
break;
case BlendMaskSource::VertexColors:
blendSourceValues = s_blendMaskFromVertexStream;
break;
switch(GetFinalBlendMaskSource())
{
case BlendMaskSource::TextureMap:
blendSourceValues = MaterialSrg::m_blendMaskTexture.Sample(MaterialSrg::m_sampler, uv).rgb;
break;
case BlendMaskSource::VertexColors:
blendSourceValues = s_blendMaskFromVertexStream;
break;
}
if(!o_layer2_enabled)
{
blendSourceValues.r = 0.0;
}
if(!o_layer3_enabled)
{
blendSourceValues.g = 0.0;
}
}
return blendSourceValues;
@@ -167,18 +183,26 @@ float3 GetBlendSourceValues(float2 uv)
//! layer3 = b
float3 GetBlendWeights(float2 uv)
{
float3 blendSourceValues = GetBlendSourceValues(uv);
// Calculate blend weights such that multiplying and adding them with layer data is equivalent
// to lerping between each layer.
// final = lerp(final, layer1, blendWeights.r)
// final = lerp(final, layer2, blendWeights.g)
// final = lerp(final, layer3, blendWeights.b)
float3 blendWeights;
blendWeights.b = blendSourceValues.g;
blendWeights.g = (1.0 - blendSourceValues.g) * blendSourceValues.r;
blendWeights.r = (1.0 - blendSourceValues.g) * (1.0 - blendSourceValues.r);
if(o_layer2_enabled || o_layer3_enabled)
{
float3 blendSourceValues = GetBlendSourceValues(uv);
// Calculate blend weights such that multiplying and adding them with layer data is equivalent
// to lerping between each layer.
// final = lerp(final, layer1, blendWeights.r)
// final = lerp(final, layer2, blendWeights.g)
// final = lerp(final, layer3, blendWeights.b)
blendWeights.b = blendSourceValues.g;
blendWeights.g = (1.0 - blendSourceValues.g) * blendSourceValues.r;
blendWeights.r = (1.0 - blendSourceValues.g) * (1.0 - blendSourceValues.r);
}
else
{
blendWeights = float3(1,0,0);
}
return blendWeights;
}
@@ -230,7 +254,7 @@ DepthResult GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy)
layerDepthValues.r -= MaterialSrg::m_layer1_m_depthOffset;
}
if(o_layer2_o_useDepthMap)
if(o_layer2_enabled && o_layer2_o_useDepthMap)
{
float2 layerUv = uv;
if(MaterialSrg::m_parallaxUvIndex == 0)
@@ -243,7 +267,7 @@ DepthResult GetDepth(float2 uv, float2 uv_ddx, float2 uv_ddy)
layerDepthValues.g -= MaterialSrg::m_layer2_m_depthOffset;
}
if(o_layer3_o_useDepthMap)
if(o_layer3_enabled && o_layer3_o_useDepthMap)
{
float2 layerUv = uv;
if(MaterialSrg::m_parallaxUvIndex == 0)
@@ -387,20 +387,30 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float
// ----------- Layer 2 -----------
ProcessedMaterialInputs lightingInputLayer2;
if(o_layer2_enabled)
{
StandardMaterialInputs inputs;
FILL_STANDARD_MATERIAL_INPUTS(inputs, MaterialSrg::m_layer2_, o_layer2_, blendWeights.g)
lightingInputLayer2 = ProcessStandardMaterialInputs(inputs);
}
else
{
lightingInputLayer2.InitializeToZero();
}
// ----------- Layer 3 -----------
ProcessedMaterialInputs lightingInputLayer3;
if(o_layer3_enabled)
{
StandardMaterialInputs inputs;
FILL_STANDARD_MATERIAL_INPUTS(inputs, MaterialSrg::m_layer3_, o_layer3_, blendWeights.b)
lightingInputLayer3 = ProcessStandardMaterialInputs(inputs);
}
else
{
lightingInputLayer3.InitializeToZero();
}
// ------- Combine all layers ---------
@@ -411,8 +421,14 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float
// ------- Combine Normals ---------
float3 normalTS = lightingInputLayer1.m_normalTS;
normalTS = ReorientTangentSpaceNormal(normalTS, lightingInputLayer2.m_normalTS);
normalTS = ReorientTangentSpaceNormal(normalTS, lightingInputLayer3.m_normalTS);
if(o_layer2_enabled)
{
normalTS = ReorientTangentSpaceNormal(normalTS, lightingInputLayer2.m_normalTS);
}
if(o_layer3_enabled)
{
normalTS = ReorientTangentSpaceNormal(normalTS, lightingInputLayer3.m_normalTS);
}
// [GFX TODO][ATOM-14591]: This will only work if the normal maps all use the same UV stream. We would need to add support for having them in different UV streams.
surface.normal = normalize(TangentSpaceToWorld(normalTS, IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex]));
@@ -4,6 +4,10 @@
"parentMaterial": "",
"propertyLayoutVersion": 3,
"properties": {
"blend": {
"enableLayer2": true,
"enableLayer3": true
},
"layer1_baseColor": {
"color": [
0.3495536744594574,
@@ -0,0 +1,11 @@
{
"description": "",
"materialType": "Materials/Types/StandardMultilayerPBR.materialtype",
"parentMaterial": "TestData/Materials/StandardMultilayerPbrTestCases/001_ManyFeatures.material",
"propertyLayoutVersion": 3,
"properties": {
"blend": {
"enableLayer2": false
}
}
}
@@ -0,0 +1,11 @@
{
"description": "",
"materialType": "Materials/Types/StandardMultilayerPBR.materialtype",
"parentMaterial": "TestData/Materials/StandardMultilayerPbrTestCases/001_ManyFeatures.material",
"propertyLayoutVersion": 3,
"properties": {
"blend": {
"enableLayer3": false
}
}
}
@@ -4,6 +4,10 @@
"parentMaterial": "",
"propertyLayoutVersion": 3,
"properties": {
"blend": {
"enableLayer2": true,
"enableLayer3": true
},
"layer1_baseColor": {
"textureMap": "TestData/Textures/cc0/bark1_col.jpg"
},