pass normals and worldPosition to pixel shader

This commit is contained in:
lightling 2022-03-19 14:47:50 -04:00
parent 948fafec16
commit 096923a5aa
Signed by: lightling
GPG key ID: 016F11E0AA296B67
4 changed files with 11 additions and 2 deletions

View file

@ -198,6 +198,7 @@ void Game::Draw(float deltaTime, float totalTime)
vs->SetMatrix4x4("world", entity->GetTransform()->GetWorldMatrix()); vs->SetMatrix4x4("world", entity->GetTransform()->GetWorldMatrix());
vs->SetMatrix4x4("view", camera->GetViewMatrix()); vs->SetMatrix4x4("view", camera->GetViewMatrix());
vs->SetMatrix4x4("projection", camera->GetProjectionMatrix()); vs->SetMatrix4x4("projection", camera->GetProjectionMatrix());
vs->SetMatrix4x4("worldInvTranspose", camera->GetTransform()->GetWorldMatrixInverseTranspose());
vs->CopyAllBufferData(); vs->CopyAllBufferData();
std::shared_ptr<SimplePixelShader> ps = entity->GetMaterial()->GetPixelShader(); std::shared_ptr<SimplePixelShader> ps = entity->GetMaterial()->GetPixelShader();

View file

@ -15,6 +15,8 @@ struct VertexToPixel
// v v v // v v v
float4 screenPosition : SV_POSITION; float4 screenPosition : SV_POSITION;
float2 uv : TEXCOORD; float2 uv : TEXCOORD;
float3 normal : NORMAL;
float3 worldPosition : POSITION;
}; };
// Struct representing a single vertex worth of data // Struct representing a single vertex worth of data

View file

@ -7,7 +7,8 @@ cbuffer ExternalData : register(b0)
float3 ambient; 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);
} }

View file

@ -5,6 +5,7 @@ cbuffer ExternalData : register(b0)
matrix world; matrix world;
matrix view; matrix view;
matrix projection; 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 // - We don't need to alter it here, but we do need to send it to the pixel shader
output.uv = input.uv; 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 // Whatever we return will make its way through the pipeline to the
// next programmable stage we're using (the pixel shader for now) // next programmable stage we're using (the pixel shader for now)
return output; return output;