M13.22: GPU compositing of Advanced 3D runs with blend modes, track mattes (2D and 3D), Preserve Transparency, and environment backgrounds (Classic and Advanced 3D skies)
render: three_d::adv::SplitRun (Renderer::split_adv_run) hands draw_run's split path to an accelerator as data (main scene, special layers far to near, 3D mattes drawn solo); Renderer::sky_draw / three_d::SkyDraw for Environment Light Background layers. gpu: the walk draws skies (adv_sky kernel), resolves each special layer, hides it behind the nearer main scene (occlude kernel) and composites it through the 2D path without readbacks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a909de43b7
commit
0c4e533460
@@ -255,3 +255,24 @@ fn wire(@builtin(global_invocation_id) id: vec3<u32>) {
|
||||
let p = table[id.x];
|
||||
textureStore(out, vec2<i32>(i32(p.x), i32(p.y)), vec4<f32>(1.0));
|
||||
}
|
||||
|
||||
// A layer rendered on its own (color_in, finished) hidden where the run's main scene is nearer
|
||||
// (`adv::draw_run`): depth = its depth, src = the main scene's colour, radius = the main
|
||||
// scene's depth. Pixels it didn't draw (BIG) are never hidden, as ∞ compares on the CPU.
|
||||
// P.u0 = (width, height)
|
||||
@compute @workgroup_size(16, 16)
|
||||
fn occlude(@builtin(global_invocation_id) id: vec3<u32>) {
|
||||
let w = P.u0.x;
|
||||
if (id.x >= w || id.y >= P.u0.y) {
|
||||
return;
|
||||
}
|
||||
let i = id.y * w + id.x;
|
||||
let q = vec2<i32>(i32(id.x), i32(id.y));
|
||||
var p = textureLoad(color_in, q, 0);
|
||||
let z = depth[i];
|
||||
let mz = radius[i];
|
||||
if (z < BIG * 0.5 && mz < z - 0.01 * max(abs(z), 1.0)) {
|
||||
p *= 1.0 - clamp(src[i].w, 0.0, 1.0);
|
||||
}
|
||||
textureStore(out, q, p);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// Environment Light Background layers (`three_d::compose::draw_sky`): the layer's
|
||||
// equirectangular image looked up by each pixel's view ray through the camera, composited over
|
||||
// the canvas. src = the canvas, aux = the layer's buffer. f[0] = (forward, zoom); f[1] =
|
||||
// (right, orthographic); f[2] = (down, environment rotation); f[3] = (x offset, y offset,
|
||||
// 1 / scale, opacity) with the offsets ROI / scale − view size / 2; f[4] = (image width, height).
|
||||
|
||||
@compute @workgroup_size(16, 16)
|
||||
fn adv_sky(@builtin(global_invocation_id) gid: vec3<u32>) {
|
||||
let p = vec2<i32>(gid.xy);
|
||||
let dims = out_dims();
|
||||
if (p.x >= dims.x || p.y >= dims.y) {
|
||||
return;
|
||||
}
|
||||
let fwd = P.f[0].xyz;
|
||||
var dir = fwd;
|
||||
if (P.f[1].w == 0.0) {
|
||||
let cx = (f32(p.x) + 0.5) * P.f[3].z + P.f[3].x;
|
||||
let cy = (f32(p.y) + 0.5) * P.f[3].z + P.f[3].y;
|
||||
dir = normalize(fwd * P.f[0].w + P.f[1].xyz * cx + P.f[2].xyz * cy);
|
||||
}
|
||||
// shade::equirect_uv.
|
||||
let pi = 3.141592653589793;
|
||||
var u = 0.5 + (atan2(dir.x, dir.z) + P.f[2].w) / (2.0 * pi);
|
||||
let v = acos(clamp(-dir.y, -1.0, 1.0)) / pi;
|
||||
u = u - floor(u);
|
||||
let iw = P.f[4].x;
|
||||
let ih = P.f[4].y;
|
||||
let s = sample_bilinear(aux, clamp(u * iw, 0.5, iw - 0.5), clamp(v * ih, 0.5, ih - 0.5));
|
||||
let op = P.f[3].w;
|
||||
let d = textureLoad(src, p, 0);
|
||||
textureStore(out, p, s * op + d * (1.0 - s.w * op));
|
||||
}
|
||||
Reference in New Issue
Block a user