Follow vanilla's block outline rules: high contrast option, F1 and adventure
This commit is contained in:
@@ -10746,7 +10746,11 @@ impl Game<'_> {
|
||||
let debug_crosshair = horizon_client::gizmos::camera_relative(&crosshair.on_top, at, view);
|
||||
// LevelExtractor.extractBlockOutline: model translucency controls draw order.
|
||||
let mut outline_after_terrain = false;
|
||||
let outline = if self.screen == Screen::Playing && !self.spectator() {
|
||||
// GameRenderer.shouldRenderBlockOutline: not with the HUD hidden (F1), and only for a
|
||||
// player who may build. Adventure players only get one with a CAN_BREAK or
|
||||
// CAN_PLACE_ON item and spectators with a menu block; Horizon reads neither the
|
||||
// components nor opens menus for spectators, so those never show it.
|
||||
let outline = if self.screen == Screen::Playing && !self.ui.hide_gui && self.may_build() {
|
||||
self.pick()
|
||||
.map(|h| {
|
||||
let state = self.world.block(h.pos[0], h.pos[1], h.pos[2]);
|
||||
@@ -10931,6 +10935,7 @@ impl Game<'_> {
|
||||
dark_disc: self.dark_disc(camera),
|
||||
outline,
|
||||
outline_after_terrain,
|
||||
outline_high_contrast: self.settings.file.bool("highContrastBlockOutline"),
|
||||
debug_lines: &debug_lines,
|
||||
debug_lines_on_top: &debug_lines_on_top,
|
||||
debug_crosshair: &debug_crosshair,
|
||||
@@ -13627,6 +13632,7 @@ fn loading_frame(hud: &HudBatch) -> Frame<'_> {
|
||||
dark_disc: false,
|
||||
outline: Vec::new(),
|
||||
outline_after_terrain: false,
|
||||
outline_high_contrast: false,
|
||||
debug_lines: &[],
|
||||
debug_lines_on_top: &[],
|
||||
debug_crosshair: &[],
|
||||
|
||||
@@ -247,6 +247,8 @@ pub struct Frame<'a> {
|
||||
pub outline: Vec<[f64; 6]>,
|
||||
/// `BlockOutlineRenderState.isTranslucent`: draw after translucent terrain.
|
||||
pub outline_after_terrain: bool,
|
||||
/// `BlockOutlineRenderState.highContrast`: a thick black outline under a bright one.
|
||||
pub outline_high_contrast: bool,
|
||||
/// `lines` with a colour and pixel width (`gizmos::camera_relative`):
|
||||
/// the fishing line and debug gizmos, depth tested, then gizmos drawn
|
||||
/// over everything.
|
||||
@@ -377,6 +379,7 @@ pub struct Renderer {
|
||||
sky: wgpu::RenderPipeline,
|
||||
dark_disc: wgpu::RenderPipeline,
|
||||
lines: wgpu::RenderPipeline,
|
||||
lines_secondary: wgpu::RenderPipeline,
|
||||
/// Gizmo lines (`RenderTypes.linesTranslucentNoDepthWrite`) and the
|
||||
/// always-on-top ones.
|
||||
debug_lines: wgpu::RenderPipeline,
|
||||
@@ -1213,12 +1216,6 @@ impl Renderer {
|
||||
attributes: &instance_attributes,
|
||||
}),
|
||||
];
|
||||
let line_attributes = wgpu::vertex_attr_array![0=>Float32x3,1=>Float32x3];
|
||||
let line_buffers = [Some(wgpu::VertexBufferLayout {
|
||||
array_stride: 24,
|
||||
step_mode: wgpu::VertexStepMode::Instance,
|
||||
attributes: &line_attributes,
|
||||
})];
|
||||
let alpha_blend = wgpu::BlendState::ALPHA_BLENDING;
|
||||
let debug_line_attributes =
|
||||
wgpu::vertex_attr_array![0=>Float32x3,1=>Float32x3,2=>Unorm8x4,3=>Float32];
|
||||
@@ -1351,13 +1348,25 @@ impl Renderer {
|
||||
"Block outline",
|
||||
"vs_line",
|
||||
"fs_line",
|
||||
&line_buffers,
|
||||
&debug_line_buffers,
|
||||
wgpu::PrimitiveTopology::TriangleStrip,
|
||||
None,
|
||||
true,
|
||||
true,
|
||||
Some(alpha_blend),
|
||||
);
|
||||
// RenderTypes.secondaryBlockOutline: the black stroke under a high contrast outline.
|
||||
let lines_secondary = pipeline(
|
||||
"Block outline secondary",
|
||||
"vs_line",
|
||||
"fs_line",
|
||||
&debug_line_buffers,
|
||||
wgpu::PrimitiveTopology::TriangleStrip,
|
||||
None,
|
||||
false,
|
||||
true,
|
||||
Some(alpha_blend),
|
||||
);
|
||||
let debug_lines = pipeline(
|
||||
"Debug lines",
|
||||
"vs_debug_line",
|
||||
@@ -1531,7 +1540,7 @@ impl Renderer {
|
||||
});
|
||||
let outline = device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: Some("Outline"),
|
||||
size: 24 * MAX_OUTLINE_EDGES,
|
||||
size: 32 * 2 * MAX_OUTLINE_EDGES,
|
||||
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
||||
mapped_at_creation: false,
|
||||
});
|
||||
@@ -2361,6 +2370,7 @@ impl Renderer {
|
||||
sky,
|
||||
dark_disc,
|
||||
lines,
|
||||
lines_secondary,
|
||||
debug_lines,
|
||||
debug_lines_on_top,
|
||||
debug_line_buffer,
|
||||
@@ -2482,6 +2492,18 @@ impl Renderer {
|
||||
present_modes,
|
||||
})
|
||||
}
|
||||
/// LevelRenderer.submitBlockOutline: the buffer holds `edges` per stroke, the black
|
||||
/// secondary stroke first when high contrast is on.
|
||||
fn draw_outline(&self, pass: &mut wgpu::RenderPass<'_>, edges: u32, high_contrast: bool) {
|
||||
pass.set_vertex_buffer(0, self.outline.slice(..));
|
||||
if high_contrast {
|
||||
pass.set_pipeline(&self.lines_secondary);
|
||||
pass.draw(0..4, 0..edges);
|
||||
}
|
||||
pass.set_pipeline(&self.lines);
|
||||
let first = if high_contrast { edges } else { 0 };
|
||||
pass.draw(0..4, first..first + edges);
|
||||
}
|
||||
fn quad_indices(device: &wgpu::Device, quads: u32) -> wgpu::Buffer {
|
||||
let indices: Vec<u32> = (0..quads)
|
||||
.flat_map(|q| {
|
||||
@@ -3954,7 +3976,26 @@ impl Renderer {
|
||||
);
|
||||
let outline_edges = frame.outline.len().min(MAX_OUTLINE_EDGES as usize);
|
||||
if outline_edges > 0 {
|
||||
let lines = outline_vertices(&frame.outline[..outline_edges], camera);
|
||||
// The same per-line colour and pixel width layout as the gizmo lines. A high
|
||||
// contrast outline is two strokes: the black one first, the bright one after it.
|
||||
let edges = outline_vertices(&frame.outline[..outline_edges], camera);
|
||||
let width = outline_width(self.config.width);
|
||||
let stroke = |color: u32, width: f32| {
|
||||
edges.iter().map(move |e| {
|
||||
let mut line = [0.0; 8];
|
||||
line[..6].copy_from_slice(e);
|
||||
line[6] = f32::from_bits(color);
|
||||
line[7] = width;
|
||||
line
|
||||
})
|
||||
};
|
||||
let lines: Vec<[f32; 8]> = if frame.outline_high_contrast {
|
||||
stroke(0xff00_0000, 7.0)
|
||||
.chain(stroke(0xff57_ffe1, width))
|
||||
.collect()
|
||||
} else {
|
||||
stroke(0x6600_0000, width).collect()
|
||||
};
|
||||
self.uploads
|
||||
.buffer(&mut encoder, &self.outline, 0, bytemuck::cast_slice(&lines));
|
||||
}
|
||||
@@ -4562,9 +4603,7 @@ impl Renderer {
|
||||
pass.set_bind_group(0, &self.group, &[]);
|
||||
}
|
||||
if outline_edges > 0 && !frame.outline_after_terrain {
|
||||
pass.set_pipeline(&self.lines);
|
||||
pass.set_vertex_buffer(0, self.outline.slice(..));
|
||||
pass.draw(0..4, 0..outline_edges as u32);
|
||||
self.draw_outline(&mut pass, outline_edges as u32, frame.outline_high_contrast);
|
||||
}
|
||||
if debug_depth > 0 {
|
||||
pass.set_pipeline(&self.debug_lines);
|
||||
@@ -4619,9 +4658,7 @@ impl Renderer {
|
||||
// LevelRenderer.executeClassicTransparency: translucent targets'
|
||||
// outlines follow terrain, so its blending cannot wash them out.
|
||||
if outline_edges > 0 && frame.outline_after_terrain {
|
||||
pass.set_pipeline(&self.lines);
|
||||
pass.set_vertex_buffer(0, self.outline.slice(..));
|
||||
pass.draw(0..4, 0..outline_edges as u32);
|
||||
self.draw_outline(&mut pass, outline_edges as u32, frame.outline_high_contrast);
|
||||
}
|
||||
pass.set_index_buffer(self.indices.slice(..), wgpu::IndexFormat::Uint32);
|
||||
// LevelRenderer: the world border after translucent terrain and weather.
|
||||
|
||||
@@ -258,7 +258,7 @@ fn sky_along_ray(d: vec3<f32>) -> vec3<f32> {
|
||||
}
|
||||
|
||||
// rendertype_lines.vsh: screen-space stroke and camera-space depth separation.
|
||||
fn outline_clip(vertex: u32, start: vec3<f32>, end: vec3<f32>) -> vec4<f32> {
|
||||
fn outline_clip(vertex: u32, start: vec3<f32>, end: vec3<f32>, width: f32) -> vec4<f32> {
|
||||
let position = select(start, end, vertex >= 2u);
|
||||
let normal = normalize(end - start);
|
||||
let view_shrink = 1.0 - 1.0 / 256.0;
|
||||
@@ -268,7 +268,7 @@ fn outline_clip(vertex: u32, start: vec3<f32>, end: vec3<f32>) -> vec4<f32> {
|
||||
let ndc2 = line_end.xyz / line_end.w;
|
||||
let screen = globals.outline_params.xy;
|
||||
let direction = normalize((ndc2.xy - ndc1.xy) * screen);
|
||||
var offset = vec2(-direction.y, direction.x) * globals.outline_params.z / screen;
|
||||
var offset = vec2(-direction.y, direction.x) * width / screen;
|
||||
if offset.x < 0.0 { offset = -offset; }
|
||||
if vertex % 2u != 0u { offset = -offset; }
|
||||
return vec4((ndc1 + vec3(offset, 0.0)) * line_start.w, line_start.w);
|
||||
@@ -277,18 +277,22 @@ struct LineOut {
|
||||
@builtin(position) clip: vec4<f32>,
|
||||
@location(0) spherical: f32,
|
||||
@location(1) cylindrical: f32,
|
||||
@location(2) color: vec4<f32>,
|
||||
}
|
||||
@vertex fn vs_line(@builtin(vertex_index) vertex: u32,
|
||||
@location(0) start: vec3<f32>, @location(1) end: vec3<f32>) -> LineOut {
|
||||
@location(0) start: vec3<f32>, @location(1) end: vec3<f32>,
|
||||
@location(2) argb: vec4<f32>, @location(3) width: f32) -> LineOut {
|
||||
let position = select(start, end, vertex >= 2u);
|
||||
var out: LineOut;
|
||||
out.clip = outline_clip(vertex, start, end);
|
||||
out.clip = outline_clip(vertex, start, end, width);
|
||||
out.spherical = length(position);
|
||||
out.cylindrical = max(length(position.xz), abs(position.y));
|
||||
// ARGB in a little-endian u32 reads as B, G, R, A.
|
||||
out.color = argb.zyxw;
|
||||
return out;
|
||||
}
|
||||
@fragment fn fs_line(in: LineOut) -> @location(0) vec4<f32> {
|
||||
return apply_fog(vec4(0.0, 0.0, 0.0, 0.4), in.spherical, in.cylindrical);
|
||||
return apply_fog(in.color, in.spherical, in.cylindrical);
|
||||
}
|
||||
// Gizmo lines (rendertype_lines with a per-vertex colour and LineWidth in
|
||||
// pixels; no layering transform).
|
||||
|
||||
Reference in New Issue
Block a user