1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-24 17:49:52 +01:00

fix bilinear shader (for real this time!)

This commit is contained in:
FunkyFr3sh 2023-08-23 01:59:51 +02:00
parent b5be29f6f1
commit afb3d2dea3

View File

@ -127,44 +127,48 @@ const BYTE D3D9_PALETTE_SHADER[] =
// //
ps_2_0 ps_2_0
def c1, 0.5, 0, 0.99609375, 0.001953125 def c1, -0.5, 0.5, 1.5, 0
dcl t0.xy def c2, 0.99609375, 0.001953125, 0, 0
dcl_2d s0 dcl t0.xy
dcl_2d s1 dcl_2d s0
mov r0.y, c1.y dcl_2d s1
rcp r1.x, c0.x mov r0.w, c1.x
rcp r1.y, c0.y mad r0.xy, t0, c0, r0.w
mul r0.zw, t0.wzyx, c0.wzyx frc r0.zw, r0.wzyx
frc r0.zw, r0 add r0.xy, -r0.wzyx, r0
add r2.xy, -r0.wzyx, c1.x add r0.zw, r0.wzyx, c1.z
mad r2.xy, r2, r1, t0 add r0.xy, r0, c1.y
add r3.xy, r1, r2 rcp r1.x, c0.x
mov r1.z, c1.y rcp r1.y, c0.y
add r4.x, r1.z, r2.x mul r2.xy, r0.wzyx, r1
add r4.y, r1.y, r2.y mul r1.xy, r0, r1
add r1.x, r1.x, r2.x mad r0.xy, t0, c0, -r0
add r1.y, r1.z, r2.y mov r3.x, r2.x
texld r3, r3, s0 mov r3.y, r1.y
texld r2, r2, s0 mov r4.x, r1.x
texld r1, r1, s0 mov r4.y, r2.y
texld r4, r4, s0 texld r3, r3, s0
mad r0.x, r3.x, c1.z, c1.w texld r1, r1, s0
mov r3.y, c1.y texld r2, r2, s0
mad r2.x, r2.x, c1.z, c1.w texld r4, r4, s0
mad r1.x, r1.x, c1.z, c1.w mad r3.x, r3.x, c2.x, c2.y
mad r3.x, r4.x, c1.z, c1.w mov r3.y, c1.w
mov r1.y, c1.y mad r1.x, r1.x, c2.x, c2.y
mov r2.y, c1.y mov r1.y, c1.w
texld r4, r0, s1 mad r2.x, r2.x, c2.x, c2.y
texld r3, r3, s1 mad r4.x, r4.x, c2.x, c2.y
texld r1, r1, s1 mov r4.y, c1.w
texld r2, r2, s1 mov r2.y, c1.w
lrp r5, r0.w, r4, r3 texld r3, r3, s1
lrp r3, r0.w, r1, r2 texld r1, r1, s1
lrp r1, r0.z, r5, r3 texld r4, r4, s1
mov oC0, r1 texld r2, r2, s1
lrp r5, r0.x, r3, r1
lrp r1, r0.x, r2, r4
lrp r2, r0.y, r1, r5
mov oC0, r2
// approximately 32 instruction slots used (8 texture, 24 arithmetic) // approximately 35 instruction slots used (8 texture, 27 arithmetic)
// fxc.exe /Tps_2_0 shader.hlsl /Fhshader.h // fxc.exe /Tps_2_0 shader.hlsl /Fhshader.h
/* /*
@ -173,18 +177,24 @@ uniform sampler2D PaletteTex;
float4 TextureSize : register(c0); float4 TextureSize : register(c0);
#define SourceSize float4(TextureSize.xy, 1.0 / TextureSize.xy)
float4 bilinear(float2 coord) float4 bilinear(float2 coord)
{ {
float2 size = 1.0 / TextureSize.xy; float2 samplePos = coord * SourceSize.xy;
float2 f = frac(coord * TextureSize.xy); float2 texPos1 = floor(samplePos - 0.5f) + 0.5f;
float2 texPos2 = texPos1 + 1.0f;
coord += (.5 - f) * size;
float2 f = samplePos - texPos1;
float tli = tex2D(SurfaceTex, coord).r;
float tri = tex2D(SurfaceTex, coord + float2(size.x, 0.0) ).r; texPos1 *= SourceSize.zw;
float bli = tex2D(SurfaceTex, coord + float2(0.0, size.y)).r; texPos2 *= SourceSize.zw;
float bri = tex2D(SurfaceTex, coord + float2(size.x, size.y)).r;
float tli = tex2D(SurfaceTex, float2(texPos1.x, texPos1.y)).r;
float tri = tex2D(SurfaceTex, float2(texPos2.x, texPos1.y)).r;
float bli = tex2D(SurfaceTex, float2(texPos1.x, texPos2.y)).r;
float bri = tex2D(SurfaceTex, float2(texPos2.x, texPos2.y)).r;
float4 tl = tex2D(PaletteTex, float2(tli * (255./256) + (0.5/256), 0)); float4 tl = tex2D(PaletteTex, float2(tli * (255./256) + (0.5/256), 0));
float4 tr = tex2D(PaletteTex, float2(tri * (255./256) + (0.5/256), 0)); float4 tr = tex2D(PaletteTex, float2(tri * (255./256) + (0.5/256), 0));
float4 bl = tex2D(PaletteTex, float2(bli * (255./256) + (0.5/256), 0)); float4 bl = tex2D(PaletteTex, float2(bli * (255./256) + (0.5/256), 0));
@ -192,7 +202,7 @@ float4 bilinear(float2 coord)
float4 top = lerp(tl, tr, f.x); float4 top = lerp(tl, tr, f.x);
float4 bot = lerp(bl, br, f.x); float4 bot = lerp(bl, br, f.x);
return lerp(top, bot, f.y); return lerp(top, bot, f.y);
} }
@ -204,142 +214,165 @@ float4 main(float2 texCoords : TEXCOORD) : COLOR
#endif #endif
const BYTE D3D9_PALETTE_SHADER_BILINEAR[] = const BYTE D3D9_PALETTE_SHADER_BILINEAR[] =
{ {
0, 2, 255, 255, 254, 255, 0, 2, 255, 255, 254, 255,
56, 0, 67, 84, 65, 66, 56, 0, 67, 84, 65, 66,
28, 0, 0, 0, 179, 0, 28, 0, 0, 0, 179, 0,
0, 0, 0, 2, 255, 255, 0, 0, 0, 2, 255, 255,
3, 0, 0, 0, 28, 0, 3, 0, 0, 0, 28, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0,
172, 0, 0, 0, 88, 0, 172, 0, 0, 0, 88, 0,
0, 0, 3, 0, 1, 0, 0, 0, 3, 0, 1, 0,
1, 0, 0, 0, 100, 0, 1, 0, 0, 0, 100, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
116, 0, 0, 0, 3, 0, 116, 0, 0, 0, 3, 0,
0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0,
128, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0,
0, 0, 144, 0, 0, 0, 0, 0, 144, 0, 0, 0,
2, 0, 0, 0, 1, 0, 2, 0, 0, 0, 1, 0,
2, 0, 156, 0, 0, 0, 2, 0, 156, 0, 0, 0,
0, 0, 0, 0, 80, 97, 0, 0, 0, 0, 80, 97,
108, 101, 116, 116, 101, 84, 108, 101, 116, 116, 101, 84,
101, 120, 0, 171, 4, 0, 101, 120, 0, 171, 4, 0,
12, 0, 1, 0, 1, 0, 12, 0, 1, 0, 1, 0,
1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
0, 0, 83, 117, 114, 102, 0, 0, 83, 117, 114, 102,
97, 99, 101, 84, 101, 120, 97, 99, 101, 84, 101, 120,
0, 171, 4, 0, 12, 0, 0, 171, 4, 0, 12, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
84, 101, 120, 116, 117, 114, 84, 101, 120, 116, 117, 114,
101, 83, 105, 122, 101, 0, 101, 83, 105, 122, 101, 0,
1, 0, 3, 0, 1, 0, 1, 0, 3, 0, 1, 0,
4, 0, 1, 0, 0, 0, 4, 0, 1, 0, 0, 0,
0, 0, 0, 0, 112, 115, 0, 0, 0, 0, 112, 115,
95, 50, 95, 48, 0, 77, 95, 50, 95, 48, 0, 77,
105, 99, 114, 111, 115, 111, 105, 99, 114, 111, 115, 111,
102, 116, 32, 40, 82, 41, 102, 116, 32, 40, 82, 41,
32, 72, 76, 83, 76, 32, 32, 72, 76, 83, 76, 32,
83, 104, 97, 100, 101, 114, 83, 104, 97, 100, 101, 114,
32, 67, 111, 109, 112, 105, 32, 67, 111, 109, 112, 105,
108, 101, 114, 32, 49, 48, 108, 101, 114, 32, 49, 48,
46, 49, 0, 171, 81, 0, 46, 49, 0, 171, 81, 0,
0, 5, 1, 0, 15, 160, 0, 5, 1, 0, 15, 160,
0, 0, 0, 63, 0, 0, 0, 0, 0, 191, 0, 0,
0, 0, 0, 0, 127, 63, 0, 63, 0, 0, 192, 63,
0, 0, 0, 59, 31, 0, 0, 0, 0, 0, 81, 0,
0, 2, 0, 0, 0, 128, 0, 5, 2, 0, 15, 160,
0, 0, 3, 176, 31, 0, 0, 0, 127, 63, 0, 0,
0, 2, 0, 0, 0, 144, 0, 59, 0, 0, 0, 0,
0, 8, 15, 160, 31, 0, 0, 0, 0, 0, 31, 0,
0, 2, 0, 0, 0, 144, 0, 2, 0, 0, 0, 128,
1, 8, 15, 160, 1, 0, 0, 0, 3, 176, 31, 0,
0, 2, 0, 0, 2, 128, 0, 2, 0, 0, 0, 144,
1, 0, 85, 160, 6, 0, 0, 8, 15, 160, 31, 0,
0, 2, 1, 0, 1, 128, 0, 2, 0, 0, 0, 144,
0, 0, 0, 160, 6, 0, 1, 8, 15, 160, 1, 0,
0, 2, 1, 0, 2, 128, 0, 2, 0, 0, 8, 128,
0, 0, 85, 160, 5, 0, 1, 0, 0, 160, 4, 0,
0, 3, 0, 0, 12, 128, 0, 4, 0, 0, 3, 128,
0, 0, 27, 176, 0, 0, 0, 0, 228, 176, 0, 0,
27, 160, 19, 0, 0, 2, 228, 160, 0, 0, 255, 128,
0, 0, 12, 128, 0, 0, 19, 0, 0, 2, 0, 0,
228, 128, 2, 0, 0, 3, 12, 128, 0, 0, 27, 128,
2, 0, 3, 128, 0, 0, 2, 0, 0, 3, 0, 0,
27, 129, 1, 0, 0, 160, 3, 128, 0, 0, 27, 129,
4, 0, 0, 4, 2, 0, 0, 0, 228, 128, 2, 0,
3, 128, 2, 0, 228, 128, 0, 3, 0, 0, 12, 128,
1, 0, 228, 128, 0, 0, 0, 0, 27, 128, 1, 0,
228, 176, 2, 0, 0, 3, 170, 160, 2, 0, 0, 3,
3, 0, 3, 128, 1, 0, 0, 0, 3, 128, 0, 0,
228, 128, 2, 0, 228, 128, 228, 128, 1, 0, 85, 160,
1, 0, 0, 2, 1, 0, 6, 0, 0, 2, 1, 0,
4, 128, 1, 0, 85, 160, 1, 128, 0, 0, 0, 160,
2, 0, 0, 3, 4, 0, 6, 0, 0, 2, 1, 0,
1, 128, 1, 0, 170, 128, 2, 128, 0, 0, 85, 160,
2, 0, 0, 128, 2, 0, 5, 0, 0, 3, 2, 0,
0, 3, 4, 0, 2, 128, 3, 128, 0, 0, 27, 128,
1, 0, 85, 128, 2, 0, 1, 0, 228, 128, 5, 0,
85, 128, 2, 0, 0, 3, 0, 3, 1, 0, 3, 128,
1, 0, 1, 128, 1, 0, 0, 0, 228, 128, 1, 0,
0, 128, 2, 0, 0, 128, 228, 128, 4, 0, 0, 4,
2, 0, 0, 3, 1, 0, 0, 0, 3, 128, 0, 0,
2, 128, 1, 0, 170, 128, 228, 176, 0, 0, 228, 160,
2, 0, 85, 128, 66, 0, 0, 0, 228, 129, 1, 0,
0, 3, 3, 0, 15, 128, 0, 2, 3, 0, 1, 128,
3, 0, 228, 128, 0, 8, 2, 0, 0, 128, 1, 0,
228, 160, 66, 0, 0, 3, 0, 2, 3, 0, 2, 128,
2, 0, 15, 128, 2, 0, 1, 0, 85, 128, 1, 0,
228, 128, 0, 8, 228, 160, 0, 2, 4, 0, 1, 128,
66, 0, 0, 3, 1, 0, 1, 0, 0, 128, 1, 0,
15, 128, 1, 0, 228, 128, 0, 2, 4, 0, 2, 128,
0, 8, 228, 160, 66, 0, 2, 0, 85, 128, 66, 0,
0, 3, 4, 0, 15, 128, 0, 3, 3, 0, 15, 128,
4, 0, 228, 128, 0, 8, 3, 0, 228, 128, 0, 8,
228, 160, 4, 0, 0, 4, 228, 160, 66, 0, 0, 3,
0, 0, 1, 128, 3, 0, 1, 0, 15, 128, 1, 0,
0, 128, 1, 0, 170, 160, 228, 128, 0, 8, 228, 160,
1, 0, 255, 160, 1, 0, 66, 0, 0, 3, 2, 0,
0, 2, 3, 0, 2, 128, 15, 128, 2, 0, 228, 128,
1, 0, 85, 160, 4, 0, 0, 8, 228, 160, 66, 0,
0, 4, 2, 0, 1, 128, 0, 3, 4, 0, 15, 128,
2, 0, 0, 128, 1, 0, 4, 0, 228, 128, 0, 8,
170, 160, 1, 0, 255, 160, 228, 160, 4, 0, 0, 4,
4, 0, 0, 4, 1, 0, 3, 0, 1, 128, 3, 0,
1, 128, 1, 0, 0, 128, 0, 128, 2, 0, 0, 160,
1, 0, 170, 160, 1, 0, 2, 0, 85, 160, 1, 0,
255, 160, 4, 0, 0, 4, 0, 2, 3, 0, 2, 128,
3, 0, 1, 128, 4, 0, 1, 0, 255, 160, 4, 0,
0, 128, 1, 0, 170, 160, 0, 4, 1, 0, 1, 128,
1, 0, 255, 160, 1, 0, 1, 0, 0, 128, 2, 0,
0, 2, 1, 0, 2, 128, 0, 160, 2, 0, 85, 160,
1, 0, 85, 160, 1, 0, 1, 0, 0, 2, 1, 0,
0, 2, 2, 0, 2, 128, 2, 128, 1, 0, 255, 160,
1, 0, 85, 160, 66, 0, 4, 0, 0, 4, 2, 0,
0, 3, 4, 0, 15, 128, 1, 128, 2, 0, 0, 128,
0, 0, 228, 128, 1, 8, 2, 0, 0, 160, 2, 0,
228, 160, 66, 0, 0, 3, 85, 160, 4, 0, 0, 4,
3, 0, 15, 128, 3, 0, 4, 0, 1, 128, 4, 0,
228, 128, 1, 8, 228, 160, 0, 128, 2, 0, 0, 160,
66, 0, 0, 3, 1, 0, 2, 0, 85, 160, 1, 0,
15, 128, 1, 0, 228, 128, 0, 2, 4, 0, 2, 128,
1, 8, 228, 160, 66, 0, 1, 0, 255, 160, 1, 0,
0, 3, 2, 0, 15, 128, 0, 2, 2, 0, 2, 128,
2, 0, 228, 128, 1, 8, 1, 0, 255, 160, 66, 0,
228, 160, 18, 0, 0, 4, 0, 3, 3, 0, 15, 128,
5, 0, 15, 128, 0, 0, 3, 0, 228, 128, 1, 8,
255, 128, 4, 0, 228, 128, 228, 160, 66, 0, 0, 3,
3, 0, 228, 128, 18, 0, 1, 0, 15, 128, 1, 0,
0, 4, 3, 0, 15, 128, 228, 128, 1, 8, 228, 160,
0, 0, 255, 128, 1, 0, 66, 0, 0, 3, 4, 0,
228, 128, 2, 0, 228, 128, 15, 128, 4, 0, 228, 128,
18, 0, 0, 4, 1, 0, 1, 8, 228, 160, 66, 0,
15, 128, 0, 0, 170, 128, 0, 3, 2, 0, 15, 128,
5, 0, 228, 128, 3, 0, 2, 0, 228, 128, 1, 8,
228, 128, 1, 0, 0, 2, 228, 160, 18, 0, 0, 4,
0, 8, 15, 128, 1, 0, 5, 0, 15, 128, 0, 0,
0, 128, 3, 0, 228, 128,
1, 0, 228, 128, 18, 0,
0, 4, 1, 0, 15, 128,
0, 0, 0, 128, 2, 0,
228, 128, 4, 0, 228, 128,
18, 0, 0, 4, 2, 0,
15, 128, 0, 0, 85, 128,
1, 0, 228, 128, 5, 0,
228, 128, 1, 0, 0, 2,
0, 8, 15, 128, 2, 0,
228, 128, 255, 255, 0, 0 228, 128, 255, 255, 0, 0
}; };
/* catmull rom upscaling */ /* catmull rom upscaling */