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(render): a lighting-direct surface takes a hard shadow from a sun with a size, where it took none
yhhb4b3e045c895
diff --git a/src/esengine/resource/ShaderParser.cpp b/src/esengine/resource/ShaderParser.cppindex f45c33398..8d1f88341 100644--- a/src/esengine/resource/ShaderParser.cpp+++ b/src/esengine/resource/ShaderParser.cpp@@ -1587,7 +1587,11 @@ fn shadowFactor3D(worldPos : vec3f, N : vec3f, L : vec3f, source : vec2f,// A source with no size throws one edge: a tent over the 3x3 texels around the// point, weighted by where it falls among them. Equal weights step at every// texel and the map's grid shows along the edge; a 2x2 still stair-steps it.+#ifdef ES_LIGHT_DIRECT+ if (true) {+#elseif (src <= 0.0 || g_shadowHard > 0.5) {+#endiflet texelUv = lc.u_shadowParams.y;let f = at0 / texelUv - 1.0;let c = (floor(f) + 0.5) * texelUv;@@ -2545,7 +2549,9 @@ ShaderParser::AssembledStage ShaderParser::assembleStageEx(const ParsedShader& p// ES_LINEAR world with no per-call-site wiring. It must be set before the// renderer compiles shaders; flipping it later requires a reload.std::vector<std::string> features = featuresIn;- if (parsed.lightingDirect) features.push_back("ES_LIGHT_DIRECT");+ if (parsed.lightingDirect && std::find(features.begin(), features.end(), "ES_LIGHT_DIRECT") == features.end()) {+ features.push_back("ES_LIGHT_DIRECT");+ }if (s_linearColor&& std::find(features.begin(), features.end(), "ES_LINEAR") == features.end()) {features.push_back("ES_LINEAR");@@ -2957,7 +2963,11 @@ ShaderParser::AssembledStage ShaderParser::assembleStageEx(const ParsedShader& p// A source with no size throws one edge: a tent over the 3x3 texels around the// point, weighted by where it falls among them. Equal weights step at every// texel and the map's grid shows along the edge; a 2x2 still stair-steps it.+ "#ifdef ES_LIGHT_DIRECT\n"+ " if (true) {\n"+ "#else\n"" if (src <= 0.0 || g_shadowHard > 0.5) {\n"+ "#endif\n"" highp float texelUv = u_shadowParams.y;\n"" highp vec2 f = at0 / texelUv - 1.0;\n"" highp vec2 c = (floor(f) + 0.5) * texelUv;\n"diff --git a/tests/renderer/test_shader_variant.cpp b/tests/renderer/test_shader_variant.cppindex e87d1196b..1278c43aa 100644--- a/tests/renderer/test_shader_variant.cpp+++ b/tests/renderer/test_shader_variant.cpp@@ -818,7 +818,13 @@ static void testLightingDirect() {CHECK(off.find(gone) != std::string::npos, gone);CHECK(on.find(gone) == std::string::npos, gone);}- CHECK(on.find("shadeLight(") != std::string::npos && on.find("g_shadowHard > 0.5") != std::string::npos, "the block's lights and the hard shadow stay");+ CHECK(on.find("shadeLight(") != std::string::npos && on.find("shadowTap(c + vec2f") != std::string::npos, "the block's lights and the hard shadow stay");+ CHECK(off.find("if (src <= 0.0 || g_shadowHard > 0.5) {") != std::string::npos, "with everything, a source with size takes the soft path");+ const size_t hard = on.find("let texelUv = lc.u_shadowParams.y;");+ CHECK(hard != std::string::npos && on.rfind("if (true) {", hard) != std::string::npos+ && on.find("if (src <= 0.0 || g_shadowHard > 0.5) {") == std::string::npos,+ "a source with size is shadowed hard, not left unshadowed, when the soft path is compiled out");+}int main() {