Shader packs: keep what Iris does, drop what doesn't work, apply settings on Done
Review fixes for #1414 (contribution gate): - Java packs no longer get Horizon's shadow map: it was mirrored in y and reversed in depth against the GL conventions the packs sample with, had no distortion and only the camera's sections, so BSL drew no shadows while the pass cost 0.65 ms (MakeUp, M4 Pro). shadowtex* stays a far depth, as on main; the packs' own shadow programs are #1326. - Invented uniforms removed (centerDepthSmooth fixed at 0.5, ambientOcclusionLevel and shadowMapResolution as uniforms, constant temp/rainfall/biome/held items); an unknown uniform stays zero as before. wetness keeps its Iris smoothing. Unused directives removed. - texture.<stage>.<sampler> is scoped to Iris's stages (final reads the composite ones) instead of overriding the sampler in every pass; texture.noise replaces noisetex. One noise generator and one RGBA upload for both pack kinds. - The G-buffer pass, the opaque-depth copy and the shadow pass run only for a pack that reads them (naga's per-entry-point binding use, not a text search): every pack paid all three before. - Api 2's prelude additions go in their own file after api 1's, so api 1 packs keep the names they declare (aces_tonemap, material_at...). - Stage kinds shadow, gbuffer, deferred and final ran as composite: only composite is accepted; api 2 adds formats (validated), profiles, option descriptions and a noise texture. - Shader Pack Settings applies once when the page closes, as Iris's Done (each click or slider step rebuilt the pack: 2.7 s per click, 12.7 s for one drag with BSL). Labels follow Iris (.lang, else the name). A pack whose options can't be read isn't read again every frame. - Saved option values an option doesn't list are ignored, as OptiFine's ShaderOption.setValue (a stale file broke BSL's compile). - Import: the blocking file dialog (osascript/zenity/kdialog/PowerShell on the event loop) is gone; a pack dropped on the Shader Packs page is copied and picked, as Iris's onFilesDrop. Drops elsewhere do nothing, an existing pack isn't overwritten, links aren't followed. - Docs and the example say what the code does (SSAO, not GTAO). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
//! Java (OptiFine/Iris) shader packs in `shaderpacks/` (docs/shader-packs.md):
|
||||
//! a folder holding `shaders/`, or a `.zip`. `horizon-shaderpack` translates
|
||||
//! their full-screen programs (`begin`, `prepare`, `deferred`, `composite`,
|
||||
//! `final`) to WGSL, and `gfx/java_stages.rs` runs them over Horizon's world,
|
||||
//! G-buffers, pre-translucent depth (`depthtex1`) and directional shadow map
|
||||
//! (`shadowtex0`/`shadowtex1`) as Iris runs them over its own.
|
||||
//! `final`) to WGSL, and `gfx/java_stages.rs` runs them over Horizon's world
|
||||
//! as Iris runs them over its own. Geometry programs (`gbuffers_*`,
|
||||
//! `shadow`) don't run yet: the world is drawn by Horizon.
|
||||
use horizon_shaderpack::{
|
||||
JavaPack,
|
||||
pipeline::{Directives, Program, TargetSettings},
|
||||
@@ -30,10 +30,24 @@ pub struct JavaFolder {
|
||||
pub final_pass: Option<Program>,
|
||||
/// The targets whose alternate side holds the frame's last write.
|
||||
pub flipped_at_end: BTreeSet<u32>,
|
||||
/// `sunPathRotation`, `eyeBrightnessHalflife`, shadow and wetness directives.
|
||||
/// `sunPathRotation`, `eyeBrightnessHalflife`, `wetnessHalflife` and
|
||||
/// `drynessHalflife`.
|
||||
pub directives: Directives,
|
||||
/// Whether this dimension's passes read directional shadow maps.
|
||||
pub shadow_enabled: bool,
|
||||
}
|
||||
|
||||
/// The key of `texture.noise` (`noisetex`) in [`JavaPasses::custom_textures`].
|
||||
pub const NOISE_KEY: &str = "noise";
|
||||
|
||||
/// The key of `texture.<stage>.<sampler>` in [`JavaPasses::custom_textures`]
|
||||
/// for a pass of `program` (`world0/composite2`): Iris's texture stages, where
|
||||
/// `final` reads the `composite` ones.
|
||||
pub fn texture_key(program: &str, sampler: &str) -> String {
|
||||
let name = program.rsplit('/').next().unwrap_or(program);
|
||||
let stage = match name.trim_end_matches(|c: char| c.is_ascii_digit()) {
|
||||
"final" => "composite",
|
||||
stage => stage,
|
||||
};
|
||||
format!("{stage}.{sampler}")
|
||||
}
|
||||
|
||||
/// A loaded Java pack.
|
||||
@@ -43,8 +57,9 @@ pub struct JavaPasses {
|
||||
pub uniforms: CustomUniforms,
|
||||
/// What the pack keeps of the vanilla sky (`clouds`, `sun`, `moon`).
|
||||
pub sky: SkyDirectives,
|
||||
/// Decoded RGBA8 custom textures (`sampler_name` → `(width, height, rgba)`).
|
||||
pub custom_textures: BTreeMap<String, (u32, u32, Vec<u8>)>,
|
||||
/// `texture.<stage>.<sampler>` and `texture.noise` images, by
|
||||
/// `"<stage>.<sampler>"` and [`NOISE_KEY`].
|
||||
pub custom_textures: BTreeMap<String, crate::shader_pack::Rgba>,
|
||||
}
|
||||
|
||||
impl JavaPasses {
|
||||
@@ -135,7 +150,6 @@ pub fn load(
|
||||
final_pass,
|
||||
flipped_at_end: plan.flipped_at_end,
|
||||
directives: plan.directives,
|
||||
shadow_enabled: plan.shadow_enabled,
|
||||
});
|
||||
}
|
||||
if folders.is_empty() {
|
||||
@@ -143,15 +157,23 @@ pub fn load(
|
||||
}
|
||||
let mut custom_textures = BTreeMap::new();
|
||||
for tex in properties.custom_textures() {
|
||||
if let Some(bytes) = pack.files.read_bytes(&tex.path) {
|
||||
match crate::shader_pack::decode_png_rgba(&bytes) {
|
||||
Ok(decoded) => {
|
||||
custom_textures.insert(tex.sampler, decoded);
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!("Horizon: shader pack texture {}: {e}", tex.path);
|
||||
}
|
||||
let key = match tex.stage {
|
||||
Some(stage) => format!("{stage}.{}", tex.sampler),
|
||||
None if tex.sampler == NOISE_KEY => NOISE_KEY.to_owned(),
|
||||
None => continue,
|
||||
};
|
||||
// Only PNGs for now: resource locations and raw `.dat` textures are
|
||||
// skipped and the sampler reads what it would without them.
|
||||
let image = pack
|
||||
.files
|
||||
.read_bytes(&tex.path)
|
||||
.ok_or_else(|| "not in the pack".to_owned())
|
||||
.and_then(|bytes| crate::shader_pack::decode_png(&bytes));
|
||||
match image {
|
||||
Ok(image) => {
|
||||
custom_textures.insert(key, image);
|
||||
}
|
||||
Err(e) => log::warn!("Horizon: shader pack texture {}: {e}", tex.path),
|
||||
}
|
||||
}
|
||||
let uniforms = properties.custom_uniforms();
|
||||
@@ -170,6 +192,17 @@ pub fn load(
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn custom_textures_belong_to_iris_s_stages() {
|
||||
assert_eq!(texture_key("world0/composite2", "gaux1"), "composite.gaux1");
|
||||
assert_eq!(texture_key("final", "colortex4"), "composite.colortex4");
|
||||
assert_eq!(
|
||||
texture_key("world-1/deferred10", "noisetex"),
|
||||
"deferred.noisetex"
|
||||
);
|
||||
assert_eq!(texture_key("prepare", "depthtex2"), "prepare.depthtex2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn loads_the_full_screen_passes_of_a_java_pack() {
|
||||
let dir = Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
|
||||
Reference in New Issue
Block a user