Develop a mask layer's film on its own settings
A layer offered the film's sliders and they moved nothing: its copy of the node was never given the stock, so it stayed inactive. Film now works in a layer the way the other adjustments do, as offsets to the photograph's settings, but blended as settings rather than as results, since a film is a rendering and cross-fading two developments is not what a region on a pushed film looks like. - dr-film bakes no slider. Exposure is a gain in the shader; push interpolates the stock's measured processes, one curve row each; the print is split at the paper's log exposure, so print exposure is an addition between two lookups and exact at any setting. The enlarger stays balanced at the photograph's exposure. - film_sim reads all four settings as uniforms, format one-hot over a grain count per format, so every uniform is linear in what it does. - Operation::blends_settings lets the composer average each overlapping layer's uniforms with the global ones by mask weight, the global setting taking whatever weight the layers leave, and run the fragment once. Three layers at full weight give the mean of their settings. - The stock picker is hidden on a layer. Only the photograph's exposure re-solves the print balance; push, print exposure and format need no rebake at all now.
This commit is contained in:
@@ -22,9 +22,11 @@
|
||||
//!
|
||||
//! For the same reason [`crate::ops::vignetting`]'s coefficients are not: they
|
||||
//! are measurements of a physical thing, not something a slider moves. The
|
||||
//! sliders here are exposure and print exposure, which are what a photographer
|
||||
//! and a printer actually control. `dr-film` turns a stock plus those two
|
||||
//! numbers into [`FilmTables`]; this node knows only the layout.
|
||||
//! sliders here are exposure, push, print exposure and format, which are what
|
||||
//! a photographer and a printer actually control. `dr-film` turns a stock into
|
||||
//! [`FilmTables`] that hold none of them; the shader applies all four per
|
||||
//! pixel, which is what lets a mask layer hold its own (see
|
||||
//! [`Operation::blends_settings`]). This node knows only the layout.
|
||||
//!
|
||||
//! Declared as a plain struct here rather than imported, so that dr-pipeline
|
||||
//! keeps its no-dependency property (ARCH §6.5a) exactly as `vignetting` does
|
||||
@@ -63,6 +65,15 @@ static FORMATS: [LocalizedKey; 6] = [
|
||||
/// take; [`FilmTables::is_well_formed`] is what stops the two drifting.
|
||||
pub const CURVE_SAMPLES: usize = 256;
|
||||
|
||||
/// The most development times a stock may measure — a curve row and a push
|
||||
/// station each. Must agree with `dr_film::bake::MAX_CURVE_ROWS`, for the
|
||||
/// reason [`CURVE_SAMPLES`] must; the uniform block holds this many stations.
|
||||
pub const MAX_CURVE_ROWS: usize = 8;
|
||||
|
||||
/// How many frames [`FORMATS`] offers, and so how many grain counts a stock
|
||||
/// carries.
|
||||
pub const FORMAT_COUNT: usize = 6;
|
||||
|
||||
/// The uniform field names the fragment reads the exposure matrix from.
|
||||
///
|
||||
/// A table rather than a formatted string, because a `Uniform`'s name is
|
||||
@@ -74,6 +85,24 @@ static MATRIX_FIELDS: [[&str; 3]; 3] = [
|
||||
["m20", "m21", "m22"],
|
||||
];
|
||||
|
||||
/// Grains per pixel, per format and layer: `gn{format}{layer}`.
|
||||
static GRAIN_FIELDS: [[&str; 3]; FORMAT_COUNT] = [
|
||||
["gn00", "gn01", "gn02"],
|
||||
["gn10", "gn11", "gn12"],
|
||||
["gn20", "gn21", "gn22"],
|
||||
["gn30", "gn31", "gn32"],
|
||||
["gn40", "gn41", "gn42"],
|
||||
["gn50", "gn51", "gn52"],
|
||||
];
|
||||
|
||||
/// The push each curve row was developed to, padded with the last.
|
||||
static PUSH_FIELDS: [&str; MAX_CURVE_ROWS] =
|
||||
["ps0", "ps1", "ps2", "ps3", "ps4", "ps5", "ps6", "ps7"];
|
||||
|
||||
/// Which format this is, one-hot. See [`FilmSim::uniforms`] for why a choice
|
||||
/// reaches the shader as six weights rather than an index.
|
||||
static FORMAT_FIELDS: [&str; FORMAT_COUNT] = ["fmt0", "fmt1", "fmt2", "fmt3", "fmt4", "fmt5"];
|
||||
|
||||
static DESCRIPTOR: LazyLock<Arc<OpDescriptor>> = LazyLock::new(|| {
|
||||
Arc::new(OpDescriptor {
|
||||
// Tone and colour both, and not `Effect`: a stock is not something applied
|
||||
@@ -115,48 +144,86 @@ static DESCRIPTOR: LazyLock<Arc<OpDescriptor>> = LazyLock::new(|| {
|
||||
/// Layout is the contract between the two crates, so it is written down here
|
||||
/// and checked rather than assumed:
|
||||
///
|
||||
/// - `exposure_matrix[l][c]` — layer `l`'s response to linear sRGB channel `c`.
|
||||
/// - `curves` — `CURVE_SAMPLES` density triples, uniform over
|
||||
/// `[curve_log_min, curve_log_max]`.
|
||||
/// - `lut` — `lut_size³` linear sRGB triples, uniform over `[0, density_max]`
|
||||
/// on each axis, with the **red axis varying fastest**: index
|
||||
/// `(b * size + g) * size + r`. That is the order a 3D texture upload
|
||||
/// expects, so the consumer hands the slice straight to the driver. Filling
|
||||
/// it the other way round transposes red and blue in the finished picture —
|
||||
/// which is a plausible photograph of the wrong colour, and which the unit
|
||||
/// tests on both sides of this seam happily pass, because each side is
|
||||
/// internally consistent. `dr-film` pins it; `dr-gpu`'s `film_sim` test
|
||||
/// catches it end to end.
|
||||
/// - `exposure_matrix[l][c]` — layer `l`'s response to linear sRGB channel
|
||||
/// `c`, at unit gain: camera exposure is a per-pixel setting.
|
||||
/// - `curves` — one row of `CURVE_SAMPLES` density triples per
|
||||
/// `push_stations` entry, uniform over `[curve_log_min, curve_log_max]`,
|
||||
/// and then, when printed, one more row: the paper's, uniform over
|
||||
/// `[paper.log_min, paper.log_max]`.
|
||||
/// - `lut` — `lut_size³` triples uniform over `[0, density_max]` on each
|
||||
/// axis, with the **red axis varying fastest**: index
|
||||
/// `(b * size + g) * size + r`. Linear sRGB when the film is viewed
|
||||
/// directly; the paper's log₁₀ exposure through the negative when it is
|
||||
/// printed, followed by a second cube, paper density over
|
||||
/// `[0, paper.density_max]` to linear sRGB. That is the order a 3D texture
|
||||
/// upload expects with the cubes stacked in depth, so the consumer hands the
|
||||
/// slice straight to the driver. Filling it the other way round transposes
|
||||
/// red and blue in the finished picture — which is a plausible photograph
|
||||
/// of the wrong colour, and which the unit tests on both sides of this seam
|
||||
/// happily pass, because each side is internally consistent. `dr-film` pins
|
||||
/// it; `dr-gpu`'s `film_sim` test catches it end to end.
|
||||
///
|
||||
/// Everything the sliders move — exposure, push, print exposure, format — is
|
||||
/// absent. They are per-pixel settings the shader applies against these
|
||||
/// tables, which is what lets a mask layer hold its own.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct FilmTables {
|
||||
pub exposure_matrix: [[f32; 3]; 3],
|
||||
pub curves: Vec<[f32; 3]>,
|
||||
/// The push each film row was developed to, ascending: one entry for a
|
||||
/// stock measured at a single process.
|
||||
pub push_stations: Vec<f32>,
|
||||
pub curve_log_min: f32,
|
||||
pub curve_log_max: f32,
|
||||
pub lut: Vec<[f32; 3]>,
|
||||
pub density_max: f32,
|
||||
pub lut_size: usize,
|
||||
/// The print, for a negative printed on paper.
|
||||
pub paper: Option<PaperTables>,
|
||||
/// TRACES: FR-DEV-3f
|
||||
/// Grains in one pixel's patch of film, per layer, with the density
|
||||
/// ceiling and uniformity the variance is taken against. Zero particles
|
||||
/// means no grain, which is how the control is turned off.
|
||||
pub grain_particles: [f32; 3],
|
||||
/// Grains in one pixel's patch of film, per format and then per layer,
|
||||
/// with the density ceiling and uniformity the variance is taken against.
|
||||
/// Zero particles means no grain, which is how the control is turned off.
|
||||
pub grain_particles: [[f32; 3]; FORMAT_COUNT],
|
||||
pub grain_density_max: [f32; 3],
|
||||
pub grain_uniformity: f32,
|
||||
}
|
||||
|
||||
/// The print half of [`FilmTables`]: where the paper's row and cube are read.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct PaperTables {
|
||||
/// The enlarger's filtration, per layer, in log₁₀ exposure.
|
||||
pub balance: [f32; 3],
|
||||
pub log_min: f32,
|
||||
pub log_max: f32,
|
||||
pub density_max: f32,
|
||||
}
|
||||
|
||||
impl FilmTables {
|
||||
/// Film rows, not counting the paper's.
|
||||
pub fn curve_rows(&self) -> usize {
|
||||
self.push_stations.len()
|
||||
}
|
||||
|
||||
/// Whether these tables are the shape the shader will index them at.
|
||||
///
|
||||
/// Checked on the way in, because the failure otherwise is a shader
|
||||
/// sampling past the end of a texture: undefined, silent, and different on
|
||||
/// every driver.
|
||||
pub fn is_well_formed(&self) -> bool {
|
||||
self.curves.len() == CURVE_SAMPLES
|
||||
let rows = self.curve_rows();
|
||||
let printed = usize::from(self.paper.is_some());
|
||||
let paper_ok = self
|
||||
.paper
|
||||
.is_none_or(|p| p.density_max > 0.0 && p.log_max > p.log_min);
|
||||
(1..=MAX_CURVE_ROWS).contains(&rows)
|
||||
&& self.push_stations.windows(2).all(|w| w[0] < w[1])
|
||||
&& self.curves.len() == CURVE_SAMPLES * (rows + printed)
|
||||
&& self.lut_size >= 2
|
||||
&& self.lut.len() == self.lut_size.pow(3)
|
||||
&& self.lut.len() == self.lut_size.pow(3) * (1 + printed)
|
||||
&& self.density_max > 0.0
|
||||
&& self.curve_log_max > self.curve_log_min
|
||||
&& paper_ok
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,60 +313,80 @@ impl Operation for FilmSim {
|
||||
self.set_tables(tables.cloned());
|
||||
}
|
||||
|
||||
fn film_tables(&self) -> Option<&FilmTables> {
|
||||
self.tables.as_ref()
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-3f
|
||||
/// A layer's film is its settings, not its own picture blended over the
|
||||
/// global one.
|
||||
///
|
||||
/// Blending outputs would be a photograph developed twice and cross-faded;
|
||||
/// a region on a pushed film is not that. Every uniform below is linear
|
||||
/// in what it controls, so the composer can take each layer's weighted
|
||||
/// average of them and develop the pixel once.
|
||||
fn blends_settings(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// Every value here is linear in what the shader does with it, which is
|
||||
/// what [`Self::blends_settings`] rests on. The format is the one that
|
||||
/// needs arranging: an index averaged between layers is a format nobody
|
||||
/// chose, so it goes out one-hot and the shader mixes the six grain
|
||||
/// counts by it — two layers on 35 mm and 6x7 meet at the average grain.
|
||||
fn uniforms(&self) -> Vec<Uniform> {
|
||||
let Some(t) = &self.tables else {
|
||||
return Vec::new();
|
||||
};
|
||||
let m = t.exposure_matrix;
|
||||
// Exposure rides in the matrix on the CPU when the stock is baked, so
|
||||
// what is left here is the *shader's* copy of the same nine numbers.
|
||||
// Spelled out one at a time because a uniform is a named `f32` in this
|
||||
// pipeline and a matrix would be a second kind of thing for one caller.
|
||||
let mut out = Vec::with_capacity(MATRIX_FIELDS.len() + 5);
|
||||
for (l, row) in m.iter().enumerate() {
|
||||
let mut out = Vec::with_capacity(64);
|
||||
let mut push = |name: &'static str, value: f32| out.push(Uniform { name, value });
|
||||
for (l, row) in t.exposure_matrix.iter().enumerate() {
|
||||
for (c, v) in row.iter().enumerate() {
|
||||
out.push(Uniform {
|
||||
name: MATRIX_FIELDS[l][c],
|
||||
value: *v,
|
||||
});
|
||||
push(MATRIX_FIELDS[l][c], *v);
|
||||
}
|
||||
}
|
||||
for (l, name) in ["gn0", "gn1", "gn2"].into_iter().enumerate() {
|
||||
out.push(Uniform {
|
||||
name,
|
||||
value: t.grain_particles[l],
|
||||
});
|
||||
for (f, per_layer) in t.grain_particles.iter().enumerate() {
|
||||
for (l, v) in per_layer.iter().enumerate() {
|
||||
push(GRAIN_FIELDS[f][l], *v);
|
||||
}
|
||||
}
|
||||
for (l, name) in ["gd0", "gd1", "gd2"].into_iter().enumerate() {
|
||||
out.push(Uniform {
|
||||
name,
|
||||
value: t.grain_density_max[l],
|
||||
});
|
||||
push(name, t.grain_density_max[l]);
|
||||
}
|
||||
out.push(Uniform {
|
||||
name: "grain_u",
|
||||
value: t.grain_uniformity,
|
||||
});
|
||||
out.push(Uniform {
|
||||
name: "log_min",
|
||||
value: t.curve_log_min,
|
||||
});
|
||||
out.push(Uniform {
|
||||
name: "log_max",
|
||||
value: t.curve_log_max,
|
||||
});
|
||||
out.push(Uniform {
|
||||
name: "density_max",
|
||||
value: t.density_max,
|
||||
});
|
||||
out.push(Uniform {
|
||||
name: "lut_size",
|
||||
value: t.lut_size as f32,
|
||||
});
|
||||
out.push(Uniform {
|
||||
name: "print_exposure",
|
||||
value: self.print_exposure,
|
||||
push("grain_u", t.grain_uniformity);
|
||||
push("log_min", t.curve_log_min);
|
||||
push("log_max", t.curve_log_max);
|
||||
push("density_max", t.density_max);
|
||||
push("lut_size", t.lut_size as f32);
|
||||
|
||||
let last = *t.push_stations.last().unwrap_or(&0.0);
|
||||
for (i, name) in PUSH_FIELDS.into_iter().enumerate() {
|
||||
push(name, t.push_stations.get(i).copied().unwrap_or(last));
|
||||
}
|
||||
push("rows", t.curve_rows() as f32);
|
||||
|
||||
let paper = t.paper.unwrap_or(PaperTables {
|
||||
balance: [0.0; 3],
|
||||
log_min: 0.0,
|
||||
log_max: 1.0,
|
||||
density_max: 1.0,
|
||||
});
|
||||
push("printed", if t.paper.is_some() { 1.0 } else { 0.0 });
|
||||
for (l, name) in ["pb0", "pb1", "pb2"].into_iter().enumerate() {
|
||||
push(name, paper.balance[l]);
|
||||
}
|
||||
push("plog_min", paper.log_min);
|
||||
push("plog_max", paper.log_max);
|
||||
push("pdmax", paper.density_max);
|
||||
|
||||
// The sliders.
|
||||
push("ev", self.exposure);
|
||||
push("push", self.push);
|
||||
push("pev", self.print_exposure);
|
||||
let chosen = (self.format.max(0.0).round() as usize).min(FORMAT_COUNT - 1);
|
||||
for (f, name) in FORMAT_FIELDS.into_iter().enumerate() {
|
||||
push(name, if f == chosen { 1.0 } else { 0.0 });
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
@@ -321,8 +408,9 @@ let scene = vec3<f32>(
|
||||
// What each emulsion layer was exposed to. A matrix, exactly: the scene
|
||||
// spectrum reconstructed from an sRGB triple is linear in that triple, so the
|
||||
// integral over wavelength collapsed into these nine numbers when the stock
|
||||
// was baked.
|
||||
let exposure = vec3<f32>(
|
||||
// was baked. The camera's exposure is a gain on it, applied here rather than
|
||||
// baked in so that a layer can hold its own.
|
||||
let exposure = exp2(ev) * vec3<f32>(
|
||||
dot(vec3<f32>(m00, m01, m02), scene),
|
||||
dot(vec3<f32>(m10, m11, m12), scene),
|
||||
dot(vec3<f32>(m20, m21, m22), scene),
|
||||
@@ -331,12 +419,16 @@ let exposure = vec3<f32>(
|
||||
// the curve, and the toe is where it belongs.
|
||||
let log_exposure = log10(max(exposure, vec3<f32>(0.0)) + 1e-10);
|
||||
|
||||
// The characteristic curve: what density each layer develops to. Clamped, not
|
||||
// extrapolated — past the shoulder a real emulsion stops responding, and
|
||||
// extrapolating would turn a blown highlight into a colour cast that grows the
|
||||
// more it is overexposed.
|
||||
let density = film_curve(clamp((log_exposure - log_min) / (log_max - log_min),
|
||||
vec3<f32>(0.0), vec3<f32>(1.0)));
|
||||
// The characteristic curve: what density each layer develops to, at this
|
||||
// pixel's push. Clamped, not extrapolated — past the shoulder a real emulsion
|
||||
// stops responding, and extrapolating would turn a blown highlight into a
|
||||
// colour cast that grows the more it is overexposed.
|
||||
let density = film_curve_pushed(
|
||||
clamp((log_exposure - log_min) / (log_max - log_min), vec3<f32>(0.0), vec3<f32>(1.0)),
|
||||
push,
|
||||
array<f32, 8>(ps0, ps1, ps2, ps3, ps4, ps5, ps6, ps7),
|
||||
u32(rows),
|
||||
);
|
||||
|
||||
// TRACES: FR-DEV-3f
|
||||
// Grain, on the density and before the dye.
|
||||
@@ -346,16 +438,40 @@ let density = film_curve(clamp((log_exposure - log_min) / (log_max - log_min),
|
||||
// through whatever density resulted. Adding noise to the finished colour --
|
||||
// which is what an effect does -- tints the highlights wrong, because that
|
||||
// noise never passes through the dye at all.
|
||||
let grained = film_grain(density, source_px,
|
||||
vec3<f32>(gn0, gn1, gn2),
|
||||
//
|
||||
// The format's grain count, mixed by the one-hot weights: exactly one format's
|
||||
// on the whole photograph, and the weighted average under overlapping layers.
|
||||
let particles = fmt0 * vec3<f32>(gn00, gn01, gn02)
|
||||
+ fmt1 * vec3<f32>(gn10, gn11, gn12)
|
||||
+ fmt2 * vec3<f32>(gn20, gn21, gn22)
|
||||
+ fmt3 * vec3<f32>(gn30, gn31, gn32)
|
||||
+ fmt4 * vec3<f32>(gn40, gn41, gn42)
|
||||
+ fmt5 * vec3<f32>(gn50, gn51, gn52);
|
||||
let grained = film_grain(density, source_px, particles,
|
||||
vec3<f32>(gd0, gd1, gd2),
|
||||
grain_u);
|
||||
|
||||
// Dye absorption, the print through the negative, the paper, the viewing
|
||||
// illuminant and the chromatic adaptation — all of which take exactly three
|
||||
// numbers in, which is why they fit in one lookup.
|
||||
c = film_lut(clamp(grained / density_max, vec3<f32>(0.0), vec3<f32>(1.0)), lut_size);"
|
||||
.into()
|
||||
// Dye absorption through to what comes next — all of it takes exactly three
|
||||
// numbers in, which is why it fits in one lookup. Viewed directly, that is
|
||||
// the picture; printed, it is the light the paper receives through the
|
||||
// negative, in log exposure.
|
||||
let through = film_lut(clamp(grained / density_max, vec3<f32>(0.0), vec3<f32>(1.0)),
|
||||
lut_size, 0);
|
||||
if (printed > 0.5) {
|
||||
// The enlarger: its filtration, and then its exposure, the same stops on
|
||||
// every layer — which is why print exposure is an addition here and not
|
||||
// a table, and so exact at any setting.
|
||||
let paper_log = through + vec3<f32>(pb0, pb1, pb2) + pev * 0.30103;
|
||||
let paper_density = film_curve(
|
||||
clamp((paper_log - plog_min) / (plog_max - plog_min), vec3<f32>(0.0), vec3<f32>(1.0)),
|
||||
u32(rows),
|
||||
);
|
||||
c = film_lut(clamp(paper_density / pdmax, vec3<f32>(0.0), vec3<f32>(1.0)),
|
||||
lut_size, i32(lut_size));
|
||||
} else {
|
||||
c = through;
|
||||
}"
|
||||
.into()
|
||||
}
|
||||
|
||||
fn helpers(&self) -> &'static [crate::operation::Helper] {
|
||||
@@ -363,7 +479,7 @@ c = film_lut(clamp(grained / density_max, vec3<f32>(0.0), vec3<f32>(1.0)), lut_s
|
||||
}
|
||||
}
|
||||
|
||||
static HELPERS: [crate::operation::Helper; 5] = [
|
||||
static HELPERS: [crate::operation::Helper; 6] = [
|
||||
crate::operation::Helper {
|
||||
name: "film_hash",
|
||||
source: "\
|
||||
@@ -453,9 +569,9 @@ fn log10(v: vec3<f32>) -> vec3<f32> {
|
||||
crate::operation::Helper {
|
||||
name: "film_curve",
|
||||
source: "\
|
||||
// Three characteristic curves, sampled from a 256-wide texture and
|
||||
// interpolated by hand. `t` is already normalised to the curve's domain.
|
||||
fn film_curve(t: vec3<f32>) -> vec3<f32> {
|
||||
// Three characteristic curves, one row of a 256-wide texture, interpolated by
|
||||
// hand. `t` is already normalised to the curve's domain.
|
||||
fn film_curve(t: vec3<f32>, row: u32) -> vec3<f32> {
|
||||
let samples = u32(textureDimensions(film_curves).x);
|
||||
let last = f32(samples - 1u);
|
||||
var out = vec3<f32>(0.0);
|
||||
@@ -463,20 +579,45 @@ fn film_curve(t: vec3<f32>) -> vec3<f32> {
|
||||
let x = t[ch] * last;
|
||||
let i = min(u32(floor(x)), samples - 2u);
|
||||
let f = x - f32(i);
|
||||
let a = textureLoad(film_curves, vec2<i32>(i32(i), 0), 0);
|
||||
let b = textureLoad(film_curves, vec2<i32>(i32(i) + 1, 0), 0);
|
||||
let a = textureLoad(film_curves, vec2<i32>(i32(i), i32(row)), 0);
|
||||
let b = textureLoad(film_curves, vec2<i32>(i32(i) + 1, i32(row)), 0);
|
||||
out[ch] = mix(a[ch], b[ch], f);
|
||||
}
|
||||
return out;
|
||||
}",
|
||||
},
|
||||
crate::operation::Helper {
|
||||
name: "film_curve_pushed",
|
||||
source: "\
|
||||
// The curves at a push between two measured processes. Development is
|
||||
// interpolated in log time and push *is* log time, so a straight line between
|
||||
// the neighbouring rows is the stock's own interpolation, not an estimate of
|
||||
// it. Clamped to the first and last process, as the stock is.
|
||||
fn film_curve_pushed(t: vec3<f32>, push: f32, stations: array<f32, 8>, rows: u32) -> vec3<f32> {
|
||||
if (rows < 2u) {
|
||||
return film_curve(t, 0u);
|
||||
}
|
||||
var at = stations;
|
||||
var hi = rows - 1u;
|
||||
for (var i = 1u; i < rows; i = i + 1u) {
|
||||
if (at[i] >= push) {
|
||||
hi = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
let lo = hi - 1u;
|
||||
let f = clamp((push - at[lo]) / max(at[hi] - at[lo], 1e-6), 0.0, 1.0);
|
||||
return mix(film_curve(t, lo), film_curve(t, hi), f);
|
||||
}",
|
||||
},
|
||||
crate::operation::Helper {
|
||||
name: "film_lut",
|
||||
source: "\
|
||||
// Trilinear interpolation of the density lookup, by hand for the same reason
|
||||
// the curve above is: there is no sampler bound, and the eight loads are
|
||||
// cache-neighbours.
|
||||
fn film_lut(t: vec3<f32>, size: f32) -> vec3<f32> {
|
||||
// Trilinear interpolation of one cube of the lookup, by hand for the same
|
||||
// reason the curve above is: there is no sampler bound, and the eight loads
|
||||
// are cache-neighbours. `z0` is where the cube starts in depth: the film's at
|
||||
// zero, the paper's stacked after it.
|
||||
fn film_lut(t: vec3<f32>, size: f32, z0: i32) -> vec3<f32> {
|
||||
let n = i32(size);
|
||||
let x = t * (size - 1.0);
|
||||
let base = min(vec3<i32>(floor(x)), vec3<i32>(n - 2));
|
||||
@@ -489,7 +630,7 @@ fn film_lut(t: vec3<f32>, size: f32) -> vec3<f32> {
|
||||
let wy = select(1.0 - f.y, f.y, dy == 1);
|
||||
for (var dz = 0; dz < 2; dz = dz + 1) {
|
||||
let wz = select(1.0 - f.z, f.z, dz == 1);
|
||||
let p = base + vec3<i32>(dx, dy, dz);
|
||||
let p = base + vec3<i32>(dx, dy, dz + z0);
|
||||
out = out + wx * wy * wz
|
||||
* textureLoad(film_lut_texture, p, 0).rgb;
|
||||
}
|
||||
@@ -513,7 +654,9 @@ mod tests {
|
||||
lut: vec![[0.5, 0.5, 0.5]; 32 * 32 * 32],
|
||||
density_max: 3.0,
|
||||
lut_size: 32,
|
||||
grain_particles: [0.0; 3],
|
||||
grain_particles: [[0.0; 3]; FORMAT_COUNT],
|
||||
push_stations: vec![0.0],
|
||||
paper: None,
|
||||
grain_density_max: [3.0; 3],
|
||||
grain_uniformity: 0.97,
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ pub use colour_mixer::ColourMixer;
|
||||
pub use curve::ToneCurve;
|
||||
pub use dehaze::Dehaze;
|
||||
pub use distortion::Distortion;
|
||||
pub use film_sim::{FilmSim, FilmTables};
|
||||
pub use film_sim::{FilmSim, FilmTables, PaperTables};
|
||||
// Clarity and texture are one implementation at two scales; see the module's
|
||||
// documentation for why that is two nodes and not one.
|
||||
pub use local_contrast::{Clarity, Texture};
|
||||
|
||||
Reference in New Issue
Block a user