diff --git a/Source/Engine/Graphics/RenderView.cpp b/Source/Engine/Graphics/RenderView.cpp index 730895267..e03a22b3d 100644 --- a/Source/Engine/Graphics/RenderView.cpp +++ b/Source/Engine/Graphics/RenderView.cpp @@ -64,7 +64,7 @@ void RenderView::Prepare(RenderContext& renderContext) void RenderView::PrepareCache(const RenderContext& renderContext, float width, float height, const Float2& temporalAAJitter, const RenderView* mainView) { // The same format used by the Flax common shaders and postFx materials - ViewInfo = Float4(1.0f / Projection.M11, 1.0f / Projection.M22, Far / (Far - Near), (-Far * Near) / (Far - Near) / Far); + ViewInfo = Float4(1.0f / Projection.M11, 1.0f / Projection.M22, Near / (Far - Near), (Far * Near) / (Far - Near) / Far); ScreenSize = Float4(width, height, 1.0f / width, 1.0f / height); TemporalAAJitter.Z = TemporalAAJitter.X; diff --git a/Source/Engine/Renderer/DepthOfFieldPass.cpp b/Source/Engine/Renderer/DepthOfFieldPass.cpp index 59a21094d..629f77d82 100644 --- a/Source/Engine/Renderer/DepthOfFieldPass.cpp +++ b/Source/Engine/Renderer/DepthOfFieldPass.cpp @@ -277,8 +277,8 @@ void DepthOfFieldPass::Render(RenderContext& renderContext, GPUTexture*& frame, cbData.BokehTargetSize.Y = static_cast(bokehTargetHeight); // TODO: use projection matrix instead of this far and near stuff? - cbData.ProjectionAB.X = farPlane / (farPlane - nearPlane); - cbData.ProjectionAB.Y = (-farPlane * nearPlane) / (farPlane - nearPlane); + cbData.ProjectionAB.X = nearPlane / (farPlane - nearPlane); + cbData.ProjectionAB.Y = (farPlane * nearPlane) / (farPlane - nearPlane); auto cb = shader->GetCB(0); context->UpdateCB(cb, &cbData); diff --git a/Source/Engine/Renderer/GBufferPass.cpp b/Source/Engine/Renderer/GBufferPass.cpp index 7a13d71a9..0e2ace66a 100644 --- a/Source/Engine/Renderer/GBufferPass.cpp +++ b/Source/Engine/Renderer/GBufferPass.cpp @@ -396,7 +396,7 @@ bool GBufferPass::IsDebugView(ViewMode mode) void GBufferPass::SetInputs(const RenderView& view, GBufferData& gBuffer) { // GBuffer params: - // ViewInfo : x-1/Projection[0,0] y-1/Projection[1,1] z-(Far / (Far - Near) w-(-Far * Near) / (Far - Near) / Far) + // ViewInfo : x-1/Projection[0,0] y-1/Projection[1,1] z-(Near / (Far - Near)) w-((Far * Near) / (Far - Near)) // ScreenSize : x-Width y-Height z-1 / Width w-1 / Height // ViewPos,ViewFar : x,y,z - world space view position w-Far // InvViewMatrix : inverse view matrix (4 rows by 4 columns) diff --git a/Source/Shaders/Common.hlsl b/Source/Shaders/Common.hlsl index 4fa3b5bb2..701546761 100644 --- a/Source/Shaders/Common.hlsl +++ b/Source/Shaders/Common.hlsl @@ -135,7 +135,7 @@ SamplerComparisonState ShadowSamplerPCF : register(s5); // Structure that contains information about GBuffer struct GBufferData { - float4 ViewInfo; // x-1/Projection[0,0], y-1/Projection[1,1], z-(Far / (Far - Near), w-(-Far * Near) / (Far - Near) / Far) + float4 ViewInfo; // x-1/Projection[0,0], y-1/Projection[1,1], z-(Near / (Far - Near)), w-((Far * Near) / (Far - Near) / Far) float4 ScreenSize; // x-Width, y-Height, z-1/Width, w-1/Height float3 ViewPos; // view position (in world space) float ViewFar; // view far plane distance (in world space) diff --git a/Source/Shaders/DepthOfField.shader b/Source/Shaders/DepthOfField.shader index e666d3852..00db90261 100644 --- a/Source/Shaders/DepthOfField.shader +++ b/Source/Shaders/DepthOfField.shader @@ -96,7 +96,7 @@ Texture2D Input1 : register(t1); // Converts z-buffer depth to linear view-space depth float LinearDepth(in float zBufferDepth) { - return ProjectionAB.y / (zBufferDepth - ProjectionAB.x); + return ProjectionAB.y / (zBufferDepth + ProjectionAB.x); } // Depth of Field depth blur generation (outputs linear depth + blur factor to R16G16 target) diff --git a/Source/Shaders/GBuffer.hlsl b/Source/Shaders/GBuffer.hlsl index a35519992..bc7e7483c 100644 --- a/Source/Shaders/GBuffer.hlsl +++ b/Source/Shaders/GBuffer.hlsl @@ -27,13 +27,13 @@ Texture2D GBuffer3 : register(t4); // Linearize raw device depth float LinearizeZ(GBufferData gBuffer, float depth) { - return gBuffer.ViewInfo.w / ((1-depth) - gBuffer.ViewInfo.z); + return gBuffer.ViewInfo.w / (depth + gBuffer.ViewInfo.z); } // Convert linear depth to device depth float LinearZ2DeviceDepth(GBufferData gBuffer, float linearDepth) { - return 1 - ((gBuffer.ViewInfo.w / linearDepth) + gBuffer.ViewInfo.z); + return ((gBuffer.ViewInfo.w / linearDepth) - gBuffer.ViewInfo.z); } // Get view space position at given pixel coordinate with given device depth diff --git a/Source/Shaders/SSAO.shader b/Source/Shaders/SSAO.shader index e72d9a30c..c1282a94d 100644 --- a/Source/Shaders/SSAO.shader +++ b/Source/Shaders/SSAO.shader @@ -275,7 +275,7 @@ void PrepareDepthMip(const float4 inPos, int mipLevel, out float outD0, out floa { float4 depths = depthsArr[i]; - float closest = min(min(depths.x, depths.y), min(depths.z, depths.w)); + float closest = max(max(depths.x, depths.y), max(depths.z, depths.w)); CalculateRadiusParameters(abs(closest), 1.0, dummyUnused1, dummyUnused2, falloffCalcMulSq); diff --git a/Source/Shaders/SSR.hlsl b/Source/Shaders/SSR.hlsl index 22685563b..0adf84a83 100644 --- a/Source/Shaders/SSR.hlsl +++ b/Source/Shaders/SSR.hlsl @@ -98,7 +98,7 @@ float3 TraceScreenSpaceReflection(float2 uv, GBufferSample gBuffer, Texture2D de { // Sample depth buffer and calculate depth difference currSample = SAMPLE_RT(depthBuffer, currOffset.xy).r; - depthDiff = currOffset.z - currSample; + depthDiff = currSample - currOffset.z; // Check intersection if (depthDiff >= 0)