view vector ortho projection fix

This commit is contained in:
Turánszki János
2024-09-28 12:04:49 +02:00
parent 6e0145719e
commit 0ed2a94cb6
+5 -1
View File
@@ -543,8 +543,12 @@ float4 main(PixelInput input, in bool is_frontface : SV_IsFrontFace) : SV_Target
#endif // OBJECTSHADER_USE_AO
#ifdef OBJECTSHADER_USE_POSITION3D
float2 clipspace = uv_to_clipspace(ScreenCoord);
float4 unprojectedNEAR = mul(GetCamera().inverse_view_projection, float4(clipspace, 1, 1));
unprojectedNEAR.xyz /= unprojectedNEAR.w;
surface.P = input.pos3D;
surface.V = GetCamera().position - surface.P;
surface.V = unprojectedNEAR.xyz - surface.P; // instead of camera.position - surface.P, unprojectedNEAR is used because it will also work correctly for orthographic projection!
float dist = length(surface.V);
surface.V /= dist;
#endif // OBJECTSHADER_USE_POSITION3D