From 8885412350dac42fb0152afa65296c7e3b1ddd42 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 31 Aug 2022 23:16:29 +0200 Subject: [PATCH] Fix SSR shader on D3D10 --- Content/Shaders/SSR.flax | 4 ++-- Source/Shaders/GI/GlobalSurfaceAtlas.hlsl | 4 ++++ Source/Shaders/Gather.hlsl | 26 +++++++++++++++++++++++ Source/Shaders/SSR.shader | 2 +- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Content/Shaders/SSR.flax b/Content/Shaders/SSR.flax index 36d193f28..09d4db9d7 100644 --- a/Content/Shaders/SSR.flax +++ b/Content/Shaders/SSR.flax @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9403835414767ee73082d543b0e0f0827e2dfaf7e108ccb06145acb5f8576c03 -size 11173 +oid sha256:51826aca596ee714a557d74adcee138e674d30197cffebe454e20474713f3b37 +size 10916 diff --git a/Source/Shaders/GI/GlobalSurfaceAtlas.hlsl b/Source/Shaders/GI/GlobalSurfaceAtlas.hlsl index 30bab5742..93633dbec 100644 --- a/Source/Shaders/GI/GlobalSurfaceAtlas.hlsl +++ b/Source/Shaders/GI/GlobalSurfaceAtlas.hlsl @@ -3,6 +3,10 @@ #include "./Flax/Common.hlsl" #include "./Flax/Collisions.hlsl" +#if CAN_USE_GATHER +#define CAN_USE_GLOBAL_SURFACE_ATLAS 1 +#endif + // This must match C++ #define GLOBAL_SURFACE_ATLAS_CHUNKS_RESOLUTION 40 // Amount of chunks (in each direction) to split atlas draw distance for objects culling #define GLOBAL_SURFACE_ATLAS_CHUNKS_GROUP_SIZE 4 diff --git a/Source/Shaders/Gather.hlsl b/Source/Shaders/Gather.hlsl index f6540fe86..76950bd66 100644 --- a/Source/Shaders/Gather.hlsl +++ b/Source/Shaders/Gather.hlsl @@ -70,4 +70,30 @@ float4 TextureGatherRed(Texture2D tex, SamplerState sam, float2 uv, int2 #endif } +float4 TextureGatherGreen(Texture2D tex, SamplerState sam, float2 uv) +{ +#if CAN_USE_GATHER + return tex.GatherGreen(sam, uv); +#else + float x = tex.Sample(sam, uv, int2(0, 1)).g; + float y = tex.Sample(sam, uv, int2(1, 1)).g; + float z = tex.Sample(sam, uv, int2(1, 0)).g; + float w = tex.Sample(sam, uv, int2(0, 0)).g; + return float4(x, y, z, w); +#endif +} + +float4 TextureGatherBlue(Texture2D tex, SamplerState sam, float2 uv) +{ +#if CAN_USE_GATHER + return tex.GatherBlue(sam, uv); +#else + float x = tex.Sample(sam, uv, int2(0, 1)).b; + float y = tex.Sample(sam, uv, int2(1, 1)).b; + float z = tex.Sample(sam, uv, int2(1, 0)).b; + float w = tex.Sample(sam, uv, int2(0, 0)).b; + return float4(x, y, z, w); +#endif +} + #endif diff --git a/Source/Shaders/SSR.shader b/Source/Shaders/SSR.shader index e6c57e943..765952cfb 100644 --- a/Source/Shaders/SSR.shader +++ b/Source/Shaders/SSR.shader @@ -134,7 +134,7 @@ float4 PS_RayTracePass(Quad_VS2PS input) : SV_Target0 float3 reflectWS = ScreenSpaceReflectionDirection(input.TexCoord, gBuffer, gBufferData.ViewPos, TemporalEffect, TemporalTime, BRDFBias); // Fallback to Global SDF and Global Surface Atlas tracing -#if USE_GLOBAL_SURFACE_ATLAS +#if USE_GLOBAL_SURFACE_ATLAS && CAN_USE_GLOBAL_SURFACE_ATLAS GlobalSDFTrace sdfTrace; float maxDistance = 100000; float selfOcclusionBias = GlobalSDF.CascadeVoxelSize[0];