c813261574
A pack's `fn material(input: MaterialInput) -> Surface` now gives the lit colour of every terrain surface: sections and distant tiles, solid, cutout and translucent, in both the instanced and the flat draws. Terrain keeps Horizon's meshes, culling and draw lists; only its pipelines change. Their shader is the pack's stage, a prefixed copy of terrain.wgsl's terrain section, and entries that hand the pack the texture, the vertex tint, the light levels and the lightmap's colour apart, then apply the alpha test and fog as `fs_solid` and `fs_translucent` do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
75 lines
2.7 KiB
Rust
75 lines
2.7 KiB
Rust
//! One of Horizon's own shader packs while it runs (docs/shaders.md): the frame its stages
|
|
//! read, its sky, material and post stages, and the timer of their passes.
|
|
|
|
use horizon_shader_api::{Report, StageKind};
|
|
|
|
use super::native_material::{NativeMaterial, TerrainShape};
|
|
use super::native_post::{NativeFrame, NativePost};
|
|
use super::native_sky::NativeSky;
|
|
use super::pack_timing::PassTiming;
|
|
|
|
pub struct NativePack {
|
|
pub frame: NativeFrame,
|
|
pub sky: Option<NativeSky>,
|
|
pub material: Option<NativeMaterial>,
|
|
pub post: Option<NativePost>,
|
|
/// GPU time of each pass, while the renderer asks for it (`pack_timing.rs`).
|
|
pub timing: Option<PassTiming>,
|
|
}
|
|
|
|
impl NativePack {
|
|
/// The pack of the checked stages `report` with the option values `constants`, drawing
|
|
/// onto the world's targets as `terrain` describes; the sky reads the terrain's group 0.
|
|
/// Also returns its stages' labels, in the order they draw. Errors name the stage wgpu
|
|
/// refused.
|
|
pub fn new(
|
|
device: &wgpu::Device,
|
|
terrain: &TerrainShape<'_>,
|
|
report: Report,
|
|
constants: &[(String, f64)],
|
|
) -> Result<(Self, Vec<String>), String> {
|
|
let (globals, format) = (terrain.globals, terrain.format);
|
|
let frame = NativeFrame::new(device);
|
|
let (post, others): (Vec<_>, Vec<_>) = report
|
|
.stages
|
|
.into_iter()
|
|
.partition(|s| s.kind == StageKind::Post);
|
|
let sky = others
|
|
.iter()
|
|
.find(|s| s.kind == StageKind::Sky)
|
|
.map(|stage| NativeSky::new(device, globals, &frame, stage, constants, format))
|
|
.transpose()?;
|
|
let material = others
|
|
.iter()
|
|
.find(|s| s.kind == StageKind::Material)
|
|
.map(|stage| NativeMaterial::new(device, terrain, &frame, stage, constants))
|
|
.transpose()?;
|
|
let post = (!post.is_empty())
|
|
.then(|| NativePost::new(device, post, constants, format, &frame))
|
|
.transpose()?;
|
|
let mut labels: Vec<String> = sky.iter().map(|s| s.label.clone()).collect();
|
|
labels.extend(
|
|
others
|
|
.iter()
|
|
.filter(|s| material.is_some() && s.kind == StageKind::Material)
|
|
.map(|s| s.label.clone()),
|
|
);
|
|
if let Some(post) = &post {
|
|
labels.extend(post.labels().into_iter().map(str::to_owned));
|
|
}
|
|
let pack = Self {
|
|
frame,
|
|
sky,
|
|
material,
|
|
post,
|
|
timing: None,
|
|
};
|
|
Ok((pack, labels))
|
|
}
|
|
|
|
/// Whether the pack draws anything the game runs today.
|
|
pub fn draws(&self) -> bool {
|
|
self.sky.is_some() || self.material.is_some() || self.post.is_some()
|
|
}
|
|
}
|