123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- /*
- * 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 <viewsrg.srgi>
- #include <Atom/Features/PBR/DefaultObjectSrg.azsli>
- //#include <Atom/Features/Pipeline/Forward/ForwardPassSrg.azsli>
- //#include <Atom/Features/Pipeline/Forward/ForwardPassOutput.azsli>
- //#include <Atom/Features/PBR/AlphaUtils.azsli>
- #include <Atom/Features/ColorManagement/TransformColor.azsli>
- //#include <Atom/Features/PBR/Lighting/StandardLighting.azsli>
- #include <Atom/Features/PBR/Surfaces/StandardSurface.azsli>
- //#include <Atom/Features/PBR/Decals.azsli>
- struct VSInput
- {
- float3 m_position : POSITION;
- float3 m_normal : NORMAL;
- float4 m_tangent : TANGENT;
- float3 m_bitangent : BITANGENT;
- };
- struct VSOutput
- {
- precise linear centroid float4 m_position : SV_Position;
- float3 m_normal: NORMAL;
- float3 m_tangent : TANGENT;
- float3 m_bitangent : BITANGENT;
- float3 m_worldPosition : UV0;
- };
- #include <Atom/Features/Vertex/VertexHelper.azsli>
- void MaterialFunction_AdjustLocalPosition(inout float3 localPosition);
- void MaterialFunction_AdjustWorldPosition(inout float3 worldPosition);
- void MaterialFunction_AdjustSurface(inout Surface outSurface);
- VSOutput MaterialVS(VSInput IN)
- {
- VSOutput OUT;
-
- MaterialFunction_AdjustLocalPosition(IN.m_position);
- float3 worldPosition = mul(ObjectSrg::GetWorldMatrix(), float4(IN.m_position, 1.0)).xyz;
-
- MaterialFunction_AdjustWorldPosition(worldPosition);
- VertexHelper(IN, OUT, worldPosition);
- return OUT;
- }
- struct DeferredMaterialOutput
- {
- float4 m_baseColor : SV_Target0;
- float4 m_roughnessMetal : SV_Target1;
- float4 m_normal : SV_Target2;
- };
- #define MATERIALPIPELINE_SHADER_HAS_PIXEL_STAGE 1
- DeferredMaterialOutput MaterialPS(VSOutput IN)
- {
- // ------- Surface -------
- // Note, some of the data being set up in this "Surface" section isn't necessary for the deferred material pass,
- // we are just doing it for consistency with how the same code is structured in the other material pipelines.
- Surface surface;
- surface.position = IN.m_worldPosition.xyz;
- surface.vertexNormal = normalize(IN.m_normal);
- // These are the values we expect MaterialFunction_EvaluateSurface to potentially replace.
- surface.normal = surface.vertexNormal;
- surface.roughnessLinear = 0.0;
- float3 baseColor = float3(0.5, 0.5, 0.5);
- float metallic = 0.0;
- float specularF0Factor = 0.5f;
- surface.SetAlbedoAndSpecularF0(baseColor, specularF0Factor, metallic);
- surface.clearCoat.InitializeToZero();
- MaterialFunction_AdjustSurface(surface);
-
- surface.CalculateRoughnessA();
- // ------- Output -------
- DeferredMaterialOutput OUT;
- OUT.m_baseColor = float4(surface.baseColor, 1);
- OUT.m_roughnessMetal = float4(surface.roughnessLinear, surface.metallic, 0, 0);
- OUT.m_normal.rgb = EncodeNormalSignedOctahedron(surface.normal);
-
- //TODO: switch this after o_enableIBL is hooked up
- //OUT.m_normal.a = EncodeUnorm2BitFlags(o_enableIBL, o_specularF0_enableMultiScatterCompensation);
- OUT.m_normal.a = EncodeUnorm2BitFlags(true, o_specularF0_enableMultiScatterCompensation);
- return OUT;
- }
|