Skip to content

Commit cacc492

Browse files
committed
Attempt to rotate texcoords
1 parent 5989a04 commit cacc492

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

out.png

-166 Bytes
Loading

src/hexdoc/graphics/glsl/block_face/vertex.glsl

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
uniform mat4 m_proj;
44
uniform mat4 m_camera;
55
uniform mat4 m_model;
6+
uniform mat4 m_texture;
67

78
in vec3 in_position;
89
in vec2 in_texcoord_0;
@@ -11,5 +12,7 @@ out vec2 uv;
1112

1213
void main() {
1314
gl_Position = m_proj * m_camera * m_model * vec4(in_position, 1);
14-
uv = in_texcoord_0;
15+
16+
vec4 rotCoord = m_texture * vec4(in_texcoord_0, 0.0, 1.0);
17+
uv = rotCoord.st;
1518
}

src/hexdoc/graphics/render.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ def render_block(
214214

215215
# render each face of the element
216216
for direction, face in element.faces.items():
217+
rotation = Matrix44.from_y_rotation(math.radians(face.rotation), "f4")
218+
self.uniform("m_texture").write(rotation)
219+
217220
self.uniform("light").value = get_face_light(direction)
218221
self.uniform("texture0").value = texture_locs[face.texture.lstrip("#")]
219222

@@ -410,15 +413,15 @@ def get_face_light(direction: FaceName):
410413
case "up":
411414
return LIGHT_UP
412415
case "down":
413-
return LIGHT_UP / 2
416+
return LIGHT_UP / 4
414417
case "south":
415418
return LIGHT_LEFT
416419
case "north":
417-
return LIGHT_LEFT / 2
420+
return LIGHT_LEFT / 4
418421
case "east":
419422
return LIGHT_RIGHT
420423
case "west":
421-
return LIGHT_RIGHT / 2
424+
return LIGHT_RIGHT / 4
422425

423426

424427
def get_default_uv(element: ModelElement, direction: FaceName):

test.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from hexdoc.minecraft.models import load_model
77
from hexdoc.minecraft.models.item import ItemModel
88

9+
# MODEL_ID = "minecraft:block/oak_stairs"
910
MODEL_ID = "minecraft:block/lectern"
1011

1112

0 commit comments

Comments
 (0)