From a7e88d8c40972d158d899e3d21e15d5a4f9a02ce Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 8 Oct 2026 08:56:25 +0000 Subject: [PATCH] [Reviewed] [3D light] Use the Three.js r185 light falloff on every GDevelop version Point and spot lights now fade with the physically based falloff of Three.js r185 (used by recent GDevelop versions) on older GDevelop versions too, by patching their "legacy lights" shader. Lights then look the same whatever the GDevelop version. This is a breaking change: lights made for the previous versions need a higher intensity (and possibly a lower decay). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FXhdCRasV6YVFStxiKPZM8 --- extensions/reviewed/Light3D.json | 57 +++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/extensions/reviewed/Light3D.json b/extensions/reviewed/Light3D.json index 855a14b71..14b7117f9 100644 --- a/extensions/reviewed/Light3D.json +++ b/extensions/reviewed/Light3D.json @@ -10,7 +10,7 @@ "name": "Light3D", "previewIconUrl": "https://asset-resources.gdevelop.io/public-resources/Icons/f237ae4e3b857c556846c7b2c0b132556fd4bcdeff217034b4d9c97dc1aab1d6_lightbulb-on-outline.svg", "shortDescription": "A collection of light object for 3D.", - "version": "1.0.6", + "version": "2.0.0", "description": "A collection of light object for 3D.", "origin": { "identifier": "Light3D", @@ -23,10 +23,62 @@ "authorIds": [ "IWykYNRvhCZBN3vEgKEbBPOR3Oc2" ], + "changelog": [ + { + "version": "2.0.0", + "breaking": "- Point and spot lights now fade with the distance like they do with the 3D renderer of recent GDevelop versions (Three.js r185), including on previous GDevelop versions. Lights made for a previous version of the extension need a higher intensity (and possibly a lower decay) to look the same." + } + ], "dependencies": [], "globalVariables": [], "sceneVariables": [], "eventsFunctions": [ + { + "fullName": "", + "functionType": "Action", + "name": "onFirstSceneLoaded", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::JsCode", + "inlineCode": [ + "// Before Three.js r165, GDevelop rendered with \"legacy lights\": point and spot", + "// lights faded linearly up to their range and every light color was", + "// multiplied by PI. Recent GDevelop versions use the physically based falloff", + "// of Three.js r185 instead, which is what the light properties are tuned for.", + "// Use the same falloff with older GDevelop versions so that lights look the", + "// same with every version:", + "// - distances are divided by 100 because recent GDevelop versions render 3D", + "// with a default world scale of 100 pixels per unit, while older versions", + "// work in pixels,", + "// - the attenuation is divided by PI as the legacy light colors are multiplied by PI.", + "// It must be patched before any shader using lights is compiled, as Three.js", + "// caches compiled shaders.", + "const lightsParsBegin = THREE.ShaderChunk.lights_pars_begin;", + "if (!lightsParsBegin.includes('#if defined ( LEGACY_LIGHTS )')) {", + " return;", + "}", + "THREE.ShaderChunk.lights_pars_begin = lightsParsBegin.replace(", + " /#if defined \\( LEGACY_LIGHTS \\)[\\s\\S]*?#else/,", + " [", + " '#if defined ( LEGACY_LIGHTS )',", + " '\\t\\tfloat distanceFalloff = 1.0 / max( pow( lightDistance * 0.01, decayExponent ), 0.01 );',", + " '\\t\\tif ( cutoffDistance > 0.0 ) {',", + " '\\t\\t\\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );',", + " '\\t\\t}',", + " '\\t\\treturn distanceFalloff * RECIPROCAL_PI;',", + " '\\t#else',", + " ].join('\\n')", + ");" + ], + "parameterObjects": "", + "useStrict": true, + "eventsSheetExpanded": true + } + ], + "parameters": [], + "objectGroups": [] + }, { "description": "Define spot light helper classes JavaScript code.", "fullName": "Define spot light helper classes", @@ -1232,6 +1284,9 @@ "eventsFunctionsFolderStructure": { "folderName": "__ROOT", "children": [ + { + "functionName": "onFirstSceneLoaded" + }, { "functionName": "DefineHelperClasses" },