Skip to content

Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.

HDR: light sources keep shining under water

Senjina503ce42c900
diff --git a/crates/horizon-client-render/src/gfx.rs b/crates/horizon-client-render/src/gfx.rs
index 7bb9bb7ce..29278d20f 100644
--- a/crates/horizon-client-render/src/gfx.rs
+++ b/crates/horizon-client-render/src/gfx.rs
@@ -837,7 +837,7 @@ pub struct Renderer {
border_vertices: wgpu::Buffer,
/// Screen effects: alpha-blended, then vignette (`dst * (1 - src)`)
/// pipelines, each for every sampling (index `blend * 4 + sampling`).
- screen_pipelines: [wgpu::RenderPipeline; 8],
+ screen_pipelines: [wgpu::RenderPipeline; 16],
screen_buffer: wgpu::Buffer,
screen_capacity: u64,
entity_group: wgpu::BindGroup,
@@ -3337,7 +3337,7 @@ impl Renderer {
};
// One per blend and `.png.mcmeta` sampling (screen_effects::SAMPLE_*):
// the shader is specialised, so a pixel pays for none of the others.
- let screen_pipelines: [wgpu::RenderPipeline; 8] = std::array::from_fn(|i| {
+ let screen_pipelines: [wgpu::RenderPipeline; 16] = std::array::from_fn(|i| {
let blur = i as u32 & crate::screen_effects::SAMPLE_BLUR != 0;
let (entry, blend) = match (i & 4 == 0, blur) {
(true, false) => ("fs_screen", alpha_blend),
@@ -3373,7 +3373,12 @@ impl Renderer {
targets: &[Some(wgpu::ColorTargetState {
format: config.format.remove_srgb_suffix(),
blend: Some(blend),
- write_mask: wgpu::ColorWrites::ALL,
+ // 8 and up: colour only, for a tint of the world in HDR output.
+ write_mask: if i & 8 == 0 {
+ wgpu::ColorWrites::ALL
+ } else {
+ wgpu::ColorWrites::COLOR
+ },
})],
}),
multiview_mask: None,
@@ -8156,9 +8161,47 @@ impl Renderer {
crate::screen_effects::Blend::Alpha => 0,
crate::screen_effects::Blend::Vignette => 4,
};
- pass.set_pipeline(&self.screen_pipelines[blend + (quad.sampling & 3) as usize]);
+ let tint = if quad.world_tint && self.hdr.is_some() {
+ 8
+ } else {
+ 0
+ };
+ pass.set_pipeline(
+ &self.screen_pipelines[tint + blend + (quad.sampling & 3) as usize],
+ );
pass.draw_indexed(0..6, (i * 4) as i32, 0..1);
}
+ drop(pass);
+ // A tint leaves the frame's alpha and goes over the kept world too: light sources
+ // under water still show the world, and still shine.
+ if let Some(view) = self.hdr.as_ref().and_then(|h| h.kept_world_view())
+ && frame.screen.iter().any(|quad| quad.world_tint)
+ {
+ let attachments = [Some(wgpu::RenderPassColorAttachment {
+ view: &view,
+ resolve_target: None,
+ depth_slice: None,
+ ops: wgpu::Operations {
+ load: wgpu::LoadOp::Load,
+ store: wgpu::StoreOp::Store,
+ },
+ })];
+ let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
+ label: Some("Screen tints over the kept world"),
+ timestamp_writes: None,
+ color_attachments: &attachments,
+ ..Default::default()
+ });
+ pass.set_bind_group(0, &self.entity_group, &[]);
+ pass.set_index_buffer(self.indices.slice(..), wgpu::IndexFormat::Uint32);
+ pass.set_vertex_buffer(0, self.screen_buffer.slice(..));
+ for (i, quad) in frame.screen.iter().enumerate() {
+ if quad.world_tint {
+ pass.set_pipeline(&self.screen_pipelines[8 + (quad.sampling & 3) as usize]);
+ pass.draw_indexed(0..6, (i * 4) as i32, 0..1);
+ }
+ }
+ }
}
// GameRenderer.render3dHud: the debug crosshair after the hand and
// the screen effects.
diff --git a/crates/horizon-client-render/src/gfx/hdr.rs b/crates/horizon-client-render/src/gfx/hdr.rs
index fce1ee2ff..851923f32 100644
--- a/crates/horizon-client-render/src/gfx/hdr.rs
+++ b/crates/horizon-client-render/src/gfx/hdr.rs
@@ -320,7 +320,10 @@ impl Hdr {
"Horizon HDR frame",
wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC,
);
- let world = texture("Horizon HDR world", wgpu::TextureUsages::COPY_DST);
+ let world = texture(
+ "Horizon HDR world",
+ wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::RENDER_ATTACHMENT,
+ );
let view = |t: &wgpu::Texture| t.create_view(&Default::default());
let group = device.create_bind_group(&wgpu::BindGroupDescriptor {
label: Some("Horizon HDR bindings"),
@@ -438,6 +441,12 @@ impl Hdr {
pass.draw(0..3, 0..1);
}
+ /// The world as `keep_world` kept it, for what tints it rather than covering it.
+ pub fn kept_world_view(&self) -> Option<wgpu::TextureView> {
+ let t = self.targets.as_ref()?;
+ Some(t.world.create_view(&Default::default()))
+ }
+
/// Writes the finished frame to the swapchain image `target`.
/// The tiers' windows for the shaders that mark the frame (`Globals::hdr_windows`):
/// where each starts, then where each is full.
diff --git a/crates/horizon-client-render/src/screen_effects.rs b/crates/horizon-client-render/src/screen_effects.rs
index 56e143634..81addea96 100644
--- a/crates/horizon-client-render/src/screen_effects.rs
+++ b/crates/horizon-client-render/src/screen_effects.rs
@@ -44,6 +44,9 @@ pub struct ScreenQuad {
pub blend: Blend,
/// How the sprite is sampled: [`SAMPLE_BLUR`] and [`SAMPLE_CLAMP`].
pub sampling: u32,
+ /// A tint of the whole view (the underwater overlay), not something in front of it: in HDR
+ /// output the world shines through it (`Renderer::draw_overlay`).
+ pub world_tint: bool,
}
/// What the camera sees this frame.
@@ -160,6 +163,7 @@ impl ScreenEffects {
}),
blend: Blend::Alpha,
sampling,
+ world_tint: false,
};
let full = [[-1.0, -1.0], [1.0, -1.0], [1.0, 1.0], [-1.0, 1.0]];
// ScreenEffectRenderer.submitBlockSprite: u1/v1 at (-1, -1), colour 0xFF191919.
@@ -180,13 +184,16 @@ impl ScreenEffects {
{
let (u, v) = (-yaw / 64.0, pitch / 64.0);
let uv = [[u + 4.0, v + 4.0], [u, v + 4.0], [u, v], [u + 4.0, v]];
- out.push(hand_quad(
- full,
- uv,
- rect,
- [brightness, brightness, brightness, 0.1],
- texture_sampling("misc/underwater"),
- ));
+ out.push(ScreenQuad {
+ world_tint: true,
+ ..hand_quad(
+ full,
+ uv,
+ rect,
+ [brightness, brightness, brightness, 0.1],
+ texture_sampling("misc/underwater"),
+ )
+ });
}
if input.on_fire
&& let Some(rect) = sprite("block/fire_1")
@@ -224,6 +231,7 @@ impl ScreenEffects {
}),
blend,
sampling,
+ world_tint: false,
};
let rgba = |c: u32| {
let [a, r, g, b] = c.to_be_bytes();
@@ -397,6 +405,9 @@ mod tests {
});
let sampling: Vec<_> = quads.iter().map(|q| q.sampling).collect();
assert_eq!(sampling, [0, SAMPLE_CLAMP, SAMPLE_BLUR]);
+ // Only the underwater overlay tints the world; the block in the way covers it.
+ let tints: Vec<_> = quads.iter().map(|q| q.world_tint).collect();
+ assert_eq!(tints, [false, true, false]);
}
#[test]
fn mcmeta_texture_section() {