Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(postprocess): per-pass texture params + true-LUT color grading

yhha8e4bee4bbfe
diff --git a/desktop/package.json b/desktop/package.json
index 465e93c02..8a4960a04 100644
--- a/desktop/package.json
+++ b/desktop/package.json
@@ -54,7 +54,8 @@
"mcp": "electron electron/mcp/server.mjs",
"mcp:smoke": "vite build && node electron/mcp/smoke.mjs",
"verify:render:tilemap:hex": "vite build && ESTELLA_VERIFY_SCENE=/scenes/tilemap-hex.esscene ESTELLA_VERIFY_MANIFEST=/scenes/tilemap-hex.textures.json ESTELLA_VERIFY_W=256 ESTELLA_VERIFY_H=256 ESTELLA_VERIFY_STEPS=6 ESTELLA_VERIFY_EXPECT=\"[{\\\"x\\\":0.40,\\\"y\\\":0.40,\\\"rgb\\\":[255,0,0]},{\\\"x\\\":0.60,\\\"y\\\":0.40,\\\"rgb\\\":[0,255,0]},{\\\"x\\\":0.50,\\\"y\\\":0.55,\\\"rgb\\\":[0,0,255]},{\\\"x\\\":0.70,\\\"y\\\":0.55,\\\"rgb\\\":[255,255,0]}]\" electron scripts/headless-verify.mjs",
- "verify:render:parallax:shape": "vite build && ESTELLA_VERIFY_SCENE=/scenes/parallax-shape.esscene ESTELLA_VERIFY_MANIFEST=/scenes/parallax-shape.textures.json ESTELLA_VERIFY_STEPS=4 ESTELLA_VERIFY_EXPECT=\"[{\\\"x\\\":0.5,\\\"y\\\":0.5,\\\"rgb\\\":[0,255,0],\\\"tol\\\":40},{\\\"x\\\":0.25,\\\"y\\\":0.5,\\\"rgb\\\":[255,0,0],\\\"tol\\\":40}]\" electron scripts/headless-verify.mjs"
+ "verify:render:parallax:shape": "vite build && ESTELLA_VERIFY_SCENE=/scenes/parallax-shape.esscene ESTELLA_VERIFY_MANIFEST=/scenes/parallax-shape.textures.json ESTELLA_VERIFY_STEPS=4 ESTELLA_VERIFY_EXPECT=\"[{\\\"x\\\":0.5,\\\"y\\\":0.5,\\\"rgb\\\":[0,255,0],\\\"tol\\\":40},{\\\"x\\\":0.25,\\\"y\\\":0.5,\\\"rgb\\\":[255,0,0],\\\"tol\\\":40}]\" electron scripts/headless-verify.mjs",
+ "verify:render:postprocess:lut": "vite build && ESTELLA_VERIFY_PLAY=1 ESTELLA_VERIFY_SCENE=/scenes/lut-grade.esscene ESTELLA_VERIFY_MANIFEST=/scenes/lut-grade.textures.json ESTELLA_VERIFY_W=256 ESTELLA_VERIFY_H=256 ESTELLA_VERIFY_STEPS=10 ESTELLA_VERIFY_EXPECT=\"[{\\\"x\\\":0.292,\\\"y\\\":0.5,\\\"rgb\\\":[0,0,255],\\\"tol\\\":40},{\\\"x\\\":0.708,\\\"y\\\":0.5,\\\"rgb\\\":[255,0,0],\\\"tol\\\":40}]\" electron scripts/headless-verify.mjs"
},
"dependencies": {
"@modelcontextprotocol/sdk": "^1.29.0",
diff --git a/desktop/public/scenes/lut-grade.esscene b/desktop/public/scenes/lut-grade.esscene
new file mode 100644
index 000000000..74a98eb25
--- /dev/null
+++ b/desktop/public/scenes/lut-grade.esscene
@@ -0,0 +1,50 @@
+{
+ "version": "1.0",
+ "name": "LutGrade",
+ "entities": [
+ {
+ "id": 0,
+ "name": "Camera",
+ "parent": null,
+ "children": [],
+ "components": [
+ { "type": "Transform", "data": { "position": { "x": 0, "y": 0, "z": 10 } } },
+ { "type": "Camera", "data": { "projectionType": 1, "orthoSize": 240, "isActive": true, "priority": 0 } }
+ ],
+ "visible": true
+ },
+ {
+ "id": 1,
+ "name": "RedShape",
+ "parent": null,
+ "children": [],
+ "components": [
+ { "type": "Transform", "data": { "position": { "x": -100, "y": 0, "z": 0 } } },
+ { "type": "ShapeRenderer", "data": { "shapeType": 0, "size": { "x": 80, "y": 80 }, "color": { "r": 1, "g": 0, "b": 0, "a": 1 }, "enabled": true } }
+ ],
+ "visible": true
+ },
+ {
+ "id": 2,
+ "name": "BlueShape",
+ "parent": null,
+ "children": [],
+ "components": [
+ { "type": "Transform", "data": { "position": { "x": 100, "y": 0, "z": 0 } } },
+ { "type": "ShapeRenderer", "data": { "shapeType": 0, "size": { "x": 80, "y": 80 }, "color": { "r": 0, "g": 0, "b": 1, "a": 1 }, "enabled": true } }
+ ],
+ "visible": true
+ },
+ {
+ "id": 3,
+ "name": "Grade",
+ "parent": null,
+ "children": [],
+ "components": [
+ { "type": "Transform", "data": { "position": { "x": 0, "y": 0, "z": 0 } } },
+ { "type": "PostProcessVolume", "data": { "isGlobal": true, "priority": 0, "weight": 1, "blendDistance": 0, "shape": "box", "size": { "x": 5, "y": 5 }, "effects": [ { "type": "lutGrade", "enabled": true, "uniforms": { "u_intensity": 1 }, "textures": { "u_lut": "/scenes/lut-grade/lut.png" } } ] } }
+ ],
+ "visible": true
+ }
+ ]
+}
diff --git a/desktop/public/scenes/lut-grade.textures.json b/desktop/public/scenes/lut-grade.textures.json
new file mode 100644
index 000000000..0967ef424
--- /dev/null
+++ b/desktop/public/scenes/lut-grade.textures.json
@@ -0,0 +1 @@
+{}
diff --git a/desktop/public/scenes/lut-grade/lut.png b/desktop/public/scenes/lut-grade/lut.png
new file mode 100644
index 000000000..028a90a14
Binary files /dev/null and b/desktop/public/scenes/lut-grade/lut.png differ
diff --git a/sdk/src/component.ts b/sdk/src/component.ts
index 8b9ddaf52..15bbe561e 100644
--- a/sdk/src/component.ts
+++ b/sdk/src/component.ts
@@ -768,7 +768,13 @@ export const SceneOwner = defineComponent<SceneOwnerData>('SceneOwner', {
});
export interface PostProcessVolumeData {
- effects: { type: string; enabled: boolean; uniforms: Record<string, number> }[];
+ effects: {
+ type: string;
+ enabled: boolean;
+ uniforms: Record<string, number>;
+ /** Texture params (LUTs, masks): sampler uniform -> serialized texture ref. */
+ textures?: Record<string, string>;
+ }[];
isGlobal: boolean;
shape: 'box' | 'sphere';
size: { x: number; y: number };
@@ -785,6 +791,23 @@ export const PostProcessVolume = defineComponent<PostProcessVolumeData>('PostPro
priority: 0,
weight: 1,
blendDistance: 0,
+}, {
+ // The COMPLETE asset manifest for discovery: effect texture params (LUTs,
+ // masks) preload with the scene so the volume system's cache lookups hit.
+ discoverAssets: (data) => {
+ const refs: AssetRef[] = [];
+ const effects = data.effects;
+ if (Array.isArray(effects)) {
+ for (const effect of effects) {
+ const textures = (effect as { textures?: Record<string, unknown> }).textures;
+ if (!textures) continue;
+ for (const ref of Object.values(textures)) {
+ if (typeof ref === 'string' && ref) refs.push({ type: 'texture', path: ref });
+ }
+ }
+ }
+ return refs;
+ },
});
export type {
diff --git a/sdk/src/postprocess/PostProcessAPI.ts b/sdk/src/postprocess/PostProcessAPI.ts
index fe61132db..4639d1ce0 100644
--- a/sdk/src/postprocess/PostProcessAPI.ts
+++ b/sdk/src/postprocess/PostProcessAPI.ts
@@ -72,6 +72,14 @@ export function syncStackToWasm(stack: PostProcessStack): void {
handleWasmError(e, `PostProcess._applyForCamera:setUniformVec4("${pass.name}", "${name}")`);
}
}
+
+ for (const [name, handle] of pass.textureUniforms) {
+ try {
+ m.postprocess_setPassTexture(pass.name, name, handle);
+ } catch (e) {
+ handleWasmError(e, `PostProcess._applyForCamera:setPassTexture("${pass.name}", "${name}")`);
+ }
+ }
}
stack.clearDirty();
diff --git a/sdk/src/postprocess/PostProcessPlugin.ts b/sdk/src/postprocess/PostProcessPlugin.ts
index 814c54d40..9e77cfa44 100644
--- a/sdk/src/postprocess/PostProcessPlugin.ts
+++ b/sdk/src/postprocess/PostProcessPlugin.ts
@@ -2,8 +2,9 @@
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
import type { App, Plugin } from '../app';
import { Schedule } from '../system';
+import { Assets } from '../asset/AssetPlugin';
import { PostProcess, PostProcessApi } from './PostProcessAPI';
-import { postProcessVolumeSystem, cleanupVolumeSystem, PostProcessVolumeConfigResource } from './volumeSystem';
+import { postProcessVolumeSystem, cleanupVolumeSystem, setVolumeTextureResolver, PostProcessVolumeConfigResource } from './volumeSystem';
export class PostProcessPlugin implements Plugin {
name = 'postProcess';
@@ -16,6 +17,11 @@ export class PostProcessPlugin implements Plugin {
app.pipeline?.setPostProcess(api);
app.insertResource(PostProcessVolumeConfigResource, { enabled: true });
+ // Effect texture params (LUTs, masks) resolve through this App's Assets;
+ // PostProcessVolume's discoverAssets preloads the refs, so this is a
+ // cache lookup by the time a volume applies.
+ setVolumeTextureResolver((ref) =>
+ app.hasResource(Assets) ? (app.getResource(Assets).getTexture(ref)?.handle ?? 0) : 0);
app.addSystemToSchedule(Schedule.PostUpdate, postProcessVolumeSystem);
}
diff --git a/sdk/src/postprocess/PostProcessStack.ts b/sdk/src/postprocess/PostProcessStack.ts
index 4b01208d3..7abc30676 100644
--- a/sdk/src/postprocess/PostProcessStack.ts
+++ b/sdk/src/postprocess/PostProcessStack.ts
@@ -9,6 +9,8 @@ export interface PassConfig {
enabled: boolean;
floatUniforms: Map<string, number>;
vec4Uniforms: Map<string, Vec4>;
+ /** Effect-declared textures (LUTs, masks): sampler uniform -> SDK texture handle. */
+ textureUniforms: Map<string, number>;
}
/**
@@ -58,6 +60,7 @@ export class PostProcessStack {
enabled: true,
floatUniforms: new Map(),
vec4Uniforms: new Map(),
+ textureUniforms: new Map(),
});
this.dirty_ = true;
return this;
@@ -100,6 +103,18 @@ export class PostProcessStack {
return this;
}
+ /** Binds a texture (SDK texture handle) to a pass's sampler uniform. */
+ setTexture(passName: string, uniform: string, textureHandle: number): this {
+ const pass = this.passes_.find(p => p.name === passName);
+ if (pass) {
+ if (pass.textureUniforms.get(uniform) !== textureHandle) {
+ pass.textureUniforms.set(uniform, textureHandle);
+ this.dirty_ = true;
+ }
+ }
+ return this;
+ }
+
setUniformVec4(passName: string, uniform: string, value: Vec4): this {
const pass = this.passes_.find(p => p.name === passName);
if (pass) {
diff --git a/sdk/src/postprocess/effects.ts b/sdk/src/postprocess/effects.ts
index b61c9313b..107b6443a 100644
--- a/sdk/src/postprocess/effects.ts
+++ b/sdk/src/postprocess/effects.ts
@@ -12,6 +12,12 @@ export interface EffectUniformDef {
defaultValue: number;
}
+/** A texture parameter (LUT, mask): the sampler uniform it binds to. */
+export interface EffectTextureDef {
+ name: string;
+ label: string;
+}
+
export interface EffectSubPass {
name: string;
factory: () => ShaderHandle;
@@ -22,6 +28,8 @@ export interface EffectDef {
label: string;
factory: () => ShaderHandle;
uniforms: EffectUniformDef[];
+ /** Texture params, carried on the volume as serialized refs (`textures`). */
+ textures?: EffectTextureDef[];
multiPass?: EffectSubPass[];
}
@@ -149,3 +157,15 @@ registerEffect({
{ name: 'u_pixelSize', label: 'Pixel Size', min: 1, max: 64, step: 1, defaultValue: 4 },
],
});
+
+registerEffect({
+ type: 'lutGrade',
+ label: 'LUT Grade',
+ factory: () => postProcessEffects.createLutGrade(),
+ uniforms: [
+ { name: 'u_intensity', label: 'Intensity', min: 0, max: 1, step: 0.01, defaultValue: 1 },
+ ],
+ textures: [
+ { name: 'u_lut', label: 'LUT (1024x32, 32 slices)' },
+ ],
+});
diff --git a/sdk/src/postprocess/postProcessEffects.ts b/sdk/src/postprocess/postProcessEffects.ts
index 9e0b9b571..0584086d0 100644
--- a/sdk/src/postprocess/postProcessEffects.ts
+++ b/sdk/src/postprocess/postProcessEffects.ts
@@ -12,6 +12,41 @@ import { Material } from '../material';
import { POSTPROCESS_VERTEX } from './shaders';
export const postProcessEffects = {
+ createLutGrade(): ShaderHandle {
+ // True LUT color grading: a 2D-packed 32^3 LUT (1024x32 — 32 slices of
+ // 32x32 laid out along X; slice index = blue). Sampled twice around the
+ // blue coordinate and mixed, giving trilinear-quality grading from a
+ // plain PNG. The LUT texture binds via the pass's texture params
+ // (PostProcessVolume `textures: { u_lut: <ref> }`).
+ const fragmentSrc = `#version 300 es
+precision highp float;
+
+in vec2 v_texCoord;
+uniform sampler2D u_texture;
+uniform sampler2D u_lut;
+uniform float u_intensity;
+out vec4 fragColor;
+
+vec3 sampleLut(vec3 c) {
+ const float size = 32.0;
+ float b = clamp(c.b, 0.0, 1.0) * (size - 1.0);
+ float slice0 = floor(b);
+ float slice1 = min(slice0 + 1.0, size - 1.0);
+ float u = (clamp(c.r, 0.0, 1.0) * (size - 1.0) + 0.5) / (size * size);
+ float v = (clamp(c.g, 0.0, 1.0) * (size - 1.0) + 0.5) / size;
+ vec3 a = texture(u_lut, vec2(u + slice0 / size, v)).rgb;
+ vec3 d = texture(u_lut, vec2(u + slice1 / size, v)).rgb;
+ return mix(a, d, b - slice0);
+}
+
+void main() {
+ vec4 color = texture(u_texture, v_texCoord);
+ fragColor = vec4(mix(color.rgb, sampleLut(color.rgb), u_intensity), color.a);
+}
+`;
+ return Material.createShader(POSTPROCESS_VERTEX, fragmentSrc);
+ },
+
createBlur(): ShaderHandle {
const fragmentSrc = `#version 300 es
precision highp float;
diff --git a/sdk/src/postprocess/volumeBlending.ts b/sdk/src/postprocess/volumeBlending.ts
index 519cd60db..876c74dea 100644
--- a/sdk/src/postprocess/volumeBlending.ts
+++ b/sdk/src/postprocess/volumeBlending.ts
@@ -15,6 +15,9 @@ export interface ActiveVolume {
export interface BlendedEffect {
enabled: boolean;
uniforms: Map<string, number>;
+ /** Texture params (sampler uniform -> serialized texture ref). Textures don't
+ * interpolate: the last volume in priority order that sets one wins. */
+ textures: Map<string, string>;
}
export function signedDistanceBox(
@@ -89,8 +92,19 @@ export function blendVolumeEffects(
for (const [key, value] of Object.entries(effect.uniforms)) {
uniforms.set(key, value * factor);
}
- result.set(effect.type, { enabled: true, uniforms });
+ const textures = new Map<string, string>();
+ if (effect.textures) {
+ for (const [key, ref] of Object.entries(effect.textures)) {
+ if (ref) textures.set(key, ref);
+ }
+ }
+ result.set(effect.type, { enabled: true, uniforms, textures });
} else {
+ if (effect.textures) {
+ for (const [key, ref] of Object.entries(effect.textures)) {
+ if (ref) existing.textures.set(key, ref);
+ }
+ }
for (const [key, value] of Object.entries(effect.uniforms)) {
const prev = existing.uniforms.get(key) ?? 0;
existing.uniforms.set(key, prev + (value - prev) * factor);
diff --git a/sdk/src/postprocess/volumeSystem.ts b/sdk/src/postprocess/volumeSystem.ts
index 16fc78800..347337f30 100644
--- a/sdk/src/postprocess/volumeSystem.ts
+++ b/sdk/src/postprocess/volumeSystem.ts
@@ -20,6 +20,14 @@ export const PostProcessVolumeConfigResource = defineResource<PostProcessVolumeC
'PostProcessVolumeConfig'
);
+// Texture-param refs resolve through the App's Assets (set by PostProcessPlugin);
+// preloaded by PostProcessVolume's discoverAssets, so lookups are cache hits.
+let volumeTextureResolver: ((ref: string) => number) | null = null;
+
+export function setVolumeTextureResolver(resolver: ((ref: string) => number) | null): void {
+ volumeTextureResolver = resolver;
+}
+
function getOrCreateShader(api: PostProcessApi, key: string, factory: () => ShaderHandle): ShaderHandle {
const existing = api.volumeShaders.get(key);
if (existing !== undefined) return existing;
@@ -29,10 +37,22 @@ function getOrCreateShader(api: PostProcessApi, key: string, factory: () => Shad
return shader;
}
+function applyTextures(
+ stack: ReturnType<PostProcessApi['createStack']>,
+ passName: string,
+ textures: Map<string, string>,
+): void {
+ if (textures.size === 0 || !volumeTextureResolver) return;
+ for (const [uniformName, ref] of textures) {
+ const handle = volumeTextureResolver(ref);
+ if (handle) stack.setTexture(passName, uniformName, handle);
+ }
+}
+
function applyBlendedEffects(
api: PostProcessApi,
camera: Entity,
- effects: Map<string, { enabled: boolean; uniforms: Map<string, number> }>,
+ effects: Map<string, { enabled: boolean; uniforms: Map<string, number>; textures: Map<string, string> }>,
): void {
if (effects.size === 0) {
const existing = api.volumeStacks.get(camera);
@@ -65,6 +85,7 @@ function applyBlendedEffects(
for (const [uniformName, uniformValue] of effectData.uniforms) {
stack.setUniform(subPass.name, uniformName, uniformValue);
}
+ applyTextures(stack, subPass.name, effectData.textures);
}
} else {
const shader = getOrCreateShader(api, effectType, def.factory);
@@ -72,6 +93,7 @@ function applyBlendedEffects(
for (const [uniformName, uniformValue] of effectData.uniforms) {
stack.setUniform(effectType, uniformName, uniformValue);
}
+ applyTextures(stack, effectType, effectData.textures);
}
}
@@ -109,7 +131,7 @@ export const postProcessVolumeSystem = defineSystem(
const blended = activeVolumes.length > 0
? blendVolumeEffects(activeVolumes)
- : new Map<string, { enabled: boolean; uniforms: Map<string, number> }>();
+ : new Map<string, { enabled: boolean; uniforms: Map<string, number>; textures: Map<string, string> }>();
applyBlendedEffects(api, cameraEntity, blended);
}
diff --git a/sdk/src/wasm.ts b/sdk/src/wasm.ts
index 94fb3d803..b97f8405e 100644
--- a/sdk/src/wasm.ts
+++ b/sdk/src/wasm.ts
@@ -237,6 +237,7 @@ export interface ESEngineModule {
postprocess_setPassEnabled(name: string, enabled: boolean): void;
postprocess_isPassEnabled(name: string): boolean;
postprocess_setUniformFloat(passName: string, uniform: string, value: number): void;
+ postprocess_setPassTexture(passName: string, uniform: string, textureHandle: number): void;
postprocess_setUniformVec4(passName: string, uniform: string, x: number, y: number, z: number, w: number): void;
postprocess_begin(): void;
postprocess_end(): void;
diff --git a/src/esengine/bindings/PostProcessBindings.cpp b/src/esengine/bindings/PostProcessBindings.cpp
index 30aa61352..38a0526f0 100644
--- a/src/esengine/bindings/PostProcessBindings.cpp
+++ b/src/esengine/bindings/PostProcessBindings.cpp
@@ -82,6 +82,20 @@ void postprocess_setUniformFloat(const std::string& passName,
}
}
+void postprocess_setPassTexture(const std::string& passName,
+ const std::string& uniform, u32 textureHandle) {
+ if (!g_postProcessPipeline) return;
+ u32 glId = 0;
+ if (textureHandle != 0) {
+ if (auto* rm = ctx().tryGet<resource::ResourceManager>()) {
+ if (auto* tex = rm->getTexture(resource::TextureHandle(textureHandle))) {
+ glId = tex->getId();
+ }
+ }
+ }
+ g_postProcessPipeline->setPassTexture(passName, uniform, glId);
+}
+
void postprocess_setUniformVec4(const std::string& passName,
const std::string& uniform,
f32 x, f32 y, f32 z, f32 w) {
diff --git a/src/esengine/bindings/PostProcessBindings.hpp b/src/esengine/bindings/PostProcessBindings.hpp
index 1bb60d9ad..9415db262 100644
--- a/src/esengine/bindings/PostProcessBindings.hpp
+++ b/src/esengine/bindings/PostProcessBindings.hpp
@@ -17,6 +17,8 @@ void postprocess_setPassEnabled(const std::string& name, bool enabled);
bool postprocess_isPassEnabled(const std::string& name);
void postprocess_setUniformFloat(const std::string& passName,
const std::string& uniform, f32 value);
+void postprocess_setPassTexture(const std::string& passName,
+ const std::string& uniform, u32 textureHandle);
void postprocess_setUniformVec4(const std::string& passName,
const std::string& uniform,
f32 x, f32 y, f32 z, f32 w);
diff --git a/src/esengine/bindings/WebSDKEntry.cpp b/src/esengine/bindings/WebSDKEntry.cpp
index db1af655e..f50f750bf 100644
--- a/src/esengine/bindings/WebSDKEntry.cpp
+++ b/src/esengine/bindings/WebSDKEntry.cpp
@@ -472,6 +472,7 @@ EMSCRIPTEN_BINDINGS(esengine_renderer) {
emscripten::function("postprocess_isPassEnabled", &esengine::postprocess_isPassEnabled);
emscripten::function("postprocess_setUniformFloat", &esengine::postprocess_setUniformFloat);
emscripten::function("postprocess_setUniformVec4", &esengine::postprocess_setUniformVec4);
+ emscripten::function("postprocess_setPassTexture", &esengine::postprocess_setPassTexture);
emscripten::function("postprocess_begin", &esengine::postprocess_begin);
emscripten::function("postprocess_end", &esengine::postprocess_end);
emscripten::function("postprocess_getPassCount", &esengine::postprocess_getPassCount);
diff --git a/src/esengine/renderer/PostProcessPipeline.cpp b/src/esengine/renderer/PostProcessPipeline.cpp
index 55c1fd6dd..c9e78b82a 100644
--- a/src/esengine/renderer/PostProcessPipeline.cpp
+++ b/src/esengine/renderer/PostProcessPipeline.cpp
@@ -213,6 +213,16 @@ void PostProcessPipeline::setPassUniformFloat(const std::string& passName,
}
}
+void PostProcessPipeline::setPassTexture(const std::string& passName,
+ const std::string& uniform, u32 glTextureId) {
+ auto* pass = findPass(passName);
+ if (!pass) return;
+ for (auto& [name, id] : pass->textureUniforms) {
+ if (name == uniform) { id = glTextureId; return; }
+ }
+ pass->textureUniforms.emplace_back(uniform, glTextureId);
+}
+
void PostProcessPipeline::setPassUniformVec4(const std::string& passName,
const std::string& uniform,
const glm::vec4& value) {
@@ -364,6 +374,16 @@ void PostProcessPipeline::renderPass(const PostProcessPass& pass, TextureHandle
shader->setUniform("u_resolution", glm::vec2(static_cast<f32>(width_), static_cast<f32>(height_)));
}
+ // Effect-declared textures (LUTs, masks) bind above the two engine units.
+ u32 extraUnit = 2;
+ for (const auto& [name, glId] : pass.textureUniforms) {
+ if (glId != 0 && shader->hasUniform(name)) {
+ device->bindTexture(extraUnit, TextureHandle{glId});
+ shader->setUniform(name, static_cast<i32>(extraUnit));
+ }
+ ++extraUnit;
+ }
+
// A multi-pass effect (e.g. bloom) applies its full uniform set to every one
// of its sub-pass shaders, each of which declares only a subset — upload each
// uniform only to the passes that actually use it.
diff --git a/src/esengine/renderer/PostProcessPipeline.hpp b/src/esengine/renderer/PostProcessPipeline.hpp
index 82c424687..b59eb0e3a 100644
--- a/src/esengine/renderer/PostProcessPipeline.hpp
+++ b/src/esengine/renderer/PostProcessPipeline.hpp
@@ -41,6 +41,9 @@ struct PostProcessPass {
bool enabled = true;
std::unordered_map<std::string, f32> floatUniforms;
std::unordered_map<std::string, glm::vec4> vec4Uniforms;
+ /// Effect-declared textures (LUTs, masks): sampler uniform name -> GL texture
+ /// id, bound in order above the two engine units (0 = input, 1 = scene).
+ std::vector<std::pair<std::string, u32>> textureUniforms;
};
/**
@@ -100,6 +103,12 @@ public:
*/
void setPassUniformFloat(const std::string& passName, const std::string& uniform, f32 value);
+ /**
+ * @brief Binds a texture to a pass's sampler uniform (unit 2 upward, in
+ * registration order). Replaces an existing binding of the same name.
+ */
+ void setPassTexture(const std::string& passName, const std::string& uniform, u32 glTextureId);
+
/**
* @brief Sets a vec4 uniform for a pass
*/