This commit is contained in:
2026-01-21 09:05:02 -06:00
parent 18ca9e14ba
commit f7be9c3344
30 changed files with 237 additions and 246 deletions

View File

@@ -23,7 +23,7 @@ compositor.compile = function(config) {
// Clear screen
if (config.clear)
ctx.passes.push({type: 'clear', target: 'screen', color: config.clear})
push(ctx.passes, {type: 'clear', target: 'screen', color: config.clear})
// Process each plane (supports both 'planes' and legacy 'layers' key)
var planes = config.planes || config.layers || []
@@ -41,7 +41,7 @@ compositor.compile = function(config) {
}
function compile_imgui_layer(layer, ctx) {
ctx.passes.push({
push(ctx.passes, {
type: 'imgui',
target: 'screen',
draw: layer.draw
@@ -70,7 +70,7 @@ function compile_plane(plane_config, ctx, group_effects) {
// Add manual drawables
if (plane_config.drawables) {
for (var i = 0; i < length(plane_config.drawables); i++)
all_sprites.push(plane_config.drawables[i])
push(all_sprites, plane_config.drawables[i])
}
// Find which sprites belong to groups with effects
@@ -98,14 +98,14 @@ function compile_plane(plane_config, ctx, group_effects) {
if (group_effects[gname]) {
if (!effect_groups[gname])
effect_groups[gname] = {sprites: [], effects: group_effects[gname].effects}
effect_groups[gname].sprites.push(s)
push(effect_groups[gname].sprites, s)
assigned = true
break // Only assign to first matching effect group
}
}
// Add to base sprites if not assigned to effect group and not mask-only
if (!assigned && !is_mask_only) base_sprites.push(s)
if (!assigned && !is_mask_only) push(base_sprites, s)
}
// Allocate plane target
@@ -113,7 +113,7 @@ function compile_plane(plane_config, ctx, group_effects) {
// Clear plane
if (plane_config.clear)
ctx.passes.push({type: 'clear', target: plane_target, color: plane_config.clear})
push(ctx.passes, {type: 'clear', target: plane_target, color: plane_config.clear})
// Render each effect group to temp target, apply effects, composite back
arrfor(array(effect_groups), gname => {
@@ -123,7 +123,7 @@ function compile_plane(plane_config, ctx, group_effects) {
var group_target = ctx.alloc(res.width, res.height, gname + '_content')
// Render group content
ctx.passes.push({
push(ctx.passes, {
type: 'render',
renderer: 'film2d',
drawables: eg.sprites,
@@ -142,7 +142,7 @@ function compile_plane(plane_config, ctx, group_effects) {
}
// Composite result to plane
ctx.passes.push({
push(ctx.passes, {
type: 'composite',
source: current,
dest: plane_target,
@@ -154,7 +154,7 @@ function compile_plane(plane_config, ctx, group_effects) {
// Render base sprites (no effects)
if (length(base_sprites) > 0) {
ctx.passes.push({
push(ctx.passes, {
type: 'render',
renderer: 'film2d',
drawables: base_sprites,
@@ -167,7 +167,7 @@ function compile_plane(plane_config, ctx, group_effects) {
}
// Composite plane to screen
ctx.passes.push({
push(ctx.passes, {
type: 'blit_to_screen',
source: plane_target,
source_size: res,
@@ -185,7 +185,7 @@ function apply_effect(ctx, effect, input, size, camera, hint, current_plane, gro
var blur2 = ctx.alloc(size.width, size.height, hint + '_blur2')
// Threshold
ctx.passes.push({
push(ctx.passes, {
type: 'shader_pass',
shader: 'threshold',
input: input,
@@ -197,13 +197,13 @@ function apply_effect(ctx, effect, input, size, camera, hint, current_plane, gro
var blur_passes = effect.blur_passes || 2
var blur_in = bright
for (var p = 0; p < blur_passes; p++) {
ctx.passes.push({type: 'shader_pass', shader: 'blur', input: blur_in, output: blur1, uniforms: {direction: {x: 1, y: 0}, texel_size: {x: 1/size.width, y: 1/size.height}}})
ctx.passes.push({type: 'shader_pass', shader: 'blur', input: blur1, output: blur2, uniforms: {direction: {x: 0, y: 1}, texel_size: {x: 1/size.width, y: 1/size.height}}})
push(ctx.passes, {type: 'shader_pass', shader: 'blur', input: blur_in, output: blur1, uniforms: {direction: {x: 1, y: 0}, texel_size: {x: 1/size.width, y: 1/size.height}}})
push(ctx.passes, {type: 'shader_pass', shader: 'blur', input: blur1, output: blur2, uniforms: {direction: {x: 0, y: 1}, texel_size: {x: 1/size.width, y: 1/size.height}}})
blur_in = blur2
}
// Composite bloom
ctx.passes.push({type: 'composite_textures', base: input, overlay: blur2, output: output, mode: 'add'})
push(ctx.passes, {type: 'composite_textures', base: input, overlay: blur2, output: output, mode: 'add'})
} else if (effect.type == 'mask') {
var mask_group = effect.mask_group
@@ -214,7 +214,7 @@ function apply_effect(ctx, effect, input, size, camera, hint, current_plane, gro
var mask_target = ctx.alloc(size.width, size.height, hint + '_mask')
// Render mask
ctx.passes.push({
push(ctx.passes, {
type: 'render',
renderer: 'film2d',
drawables: mask_sprites,
@@ -225,7 +225,7 @@ function apply_effect(ctx, effect, input, size, camera, hint, current_plane, gro
})
// Apply mask
ctx.passes.push({
push(ctx.passes, {
type: 'apply_mask',
content: input,
mask: mask_target,
@@ -235,11 +235,11 @@ function apply_effect(ctx, effect, input, size, camera, hint, current_plane, gro
})
} else {
// No mask sprites, pass through
ctx.passes.push({type: 'blit', source: input, dest: output})
push(ctx.passes, {type: 'blit', source: input, dest: output})
}
} else {
// Unknown effect, pass through
ctx.passes.push({type: 'blit', source: input, dest: output})
push(ctx.passes, {type: 'blit', source: input, dest: output})
}
return output
@@ -267,8 +267,8 @@ compositor.execute = function(plan) {
if (pass.type == 'clear') {
var target = resolve(pass.target)
commands.push({cmd: 'begin_render', target: target, clear: pass.color})
commands.push({cmd: 'end_render'})
push(commands, {cmd: 'begin_render', target: target, clear: pass.color})
push(commands, {cmd: 'end_render'})
} else if (pass.type == 'render') {
var result = film2d.render({
@@ -280,10 +280,10 @@ compositor.execute = function(plan) {
clear: pass.clear
}, backend)
for (var c = 0; c < length(result.commands); c++)
commands.push(result.commands[c])
push(commands, result.commands[c])
} else if (pass.type == 'shader_pass') {
commands.push({
push(commands, {
cmd: 'shader_pass',
shader: pass.shader,
input: resolve(pass.input),
@@ -292,7 +292,7 @@ compositor.execute = function(plan) {
})
} else if (pass.type == 'composite_textures') {
commands.push({
push(commands, {
cmd: 'composite_textures',
base: resolve(pass.base),
overlay: resolve(pass.overlay),
@@ -301,7 +301,7 @@ compositor.execute = function(plan) {
})
} else if (pass.type == 'apply_mask') {
commands.push({
push(commands, {
cmd: 'apply_mask',
content_texture: resolve(pass.content),
mask_texture: resolve(pass.mask),
@@ -311,7 +311,7 @@ compositor.execute = function(plan) {
})
} else if (pass.type == 'composite') {
commands.push({
push(commands, {
cmd: 'blit',
texture: resolve(pass.source),
target: resolve(pass.dest),
@@ -320,7 +320,7 @@ compositor.execute = function(plan) {
} else if (pass.type == 'blit_to_screen') {
var rect = _calc_presentation(pass.source_size, pass.dest_size, pass.presentation)
commands.push({
push(commands, {
cmd: 'blit',
texture: resolve(pass.source),
target: 'screen',
@@ -330,14 +330,14 @@ compositor.execute = function(plan) {
} else if (pass.type == 'blit') {
var src = resolve(pass.source)
var dst = resolve(pass.dest)
commands.push({
push(commands, {
cmd: 'blit',
texture: src,
target: dst,
dst_rect: {x: 0, y: 0, width: dst.width, height: dst.height}
})
} else if (pass.type == 'imgui') {
commands.push({
push(commands, {
cmd: 'imgui',
target: resolve(pass.target),
draw: pass.draw