Skip to content

Commit 6bc4a0d

Browse files
Enhanced Burnout Blur (#140)
* Initial shader attempt Signed-off-by: Isaac Marovitz <isaacryu@icloud.com> * Fix g_Velocity offset for Vk Signed-off-by: Isaac Marovitz <isaacryu@icloud.com> * Metal Shaders Signed-off-by: Isaac Marovitz <isaacryu@icloud.com> * Make it actually work Signed-off-by: Isaac Marovitz <isaacryu@icloud.com> * Dont commit debug stuff Signed-off-by: Isaac Marovitz <isaacryu@icloud.com> * Enhanced Radial Blur Signed-off-by: Isaac Marovitz <isaacryu@icloud.com> * Remove old shader Signed-off-by: Isaac Marovitz <isaacryu@icloud.com> * Fix D3D12 * Fix missing EOF new lines Signed-off-by: Isaac Marovitz <isaacryu@icloud.com> --------- Signed-off-by: Isaac Marovitz <isaacryu@icloud.com> Co-authored-by: Hyper <34012267+hyperbx@users.noreply.github.com>
1 parent f662491 commit 6bc4a0d

10 files changed

Lines changed: 218 additions & 144 deletions

MarathonRecomp/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,8 @@ compile_pixel_shader(copy_depth_ps)
483483
compile_pixel_shader(csd_filter_ps)
484484
compile_vertex_shader(csd_no_tex_vs)
485485
compile_vertex_shader(csd_vs)
486-
compile_pixel_shader(enhanced_motion_blur_ps)
486+
compile_vertex_shader(enhanced_burnout_blur_vs)
487+
compile_pixel_shader(enhanced_burnout_blur_ps)
487488
compile_pixel_shader(gaussian_blur_3x3)
488489
compile_pixel_shader(gaussian_blur_5x5)
489490
compile_pixel_shader(gaussian_blur_7x7)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h"
2+
3+
#ifdef __spirv__
4+
5+
#define s0_Texture2DDescriptorIndex vk::RawBufferLoad<uint>(g_PushConstants.SharedConstants + 0)
6+
#define s0_SamplerDescriptorIndex vk::RawBufferLoad<uint>(g_PushConstants.SharedConstants + 192)
7+
8+
#else
9+
10+
cbuffer SharedConstants : register(b2, space4)
11+
{
12+
uint s0_Texture2DDescriptorIndex : packoffset(c0.x);
13+
uint s0_SamplerDescriptorIndex : packoffset(c12.x);
14+
DEFINE_SHARED_CONSTANTS();
15+
};
16+
17+
#endif
18+
19+
float4 shaderMain(
20+
in float4 oPos : SV_Position,
21+
in float2 oTexCoord0 : TEXCOORD0,
22+
in float2 oVelocity : TEXCOORD1,
23+
in float2 oVelScale : TEXCOORD2) : SV_Target
24+
{
25+
Texture2D<float4> texture = g_Texture2DDescriptorHeap[s0_Texture2DDescriptorIndex];
26+
SamplerState samplerState = g_SamplerDescriptorHeap[s0_SamplerDescriptorIndex];
27+
28+
float velocityMag = sqrt(dot(oVelocity, oVelocity));
29+
float blurAmount = saturate(velocityMag - 0.25);
30+
31+
if (blurAmount == 0.0)
32+
return texture.SampleLevel(samplerState, oTexCoord0, 0);
33+
34+
blurAmount = min(blurAmount * blurAmount, 0.25);
35+
36+
float blurStrength = blurAmount * velocityMag;
37+
int g_SampleCount = clamp((int)(blurStrength * 256.0), 4, 64);
38+
float2 scaledVelStep = oVelScale / (float)g_SampleCount;
39+
40+
float4 result = float4(0.0, 0.0, 0.0, 0.0);
41+
42+
for (int i = 0; i < g_SampleCount; i++)
43+
{
44+
float2 offset = blurAmount * scaledVelStep * (float)i;
45+
float2 samplePos = oTexCoord0 + offset;
46+
47+
result += texture.SampleLevel(samplerState, samplePos, 0);
48+
}
49+
50+
return result * (1.0 / (float)g_SampleCount);
51+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h"
2+
3+
#ifdef __spirv__
4+
5+
#define g_Velocity vk::RawBufferLoad<float4>(g_PushConstants.VertexShaderConstants + 3360, 0x10)
6+
7+
#else
8+
9+
cbuffer VertexShaderConstants : register(b1, space4)
10+
{
11+
float4 g_Velocity : packoffset(c210);
12+
};
13+
14+
#endif
15+
16+
void shaderMain(
17+
[[vk::location(0)]] in float4 iPosition0 : POSITION0,
18+
[[vk::location(13)]] in float2 iTexCoord0 : TEXCOORD0,
19+
out float4 oPos : SV_Position,
20+
out float2 oTexCoord0 : TEXCOORD0,
21+
out float2 oVelocity : TEXCOORD1,
22+
out float2 oVelScale : TEXCOORD2)
23+
{
24+
oPos = iPosition0;
25+
oTexCoord0 = iTexCoord0;
26+
27+
float2 centeredUV;
28+
centeredUV.x = iTexCoord0.y * 2.0 - 1.0;
29+
centeredUV.y = iTexCoord0.x * 2.0 - 1.0;
30+
31+
oVelocity.x = -g_Velocity.x - centeredUV.y;
32+
oVelocity.y = centeredUV.x - g_Velocity.y;
33+
34+
float2 scaledVec = oVelocity * g_Velocity.w;
35+
oVelScale.x = scaledVec.x * 0.00002;
36+
oVelScale.y = -scaledVec.y * 0.00001;
37+
}

MarathonRecomp/gpu/shader/hlsl/enhanced_motion_blur_ps.hlsl

Lines changed: 0 additions & 75 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h"
2+
3+
#define s0_TextureDescriptorIndex (*(reinterpret_cast<device int*>(g_PushConstants.SharedConstants + 0)))
4+
#define s0_SamplerDescriptorIndex (*(reinterpret_cast<device uint*>(g_PushConstants.SharedConstants + 192)))
5+
6+
struct Interpolators
7+
{
8+
float4 oPos [[position]];
9+
float2 oTexCoord0 [[user(TEXCOORD0)]];
10+
float2 oVelocity [[user(TEXCOORD1)]];
11+
float2 oVelScale [[user(TEXCOORD2)]];
12+
};
13+
14+
[[fragment]]
15+
float4 shaderMain(Interpolators input [[stage_in]],
16+
constant Texture2DDescriptorHeap* g_Texture2DDescriptorHeap [[buffer(0)]],
17+
constant SamplerDescriptorHeap* g_SamplerDescriptorHeap [[buffer(3)]],
18+
constant PushConstants& g_PushConstants [[buffer(8)]])
19+
{
20+
texture2d<float> texture = g_Texture2DDescriptorHeap[s0_TextureDescriptorIndex].tex;
21+
sampler samp = g_SamplerDescriptorHeap[s0_SamplerDescriptorIndex].samp;
22+
23+
float velocityMag = sqrt(dot(input.oVelocity, input.oVelocity));
24+
float blurAmount = saturate(velocityMag - 0.25);
25+
26+
if (blurAmount == 0.0)
27+
return texture.sample(samp, input.oTexCoord0, level(0));
28+
29+
blurAmount = min(blurAmount * blurAmount, 0.25);
30+
31+
float blurStrength = blurAmount * velocityMag;
32+
int g_SampleCount = clamp((int)(blurStrength * 256.0), 4, 64);
33+
float2 scaledVelStep = input.oVelScale / (float)g_SampleCount;
34+
35+
float4 result = float4(0.0);
36+
37+
for (int i = 0; i < g_SampleCount; i++)
38+
{
39+
float2 offset = blurAmount * scaledVelStep * (float)i;
40+
float2 samplePos = input.oTexCoord0 + offset;
41+
42+
result += texture.sample(samp, samplePos, level(0));
43+
}
44+
45+
return result * (1.0 / (float)g_SampleCount);
46+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include "../../../../tools/XenosRecomp/XenosRecomp/shader_common.h"
2+
3+
// #define g_SampleCount (*(reinterpret_cast<device int*>(g_PushConstants.VertexShaderConstants + 0)))
4+
#define g_Velocity (*(reinterpret_cast<device float4*>(g_PushConstants.VertexShaderConstants + 3360)))
5+
6+
struct VertexShaderInput
7+
{
8+
float4 iPosition0 [[attribute(0)]];
9+
float2 iTexCoord0 [[attribute(13)]];
10+
};
11+
12+
struct Interpolators
13+
{
14+
float4 oPos [[position]];
15+
float2 oTexCoord0 [[user(TEXCOORD0)]];
16+
float2 oVelocity [[user(TEXCOORD1)]];
17+
float2 oVelScale [[user(TEXCOORD2)]];
18+
};
19+
20+
[[vertex]]
21+
Interpolators shaderMain(VertexShaderInput input [[stage_in]],
22+
constant PushConstants& g_PushConstants [[buffer(8)]])
23+
{
24+
Interpolators output;
25+
26+
output.oPos = input.iPosition0;
27+
output.oTexCoord0 = input.iTexCoord0;
28+
29+
float2 centeredUV;
30+
centeredUV.x = input.iTexCoord0.y * 2.0 - 1.0;
31+
centeredUV.y = input.iTexCoord0.x * 2.0 - 1.0;
32+
33+
output.oVelocity.x = -g_Velocity.x - centeredUV.y;
34+
output.oVelocity.y = centeredUV.x - g_Velocity.y;
35+
36+
float2 scaledVec = output.oVelocity * g_Velocity.w;
37+
output.oVelScale.x = scaledVec.x * 0.00002;
38+
output.oVelScale.y = -scaledVec.y * 0.00001;
39+
40+
return output;
41+
}

MarathonRecomp/gpu/shader/msl/enhanced_motion_blur_ps.metal

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)