-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPixelShaderGBA8.h
More file actions
144 lines (112 loc) · 4.65 KB
/
PixelShaderGBA8.h
File metadata and controls
144 lines (112 loc) · 4.65 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#ifndef PIXELSHADERGBA8_H
#define PIXELSHADERGBA8_H
#include "RenderCommon.h"
namespace P3D
{
template<const unsigned int render_flags> class PixelShaderGBA8
{
public:
static void DrawScanlinePixelPair(pixel* fb, z_val *zb, const z_val zv1, const z_val zv2, const pixel* texels, const fp u1, const fp v1, const fp u2, const fp v2, const fp f1, const fp f2, const fp l1, const fp l2, const pixel fog_color, const unsigned char* fog_light_map = nullptr)
{
if constexpr (render_flags & ZTest)
{
if(zv1 >= zb[0]) //Reject left?
{
if(zv2 >= zb[1]) //Reject right?
return; //Both Z Reject.
//Accept right.
DrawScanlinePixelHigh(fb+1, zb+1, zv2, texels, u2, v2, f2, l2, fog_color);
return;
}
else //Accept left.
{
if(zv2 >= zb[1]) //Reject right?
{
DrawScanlinePixelLow(fb, zb, zv1, texels, u1, v1, f1, l1, fog_color);
return;
}
}
}
const unsigned int tx = (int)u1 & TEX_MASK;
const unsigned int ty = ((int)v1 & TEX_MASK) << TEX_SHIFT;
const unsigned int tx2 = (int)u2 & TEX_MASK;
const unsigned int ty2 = ((int)v2 & TEX_MASK) << TEX_SHIFT;
pixel p1 = texels[(ty + tx)], p2 = texels[(ty2 + tx2)];
if constexpr(render_flags & (Fog | VertexLight))
{
p1 = FogLightPixel(p1, f1, l1, fog_light_map);
p2 = FogLightPixel(p2, f2, l2, fog_light_map);
}
*(unsigned short*)fb = (p1 | (p2 << 8));
if constexpr (render_flags & ZWrite)
{
zb[0] = zv1, zb[1] = zv2;
}
}
static void DrawScanlinePixelHigh(pixel *fb, z_val *zb, const z_val zv, const pixel* texels, const fp u, const fp v, const fp f, const fp l, const pixel, const unsigned char* fog_light_map = nullptr)
{
if constexpr (render_flags & ZTest)
{
if(*zb <= zv)
return;
}
if constexpr (render_flags & ZWrite)
{
*zb = zv;
}
const unsigned int tx = (int)u & TEX_MASK;
const unsigned int ty = ((int)v & TEX_MASK) << TEX_SHIFT;
pixel p1 = texels[(ty + tx)];
if constexpr(render_flags & (Fog | VertexLight))
{
p1 = FogLightPixel(p1, f, l, fog_light_map);
}
unsigned short* p16 = (unsigned short*)(fb-1);
const pixel* p8 = (pixel*)p16;
const unsigned short texel = (p1 << 8) | *p8;
*p16 = texel;
}
static void DrawScanlinePixelLow(pixel *fb, z_val *zb, const z_val zv, const pixel* texels, const fp u, const fp v, const fp f, const fp l, const pixel, const unsigned char* fog_light_map = nullptr)
{
if constexpr (render_flags & ZTest)
{
if(*zb <= zv)
return;
}
if constexpr (render_flags & ZWrite)
{
*zb = zv;
}
const unsigned int tx = (int)u & TEX_MASK;
const unsigned int ty = ((int)v & TEX_MASK) << TEX_SHIFT;
pixel p1 = texels[(ty + tx)];
if constexpr(render_flags & (Fog | VertexLight))
{
p1 = FogLightPixel(p1, f, l, fog_light_map);
}
unsigned short* p16 = (unsigned short*)(fb);
const pixel* p8 = (pixel*)p16;
const unsigned short texel = p1 | (p8[1] << 8);
*p16 = texel;
}
static constexpr pixel FogLightPixel(pixel src_color, fp fog_frac, fp light_frac, const unsigned char* fog_light_map)
{
unsigned int light = 0, fog = 0;
if constexpr(render_flags & VertexLight)
{
light = pASL(pClamp(fp(0), light_frac, LIGHT_MAX), LIGHT_SHIFT);
}
if constexpr(render_flags & Fog)
{
fog = pASL(pClamp(fp(0), fog_frac, FOG_MAX), FOG_SHIFT);
}
const unsigned int texel = src_color;
return fog_light_map[FogLightIndex(texel, fog, light)];
}
static constexpr unsigned int FogLightIndex(const unsigned int color, const unsigned int fog, const unsigned int light)
{
return (light * (FOG_LEVELS * 256)) + (fog * 256) + color;
}
};
};
#endif // PIXELSHADERGBA8_H