diff --git a/Content/Editor/MaterialTemplates/VolumeParticle.shader b/Content/Editor/MaterialTemplates/VolumeParticle.shader index c21e7c3bb..c87c881b0 100644 --- a/Content/Editor/MaterialTemplates/VolumeParticle.shader +++ b/Content/Editor/MaterialTemplates/VolumeParticle.shader @@ -207,7 +207,7 @@ void PS_VolumetricFog(Quad_GS2PS input, out float4 VBufferA : SV_Target0, out fl float2 volumeUV = (gridCoordinate.xy + cellOffset.xy) / GridSize.xy; float zSlice = gridCoordinate.z + cellOffset.z; float sceneDepth = (zSlice / GridSize.z) * VolumetricFogMaxDistance / ViewFar; - float deviceDepth = (ViewInfo.w / sceneDepth) + ViewInfo.z; + float deviceDepth = (ViewInfo.w / sceneDepth) - ViewInfo.z; float4 clipPos = float4(volumeUV * float2(2.0, -2.0) + float2(-1.0, 1.0), deviceDepth, 1.0); float4 wsPos = mul(clipPos, InverseViewProjectionMatrix); float3 positionWS = wsPos.xyz / wsPos.w; diff --git a/Source/Editor/Gizmo/SelectionOutline.cs b/Source/Editor/Gizmo/SelectionOutline.cs index a364b3fb8..59859be5f 100644 --- a/Source/Editor/Gizmo/SelectionOutline.cs +++ b/Source/Editor/Gizmo/SelectionOutline.cs @@ -145,7 +145,7 @@ namespace FlaxEditor.Gizmo _material.SetParameterValue("OutlineColor0", _color0); _material.SetParameterValue("OutlineColor1", _color1); _material.SetParameterValue("CustomDepth", customDepth); - _material.SetParameterValue("ViewInfo", new Float4(1.0f / projection.M11, 1.0f / projection.M22, far / (far - near), (-far * near) / (far - near) / far)); + _material.SetParameterValue("ViewInfo", new Float4(1.0f / projection.M11, 1.0f / projection.M22, near / (far - near), (far * near) / (far - near) / far)); Renderer.DrawPostFxMaterial(context, ref renderContext, _material, output, input.View()); // Cleanup diff --git a/Source/Engine/Particles/Graph/GPU/ParticleEmitterGraph.GPU.ParticleModules.cpp b/Source/Engine/Particles/Graph/GPU/ParticleEmitterGraph.GPU.ParticleModules.cpp index 04dbbbc32..cf0df0f78 100644 --- a/Source/Engine/Particles/Graph/GPU/ParticleEmitterGraph.GPU.ParticleModules.cpp +++ b/Source/Engine/Particles/Graph/GPU/ParticleEmitterGraph.GPU.ParticleModules.cpp @@ -840,7 +840,7 @@ void ParticleEmitterGPUGenerator::ProcessModule(Node* node) " uint2 pixel = uv * ScreenSize.xy;\n" " float depth = {11}.Load(uint3(pixel, 0)).r;\n" - " float linearDepth = ViewInfo.w / (depth - ViewInfo.z) * ViewFar;\n" + " float linearDepth = ViewInfo.w / (depth + ViewInfo.z) * ViewFar;\n" " if (viewPos.z > linearDepth - {5} && viewPos.z < linearDepth + {5} + {10})\n" " {{\n" diff --git a/Source/Engine/Particles/Graph/GPU/ParticleEmitterGraph.GPU.Textures.cpp b/Source/Engine/Particles/Graph/GPU/ParticleEmitterGraph.GPU.Textures.cpp index bd8777f64..808de0f7e 100644 --- a/Source/Engine/Particles/Graph/GPU/ParticleEmitterGraph.GPU.Textures.cpp +++ b/Source/Engine/Particles/Graph/GPU/ParticleEmitterGraph.GPU.Textures.cpp @@ -144,7 +144,7 @@ void ParticleEmitterGPUGenerator::sampleSceneDepth(Node* caller, Value& value, B void ParticleEmitterGPUGenerator::linearizeSceneDepth(Node* caller, const Value& depth, Value& value) { - value = writeLocal(VariantType::Float, String::Format(TEXT("ViewInfo.w / ({0}.x - ViewInfo.z)"), depth.Value), caller); + value = writeLocal(VariantType::Float, String::Format(TEXT("ViewInfo.w / ({0}.x + ViewInfo.z)"), depth.Value), caller); } void ParticleEmitterGPUGenerator::ProcessGroupTextures(Box* box, Node* node, Value& value) diff --git a/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Textures.cpp b/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Textures.cpp index 9b0a334e6..0ab853386 100644 --- a/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Textures.cpp +++ b/Source/Engine/Tools/MaterialGenerator/MaterialGenerator.Textures.cpp @@ -160,7 +160,7 @@ void MaterialGenerator::sampleSceneDepth(Node* caller, Value& value, Box* box) void MaterialGenerator::linearizeSceneDepth(Node* caller, const Value& depth, Value& value) { - value = writeLocal(VariantType::Float, String::Format(TEXT("ViewInfo.w / ({0}.x - ViewInfo.z)"), depth.Value), caller); + value = writeLocal(VariantType::Float, String::Format(TEXT("ViewInfo.w / ({0}.x + ViewInfo.z)"), depth.Value), caller); } void MaterialGenerator::ProcessGroupTextures(Box* box, Node* node, Value& value) diff --git a/Source/Shaders/GI/GlobalSurfaceAtlas.shader b/Source/Shaders/GI/GlobalSurfaceAtlas.shader index 4765614ae..b06f797c4 100644 --- a/Source/Shaders/GI/GlobalSurfaceAtlas.shader +++ b/Source/Shaders/GI/GlobalSurfaceAtlas.shader @@ -121,7 +121,7 @@ float4 PS_Lighting(AtlasVertexOutput input) : SV_Target float tileDepth = SampleZ(atlasUV); //float tileNear = -GLOBAL_SURFACE_ATLAS_TILE_PROJ_PLANE_OFFSET; //float tileFar = tile.ViewBoundsSize.z + 2 * GLOBAL_SURFACE_ATLAS_TILE_PROJ_PLANE_OFFSET; - //gBufferData.ViewInfo.zw = float2(tileFar / (tileFar - tileNear), (-tileFar * tileNear) / (tileFar - tileNear) / tileFar); + //gBufferData.ViewInfo.zw = float2(tileNear / (tileFar - tileNear), (tileFar * tileNear) / (tileFar - tileNear) / tileFar); //gBufferData.ViewInfo.zw = float2(1, 0); //float tileLinearDepth = LinearizeZ(gBufferData, tileDepth); float3 tileSpacePos = float3(input.TileUV.x - 0.5f, 0.5f - input.TileUV.y, tileDepth); diff --git a/Source/Shaders/Shadows.shader b/Source/Shaders/Shadows.shader index 9db800f33..fd2625f60 100644 --- a/Source/Shaders/Shadows.shader +++ b/Source/Shaders/Shadows.shader @@ -44,7 +44,7 @@ float RayCastScreenSpaceShadow(GBufferData gBufferData, GBufferSample gBuffer, f float3 rayUV = rayCS.xyz / rayCS.w; rayUV.xy = rayUV.xy * float2(0.5, -0.5) + float2(0.5, 0.5); float sceneDepth = SampleDepth(gBufferData, rayUV.xy) * gBufferData.ViewFar; - float rayDepth = (gBufferData.ViewInfo.w / (rayUV.z - gBufferData.ViewInfo.z)) * gBufferData.ViewFar * 0.998; + float rayDepth = LinearizeZ(rayUV.z) * gBufferData.ViewFar * 0.998; float surfaceThickness = 0.035f + rayDepth * rayLength; float depthTestHardness = 0.005f; float lightAmount = saturate((rayDepth - sceneDepth) / depthTestHardness) * saturate((sceneDepth + surfaceThickness - rayDepth) / depthTestHardness); diff --git a/Source/Shaders/ShadowsCommon.hlsl b/Source/Shaders/ShadowsCommon.hlsl index 23ddf4214..7c38d7ce6 100644 --- a/Source/Shaders/ShadowsCommon.hlsl +++ b/Source/Shaders/ShadowsCommon.hlsl @@ -47,9 +47,9 @@ float3 GetShadowPositionOffset(float offsetScale, float NoL, float3 normal) float CalculateSubsurfaceOcclusion(float opacity, float sceneDepth, float shadowMapDepth) { - float thickness = max(sceneDepth - shadowMapDepth, 0); + float thickness = max(shadowMapDepth - sceneDepth, 0); float occlusion = 1 - thickness * lerp(1.0f, 100.0f, opacity); - return shadowMapDepth > 0.99f ? 1 : occlusion; + return shadowMapDepth < 0.01f ? 1 : occlusion; } #endif