[PR #4456] [MERGED] fix(render): terrain samples block textures like vanilla #5636

Closed
opened 2026-11-03 05:13:58 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4456
Author: @reservedbytes
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @ludovic111

Base: main ← Head: fix/terrain-sampling


📝 Commits (1)

  • b56f94b fix(render): terrain samples block textures like vanilla

📊 Changes

3 files changed (+65 additions, -48 deletions)

View changed files

📝 crates/horizon-client-render/src/gfx.rs (+47 -29)
📝 crates/horizon-client-render/src/lod/mesh.rs (+2 -2)
📝 crates/horizon-client-render/src/terrain.wgsl (+16 -17)

📄 Description

What and why

Far terrain shimmers in Horizon with Texture Filtering None (the default): grass turns grainy and water sparkles, with a hard line where the mip level changes

Since #4843, RGSS and Anisotropic sample like vanilla, but None still takes a nearest sampler (min, mag and mips) and plain sampling

Vanilla doesn't special-case None: it draws chunks with the same linear sampler in every mode and runs sampleNearest whenever RGSS is off

This makes None do the same thing, with #4843's own code

  • the sprite sampler is the linear, clamped one in every mode, with anisotropy 1 unless Anisotropic

  • sprite() in terrain.wgsl runs sample_rgss for RGSS and sample_nearest otherwise, so the None special case is gone

RGSS and Anisotropic don't change

Only the chunk pipelines use that sampler, so entities and items don't change, as in vanilla

Distant terrain tiles merge many blocks into one face and relied on a repeating sampler

tile_uv in terrain.wgsl takes the sprite again for each block of those faces, so they keep repeating under the clamped sampler

Vanilla has no tiled faces, and the UVs of normal faces stay in the sprite, so they don't change

This also fixes the same smearing on RGSS and Anisotropic since #4843

On the first version of this branch I compared it against vanilla 26.3 on the same world, camera and options

Far water with the camera still: 2.3% of pixels flicker each frame before, 0.08% after, vanilla 0.01 to 0.03%

Near grass keeps the same detail as vanilla

The cost is small, about 0.1 ms of GPU per frame at 4K on an RTX 3080 (vanilla does the same thing)

I think the numbers still hold, since None now runs the same sampling... the only difference from that version for normal faces is the clamped address mode, which vanilla uses too

Should fix #4360

Cutout and glass

With a linear sampler, the alpha at the edge between a transparent and an opaque texel is blended, so the cutout test sees filtered alpha

Vanilla does exactly that: terrain.fsh tests ALPHA_CUTOUT on the sampleNearest result times the vertex colour, after the fade-in mix

fs_solid does the same with 0.5, which is vanilla's cutout terrain threshold, so leaves, glass and glass panes cut out where vanilla's do

Glass and glass panes are cutout in vanilla (only fully clear or opaque texels), and Horizon puts them in the same layer

Up close the blend is one screen pixel wide, as in vanilla, so near edges stay sharp

One gap stays, not from this PR: fs_translucent discards below 0.01, vanilla's translucent terrain below 0.1

It applies to every filtering mode, so I think it's better as its own one-line PR

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

LevelRenderer.java:440-445: the chunk layer sampler is CLAMP_TO_EDGE, LINEAR, LINEAR in every mode, with maxAnisotropyValue only for ANISOTROPIC and 1 otherwise

GlSampler makes LINEAR min GL_LINEAR_MIPMAP_LINEAR, and VulkanGpuSampler.java:45 gives it linear mips

shaders/core/terrain.fsh:36: UseRgss == 1 ? sampleRGSS(...) : sampleNearest(...)

shaders/core/terrain.fsh:40-44: the ALPHA_CUTOUT discard

shaders/include/texture_sampling.glsl:4-23: sampleNearest

RenderPipelines.java:376: cutout terrain ALPHA_CUTOUT 0.5, :391: translucent terrain 0.1

ChunkSectionLayer.java:28-33: translucent if a texel is partly transparent, cutout if one is fully transparent

Self-check

pr_ready (tools/pr_ready.py --quick on pop-os, against origin/main at 6e263d79f, 4 min 14 s)

Check Result
Scope ✅ 3 files, +65 −48
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 487 passed (55 s)
rustfmt ✅ (8 s)
clippy ✅ (1 min 53 s)
tests: horizon-client-render ✅ 708 passed (1 min 17 s)
doc tests ✅ 0 passed (1 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

Screenshots

From the first version of this branch, Texture Filtering None

Before
before

After
after

Vanilla
vanilla


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/4456 **Author:** [@reservedbytes](https://github.com/reservedbytes) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/terrain-sampling` --- ### 📝 Commits (1) - [`b56f94b`](https://github.com/horizon-rust/horizon/commit/b56f94b2b7ef4abc513e0ba65cbc3641dcf61c15) fix(render): terrain samples block textures like vanilla ### 📊 Changes **3 files changed** (+65 additions, -48 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/gfx.rs` (+47 -29) 📝 `crates/horizon-client-render/src/lod/mesh.rs` (+2 -2) 📝 `crates/horizon-client-render/src/terrain.wgsl` (+16 -17) </details> ### 📄 Description ## What and why Far terrain shimmers in Horizon with Texture Filtering None (the default): grass turns grainy and water sparkles, with a hard line where the mip level changes Since #4843, RGSS and Anisotropic sample like vanilla, but None still takes a nearest sampler (min, mag and mips) and plain sampling Vanilla doesn't special-case None: it draws chunks with the same linear sampler in every mode and runs `sampleNearest` whenever RGSS is off This makes None do the same thing, with #4843's own code - the sprite sampler is the linear, clamped one in every mode, with anisotropy 1 unless Anisotropic - `sprite()` in `terrain.wgsl` runs `sample_rgss` for RGSS and `sample_nearest` otherwise, so the None special case is gone RGSS and Anisotropic don't change Only the chunk pipelines use that sampler, so entities and items don't change, as in vanilla Distant terrain tiles merge many blocks into one face and relied on a repeating sampler `tile_uv` in `terrain.wgsl` takes the sprite again for each block of those faces, so they keep repeating under the clamped sampler Vanilla has no tiled faces, and the UVs of normal faces stay in the sprite, so they don't change This also fixes the same smearing on RGSS and Anisotropic since #4843 On the first version of this branch I compared it against vanilla 26.3 on the same world, camera and options Far water with the camera still: 2.3% of pixels flicker each frame before, 0.08% after, vanilla 0.01 to 0.03% Near grass keeps the same detail as vanilla The cost is small, about 0.1 ms of GPU per frame at 4K on an RTX 3080 (vanilla does the same thing) I think the numbers still hold, since None now runs the same sampling... the only difference from that version for normal faces is the clamped address mode, which vanilla uses too Should fix #4360 ## Cutout and glass With a linear sampler, the alpha at the edge between a transparent and an opaque texel is blended, so the cutout test sees filtered alpha Vanilla does exactly that: `terrain.fsh` tests `ALPHA_CUTOUT` on the `sampleNearest` result times the vertex colour, after the fade-in mix `fs_solid` does the same with 0.5, which is vanilla's cutout terrain threshold, so leaves, glass and glass panes cut out where vanilla's do Glass and glass panes are cutout in vanilla (only fully clear or opaque texels), and Horizon puts them in the same layer Up close the blend is one screen pixel wide, as in vanilla, so near edges stay sharp One gap stays, not from this PR: `fs_translucent` discards below 0.01, vanilla's translucent terrain below 0.1 It applies to every filtering mode, so I think it's better as its own one-line PR ## Kind - [x] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference `LevelRenderer.java:440-445`: the chunk layer sampler is `CLAMP_TO_EDGE`, `LINEAR`, `LINEAR` in every mode, with `maxAnisotropyValue` only for `ANISOTROPIC` and 1 otherwise `GlSampler` makes `LINEAR` min `GL_LINEAR_MIPMAP_LINEAR`, and `VulkanGpuSampler.java:45` gives it linear mips `shaders/core/terrain.fsh:36`: `UseRgss == 1 ? sampleRGSS(...) : sampleNearest(...)` `shaders/core/terrain.fsh:40-44`: the `ALPHA_CUTOUT` discard `shaders/include/texture_sampling.glsl:4-23`: `sampleNearest` `RenderPipelines.java:376`: cutout terrain `ALPHA_CUTOUT` 0.5, `:391`: translucent terrain 0.1 `ChunkSectionLayer.java:28-33`: translucent if a texel is partly transparent, cutout if one is fully transparent ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on pop-os, against origin/main at 6e263d79f, 4 min 14 s) | Check | Result | | --- | --- | | Scope | ✅ 3 files, +65 −48 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 487 passed (55 s) | | rustfmt | ✅ (8 s) | | clippy | ✅ (1 min 53 s) | | tests: horizon-client-render | ✅ 708 passed (1 min 17 s) | | doc tests | ✅ 0 passed (1 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | ## Screenshots From the first version of this branch, Texture Filtering None Before <img width="1440" height="450" alt="before" src="https://github.com/user-attachments/assets/7443c97c-4d67-47e6-b260-c0e34617e200" /> After <img width="1440" height="450" alt="after" src="https://github.com/user-attachments/assets/b3eedfcc-f8ba-4a5d-afa5-98ea15ae509e" /> Vanilla <img width="1440" height="450" alt="vanilla" src="https://github.com/user-attachments/assets/eb83c36e-2803-4340-8730-a75b3853e077" /> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:13:58 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#5636
No description provided.