Adding vertexNormal to the Surface structure and using it for shadows (#4617)

* Adding vertex shadow and using it for all shadows
* Fixing small issue with it not being initialized
* Adis recommendations for hair

Signed-off-by: mrieggeramzn <mriegger@amazon.com>
monroegm-disable-blank-issue-2
mrieggeramzn 4 years ago committed by GitHub
parent 190cf92f9d
commit c38c9739da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -185,7 +185,7 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float
float2 normalUv = IN.m_uv[MaterialSrg::m_normalMapUvIndex];
float3x3 uvMatrix = MaterialSrg::m_normalMapUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3(); // By design, only UV0 is allowed to apply transforms.
float detailLayerNormalFactor = MaterialSrg::m_detail_normal_factor * detailLayerBlendFactor;
surface.vertexNormal = normalize(IN.m_normal);
surface.normal = GetDetailedNormalInputWS(
isFrontFace, IN.m_normal,
tangents[MaterialSrg::m_normalMapUvIndex], bitangents[MaterialSrg::m_normalMapUvIndex], MaterialSrg::m_normalMap, MaterialSrg::m_sampler, normalUv, MaterialSrg::m_normalFactor, MaterialSrg::m_flipNormalX, MaterialSrg::m_flipNormalY, uvMatrix, o_normal_useTexture,

@ -237,6 +237,7 @@ PbrLightingOutput SkinPS_Common(VSOutput IN)
normalMapSample = ApplyNormalWrinkleMap(o_wrinkleLayers_normal_useTexture4, normalMapSample, MaterialSrg::m_wrinkle_normal_texture4, MaterialSrg::m_sampler, normalUv, MaterialSrg::m_flipNormalX, MaterialSrg::m_flipNormalY, IN.m_wrinkleBlendFactors.a);
}
surface.vertexNormal = normalize(IN.m_normal);
if(o_detail_normal_useTexture)
{
float3 normalTS = GetTangentSpaceNormal(normalMapSample, uvMatrix, MaterialSrg::m_normalFactor);

@ -445,6 +445,7 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float
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.vertexNormal = normalize(IN.m_normal);
surface.normal = normalize(TangentSpaceToWorld(normalTS, IN.m_normal, tangents[MaterialSrg::m_parallaxUvIndex], bitangents[MaterialSrg::m_parallaxUvIndex]));
// ------- Combine Albedo, roughness, specular, roughness ---------

@ -146,7 +146,7 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float
float2 normalUv = IN.m_uv[MaterialSrg::m_normalMapUvIndex];
float3x3 uvMatrix = MaterialSrg::m_normalMapUvIndex == 0 ? MaterialSrg::m_uvMatrix : CreateIdentity3x3(); // By design, only UV0 is allowed to apply transforms.
surface.vertexNormal = normalize(IN.m_normal);
surface.normal = GetNormalInputWS(MaterialSrg::m_normalMap, MaterialSrg::m_sampler, normalUv, MaterialSrg::m_flipNormalX, MaterialSrg::m_flipNormalY, isFrontFace, IN.m_normal,
tangents[MaterialSrg::m_normalMapUvIndex], bitangents[MaterialSrg::m_normalMapUvIndex], uvMatrix, o_normal_useTexture, MaterialSrg::m_normalFactor);

@ -24,7 +24,7 @@ void ApplyDirectionalLights(Surface surface, inout LightingData lightingData)
litRatio = DirectionalLightShadow::GetVisibility(
shadowIndex,
lightingData.shadowCoords,
surface.normal,
surface.vertexNormal,
debugInfo);
if (o_transmission_mode == TransmissionMode::ThickObject)

@ -86,7 +86,7 @@ void ApplyDiskLight(ViewSrg::DiskLight light, Surface surface, inout LightingDat
light.m_position,
surface.position,
-dirToConeTip,
surface.normal);
surface.vertexNormal);
// Use backShadowRatio to carry thickness from shadow map for thick mode
backShadowRatio = 1.0 - litRatio;

@ -83,7 +83,7 @@ void ApplyPointLight(ViewSrg::PointLight light, Surface surface, inout LightingD
light.m_position,
surface.position,
lightDir,
surface.normal);
surface.vertexNormal);
// Use backShadowRatio to carry thickness from shadow map for thick mode
backShadowRatio = 1.0 - litRatio;

@ -23,6 +23,7 @@ class Surface
float3 position; //!< Position in world-space
float3 normal; //!< Normal in world-space
float3 vertexNormal; //!< Vertex normal in world-space
float3 albedo; //!< Albedo color of the non-metallic material, will be multiplied against the diffuse lighting value
float3 specularF0; //!< Fresnel f0 spectral value of the surface
float roughnessLinear; //!< Perceptually linear roughness value authored by artists. Must be remapped to roughnessA before use

@ -22,6 +22,7 @@ class Surface
float3 position; //!< Position in world-space
float3 normal; //!< Normal in world-space
float3 vertexNormal; //!< Vertex normal in world-space
float3 albedo; //!< Albedo color of the non-metallic material, will be multiplied against the diffuse lighting value
float3 specularF0; //!< Fresnel f0 spectral value of the surface
float roughnessLinear; //!< Perceptually linear roughness value authored by artists. Must be remapped to roughnessA before use

@ -22,6 +22,7 @@ class Surface
float3 position; //!< Position in world-space
float3 normal; //!< Normal in world-space
float3 vertexNormal; //!< Vertex normal in world-space
float3 albedo; //!< Albedo color of the non-metallic material, will be multiplied against the diffuse lighting value
float3 specularF0; //!< Fresnel f0 spectral value of the surface
float roughnessLinear; //!< Perceptually linear roughness value authored by artists. Must be remapped to roughnessA before use

@ -170,6 +170,7 @@ ForwardPassOutput AutoBrick_ForwardPassPS(VSOutput IN)
// Position, Normal, Roughness
surface.position = IN.m_worldPosition.xyz;
surface.normal = normalize(normal);
surface.vertexNormal = surfaceNormal;
surface.roughnessLinear = 1.0f;
surface.CalculateRoughnessA();

@ -63,6 +63,7 @@ ForwardPassOutput MinimalPBR_MainPassPS(VSOutput IN)
// Position, Normal, Roughness
surface.position = IN.m_worldPosition.xyz;
surface.normal = normalize(IN.m_normal);
surface.vertexNormal = normalize(IN.m_normal);
surface.roughnessLinear = MinimalPBRSrg::m_roughness;
surface.CalculateRoughnessA();

@ -135,6 +135,7 @@ void SetNormalAndUpdateLightingParams(
float3 projectedNormal = cross(biNormal, tangent);
surface.normal = normalize(projectedNormal); // the normalization might be redundunt
surface.vertexNormal = surface.normal; // [To Do] - support proper vertex normals in the hair shader.
// Next is important in order to set NdotV and other PBR settings - needs to be set once per light
UpdateLightingParameters(lightingData, surface.position, surface.normal, surface.roughnessLinear);
@ -362,7 +363,7 @@ void ApplyDirectionalLights(Surface surface, inout LightingData lightingData)
litRatio = DirectionalLightShadow::GetVisibility(
shadowIndex,
lightingData.shadowCoords,
surface.normal,
surface.vertexNormal,
debugInfo);
}

@ -197,6 +197,7 @@ float3 CalculateLighting(
surface.position = vPositionWS;
surface.tangent = vTangent; // Redundant - will be calculated per light
surface.normal = float3(0, 0, 0); // Will fail lights that did not initialize properly.
surface.vertexNormal = float3(0,0,0); // [To Do] - vertex normals are not handled yet in the hair shader.
surface.roughnessLinear = material.m_roughness;
surface.cuticleTilt = material.m_cuticleTilt;
surface.thickness = thickness;

@ -18,6 +18,7 @@ class Surface
// ------- BasePbrSurfaceData -------
float3 position; //!< Position in world-space
float3 normal; //!< Normal in world-space
float3 vertexNormal; //!< Vertex normal in world-space
float3 albedo; //!< Albedo color of the non-metallic material, will be multiplied against the diffuse lighting value
float3 specularF0; //!< Fresnel f0 spectral value of the surface
float roughnessLinear; //!< Perceptually linear roughness value authored by artists. Must be remapped to roughnessA before use

@ -95,6 +95,7 @@ ForwardPassOutput TerrainPBR_MainPassPS(VSOutput IN)
detailNormal = ReorientTangentSpaceNormal(macroNormal, detailNormal);
surface.normal = lerp(detailNormal, macroNormal, detailFactor);
surface.normal = normalize(surface.normal);
surface.vertexNormal = normalize(IN.m_normal);
// ------- Macro Color -------
float3 macroColor = GetBaseColorInput(TerrainMaterialSrg::m_macroColorMap, TerrainMaterialSrg::m_sampler, origUv, TerrainMaterialSrg::m_baseColor.rgb, o_baseColor_useTexture);

Loading…
Cancel
Save