alex/beta-minecraft-rust
Minecraft Beta 1.7.3 Rewrite
BRANCH main
SNAPSHOT Draw terrain GPU-driven from packed per-section buffers with GPU occlusion culling, add a render distance slider (2-128) with a quad/disk shape, cut chunk bookkeeping at high render distances, and fix a light underflow at y=0
DOWNLOAD
root crates client src render scene paintings.rs
use common::entity::painting::Painting;
use glam::{Mat3, Vec3};
use super::Geometry;
use crate::world::ClientWorld;
impl Geometry {
pub(super) fn painting(
&mut self,
painting: Painting,
relative: Vec3,
world: &ClientWorld,
sky_darkness: u32,
) {
let art = painting.art();
let [width, height] = art.size.map(f32::from);
let [u, v] = art.uv.map(f32::from);
let rotation = Mat3::from_rotation_y((f32::from(painting.direction) * 90.0).to_radians());
let texture = crate::assets::entity_texture("art/kz.png");
let position = painting.position();
let transform = |point| relative + rotation * (point / 16.0);
for col in 0..art.size[0] / 16 {
for row in 0..art.size[1] / 16 {
let x0 = -width / 2.0 + f32::from(col * 16);
let x1 = x0 + 16.0;
let y0 = -height / 2.0 + f32::from(row * 16);
let y1 = y0 + 16.0;
let center = position
+ (rotation * Vec3::new((x0 + x1) / 32.0, (y0 + y1) / 32.0, 0.0)).as_dvec3();
let color = super::gray(super::brightness_at(world, center, sky_darkness));
let vertices = super::box_corners(Vec3::new(x0, y0, -0.5), Vec3::new(x1, y1, 0.5));
let front_uv = [
(u + width - f32::from((col + 1) * 16)) / 256.0,
(v + height - f32::from(row * 16)) / 256.0,
1.0 / 16.0,
-1.0 / 16.0,
];
for (indices, uv) in [
([1, 0, 3, 2], front_uv),
([6, 7, 4, 5], [12.0 / 16.0, 0.0, 1.0 / 16.0, 1.0 / 16.0]),
([2, 3, 7, 6], [12.0 / 16.0, 1.0 / 512.0, 1.0 / 16.0, 0.0]),
([5, 4, 0, 1], [12.0 / 16.0, 1.0 / 512.0, 1.0 / 16.0, 0.0]),
([6, 5, 1, 2], [385.0 / 512.0, 0.0, 0.0, 1.0 / 16.0]),
([3, 0, 4, 7], [385.0 / 512.0, 0.0, 0.0, 1.0 / 16.0]),
] {
self.quad(indices.map(|i| transform(vertices[i])), uv, texture, color);
}
}
}
}
}