mirror of
https://github.com/libretro/slang-shaders.git
synced 2024-11-23 08:19:54 +00:00
Update ddt.slang
* Implemented Fallback to Bilinear controlled by user param. * At its default value it gets rid of most ddt artifacts by falling back to relied bilinear filtering. * At value 1.0, it behaves as original DDT shader.
This commit is contained in:
parent
dd228b941b
commit
2ac8ca7c1b
@ -3,7 +3,7 @@
|
||||
/*
|
||||
Hyllian's DDT Shader
|
||||
|
||||
Copyright (C) 2011-2016 Hyllian/Jararaca - sergiogdb@gmail.com
|
||||
Copyright (C) 2011-2024 Hyllian/Jararaca - sergiogdb@gmail.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@ -26,15 +26,20 @@
|
||||
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
vec4 SourceSize;
|
||||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
float BIL_FALLBACK;
|
||||
} params;
|
||||
|
||||
#pragma parameter BIL_FALLBACK "Bilinear Fallback Threshold" 0.6 0.0 1.0 0.05
|
||||
|
||||
#define BIL_FALLBACK params.BIL_FALLBACK
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
mat4 MVP;
|
||||
mat4 MVP;
|
||||
} global;
|
||||
|
||||
#define saturate(c) clamp(c, 0.0, 1.0)
|
||||
@ -67,7 +72,7 @@ float luma(float3 color)
|
||||
|
||||
float3 bilinear(float p, float q, float3 A, float3 B, float3 C, float3 D)
|
||||
{
|
||||
return ((1-p)*(1-q)*A + p*(1-q)*B + (1-p)*q*C + p*q*D);
|
||||
return ((1-p)*(1-q)*A + p*(1-q)*B + (1-p)*q*C + p*q*D);
|
||||
}
|
||||
|
||||
#pragma stage vertex
|
||||
@ -83,12 +88,12 @@ void main()
|
||||
vTexCoord = TexCoord * 1.0001;
|
||||
|
||||
float2 ps = float2(params.SourceSize.z, params.SourceSize.w);
|
||||
float dx = ps.x;
|
||||
float dy = ps.y;
|
||||
float dx = ps.x;
|
||||
float dy = ps.y;
|
||||
|
||||
t1.xy = float2( dx, 0); // F
|
||||
t1.zw = float2( 0, dy); // H
|
||||
loc = vTexCoord*params.SourceSize.xy;
|
||||
t1.xy = float2( dx, 0); // F
|
||||
t1.zw = float2( 0, dy); // H
|
||||
loc = vTexCoord*params.SourceSize.xy;
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
@ -101,46 +106,51 @@ layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
void main()
|
||||
{
|
||||
float2 pos = frac(loc)-float2(0.5, 0.5); // pos = pixel position
|
||||
float2 dir = sign(pos); // dir = pixel direction
|
||||
float2 dir = sign(pos); // dir = pixel direction
|
||||
|
||||
float2 g1 = dir*t1.xy;
|
||||
float2 g2 = dir*t1.zw;
|
||||
float2 g1 = dir*t1.xy;
|
||||
float2 g2 = dir*t1.zw;
|
||||
|
||||
float3 A = tex2D(decal, vTexCoord ).xyz;
|
||||
float3 B = tex2D(decal, vTexCoord +g1 ).xyz;
|
||||
float3 C = tex2D(decal, vTexCoord +g2).xyz;
|
||||
float3 D = tex2D(decal, vTexCoord +g1+g2).xyz;
|
||||
float3 A = tex2D(decal, vTexCoord ).xyz;
|
||||
float3 B = tex2D(decal, vTexCoord +g1 ).xyz;
|
||||
float3 C = tex2D(decal, vTexCoord +g2).xyz;
|
||||
float3 D = tex2D(decal, vTexCoord +g1+g2).xyz;
|
||||
|
||||
float a = luma(A);
|
||||
float b = luma(B);
|
||||
float c = luma(C);
|
||||
float d = luma(D);
|
||||
float a = luma(A);
|
||||
float b = luma(B);
|
||||
float c = luma(C);
|
||||
float d = luma(D);
|
||||
|
||||
float p = abs(pos.x);
|
||||
float q = abs(pos.y);
|
||||
float p = abs(pos.x);
|
||||
float q = abs(pos.y);
|
||||
|
||||
float k = distance(pos,g1 * params.SourceSize.xy);
|
||||
float l = distance(pos,g2 * params.SourceSize.xy);
|
||||
float k = distance(pos,g1 * params.SourceSize.xy);
|
||||
float l = distance(pos,g2 * params.SourceSize.xy);
|
||||
|
||||
float wd1 = abs(a-d);
|
||||
float wd2 = abs(b-c);
|
||||
float wd1 = abs(a-d);
|
||||
float wd2 = abs(b-c);
|
||||
|
||||
if ( wd1 < wd2 )
|
||||
{
|
||||
if (k < l)
|
||||
{
|
||||
C = A + D - B;
|
||||
}
|
||||
else
|
||||
{
|
||||
B = A + D - C;
|
||||
}
|
||||
}
|
||||
else if (wd1 > wd2)
|
||||
{
|
||||
D = B + C - A;
|
||||
}
|
||||
float3 color = bilinear(p, q, A, B, C, D);
|
||||
|
||||
float3 color = bilinear(p, q, A, B, C, D);
|
||||
FragColor = vec4(color, 1.0);
|
||||
if ( wd1 < wd2 )
|
||||
{
|
||||
if (k < l)
|
||||
{
|
||||
C = A + D - B;
|
||||
}
|
||||
else
|
||||
{
|
||||
B = A + D - C;
|
||||
}
|
||||
}
|
||||
else if (wd1 > wd2)
|
||||
{
|
||||
D = B + C - A;
|
||||
}
|
||||
|
||||
float3 ddt = bilinear(p, q, A, B, C, D);
|
||||
|
||||
color = mix(color, ddt, smoothstep(0.0, BIL_FALLBACK, abs(wd2-wd1)));
|
||||
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user