Smaller matrices in uniforms, texcoord transform to rotate voxel faces
This commit is contained in:
@@ -119,13 +119,18 @@ pub fn refresh(self: *Chunk, blocks: *const Blocks, neighbors: Neighbors) !void
|
||||
|
||||
inline for (@typeInfo(voxels.Orientation).@"enum".fields) |field| {
|
||||
const side = @field(voxels.Orientation, field.name);
|
||||
const material = @field(block.walls, field.name).material;
|
||||
if (material != .empty and self.getOpposite(side, ix, iy, iz, blocks, neighbors) == .empty) {
|
||||
const wall: Blocks.Definition.Wall = @field(block.walls, field.name);
|
||||
if (wall.material != .empty and self.getOpposite(side, ix, iy, iz, blocks, neighbors) == .empty) {
|
||||
const matrix = getMatrix(side, origin);
|
||||
try uniforms.append(allocator_frame, .{
|
||||
.matrixOStoWS = matrix,
|
||||
.matrixOStoWSNormal = matrix,
|
||||
.material = material,
|
||||
.matrixOStoWS_i = matrix.getIVersor().dropW(),
|
||||
.matrixOStoWS_j = matrix.getJVersor().dropW(),
|
||||
.matrixOStoWS_k = matrix.getKVersor().dropW(),
|
||||
.matrixOStoWS_t = matrix.getTranslationVector().dropW(),
|
||||
|
||||
.texCoordTransform = wall.transform.getMatrix(),
|
||||
|
||||
.material = wall.material,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -909,7 +909,11 @@ fn render(self: *Game) !void {
|
||||
const ambient_light = vm.Vector3.init(0.01, 0.01, 0.01);
|
||||
|
||||
self.global_uniforms_staging_ptr.* = .{
|
||||
.matrixWStoVS = matrix_ws_to_vs,
|
||||
.matrixWStoVS_i = matrix_ws_to_vs.getIVersor().dropW(),
|
||||
.matrixWStoVS_j = matrix_ws_to_vs.getJVersor().dropW(),
|
||||
.matrixWStoVS_k = matrix_ws_to_vs.getKVersor().dropW(),
|
||||
.matrixWStoVS_t = matrix_ws_to_vs.getTranslationVector().dropW(),
|
||||
|
||||
.matrixVStoCS = matrix_vs_to_cs,
|
||||
.matrixSSPXtoCS = matrix_sspx_to_cs,
|
||||
|
||||
|
||||
@@ -184,9 +184,9 @@ pub const blocks = [9][:0]const u8{
|
||||
"Bricks.json",
|
||||
"ChiseledStoneBricks.json",
|
||||
"Cobblestone.json",
|
||||
"DiamondBlock.json",
|
||||
"GoldBlock.json",
|
||||
"IronBlock.json",
|
||||
"OakLogX.json",
|
||||
"OakLogY.json",
|
||||
"OakLogZ.json",
|
||||
"OakPlanks.json",
|
||||
"SmoothStone.json",
|
||||
"StoneBricks.json",
|
||||
|
||||
@@ -44,7 +44,11 @@ pub const Vertex = extern struct {
|
||||
pub const Index = u16;
|
||||
|
||||
pub const GlobalUniforms = extern struct {
|
||||
matrixWStoVS: vm.Matrix4x4,
|
||||
matrixWStoVS_i: vm.Vector3,
|
||||
matrixWStoVS_j: vm.Vector3,
|
||||
matrixWStoVS_k: vm.Vector3,
|
||||
matrixWStoVS_t: vm.Vector3,
|
||||
|
||||
matrixVStoCS: vm.Matrix4x4,
|
||||
matrixSSPXtoCS: vm.Matrix3x2,
|
||||
|
||||
@@ -93,8 +97,13 @@ pub const Material = extern struct {
|
||||
};
|
||||
|
||||
pub const ObjectUniforms = extern struct {
|
||||
matrixOStoWS: vm.Matrix4x4,
|
||||
matrixOStoWSNormal: vm.Matrix4x4,
|
||||
// Limited to a composition of translation and rotation
|
||||
matrixOStoWS_i: vm.Vector3,
|
||||
matrixOStoWS_j: vm.Vector3,
|
||||
matrixOStoWS_k: vm.Vector3,
|
||||
matrixOStoWS_t: vm.Vector3,
|
||||
|
||||
texCoordTransform: vm.Matrix3x2,
|
||||
|
||||
material: Materials.Id,
|
||||
};
|
||||
|
||||
@@ -59,6 +59,49 @@ pub const Transform = enum(u3) {
|
||||
mirror_rotate_cw = 5,
|
||||
mirror_rotate_ccw = 6,
|
||||
mirror_rotate_180 = 7,
|
||||
|
||||
pub fn getMatrix(self: Transform) vm.Matrix3x2 {
|
||||
return switch (self) {
|
||||
// zig fmt: off
|
||||
.identity => .identity,
|
||||
.rotate_cw => .init(
|
||||
0, -1,
|
||||
1, 0,
|
||||
0, 1,
|
||||
),
|
||||
.rotate_ccw => .init(
|
||||
0, 1,
|
||||
-1, 0,
|
||||
1, 0,
|
||||
),
|
||||
.rotate_180 => .init(
|
||||
-1, 0,
|
||||
0, -1,
|
||||
1, 1,
|
||||
),
|
||||
.mirror => .init(
|
||||
-1, 0,
|
||||
0, 1,
|
||||
1, 0,
|
||||
),
|
||||
.mirror_rotate_cw => .init(
|
||||
0, -1,
|
||||
-1, 0,
|
||||
1, 1,
|
||||
),
|
||||
.mirror_rotate_ccw => .init(
|
||||
0, 1,
|
||||
1, 0,
|
||||
0, 0,
|
||||
),
|
||||
.mirror_rotate_180 => .init(
|
||||
0, 1,
|
||||
-1, 0,
|
||||
1, 0,
|
||||
),
|
||||
// zig fmt: on
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// ┌──────────────────── x
|
||||
|
||||
Reference in New Issue
Block a user