forked from HailToDodongo/f64render
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtile.py
More file actions
75 lines (62 loc) · 1.85 KB
/
tile.py
File metadata and controls
75 lines (62 loc) · 1.85 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
import bpy
import gpu
from dataclasses import dataclass
import numpy as np
MISSING_TEXTURE_COLOR = (0, 0, 0, 1)
TEX_FLAG_MONO = 1 << 0
TEX_FLAG_4BIT = 1 << 1
TEX_FLAG_3BIT = 1 << 2
@dataclass
class F64Texture:
values: tuple[float, float, float, float, float, float, float, float, int]
buff: gpu.types.GPUTexture
def get_tile_conf(tex: "TextureProperty") -> F64Texture:
flags = 0
if tex.tex is not None:
# Note: doing 'gpu.texture.from_image' seems to cost nothing, caching is not needed
buff = gpu.texture.from_image(tex.tex)
if tex.tex_format in {"I4", "I8"}:
flags |= TEX_FLAG_MONO
if tex.tex_format in {"I4", "IA8"}:
flags |= TEX_FLAG_4BIT
if tex.tex_format == "IA4":
flags |= TEX_FLAG_3BIT
else:
buff = gpu.types.GPUTexture(
(1, 1),
format="RGBA8",
data=gpu.types.Buffer(
"FLOAT",
(1, 1, 4),
[[MISSING_TEXTURE_COLOR]],
),
)
flags |= TEX_FLAG_MONO
conf = np.array(
[
tex.S.mask,
tex.T.mask,
tex.S.shift,
tex.T.shift,
tex.S.low,
-tex.T.low,
tex.S.high,
tex.T.high,
],
dtype=np.float32,
)
conf[0:4] = 2 ** conf[0:4] # mask/shift are exponents, calc. 2^x
conf[2:4] = 1 / conf[2:4] # shift is inverted
# quantize the low/high values into 0.25 pixel increments
conf[4:] = np.round(conf[4:] * 4) / 4
# if clamp is on, negate the mask value
if tex.S.clamp:
conf[0] = -conf[0]
if tex.T.clamp:
conf[1] = -conf[1]
# if mirror is on, negate the high value
if tex.S.mirror:
conf[6] = -conf[6]
if tex.T.mirror:
conf[7] = -conf[7]
return F64Texture((*conf, flags), buff)