Effects: OCIO custom configs read Blender's v2 transforms and warn (#410)
Cause: the config reader didn't know ColorSpaceTransform or ExponentWithLinearTransform and passed colours through them silently. Blender's Linear Rec.709 -> sRGB therefore stayed in its E-white XYZ reference space (the blue cast) without the sRGB curve. Display colorspaces, view transforms, v2 views, looks, AllocationTransform, BuiltinTransform and .spi1d / .spimtx files were missing too, and nothing told the user. Fix (from the OCIO v2 documentation and the CLF "moncurve", not OCIO's source): ExponentWithLinear, ColorSpace, Look, DisplayView, Allocation and Builtin transforms (identity, ACES AP0/AP1 matrices, ACEScct / ACEScc, the sRGB / P3 / Rec.1886 / gamma / PQ displays). RangeTransform now clamps and takes one-sided ranges. Display colorspaces meet the scene reference through the default view transform. Added v2 views, view looks, the looks section and .spi1d / .spi3d / .spimtx files. A conversion is built once as a flat list of steps (Config::path / display_path) for both the CPU effect and the GPU colour program (new moncurve and clamp ops and the ACEScc curve; a program over the kernel's 255 ops renders on the CPU). Named-transform resolution is limited to 16 levels and 4096 steps, and YAML nesting to 64 levels, so hostile or looping configs stop. Transforms that are still unsupported (Grading Primary / Tone, ACES output, HLG…), unreadable configs and unknown spaces are now reported: a warning under the effect in Effect Controls, and the new effect.warning query. Tests: ocio_config::blender_like_config_converts_linear_rec709_to_srgb (CST, display colorspaces, v1 / v2 views, allocation, looks, builtin, range, loops), moncurve_matches_srgb_and_inverts, builtin_styles, yaml_nesting_is_bounded, ocio::spi_files_parse, tests_effects::ocio_effect_warns_about_unsupported_config_transforms, gpu tests_fx_lut::ocio_custom_config_v2 (GPU = CPU). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d6de68b20d
commit
492fa6de0a
@@ -10,8 +10,10 @@
|
||||
//! iterative 3D inverse): hardware 3D-texture filtering would round the interpolation weights
|
||||
//! and cannot do tetrahedral interpolation. The CPU evaluates transfer functions, CDLs and
|
||||
//! Color Profile Converter's matrix in f64; the kernel in f32 (within the 1e-3 tolerance).
|
||||
//! Custom `.ocio` configurations compile their colour spaces' transforms (matrix and offset,
|
||||
//! exponent, log / log-affine, range, CDL, file LUTs, groups, inverses) to the same program.
|
||||
//! Custom `.ocio` configurations compile their conversions (matrix and offset, exponent,
|
||||
//! exponent with linear segment, log / log-affine, allocation, range with its clamp, CDL, file
|
||||
//! LUTs and matrices, built-in curves, with colour space / look / display-view transforms
|
||||
//! resolved) to the same program; one longer than the kernel's 255 ops renders on the CPU.
|
||||
|
||||
use effectcraft_effects::{ColorOp, EffectCtx, Lut, Straight, Tf};
|
||||
|
||||
@@ -57,9 +59,13 @@ fn tf_code(t: Tf) -> [f32; 2] {
|
||||
Tf::Gamma(g) => [2.0, g as f32],
|
||||
Tf::AcesCct => [3.0, 0.0],
|
||||
Tf::Pq => [4.0, 0.0],
|
||||
Tf::AcesCc => [5.0, 0.0],
|
||||
}
|
||||
}
|
||||
|
||||
/// Most ops `fxl_run` interprets (its loop guard); longer programs render on the CPU.
|
||||
const MAX_OPS: usize = 255;
|
||||
|
||||
/// A LUT in the layout `fxl_lut_*` read at the returned offset: n1, n3, domain min (3), domain
|
||||
/// max (3), the 1D table (n1 × RGB), then the lattice (n3³ × RGB, red fastest).
|
||||
pub(crate) fn push_lut(d: &mut Vec<f32>, lut: &Lut) -> f32 {
|
||||
@@ -75,6 +81,9 @@ pub(crate) fn push_lut(d: &mut Vec<f32>, lut: &Lut) -> f32 {
|
||||
|
||||
/// Program layout: a stream of (opcode, arguments…) ending in 0, followed by LUT data.
|
||||
fn encode(ops: &[ColorOp]) -> Option<Vec<f32>> {
|
||||
if ops.len() > MAX_OPS {
|
||||
return None;
|
||||
}
|
||||
let mut prog: Vec<f32> = vec![];
|
||||
let mut tables: Vec<Vec<f32>> = vec![];
|
||||
// LUT offsets are patched once the program's length is known.
|
||||
@@ -123,6 +132,15 @@ fn encode(ops: &[ColorOp]) -> Option<Vec<f32>> {
|
||||
prog.extend(log_slope.iter().chain(log_offset).chain(lin_slope).chain(lin_offset));
|
||||
prog.extend([*inverse as u32 as f32, f64::MIN_POSITIVE.ln() as f32]);
|
||||
}
|
||||
ColorOp::MonCurve { gamma, offset, inverse, mirror } => {
|
||||
prog.push(12.0);
|
||||
prog.extend(gamma.iter().chain(offset));
|
||||
prog.extend([*inverse as u32 as f32, *mirror as u32 as f32]);
|
||||
}
|
||||
ColorOp::Clamp { lo, hi } => {
|
||||
prog.push(13.0);
|
||||
prog.extend(lo.iter().chain(hi));
|
||||
}
|
||||
ColorOp::Lut { lut, shaper, interp, inverse } => {
|
||||
prog.extend([8.0, 0.0, *interp as f32, *inverse as u32 as f32, -1.0]);
|
||||
let mut t = vec![];
|
||||
|
||||
Reference in New Issue
Block a user