c962cd472f
Add an RG16F current-to-previous render-pixel target to the HD G-buffer. Terrain and entities write previous drawn-camera projections; TAA/TAAU use matching opaque vectors and retain the depth fallback elsewhere. Object-local previous transforms and vendor SDK evaluation remain separate phases. Co-Authored-By: Kimi Code <noreply@moonshot.ai>
90 lines
4.1 KiB
Rust
90 lines
4.1 KiB
Rust
//! The G-buffer: the solid world (terrain, far LOD tiles, entities and mod models) drawn once more
|
|
//! before the world pass, with its own depth. Translucent things do not enter it.
|
|
//!
|
|
//! Contract (all at the world size, jitter included in the projection):
|
|
//! - `albedo` (`Rgba8Unorm`): rgb surface colour without light, in the display (gamma) space the
|
|
//! vanilla textures use; **a = emission** (0 none; the lighting adds `rgb * a * 1.5` on top).
|
|
//! - `normal` (`Rgba16Float`): rgb world-space unit normal (from `dpdx/dpdy`; plants use up), a unused.
|
|
//! - `levels` (`Rgba8Unorm`): x = sky light, y = block light, both the raw lightmap coordinate / 240
|
|
//! (0..1); zw unused.
|
|
//! - `motion` (`Rg16Float`): current-to-previous displacement in render-target pixels, with both
|
|
//! projections as actually drawn, jitter included. The first pass covers camera/static geometry;
|
|
//! object-local previous transforms are a separate contract.
|
|
//! - `depth` (`Depth32Float`): camera depth, **reversed-Z** (cleared to 0 = far / nothing, 1 = near).
|
|
//! An untouched pixel (depth 0) is sky.
|
|
//! - Readers: AO, lighting, water composite, TAA/TAAU (depth). Written by `gbuffer_pass`; the caller
|
|
//! draws into it with `fs_gbuffer` / `fs_entity_gbuffer`.
|
|
use super::{Hd, stamp, target};
|
|
|
|
/// The G-buffer's formats.
|
|
pub const ALBEDO: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8Unorm;
|
|
pub const NORMAL: wgpu::TextureFormat = wgpu::TextureFormat::Rgba16Float;
|
|
/// Sky and block light per pixel.
|
|
pub const LIGHT_LEVELS: wgpu::TextureFormat = wgpu::TextureFormat::Rgba8Unorm;
|
|
/// Current-to-previous motion in render-target pixels.
|
|
pub const MOTION: wgpu::TextureFormat = wgpu::TextureFormat::Rg16Float;
|
|
/// The camera depth formats (the G-buffer's and the water's own).
|
|
pub const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float;
|
|
|
|
pub(super) struct GBuffer {
|
|
pub(super) albedo: wgpu::TextureView,
|
|
pub(super) normal: wgpu::TextureView,
|
|
pub(super) levels: wgpu::TextureView,
|
|
pub(super) motion: wgpu::TextureView,
|
|
pub(super) depth: wgpu::TextureView,
|
|
}
|
|
|
|
impl GBuffer {
|
|
/// The targets at `size` (the world's).
|
|
pub(super) fn new(device: &wgpu::Device, size: [u32; 2]) -> Self {
|
|
Self {
|
|
albedo: target(device, "HD albedo", size, ALBEDO).view,
|
|
normal: target(device, "HD normal", size, NORMAL).view,
|
|
levels: target(device, "HD light levels", size, LIGHT_LEVELS).view,
|
|
motion: target(device, "HD motion", size, MOTION).view,
|
|
depth: target(device, "HD depth", size, DEPTH_FORMAT).view,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Hd {
|
|
/// The G-buffer pass's attachments: colour, normal, light and motion cleared, its own depth.
|
|
pub fn gbuffer_pass<'e>(
|
|
&mut self,
|
|
encoder: &'e mut wgpu::CommandEncoder,
|
|
) -> wgpu::RenderPass<'e> {
|
|
let clear = |view| {
|
|
Some(wgpu::RenderPassColorAttachment {
|
|
view,
|
|
resolve_target: None,
|
|
depth_slice: None,
|
|
ops: wgpu::Operations {
|
|
load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT),
|
|
store: wgpu::StoreOp::Store,
|
|
},
|
|
})
|
|
};
|
|
encoder
|
|
.begin_render_pass(&wgpu::RenderPassDescriptor {
|
|
label: Some("HD G-buffer"),
|
|
timestamp_writes: stamp(&mut self.timing, "hd g-buffer"),
|
|
color_attachments: &[
|
|
clear(&self.gbuffer.albedo),
|
|
clear(&self.gbuffer.normal),
|
|
clear(&self.gbuffer.levels),
|
|
clear(&self.gbuffer.motion),
|
|
],
|
|
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
|
|
view: &self.gbuffer.depth,
|
|
depth_ops: Some(wgpu::Operations {
|
|
load: wgpu::LoadOp::Clear(0.0),
|
|
store: wgpu::StoreOp::Store,
|
|
}),
|
|
stencil_ops: None,
|
|
}),
|
|
..Default::default()
|
|
})
|
|
.forget_lifetime()
|
|
}
|
|
}
|