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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(postfx): stop "uniform not found" spam from multi-pass effects
yhh3bd2db5ee414
diff --git a/src/esengine/renderer/PostProcessPipeline.cpp b/src/esengine/renderer/PostProcessPipeline.cppindex df3aad97d..b1e443303 100644--- a/src/esengine/renderer/PostProcessPipeline.cpp+++ b/src/esengine/renderer/PostProcessPipeline.cpp@@ -359,15 +359,24 @@ void PostProcessPipeline::renderPass(const PostProcessPass& pass, u32 inputTextushader->bind();shader->setUniform("u_texture", 0);- shader->setUniform("u_sceneTexture", 1);- shader->setUniform("u_resolution", glm::vec2(static_cast<f32>(width_), static_cast<f32>(height_)));+ // u_sceneTexture and u_resolution are engine-provided builtins that only some+ // passes use (bloom's composite taps the untouched scene; kawase/pixelate/fxaa+ // need the resolution). Supply them only where declared so passes that omit+ // them don't log a spurious "uniform not found".+ if (shader->hasUniform("u_sceneTexture")) shader->setUniform("u_sceneTexture", 1);+ if (shader->hasUniform("u_resolution")) {+ shader->setUniform("u_resolution", glm::vec2(static_cast<f32>(width_), static_cast<f32>(height_)));+ }+ // 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.for (const auto& [name, value] : pass.floatUniforms) {- shader->setUniform(name, value);+ if (shader->hasUniform(name)) shader->setUniform(name, value);}for (const auto& [name, value] : pass.vec4Uniforms) {- shader->setUniform(name, value);+ if (shader->hasUniform(name)) shader->setUniform(name, value);}drawScreenQuad();diff --git a/src/esengine/renderer/Shader.cpp b/src/esengine/renderer/Shader.cppindex 5681805df..b27e09968 100644--- a/src/esengine/renderer/Shader.cpp+++ b/src/esengine/renderer/Shader.cpp@@ -202,11 +202,11 @@ void Shader::reflectActiveUniforms() {activeUniforms_ = device_->getActiveUniforms(programId_);}-i32 Shader::getUniformLocation(const std::string& name) const {+i32 Shader::cacheUniformLocation(const std::string& name, bool warnOnMiss) const {auto [it, inserted] = uniformCache_.emplace(name, -1);if (inserted) {it->second = device_->getUniformLocation(programId_, name.c_str());- if (it->second < 0) {+ if (it->second < 0 && warnOnMiss) {ES_LOG_WARN("Shader {}: uniform '{}' not found (typo or optimized out)",programId_, name);}@@ -214,6 +214,14 @@ i32 Shader::getUniformLocation(const std::string& name) const {return it->second;}+i32 Shader::getUniformLocation(const std::string& name) const {+ return cacheUniformLocation(name, /*warnOnMiss=*/true);+}++bool Shader::hasUniform(const std::string& name) const {+ return cacheUniformLocation(name, /*warnOnMiss=*/false) >= 0;+}+void Shader::setUniform(const std::string& name, i32 value) const {device_->setUniform1i(getUniformLocation(name), value);}diff --git a/src/esengine/renderer/Shader.hpp b/src/esengine/renderer/Shader.hppindex 32e6d6d9e..677b1904e 100644--- a/src/esengine/renderer/Shader.hpp+++ b/src/esengine/renderer/Shader.hpp@@ -186,6 +186,15 @@ public:i32 getUniformLocation(const std::string& name) const;+ /**+ * @brief True if the linked program declares this uniform.+ * @details Silent probe (no "not found" warning), for call sites that+ * intentionally supply a superset of uniforms — e.g. the+ * post-process pipeline applies a whole effect's uniform set to+ * each of its sub-pass shaders, which each use only a subset.+ */+ bool hasUniform(const std::string& name) const;+/** @brief Returns reflected metadata for every active uniform, populated at link time */const std::vector<GfxUniformInfo>& getActiveUniforms() const { return activeUniforms_; }@@ -219,6 +228,9 @@ private:void reflectActiveUniforms();+ /** @brief Resolve + cache a uniform location; warns on miss only when asked. */+ i32 cacheUniformLocation(const std::string& name, bool warnOnMiss) const;+GfxDevice* device_ = nullptr; ///< Set by the create* factories; all GL goes through it.u32 programId_ = 0;