cad817c82d
A pack's `sky` function gets vanilla's colour along each view ray and draws where the vanilla sky dome draws, under the sun, moon, stars and clouds. The pipeline's shader is the pack's checked stage (`CheckedStage::source`, new) followed by a copy of terrain.wgsl's sky with every name prefixed `horizon_sky_`, so none can meet a pack's; terrain.wgsl's `fs_sky` now calls `sky_along_ray`, the same code as before. A running pack is one `NativePack`: the frame every stage reads (written once a frame), its sky and post stages and its pass timer. In a frame F3 times, the sky draws in a pass of its own so the overlay can show its time; otherwise it stays in the world's pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
61 lines
2.1 KiB
Rust
61 lines
2.1 KiB
Rust
//! One of Horizon's own shader packs while it runs (docs/shaders.md): the frame its stages
|
|
//! read, its sky and post stages, and the timer of their passes.
|
|
|
|
use horizon_shader_api::{Report, StageKind};
|
|
|
|
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 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 targets of `format`; `globals` is the terrain's group 0, which the sky reads.
|
|
/// Also returns its stages' labels, in the order they draw. Errors name the stage wgpu
|
|
/// refused.
|
|
pub fn new(
|
|
device: &wgpu::Device,
|
|
globals: &wgpu::BindGroupLayout,
|
|
report: Report,
|
|
constants: &[(String, f64)],
|
|
format: wgpu::TextureFormat,
|
|
) -> Result<(Self, Vec<String>), String> {
|
|
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 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();
|
|
if let Some(post) = &post {
|
|
labels.extend(post.labels().into_iter().map(str::to_owned));
|
|
}
|
|
let pack = Self {
|
|
frame,
|
|
sky,
|
|
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.post.is_some()
|
|
}
|
|
}
|