mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-12 21:32:52 +00:00
#3487, #3488, #3489, #3490, #3491: Levels (Individual Controls): skip the overflowing pow with a branch
WGSL's select evaluates both of its arguments, so the previous commit still ran the overflowing pow and only discarded it. An explicit branch now skips the power for a curve past the bound.
This commit is contained in:
1 file changed
+5
-2
@@ -43,9 +43,12 @@ fn fxt_lv(i: u32, v: f32, clip_b: bool, clip_w: bool) -> f32 {
|
||||
// color2::LEVELS_IC_CURVE_LIMIT keeps the curve finite. WGSL leaves an overflowing pow
|
||||
// indeterminate, so a curve past the bound saturates before pow: |t|^(1/g) > 1e30 once
|
||||
// log2|t| / g > 99.66; between 1e30 and 2^99.7 the clamp gives the same 1e30.
|
||||
// A branch, not select: select evaluates both sides, so pow would still run.
|
||||
let g = max(data[o + 2u], 0.01);
|
||||
let saturate = abs(t) > 1.0 && log2(abs(t)) / g > 99.7;
|
||||
let curve = select(clamp(fxt_gamma(t, g), -1e30, 1e30), sign(t) * 1e30, saturate);
|
||||
var curve = sign(t) * 1e30;
|
||||
if (!(abs(t) > 1.0 && log2(abs(t)) / g > 99.7)) {
|
||||
curve = clamp(fxt_gamma(t, g), -1e30, 1e30);
|
||||
}
|
||||
return data[o + 3u] + (data[o + 4u] - data[o + 3u]) * curve;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user