mirror of
https://github.com/Belobug/VIctory-Belobug-AMD.git
synced 2026-12-06 08:58:35 +00:00
The resolve's indirect diffuse light is replaced by a constant while rays do not run (magenta foliage, blocks of colours indoors); VICTORY_SHADER_PATCH changes a word of a shader's code (diagnostics)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@ -4,13 +4,15 @@
|
||||
//! by tracing rays, which do not run here yet: its program that resolves
|
||||
//! them (`CS_ScreenProbes_TemporalResolve_*`) leaves next to nothing, and
|
||||
//! whatever the sun does not reach directly is black. Right after that
|
||||
//! program, pixels darker than a soft floor are raised to it. The floor is a
|
||||
//! constant: the light in these images does not go with the title's exposure
|
||||
//! program, its output is replaced by a constant (it used to be a floor
|
||||
//! under what the program wrote, but that is garbage: see the shader). The
|
||||
//! constant is the same everywhere: the light in these images does not go with the title's exposure
|
||||
//! (well-lit surfaces hold about the same in a shot at -5.5 EV and in one at
|
||||
//! -9.75). The title's own lighting then applies it with the surfaces'
|
||||
//! colors. Raised, not added: the result is the next frame's history.
|
||||
//!
|
||||
//! `VICTORY_AMBIENT=<level>` turns it on (0.6, say); off by default.
|
||||
//! `VICTORY_AMBIENT=<level>` sets it (0.6 by default, 0 for none); `off`
|
||||
//! keeps the title's own output.
|
||||
//! shortcut: the same light everywhere, from everywhere; gone once rays run.
|
||||
|
||||
use std::sync::OnceLock;
|
||||
@ -30,20 +32,21 @@ pub(crate) const PROGRAM: &[u8] = b"CS_ScreenProbes_TemporalResolve";
|
||||
/// integers): root parameter and place in its table.
|
||||
pub(crate) const LIGHT: (u8, u32) = (1, 176);
|
||||
|
||||
/// Off: the title's own light only (0.6 looked balanced in run a2).
|
||||
const DEFAULT: f32 = 0.0;
|
||||
/// 0.6 looked balanced in run a2. `VICTORY_AMBIENT=off` leaves what the
|
||||
/// title's resolve wrote; 0 is no indirect diffuse light at all.
|
||||
const DEFAULT: f32 = 0.6;
|
||||
|
||||
/// The floor; `None` if off.
|
||||
pub(crate) fn level() -> Option<f32> {
|
||||
static LEVEL: OnceLock<f32> = OnceLock::new();
|
||||
let level = *LEVEL.get_or_init(|| {
|
||||
std::env::var("VICTORY_AMBIENT")
|
||||
.ok()
|
||||
.and_then(|v| v.trim().parse().ok())
|
||||
.filter(|l: &f32| l.is_finite() && *l >= 0.0)
|
||||
.unwrap_or(DEFAULT)
|
||||
let set = std::env::var("VICTORY_AMBIENT").unwrap_or_default();
|
||||
if set.trim() == "off" {
|
||||
return -1.0;
|
||||
}
|
||||
set.trim().parse().ok().filter(|l: &f32| l.is_finite() && *l >= 0.0).unwrap_or(DEFAULT)
|
||||
});
|
||||
(level > 0.0).then_some(level)
|
||||
(level >= 0.0).then_some(level)
|
||||
}
|
||||
|
||||
const SOURCE: &str = r#"
|
||||
@ -68,11 +71,10 @@ void main(uint3 at : SV_DispatchThreadID) {
|
||||
uint w, h;
|
||||
light.GetDimensions(w, h);
|
||||
if (at.x >= w || at.y >= h) return;
|
||||
float3 least = tint * level;
|
||||
float3 c = unpack(light[at.xy]);
|
||||
const float3 weights = float3(0.2126, 0.7152, 0.0722);
|
||||
float missing = saturate(1.0 - dot(c, weights) / dot(least, weights));
|
||||
if (missing > 0.0) light[at.xy] = pack(c + least * missing);
|
||||
// What the resolve left is not kept: without rays its inputs are never
|
||||
// written and it holds whatever their memory did (bright magenta on
|
||||
// translucent surfaces, blocks of colours indoors: run v6, 2026-11-25).
|
||||
light[at.xy] = pack(tint * level);
|
||||
}
|
||||
"#;
|
||||
|
||||
|
||||
@ -83,7 +83,19 @@ pub(crate) fn host_shader(container: &[u8], target: Target) -> Result<HostShader
|
||||
let translate =
|
||||
|c: &[u8]| victory_shader::emit::translate_for(c, target).map_err(|e| e.to_string());
|
||||
match CACHE.get() {
|
||||
Some(cache) => cached(cache, &key(build(), target), container, translate),
|
||||
Some(cache) => {
|
||||
let mut key = key(build(), target);
|
||||
// A container a diagnostic patch may apply to has entries of its
|
||||
// own, by the patches.
|
||||
let patches = victory_shader::native::diagnostic_patches();
|
||||
if patches.iter().any(|p| p.0 == container.len()) {
|
||||
let mut h = blake3::Hasher::new();
|
||||
h.update(&key);
|
||||
h.update(format!("{patches:?}").as_bytes());
|
||||
key = *h.finalize().as_bytes();
|
||||
}
|
||||
cached(cache, &key, container, translate)
|
||||
}
|
||||
None => translate(container),
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,10 +180,34 @@ impl NativeProgram {
|
||||
}
|
||||
}
|
||||
}
|
||||
for &(_, len, at, clear, set) in diagnostic_patches() {
|
||||
if code.len() == len && at + 4 <= code.len() {
|
||||
let word = u32::from_le_bytes([code[at], code[at + 1], code[at + 2], code[at + 3]]);
|
||||
code[at..at + 4].copy_from_slice(&((word & !clear) | set).to_le_bytes());
|
||||
}
|
||||
}
|
||||
code
|
||||
}
|
||||
}
|
||||
|
||||
/// Diagnostics: `VICTORY_SHADER_PATCH=<container bytes>:<code bytes>:<code
|
||||
/// offset>:<bits to clear>:<bits to set>,...` (all hexadecimal) changes one
|
||||
/// word of the machine code of the programs of that size before they are
|
||||
/// translated, to see what a part of a shader does to the picture. Each
|
||||
/// entry: container length, code length, offset, cleared bits, set bits.
|
||||
pub fn diagnostic_patches() -> &'static [(usize, usize, usize, u32, u32)] {
|
||||
static PATCHES: std::sync::OnceLock<Vec<(usize, usize, usize, u32, u32)>> = std::sync::OnceLock::new();
|
||||
PATCHES.get_or_init(|| {
|
||||
let list = std::env::var("VICTORY_SHADER_PATCH").unwrap_or_default();
|
||||
list.split(',')
|
||||
.filter_map(|entry| {
|
||||
let n: Vec<u64> = entry.split(':').filter_map(|x| u64::from_str_radix(x, 16).ok()).collect();
|
||||
(n.len() == 5).then(|| (n[0] as usize, n[1] as usize, n[2] as usize, n[3] as u32, n[4] as u32))
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
}
|
||||
|
||||
/// What a semantic is, as the stage data names it.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum Usage {
|
||||
|
||||
Reference in New Issue
Block a user