Graphics Reference
In-Depth Information
struct PSInput
{
float4
PositionSS
:
SV_Position;
float2
TexCoord
:
TEXCOORD;
float3
NormalWS
:
NORMALWS;
float3
PositionWS
:
POSITIONWS;
float3
TangentWS
:
TANGENTWS;
float3
BitangentWS
:
BITANGENTWS;
};
struct PSOutput
{
float4
Normal
:
SV_Target0;
float4
DiffuseAlbedo
:
SV_Target1;
float4
SpecularAlbedo
:
SV_Target2;
float4
Position
:
SV_Target3;
};
// G-Buffer vertex shader, with normal mapping
VSOutput
VSMain(
in VSInput
input
)
{
VSOutput
output;
// Convert position and normals to world space
output.PositionWS
= mul(
input.Position,
WorldHatrix ).xyz;
float3
normalWS
=
normalize( mul(
input.
Normal, (float3x3)WorldMatrix
) );
output.NormalWS
=
normalWS;
// Reconstruct the rest of the tangent frame
float3
tangentWS
= normalize( mul(
input.
Tangent.xyz,
(float3x3)WorldMatrix
) );
float3
bitangentWS
=
normalize( cross(
normalWS,
tangentWS ) )
* input.Tangent.w;
output.TangentWS
=
tangentWS;
output.BitangentWS
=
bitangentWS;
// Calculate the clip-space position
output.PositionCS
= mul(
input.
Position, WorldViewProjMatrix );
// Pass along the texture coordinate
output.TexCoord
=
input.TexCoord;
return
output;
}
// G-Buffer pixel shader, with normal mapping
PSOutput
PSMain(
in PSInput
input )
{
PSOutput
output;
//
Sample the diffuse
map
float3
diffuseAlbedo
=
DiffuseMap.Sample( AnisoSampler,
input.TexCoord
).rgb;
Search WWH ::
Custom Search