Skip to content

Commit 99bfa5e

Browse files
committed
Initial shader attempt
Signed-off-by: Isaac Marovitz <isaacryu@icloud.com>
1 parent f662491 commit 99bfa5e

3 files changed

Lines changed: 107 additions & 0 deletions

File tree

MarathonRecomp/CMakeLists.txt

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

0 commit comments

Comments
 (0)