diff --git a/Game.cpp b/Game.cpp index b9b241f..9ecca3a 100644 --- a/Game.cpp +++ b/Game.cpp @@ -198,6 +198,7 @@ void Game::Draw(float deltaTime, float totalTime) vs->SetMatrix4x4("world", entity->GetTransform()->GetWorldMatrix()); vs->SetMatrix4x4("view", camera->GetViewMatrix()); vs->SetMatrix4x4("projection", camera->GetProjectionMatrix()); + vs->SetMatrix4x4("worldInvTranspose", camera->GetTransform()->GetWorldMatrixInverseTranspose()); vs->CopyAllBufferData(); std::shared_ptr ps = entity->GetMaterial()->GetPixelShader(); diff --git a/Includes.hlsli b/Includes.hlsli index 80f696b..e5002e5 100644 --- a/Includes.hlsli +++ b/Includes.hlsli @@ -15,6 +15,8 @@ struct VertexToPixel // v v v float4 screenPosition : SV_POSITION; float2 uv : TEXCOORD; + float3 normal : NORMAL; + float3 worldPosition : POSITION; }; // Struct representing a single vertex worth of data diff --git a/SimplePixelShader.hlsl b/SimplePixelShader.hlsl index 88bca2f..a85c019 100644 --- a/SimplePixelShader.hlsl +++ b/SimplePixelShader.hlsl @@ -7,7 +7,8 @@ cbuffer ExternalData : register(b0) float3 ambient; } -float4 main() : SV_TARGET +float4 main(VertexToPixel input) : SV_TARGET { - return float4(ambient.rgb, 1); + input.normal = normalize(input.normal); + return float4(input.normal, 1); } diff --git a/VertexShader.hlsl b/VertexShader.hlsl index cd0ab93..1bcf48b 100644 --- a/VertexShader.hlsl +++ b/VertexShader.hlsl @@ -5,6 +5,7 @@ cbuffer ExternalData : register(b0) matrix world; matrix view; matrix projection; + matrix worldInvTranspose; } // -------------------------------------------------------- @@ -37,6 +38,10 @@ VertexToPixel main( VertexShaderInput input ) // - We don't need to alter it here, but we do need to send it to the pixel shader output.uv = input.uv; + // Pass normal and world position throuh + output.normal = mul((float3x3)worldInvTranspose, input.normal); + output.worldPosition = mul(world, float4(input.localPosition, 1)).xyz; + // Whatever we return will make its way through the pipeline to the // next programmable stage we're using (the pixel shader for now) return output;