-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSpectrum_PS.hlsl
65 lines (56 loc) · 1.89 KB
/
Spectrum_PS.hlsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
cbuffer gConstants : register(b0)
{
uint flash_invert;
uint transparent;
};
StructuredBuffer<float4> gPalette : register(t0);
StructuredBuffer<uint> gDisplay : register(t1);
StructuredBuffer<uint> gMask : register(t2);
struct VS_OUTPUT
{
float4 pos : SV_Position;
float2 tex : TEXCOORD0;
uint width : TILE_W;
uint height : TILE_H;
uint offset_x : OFFSET_X;
uint offset_y : OFFSET_Y;
uint offset : DATA_OFFSET;
};
float4 main (VS_OUTPUT input) : SV_Target
{
uint x = input.offset_x + input.tex.x * input.width;
uint y = input.offset_y + input.tex.y * input.height;
// DATA: 00 00 00 Y7 Y6 Y2 Y1 Y0 Y5 Y4 Y3 X7 X6 X5 X4 X3
// -- -- -- -- -- Y7 Y6 -- -- -- -- -- -- << 5
// -- -- -- -- -- -- -- Y5 Y4 Y3 -- -- -- << 2
// -- -- -- -- -- -- -- -- -- -- Y2 Y1 Y0 << 8
// -- -- -- -- -- X7 X6 X5 X4 X3 -- -- -- >> 3
uint data_offset =
input.offset +
((y & 0xc0) << 5) +
((y & 0x38) << 2) +
((y & 0x07) << 8) +
((x & 0xf8) >> 3);
uint data_dword = gDisplay[data_offset >> 2];
uint data_mask = 1 <<
((x & 0x18) |
(7 - (x & 0x07)));
// ATTR: 00 00 00 00 00 00 Y7 Y6 Y5 Y4 Y3 X7 X6 X5 X4 X3
// -- -- Y7 Y6 Y5 Y4 Y3 -- -- -- << 2
// -- -- X7 X6 X5 X4 X3 -- -- -- >> 3
uint attr_offset =
input.offset + 0x1800 +
((y & 0xf8) << 2) +
((x & 0xf8) >> 3);
uint attr_dword = gDisplay[attr_offset >> 2];
uint attr_byte = (attr_dword >> (x & 0x18)) & 0xff;
uint col_shift = (data_dword & data_mask) ? 0 : 3;
if (attr_byte & 0x80 && flash_invert)
col_shift ^= 3;
uint col_idx = (attr_byte >> col_shift) & 7;
if (col_idx == 0 && transparent && (gMask[data_offset >> 2] & data_mask))
discard; // masked black is transparent
if (attr_byte & 0x40) // bright?
col_idx += 8; // if so, use second half of colours
return gPalette[col_idx];
}