HD lighting: G-buffer pass, per-pixel mod point lights in HDR, bloom and tone curve; render.set-lights and render.set-lighting (API level 10)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,13 +7,13 @@
|
||||
//! version's level so the launcher can tell before it installs.
|
||||
|
||||
/// The newest level this Horizon serves.
|
||||
pub const LEVEL: u32 = 9;
|
||||
pub const LEVEL: u32 = 10;
|
||||
|
||||
/// Every function the game offers mods, as `interface.function`, with its
|
||||
/// level. Level 0 is the contract of Horizon 0.2.67 to 0.2.69. A new
|
||||
/// function takes the next level and raises [`LEVEL`] (the `api_reference`
|
||||
/// test fails until it is listed here).
|
||||
pub const FUNCTIONS: [(&str, u32); 56] = [
|
||||
pub const FUNCTIONS: [(&str, u32); 58] = [
|
||||
("log.write", 0),
|
||||
("game.get-player", 0),
|
||||
("game.get-clock", 0),
|
||||
@@ -71,6 +71,8 @@ pub const FUNCTIONS: [(&str, u32); 56] = [
|
||||
("render.set-params", 8),
|
||||
("render.set-views", 9),
|
||||
("game.world-id", 9),
|
||||
("render.set-lights", 10),
|
||||
("render.set-lighting", 10),
|
||||
];
|
||||
|
||||
/// What the game's program carries so the launcher can read its level
|
||||
|
||||
@@ -81,7 +81,7 @@ pub use render_bindings::horizon::mods::input::{Event as InputEvent, HeldItem, I
|
||||
pub use render_bindings::horizon::mods::render::{
|
||||
Corner as RenderCorner, FarTerrain as ModFarTerrain, FillShape, FrameRate, ItemShape,
|
||||
Minimap as ModMinimap, ModelInstance, ParticleSpawn, Point as RenderPoint, QuadShape,
|
||||
CameraView, Rect as RenderRect, Shape, SpriteShape, TextShape, ViewShape, Zoom as ModZoom,
|
||||
CameraView, Lighting as ModLighting, PointLight, Rect as RenderRect, Shape, SpriteShape, TextShape, ViewShape, Zoom as ModZoom,
|
||||
};
|
||||
use render_bindings::{RenderHost, horizon::mods::render};
|
||||
/// Capability `recipes`'s imports (docs/mods.md): the game's recipes and items.
|
||||
@@ -439,6 +439,9 @@ struct State {
|
||||
post_params: Vec<f32>,
|
||||
/// `render.set-views`' cameras (AirDef fork).
|
||||
views: Vec<CameraView>,
|
||||
/// `render.set-lights` and `render.set-lighting` (AirDef fork).
|
||||
lights: Vec<PointLight>,
|
||||
lighting: Option<ModLighting>,
|
||||
input: InputState,
|
||||
browser: BrowserState,
|
||||
/// Capability `storage`'s folder; made on first `set`.
|
||||
@@ -648,6 +651,8 @@ impl Mods {
|
||||
post: None,
|
||||
post_params: Vec::new(),
|
||||
views: Vec::new(),
|
||||
lights: Vec::new(),
|
||||
lighting: None,
|
||||
input: InputState::default(),
|
||||
browser: BrowserState::default(),
|
||||
data_dir,
|
||||
@@ -1219,6 +1224,18 @@ impl Mods {
|
||||
.flat_map(move |r| r.store.data().views.iter().map(move |v| (i, v)))
|
||||
})
|
||||
}
|
||||
/// Every running mod's lights (AirDef fork), with the mod's index.
|
||||
pub fn lights(&self) -> impl Iterator<Item = (usize, &PointLight)> {
|
||||
self.entries.iter().enumerate().flat_map(|(i, e)| {
|
||||
e.run
|
||||
.iter()
|
||||
.flat_map(move |r| r.store.data().lights.iter().map(move |l| (i, l)))
|
||||
})
|
||||
}
|
||||
/// The first running mod's lighting, if it set one.
|
||||
pub fn lighting(&self) -> Option<ModLighting> {
|
||||
self.entries.iter().find_map(|e| e.run.as_ref()?.store.data().lighting)
|
||||
}
|
||||
/// The columns each running mod asked the ground height of, taken.
|
||||
pub fn take_ground_queries(&mut self) -> Vec<(usize, Vec<(i32, i32)>)> {
|
||||
self.entries
|
||||
@@ -2002,6 +2019,26 @@ impl render::Host for State {
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
fn set_lights(&mut self, lights: Vec<PointLight>) {
|
||||
let finite = |v: f64| v.is_finite() && v.abs() < 30_000_000.0;
|
||||
let unit = |v: f32| if v.is_finite() { v.clamp(0.0, 1.0) } else { 0.0 };
|
||||
self.lights = lights
|
||||
.into_iter()
|
||||
.filter(|l| finite(l.x) && finite(l.y) && finite(l.z))
|
||||
.take(512)
|
||||
.map(|mut l| {
|
||||
l.color = (unit(l.color.0), unit(l.color.1), unit(l.color.2));
|
||||
l.intensity = if l.intensity.is_finite() { l.intensity.clamp(0.0, 100_000.0) } else { 0.0 };
|
||||
l.radius = if l.radius.is_finite() { l.radius.clamp(1.0, 256.0) } else { 1.0 };
|
||||
l
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
fn set_lighting(&mut self, mut lighting: ModLighting) {
|
||||
lighting.exposure = if lighting.exposure.is_finite() { lighting.exposure.clamp(0.05, 8.0) } else { 1.0 };
|
||||
lighting.bloom = if lighting.bloom.is_finite() { lighting.bloom.clamp(0.0, 1.0) } else { 0.0 };
|
||||
self.lighting = Some(lighting);
|
||||
}
|
||||
fn query_ground(&mut self, columns: Vec<(i32, i32)>) {
|
||||
let room = 512usize.saturating_sub(self.ground_queries.len());
|
||||
self.ground_queries.extend(columns.into_iter().take(room));
|
||||
|
||||
Reference in New Issue
Block a user