-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMap_VS.hlsl
More file actions
76 lines (64 loc) · 1.66 KB
/
Map_VS.hlsl
File metadata and controls
76 lines (64 loc) · 1.66 KB
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
66
67
68
69
70
71
72
73
74
75
76
#define ZX_SCREEN_SIZE 6912
cbuffer gConstants : register(b0)
{
uint total_x;
uint total_y;
float translate_x;
float translate_y;
float scale_x;
float scale_y;
float scale;
uint screen_bytes;
};
struct VS_INPUT
{
int tile_x : TILE_X;
int tile_y : TILE_Y;
uint tile_w : TILE_W;
uint tile_h : TILE_H;
uint offset_x : OFFSET_X;
uint offset_y : OFFSET_Y;
uint screen_index : SCREEN;
uint vertexid : SV_VertexID;
};
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;
};
VS_OUTPUT main(VS_INPUT input)
{
VS_OUTPUT output;
float tile_x = input.tile_x * 2.0f / total_x;
float tile_y = input.tile_y * 2.0f / total_y;
float tile_width = input.tile_w * 2.0f / total_x;
float tile_height = input.tile_h * 2.0f / total_y;
if (input.vertexid & 1)
output.pos.x = tile_x + tile_width - 1.0f;
else
output.pos.x = tile_x - 1.0f;
if (input.vertexid & 2)
output.pos.y = 1.0f - (tile_y + tile_height);
else
output.pos.y = 1.0f - tile_y;
float offset_x = translate_x * 2.0 / total_x;
float offset_y = translate_y * 2.0 / total_y;
output.pos.xy += float2(1.0f, -1.0f);
output.pos.xy *= scale;
output.pos.xy *= float2(scale_x, scale_y);
output.pos.xy += float2(offset_x, -offset_y);
output.pos.xy -= float2(1.0f, -1.0f);
output.pos.zw = float2(0.0, 1.0);
output.tex = float2(input.vertexid % 2, (input.vertexid % 4) / 2);
output.width = input.tile_w;
output.height = input.tile_h;
output.offset_x = input.offset_x;
output.offset_y = input.offset_y;
output.offset = input.screen_index * screen_bytes;
return output;
}