|
@@ -1,138 +0,0 @@
|
|
|
-/*
|
|
|
- * Copyright (c) Contributors to the Open 3D Engine Project.
|
|
|
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
|
- *
|
|
|
- * SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
|
- *
|
|
|
- */
|
|
|
-
|
|
|
-#include <scenesrg.srgi>
|
|
|
-#include <viewsrg.srgi>
|
|
|
-
|
|
|
-#include <Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli>
|
|
|
-#include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
|
|
|
-#include <Atom/Features/Shadow/DirectionalLightShadow.azsli>
|
|
|
-#include <Atom/Features/PBR/DefaultObjectSrg.azsli>
|
|
|
-#include "VertexFormats/ModelFull.hlsli"
|
|
|
-
|
|
|
-ShaderResourceGroup MaterialSrg : SRG_PerMaterial
|
|
|
-{
|
|
|
- float4 m_diffuseColor;
|
|
|
-
|
|
|
- Texture2D m_diffuseMap;
|
|
|
- Texture2D m_normalMap;
|
|
|
- Texture2D m_specularMap;
|
|
|
- TextureCube m_environmentMap;
|
|
|
-
|
|
|
- Sampler m_sampler
|
|
|
- {
|
|
|
- MaxAnisotropy = 16;
|
|
|
- AddressU = Wrap;
|
|
|
- AddressV = Wrap;
|
|
|
- AddressW = Wrap;
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
-struct VertexOutput
|
|
|
-{
|
|
|
- float4 m_position : SV_Position;
|
|
|
- float3 m_shadowCoords[ViewSrg::MaxCascadeCount] : UV2;
|
|
|
- float3 m_worldPosition : UV1;
|
|
|
- float3 m_normal : NORMAL;
|
|
|
- float3 m_tangent : TANGENT;
|
|
|
- float3 m_view : VIEW;
|
|
|
- float2 m_uv : UV0;
|
|
|
-};
|
|
|
-
|
|
|
-VertexOutput MainVS(VertexInput input)
|
|
|
-{
|
|
|
- const float4x4 objectToWorldMatrix = ObjectSrg::GetWorldMatrix();
|
|
|
-
|
|
|
- VertexOutput output;
|
|
|
- float3 worldPosition = mul(objectToWorldMatrix, GetVertex_Position(input)).xyz;
|
|
|
- output.m_worldPosition = worldPosition;
|
|
|
- output.m_position = mul(ViewSrg::m_viewProjectionMatrix, float4(worldPosition, 1.0));
|
|
|
-
|
|
|
- output.m_uv = GetVertex_UV(input);
|
|
|
-
|
|
|
- output.m_view = worldPosition - ViewSrg::m_worldPosition;
|
|
|
-
|
|
|
- const float3x3 objectToWorldMatrixIT = ObjectSrg::GetWorldMatrixInverseTranspose();
|
|
|
-
|
|
|
- output.m_normal = mul(objectToWorldMatrixIT, GetVertex_Normal(input));
|
|
|
- output.m_normal = normalize(output.m_normal);
|
|
|
- output.m_tangent = normalize(mul((float3x3)objectToWorldMatrix, GetVertex_Tangent(input)));
|
|
|
-
|
|
|
- // shadow
|
|
|
- const uint lightIndex = ViewSrg::m_shadowIndexDirectionalLight;
|
|
|
- if (lightIndex < ViewSrg::m_directionalLightCount)
|
|
|
- {
|
|
|
- DirectionalLightShadow::GetShadowCoords(
|
|
|
- lightIndex,
|
|
|
- worldPosition,
|
|
|
- output.m_normal,
|
|
|
- output.m_shadowCoords);
|
|
|
- }
|
|
|
-
|
|
|
- return output;
|
|
|
-}
|
|
|
-
|
|
|
-struct PixelOutput
|
|
|
-{
|
|
|
- float4 m_diffuse : SV_Target0;
|
|
|
- float4 m_specular : SV_Target1;
|
|
|
-};
|
|
|
-
|
|
|
-PixelOutput MainPS(VertexOutput input)
|
|
|
-{
|
|
|
- PixelOutput output;
|
|
|
- const uint shadowIndex = ViewSrg::m_shadowIndexDirectionalLight;
|
|
|
- const float3 DefaultLightDirection = normalize(float3(1, -1, 1));
|
|
|
-
|
|
|
- float3 vnormal = normalize(input.m_normal);
|
|
|
-
|
|
|
- float3 lightDir = DefaultLightDirection;
|
|
|
- float litRatio = 1;
|
|
|
- DirectionalLightShadow::DebugInfo debugInfo = {0, false};
|
|
|
- if (shadowIndex < ViewSrg::m_directionalLightCount)
|
|
|
- {
|
|
|
- lightDir = -SceneSrg::m_directionalLights[shadowIndex].m_direction;
|
|
|
-
|
|
|
- // Shadowed check
|
|
|
- litRatio = DirectionalLightShadow::GetVisibility(
|
|
|
- shadowIndex,
|
|
|
- input.m_shadowCoords,
|
|
|
- input.m_normal,
|
|
|
- debugInfo);
|
|
|
- }
|
|
|
-
|
|
|
- // Calculation of colors
|
|
|
- float4 baseColor = MaterialSrg::m_diffuseColor * MaterialSrg::m_diffuseMap.Sample(MaterialSrg::m_sampler, input.m_uv);
|
|
|
- float3 specular = MaterialSrg::m_specularMap.Sample(MaterialSrg::m_sampler, input.m_uv).yyy;
|
|
|
-
|
|
|
- // Using vertex normal instead normal map until we solve the issue that the materials generated from fbx don't have normal map
|
|
|
- float3 normal = vnormal;
|
|
|
- float3 viewDir = normalize(input.m_view);
|
|
|
- float3 H = normalize(lightDir + viewDir);
|
|
|
- float NdotH = max(0.001, dot(normal, H));
|
|
|
- float NdotL = max(0.0, dot(normal, lightDir));
|
|
|
-
|
|
|
- float3 diffuse = baseColor.xyz * (saturate(0.1f + litRatio * NdotL)); //hack: ensure there's at least a little bit of diffuse lighting
|
|
|
-
|
|
|
- specular = pow( saturate( NdotH ), 5.0) * specular * litRatio;
|
|
|
-
|
|
|
- if (shadowIndex < ViewSrg::m_directionalLightCount)
|
|
|
- {
|
|
|
- // Add debug coloring for directional light shadow
|
|
|
- diffuse = DirectionalLightShadow::AddDebugColoring(
|
|
|
- diffuse,
|
|
|
- shadowIndex,
|
|
|
- debugInfo);
|
|
|
- }
|
|
|
-
|
|
|
- float clampedAlpha = saturate(baseColor.a);
|
|
|
- output.m_diffuse = float4(diffuse.rgb, clampedAlpha);
|
|
|
- output.m_specular = float4(specular.rgb, clampedAlpha);
|
|
|
-
|
|
|
- return output;
|
|
|
-}
|