Boats: the water patch hides water inside the hull; the riding camera turns smoothly
BoatRenderer draws its water_patch part with RenderTypes.waterMask (depth only) unless the boat is under water, so translucent water behind it fails the depth test inside the hull. Horizon loaded the part but never drew it: the water surface showed through the boat. The patch now draws with a depth-only Water mask pipeline after the entities and before translucent terrain (rafts have none, as RaftRenderer). Turning in a boat stepped the camera at the tick rate: positionRider adds the boat's deltaRotation to the passenger's yRot after its yRotO was kept, and LocalPlayer.getViewYRot interpolates a passenger's yaw between them. The camera now spreads the turn over the tick's frames. Fixes #1016 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -188,3 +188,8 @@ fn linear_fog(d: f32, start: f32, end: f32) -> f32 {
|
||||
let color = textureSample(atlas, atlas_sampler, in.uv) * in.color * in.light_color;
|
||||
return color;
|
||||
}
|
||||
|
||||
// RenderPipelines.WATER_MASK: depth only (the pipeline masks the colour off).
|
||||
@fragment fn fs_water_mask() -> @location(0) vec4<f32> {
|
||||
return vec4(0.0);
|
||||
}
|
||||
|
||||
@@ -141,6 +141,8 @@ pub(super) fn boat_wood(item: &str) -> Option<&str> {
|
||||
pub(super) struct BoatModels {
|
||||
pub models: HashMap<String, Part>,
|
||||
pub chest_models: HashMap<String, Part>,
|
||||
/// `ModelLayers.BOAT_WATER_PATCH`, shared by every boat (not rafts).
|
||||
pub water_patch: Option<Part>,
|
||||
}
|
||||
impl BoatModels {
|
||||
/// Whether a boat of this wood (with or without a chest) can be drawn.
|
||||
@@ -175,6 +177,7 @@ impl BoatModels {
|
||||
Self {
|
||||
models,
|
||||
chest_models,
|
||||
water_patch: document.and_then(|d| d.model("minecraft:boat#water_patch")),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -785,6 +788,23 @@ impl Game<'_> {
|
||||
0,
|
||||
out,
|
||||
);
|
||||
// BoatRenderer.submitTypeAdditions: the water patch hides the water
|
||||
// inside the hull unless the boat is under water (RaftRenderer has none).
|
||||
if let Some(patch) = self.boat_models.water_patch.as_ref()
|
||||
&& &*b.wood != "bamboo"
|
||||
&& !matches!(b.status, Status::UnderWater | Status::UnderFlowingWater)
|
||||
{
|
||||
horizon_client::mobs::render::draw(
|
||||
patch,
|
||||
base,
|
||||
&Poses::new(patch),
|
||||
uv,
|
||||
0xFFFF_FFFF,
|
||||
packed,
|
||||
horizon_client::gfx::WATER_MASK_OVERLAY,
|
||||
out,
|
||||
);
|
||||
}
|
||||
self.cull_entity_vertices(out, entity_start);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,6 +223,14 @@ impl Game<'_> {
|
||||
.riding
|
||||
.and_then(|id| self.mobs.iter().find(|m| m.id == id))
|
||||
.map(|_| (1.0, 4.0));
|
||||
// AbstractBoat.positionRider turns a passenger by the boat's
|
||||
// deltaRotation after its yRotO was saved, and LocalPlayer.getViewYRot
|
||||
// interpolates a passenger's yaw: the boat's turn is spread over the
|
||||
// frames of a tick.
|
||||
let ride_turn = self
|
||||
.riding
|
||||
.and_then(|id| self.boats.iter().find(|b| b.id == id))
|
||||
.map_or(0.0, |b| b.delta_rotation);
|
||||
let entity = CameraEntity {
|
||||
position: [p.position.x, p.position.y, p.position.z],
|
||||
previous: [
|
||||
@@ -235,7 +243,7 @@ impl Game<'_> {
|
||||
x_rot: self.pitch,
|
||||
y_rot: self.yaw,
|
||||
x_rot_o: self.pitch,
|
||||
y_rot_o: self.yaw,
|
||||
y_rot_o: self.yaw - ride_turn,
|
||||
eye_height: p.dimensions.eye_height,
|
||||
living: Some(LivingCamera {
|
||||
scale,
|
||||
|
||||
@@ -34,6 +34,7 @@ fn entity_shader() -> String {
|
||||
|
||||
mod entity_batch;
|
||||
use entity_batch::EntityBatch;
|
||||
pub use entity_batch::WATER_MASK_OVERLAY;
|
||||
|
||||
/// Window.getAppropriateLineWidth, in framebuffer pixels.
|
||||
pub fn outline_width(width: u32) -> f32 {
|
||||
@@ -317,6 +318,8 @@ pub struct Renderer {
|
||||
crosshair_globals: wgpu::Buffer,
|
||||
entity_pipeline: wgpu::RenderPipeline,
|
||||
crumbling_pipeline: wgpu::RenderPipeline,
|
||||
/// `RenderPipelines.WATER_MASK`: depth writes only, no colour.
|
||||
water_mask_pipeline: wgpu::RenderPipeline,
|
||||
cloud_pipeline: wgpu::RenderPipeline,
|
||||
cloud_mesh: crate::clouds::Mesh,
|
||||
cloud_buffer: wgpu::Buffer,
|
||||
@@ -1539,7 +1542,16 @@ impl Renderer {
|
||||
step_mode: wgpu::VertexStepMode::Vertex,
|
||||
attributes: &entity_attributes,
|
||||
})];
|
||||
let entity_pipeline = |label, cull_mode, depth_write, compare, bias, blend, clouds| {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
let entity_pipeline_with = |label,
|
||||
cull_mode,
|
||||
depth_write,
|
||||
compare,
|
||||
bias,
|
||||
blend,
|
||||
clouds,
|
||||
fragment: &str,
|
||||
write_mask| {
|
||||
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
label: Some(label),
|
||||
layout: Some(if clouds {
|
||||
@@ -1567,18 +1579,43 @@ impl Renderer {
|
||||
multisample: Default::default(),
|
||||
fragment: Some(wgpu::FragmentState {
|
||||
module: &entity_shader,
|
||||
entry_point: Some("fs_entity"),
|
||||
entry_point: Some(fragment),
|
||||
compilation_options: Default::default(),
|
||||
targets: &[Some(wgpu::ColorTargetState {
|
||||
format: config.format.remove_srgb_suffix(),
|
||||
blend: Some(blend),
|
||||
write_mask: wgpu::ColorWrites::ALL,
|
||||
write_mask,
|
||||
})],
|
||||
}),
|
||||
multiview_mask: None,
|
||||
cache: None,
|
||||
})
|
||||
};
|
||||
let entity_pipeline = |label, cull_mode, depth_write, compare, bias, blend, clouds| {
|
||||
entity_pipeline_with(
|
||||
label,
|
||||
cull_mode,
|
||||
depth_write,
|
||||
compare,
|
||||
bias,
|
||||
blend,
|
||||
clouds,
|
||||
"fs_entity",
|
||||
wgpu::ColorWrites::ALL,
|
||||
)
|
||||
};
|
||||
// RenderPipelines.WATER_MASK: the boat's water patch writes depth only.
|
||||
let water_mask_pipeline = entity_pipeline_with(
|
||||
"Water mask",
|
||||
None,
|
||||
true,
|
||||
wgpu::CompareFunction::GreaterEqual,
|
||||
Default::default(),
|
||||
alpha_blend,
|
||||
false,
|
||||
"fs_water_mask",
|
||||
wgpu::ColorWrites::empty(),
|
||||
);
|
||||
let crumbling_pipeline = entity_pipeline(
|
||||
"Breaking cracks",
|
||||
Some(wgpu::Face::Back),
|
||||
@@ -2058,6 +2095,7 @@ impl Renderer {
|
||||
crosshair_globals,
|
||||
entity_pipeline,
|
||||
crumbling_pipeline,
|
||||
water_mask_pipeline,
|
||||
cloud_pipeline,
|
||||
cloud_mesh: Default::default(),
|
||||
cloud_buffer,
|
||||
@@ -3183,14 +3221,19 @@ impl Renderer {
|
||||
self.uploads
|
||||
.buffer(&mut encoder, &self.outline, 0, bytemuck::cast_slice(&lines));
|
||||
}
|
||||
let [entity_quads, crumbling_quads, translucent_crumbling_quads] =
|
||||
self.entity_batch.update(
|
||||
frame.entities,
|
||||
frame.additive,
|
||||
frame.hand,
|
||||
frame.see_through,
|
||||
);
|
||||
let world_quads = entity_quads + crumbling_quads + translucent_crumbling_quads;
|
||||
let [
|
||||
entity_quads,
|
||||
crumbling_quads,
|
||||
translucent_crumbling_quads,
|
||||
water_mask_quads,
|
||||
] = self.entity_batch.update(
|
||||
frame.entities,
|
||||
frame.additive,
|
||||
frame.hand,
|
||||
frame.see_through,
|
||||
);
|
||||
let world_quads =
|
||||
entity_quads + crumbling_quads + translucent_crumbling_quads + water_mask_quads;
|
||||
let cloud_quads = if let Some(input) = &frame.clouds {
|
||||
let (rebuilt, uniform) =
|
||||
crate::spans::time("clouds", || self.cloud_mesh.prepare(input));
|
||||
@@ -3552,6 +3595,19 @@ impl Renderer {
|
||||
pass.draw_indexed(0..crumbling_quads * 6, (entity_quads * 4) as i32, 0..1);
|
||||
pass.set_bind_group(0, &self.group, &[]);
|
||||
}
|
||||
// BoatRenderer's water patch (RenderTypes.waterMask): depth only,
|
||||
// before translucent terrain, so no water shows inside the boat.
|
||||
if water_mask_quads > 0 {
|
||||
pass.set_pipeline(&self.water_mask_pipeline);
|
||||
pass.set_bind_group(0, &self.entity_group, &[]);
|
||||
pass.set_vertex_buffer(0, self.entity_buffer.slice(..));
|
||||
pass.draw_indexed(
|
||||
0..water_mask_quads * 6,
|
||||
((entity_quads + crumbling_quads + translucent_crumbling_quads) * 4) as i32,
|
||||
0..1,
|
||||
);
|
||||
pass.set_bind_group(0, &self.group, &[]);
|
||||
}
|
||||
if additive_quads > 0 {
|
||||
pass.set_pipeline(&self.additive_pipeline);
|
||||
pass.set_bind_group(0, &self.entity_group, &[]);
|
||||
@@ -4116,7 +4172,7 @@ mod tests {
|
||||
let mut batch = super::EntityBatch::default();
|
||||
let counts = batch.update(&entities, &quad(3, 5), &quad(0, 6), &quad(0, 8));
|
||||
let vertices = &batch.combined;
|
||||
assert_eq!(counts, [4, 1, 1]);
|
||||
assert_eq!(counts, [4, 1, 1, 0]);
|
||||
assert_eq!(
|
||||
vertices
|
||||
.as_chunks::<4>()
|
||||
|
||||
@@ -1,12 +1,19 @@
|
||||
//! Stable entity material grouping with renderer-owned, reusable CPU scratch.
|
||||
use super::Vertex;
|
||||
|
||||
/// Entity materials by a quad's overlay (`Vertex::layer`), in draw order:
|
||||
/// ordinary entities, breaking cracks (11), translucent breaking cracks (12)
|
||||
/// and the boat water mask (13, `RenderPipelines.WATER_MASK`).
|
||||
const MATERIALS: usize = 4;
|
||||
/// The overlay of depth-only quads that hide water (`RenderTypes.waterMask`).
|
||||
pub const WATER_MASK_OVERLAY: u32 = 13;
|
||||
|
||||
#[derive(Default)]
|
||||
pub(super) struct EntityBatch {
|
||||
// Quad indices avoid copying vertices twice while grouping materials.
|
||||
// Keep initialized high-water storage; local counts delimit active entries.
|
||||
// Each bucket can hold all quads, removing per-quad Vec growth checks.
|
||||
buckets: [Vec<usize>; 3],
|
||||
buckets: [Vec<usize>; MATERIALS],
|
||||
pub(super) combined: Vec<Vertex>,
|
||||
}
|
||||
|
||||
@@ -17,18 +24,19 @@ impl EntityBatch {
|
||||
additive: &[Vertex],
|
||||
hand: &[Vertex],
|
||||
see_through: &[Vertex],
|
||||
) -> [u32; 3] {
|
||||
) -> [u32; MATERIALS] {
|
||||
let quads = entities.as_chunks::<4>().0;
|
||||
for bucket in &mut self.buckets {
|
||||
if bucket.len() < quads.len() {
|
||||
bucket.resize(quads.len(), 0);
|
||||
}
|
||||
}
|
||||
let mut counts = [0usize; 3];
|
||||
let mut counts = [0usize; MATERIALS];
|
||||
for (index, quad) in quads.iter().enumerate() {
|
||||
let material = match quad[0].layer {
|
||||
11 => 1,
|
||||
12 => 2,
|
||||
WATER_MASK_OVERLAY => 3,
|
||||
_ => 0,
|
||||
};
|
||||
self.buckets[material][counts[material]] = index;
|
||||
@@ -77,14 +85,15 @@ mod tests {
|
||||
entities: &[Vertex],
|
||||
additive: &[Vertex],
|
||||
hand: &[Vertex],
|
||||
) -> (Vec<Vertex>, [u32; 3]) {
|
||||
) -> (Vec<Vertex>, [u32; MATERIALS]) {
|
||||
let mut combined = Vec::with_capacity(entities.len() + additive.len() + hand.len());
|
||||
let mut counts = [0; 3];
|
||||
for (i, layer) in [0, 11, 12].into_iter().enumerate() {
|
||||
let mut counts = [0; MATERIALS];
|
||||
for (i, layer) in [0, 11, 12, 13].into_iter().enumerate() {
|
||||
for quad in entities.as_chunks::<4>().0 {
|
||||
let material = match quad[0].layer {
|
||||
11 => 11,
|
||||
12 => 12,
|
||||
13 => 13,
|
||||
_ => 0,
|
||||
};
|
||||
if material == layer {
|
||||
@@ -104,7 +113,7 @@ mod tests {
|
||||
pos: [index as f32, 2.0, 3.0],
|
||||
uv: [index as f32, 5.0],
|
||||
layer: if mixed {
|
||||
[7, 11, 12, 4, 0][index / 4 % 5]
|
||||
[7, 11, 12, 4, 13, 0][index / 4 % 6]
|
||||
} else {
|
||||
0
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user