shadow_entities and shadow_block (each falling back to shadow) load with
the entities' vertex inputs unless shadowEntities or shadowBlockEntities is
false (spec 2.4, 3.2; both on by default, OQ-19). They draw the same entity
and block-entity runs the gbuffers programs would, with the same per-draw
uniforms, into the shadow map after the solid terrain and before the
shadowtex1 copy. A run is uploaded when a gbuffers program or a shadow
program draws it; Horizon still draws the runs no gbuffers program covers.
Without a pack nothing changes: only the pack's entity code is touched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The shadow pass runs when some program reads a shadow buffer (shadow,
watershadow, shadowtex0/1, their HW forms, shadowcolor, shadowcolor0/1) or
shadow.enabled=true; shadow.enabled=false keeps it off (spec 2.5). Then
`shadow` (solid and cutout terrain), `shadow_water` falling back to
`shadow` (translucent terrain) and shadowcomp..shadowcomp99 load, in the
new Shadow and ShadowComp groups (2.1, 2.4). shadow_solid and shadow_cutout
are not used: the game's solid and cutout terrain is one draw.
Their output n writes shadowcolor n (6.3): draw buffer lists stop at the
first index past 1. translate_shadow gives a shadow program the shadow
camera's matrices as its model-view and projection (5.2). The game does not
draw any of them yet.
Clean-room: implemented from cleanroom/shader-packs-spec.md revision 1,
sections 2.1, 2.4, 2.5, 5.2 and 6.3; no other loader's code read.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A pack with gbuffers_hand (or textured_lit, textured, basic; spec 2.3)
draws the first-person hand and held items after the opaque world, into
its own buffers and the world's depth, without blending and with the
entities' 0.1 alpha cut. The vertices are Horizon's hand geometry, read
as entities are; `gl_ProjectionMatrix` is the hand's own projection (the
hand's field of view and bob) with depth scaled by MC_HAND_DEPTH, while
`gbufferProjection` stays the world's (5.2). Horizon's own hand draw is
skipped only when the pack draws it.
Clean-room: implemented from cleanroom/shader-packs-spec.md revision 1;
no other loader's code read.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A pack with gbuffers_weather (or its fallbacks textured_lit, textured,
basic; spec 2.3) draws the game's rain and snow after translucent
terrain, blended, with vanilla's 0.1 alpha cut. The weather quads become
entity vertices with their UV animation applied on the CPU (the same
phase Horizon's weather shader computes; a test checks it against the
weather columns bit for bit), and rain and snow each read a copy of
their sprite, so the pack's `texture` repeats down the column as a
standalone texture would. The shared atlas gains COPY_SRC for that copy.
Without a pack nothing changes: Horizon's weather draw is skipped only
when the pack draws it.
Clean-room: implemented from cleanroom/shader-packs-spec.md revision 1;
no other loader's code read.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A pack with gbuffers_clouds draws Horizon's cloud geometry itself (spec
2.3, OQ-3: no fallback), blended, after the opaque world. Horizon's own
cloud draw is skipped then, also when the pack's program writes nothing
(BSL and Complementary hide vanilla clouds that way). Without a pack the
cloud draw is unchanged.
The translator now rewrites a bare `discard;` or `return;` to
`if (true) discard;` / `if (true) return;`, so code a pack leaves after
it stays reachable for naga ("Expression not visited"). This also fixes
Complementary Unbound's gbuffers_skytextured.
Clean-room: implemented from cleanroom/shader-packs-spec.md revision 1;
no other loader's code read.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A shader pack now draws entities with `gbuffers_entities` and block
entities with `gbuffers_block` (or their fallbacks, spec 2.3), after
terrain. Each run of the entity spans is one draw with its own
`entityId` or `blockEntityId` and `entityColor` (the hurt red, the
white flashes) in a per-draw slot. Horizon still draws everything else
(particles, cracks, beams, name tags, shadows, End portals, clouds) in
its own single entity draw, without the runs the pack drew.
The entity vertices are read again at set 1, so the pack gets the face
normal where a vertex has none (block entities), `at_tangent` along the
texture's u and `mc_midTexCoord`, as for terrain.
Entities and block entities draw without blending, with the loader's
alpha test at GREATER 0.1, as cutout (OQ-23); name tags and shadows,
which blend, stay Horizon's for now.
`HORIZON_SHADER_PACK_TIMING` no longer panics when a pass skips a whole
report window (no entities in view).
Without a shader pack nothing changes: the split only runs while a pack
draws entities.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
block.properties (spec 4.1) is read: `block.<id>=` names with optional
namespaces and state filters; the most specific matching entry wins.
Terrain vertices carry their sprite layer, not their block, so the game
builds a table of the block sprite layers: each takes the id of the block
named like its sprite, else the id most blocks drawing it share; y is 1
on the water and lava sprites. Flat terrain reads it from a storage
buffer at set 3; other draws and packs without the file read (-1, -1).
Building the table takes 14 ms for BSL, 39 ms for Complementary.
Clean-room: implemented from cleanroom/shader-packs-spec.md revision 1,
4.1, 5.1, 5.3; no other loader's code read.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gbuffers_skytextured (or gbuffers_textured, gbuffers_basic) draws the
frame's sun and moon quads, with their render stages, `texture` reading
the shared atlas their sprites live in. The sky's parts draw in vanilla's
order (disc, sunset, sun, moon, stars, void), in one render pass while
consecutive programs write the same buffers. The sun and moon add to the
sky (SRC_ALPHA, ONE) unless blend.<program> says otherwise. Horizon's
world pass skips its own sun and moon when the pack draws them; a part
without a program stays Horizon's.
Clean-room: implemented from cleanroom/shader-packs-spec.md revision 1,
2.3, 5.4; no other loader's code read.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The pack's gbuffers_skybasic (or gbuffers_basic) draws vanilla's sky
geometry, as Horizon's own sky builds it: the disc at y 16, the sunset
fan while the sun is low, the stars and the void disc, each with its
render stage. One static vertex buffer; the frame's colours and rotations
sit in a small uniform the vertex inputs read. The sky draws after the
world copy and before terrain, at the far plane: only where nothing else
drew, without writing depth. It blends with the translucent default unless
blend.<program> says otherwise. Horizon's world pass then skips its own
sky disc, stars and void. The sun and moon stay Horizon's for now
(gbuffers_skytextured is next): the pack's sky covers them.
load_post takes the game's inputs per geometry (GameInputs);
GbuffersInputs gains statements run after the pack's main.
Clean-room: implemented from cleanroom/shader-packs-spec.md revision 1,
2.1, 2.3, 5.4; no other loader's code read.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A gbuffers program's renderStage, entityId, blockEntityId and entityColor
(spec 5.3, updated per draw) move to a block of their own at set 2 that
the game picks per draw with a dynamic offset: one slot per render stage.
Terrain draws as TERRAIN_SOLID, translucent terrain as
TERRAIN_TRANSLUCENT. The terrain test pack paints any other stage red.
Clean-room: implemented from cleanroom/shader-packs-spec.md revision 1,
5.3, 5.4; no other loader's code read.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With a pack whose gbuffers_water (or a fallback down gbuffers_terrain's
chain) loads, translucent terrain (water, stained glass) is drawn by it
after the deferred programs and before the composites, in place, sorted
back to front as the game sorts it, and Horizon's own translucent
terrain draw is skipped.
- blend.<program> (off, or four GL factors); translucent terrain
defaults to SRC_ALPHA ONE_MINUS_SRC_ALPHA ONE ONE_MINUS_SRC_ALPHA, and
only blendable buffer formats blend.
- depthtex1/depthtex2: depth without translucent terrain, a copy taken
just before it when a later program reads them (before it, depthtex0
itself). The hand is drawn after the pack, so depthtex2 = depthtex1.
Clean-room: implemented from cleanroom/shader-packs-spec.md revision 1,
sections 2.1, 2.3, 3.2 (blend), 6.2 (depthtex1/2); no other loader's
code read.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`uniform.<type>.<name>` and `variable.<type>.<name>` of shaders.properties (3.4): an
expression parser with C precedence, the function table (math, vectors, `if`, `between`,
`equals`, `smooth`, `random`...), evaluated on the CPU once per frame in file order after the
frame's own uniforms. `smooth` keeps its state per call site and halves the distance to its
target every fade time (OQ-26 working answer). A name neither the frame nor the pack defines
reads 0 and is listed once in the log.
Clean-room: implemented from cleanroom/shader-packs-spec.md revision 1, section 3.4; no other
loader's code read.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With a pack whose gbuffers_terrain (or a fallback) loads, solid and
cutout terrain is drawn by it into the pack's buffers, in place, between
prepare and deferred, and Horizon's own solid terrain draw is skipped.
- depthtex0 is now a Depth32Float attachment: the blit writes the
world's depth there (GL window depth, GL rows), terrain tests and
writes against it, so entities and terrain occlude each other; later
programs sample it as before.
- The vertex glue reads Horizon's TerrainVertex on both draw paths
(instanced, and flat with the page tables in bind group 1) and gives
atlas coordinates, lightmap coordinates in 0-240, the vertex colour,
mc_midTexCoord at the sprite's centre and mc_Entity = -1. Normals,
tangents and block ids come later.
- texture/gtexture/tex sample the block atlas, lightmap the lightmap;
atlasSize is set.
- Occlusion culling is off while a pack draws terrain (it reads the
depth of Horizon's terrain draw), and flat draws stay on.
- Uniforms a program reads that are not provided yet are reported.
- Program building is shared by quads and terrain (build_pass, bind).
- terrain-test: Horizon's own pack for this slice.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
load_post takes the game's terrain vertex inputs and, given them, loads
the first program of gbuffers_terrain's fallback chain that translates
(gbuffers_terrain, textured_lit, textured, basic). Program loading is
shared by the post-processing and gbuffers programs.
The translator no longer rewrites a variable, parameter or member that
has the name of a sampler (`float specular` beside `uniform sampler2D
specular`), which kept Complementary's gbuffers programs from compiling.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What the renderer needs to run a pack's post-processing, still without
wgpu: the programs of one dimension (prepare, deferred, composite and
final with their numbered variants, in the order they run), each
preprocessed and translated, with the buffers it writes and the flips
that follow it, and the buffer settings its stage files carry.
- A dimension's folder (world0, world-1, world1) replaces the base folder
when it exists. program.<name>.enabled expressions over switch options,
flip.<program>.<buffer> keys and the virtual deferred_pre and
composite_pre. Programs with a geometry stage, or that fail to
preprocess or translate, are reported and skipped.
- tests/packs/post-test: Horizon's own small test pack (tint, depth in
colortex2, depth bands on half the screen, vignette).
Black box over the public test packs: every dimension of every pack
loads its post-processing programs (2 to 9) with no note.
Nothing uses it yet: players see no change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A program's preprocessed GLSL, any version from 110 to 460, compatibility
or core, rewritten into the Vulkan-flavoured GLSL 450 that naga's frontend
reads, then parsed and validated into naga modules with the program's
interface: its uniform block (offsets from naga's layout), its samplers
and their bindings, its output locations. The rewrite works on
preprocessing tokens and keeps the pack's lines, so every error points at
the pack's own file and line through the preprocessor's line map.
- Loose uniforms go into one block shared by both stages; bool is stored
as int. Samplers are split into texture and sampler objects, combined
again where used, and passed as two arguments to the pack's functions.
- The compatibility built-ins become declarations of ours (prefix hz_):
gl_Vertex, gl_MultiTexCoordN, the matrices and ftransform(), gl_FragData,
gl_FragColor, gl_TexCoord, gl_FrontColor, gl_Fog (from vanilla's fog),
texture2D and the other old texture functions, shadow2D; varyings get
locations by name across the stages; words that became keywords after
GLSL 1.x are renamed in old code.
- naga gaps covered: modf, conditional initializers of globals (run by our
main), and unsized arrays sized from their constructor.
- The pack's main is called by one of ours that draws the quad from (0,0)
to (1,1) and adapts GL's conventions: clip y negated for every target but
the window, so memory rows are GL's rows and gl_FragCoord needs no change;
clip z from GL's [-w, w] to [0, w], so stored depth is GL's window depth.
In final, gl_FragCoord.y is counted from the bottom of the window.
Black box over the public test packs: all 105 composite-style programs
(composite, deferred, final, prepare, begin, shadowcomp of the base and
dimension folders) translate and validate.
Nothing uses it yet: players see no change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A stage file goes through comment removal, #include, conditionals and
macro expansion, and every output line remembers the pack file and line it
came from, so later errors point at the pack's own code.
- #include "x" from the including file's folder, "/x" from the shaders
folder, expanded in live code only (an include inside a false #if is not
read), ten levels at most, paths that leave the pack refused; a file is
read once per run however often it is included.
- #define, #undef, line continuations, __LINE__ and __VERSION__; #version
and #extension kept apart for the translation's own header; the block
comments of live code kept for the directives packs write in them
(DRAWBUFFERS, buffer formats); #error and unknown directives diagnosed.
Black box over the public test packs: every stage file of the base and
dimension folders (126 to 219 per pack) preprocesses with no diagnostic.
Nothing uses it yet: players see no change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
shaders.properties and the id files (block, item, entity, dimension):
key=value lines in file order with their line numbers, # comments, a value
continued on the next line by a trailing backslash, and the conditional
directives evaluated with the standard and option macros. A # line is a
directive only when its first word is one, so a commented-out key such as
#ifdefault=1 stays a comment. #define and #undef apply to the lines after
them in every one of these files: a public pack defines a macro inside
#ifdef MC_OS_MAC in its shaders.properties and tests it further down. A
later duplicate key replaces the earlier one; broken conditionals, lines
that are not key=value and duplicates are kept as notes for the pack's log.
Nothing uses it yet: players see no change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A new crate, horizon-shaders, the first piece of shader pack support written
again from a specification of the format. It opens a pack (a folder or a zip
whose root holds a shaders folder; decoy folders and files beside it are
ignored), lists the packs in a shaderpacks folder with the reason a broken
one can't be used, and reads a pack's lang files: English under the player's
locale, file names matched ignoring case (packs ship en_US.lang).
Nothing uses it yet: players see no change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>