home *** CD-ROM | disk | FTP | other *** search
- //***************************************************************************************
- // DrawNormals.hlsl by Frank Luna (C) 2015 All Rights Reserved.
- //***************************************************************************************
-
- // Defaults for number of lights.
- #ifndef NUM_DIR_LIGHTS
- #define NUM_DIR_LIGHTS 0
- #endif
-
- #ifndef NUM_POINT_LIGHTS
- #define NUM_POINT_LIGHTS 0
- #endif
-
- #ifndef NUM_SPOT_LIGHTS
- #define NUM_SPOT_LIGHTS 0
- #endif
-
- // Include common HLSL code.
- #include "Common.hlsl"
-
- struct VertexIn
- {
- float3 PosL : POSITION;
- float3 NormalL : NORMAL;
- float2 TexC : TEXCOORD;
- float3 TangentL : TANGENT;
- #ifdef SKINNED
- float3 BoneWeights : WEIGHTS;
- uint4 BoneIndices : BONEINDICES;
- #endif
- };
-
- struct VertexOut
- {
- float4 PosH : SV_POSITION;
- float3 NormalW : NORMAL;
- float3 TangentW : TANGENT;
- float2 TexC : TEXCOORD;
- };
-
- VertexOut VS(VertexIn vin)
- {
- VertexOut vout = (VertexOut)0.0f;
-
- // Fetch the material data.
- MaterialData matData = gMaterialData[gMaterialIndex];
-
- #ifdef SKINNED
- float weights[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
- weights[0] = vin.BoneWeights.x;
- weights[1] = vin.BoneWeights.y;
- weights[2] = vin.BoneWeights.z;
- weights[3] = 1.0f - weights[0] - weights[1] - weights[2];
-
- float3 posL = float3(0.0f, 0.0f, 0.0f);
- float3 normalL = float3(0.0f, 0.0f, 0.0f);
- float3 tangentL = float3(0.0f, 0.0f, 0.0f);
- for(int i = 0; i < 4; ++i)
- {
- // Assume no nonuniform scaling when transforming normals, so
- // that we do not have to use the inverse-transpose.
-
- posL += weights[i] * mul(float4(vin.PosL, 1.0f), gBoneTransforms[vin.BoneIndices[i]]).xyz;
- normalL += weights[i] * mul(vin.NormalL, (float3x3)gBoneTransforms[vin.BoneIndices[i]]);
- tangentL += weights[i] * mul(vin.TangentL.xyz, (float3x3)gBoneTransforms[vin.BoneIndices[i]]);
- }
-
- vin.PosL = posL;
- vin.NormalL = normalL;
- vin.TangentL.xyz = tangentL;
- #endif
-
- // Assumes nonuniform scaling; otherwise, need to use inverse-transpose of world matrix.
- vout.NormalW = mul(vin.NormalL, (float3x3)gWorld);
- vout.TangentW = mul(vin.TangentL, (float3x3)gWorld);
-
- // Transform to homogeneous clip space.
- float4 posW = mul(float4(vin.PosL, 1.0f), gWorld);
- vout.PosH = mul(posW, gViewProj);
-
- // Output vertex attributes for interpolation across triangle.
- float4 texC = mul(float4(vin.TexC, 0.0f, 1.0f), gTexTransform);
- vout.TexC = mul(texC, matData.MatTransform).xy;
-
- return vout;
- }
-
- float4 PS(VertexOut pin) : SV_Target
- {
- // Fetch the material data.
- MaterialData matData = gMaterialData[gMaterialIndex];
- float4 diffuseAlbedo = matData.DiffuseAlbedo;
- uint diffuseMapIndex = matData.DiffuseMapIndex;
- uint normalMapIndex = matData.NormalMapIndex;
-
- // Dynamically look up the texture in the array.
- diffuseAlbedo *= gTextureMaps[diffuseMapIndex].Sample(gsamAnisotropicWrap, pin.TexC);
-
- #ifdef ALPHA_TEST
- // Discard pixel if texture alpha < 0.1. We do this test as soon
- // as possible in the shader so that we can potentially exit the
- // shader early, thereby skipping the rest of the shader code.
- clip(diffuseAlbedo.a - 0.1f);
- #endif
-
- // Interpolating normal can unnormalize it, so renormalize it.
- pin.NormalW = normalize(pin.NormalW);
-
- // NOTE: We use interpolated vertex normal for SSAO.
-
- // Write normal in view space coordinates
- float3 normalV = mul(pin.NormalW, (float3x3)gView);
- return float4(normalV, 0.0f);
- }
-
-
-