From 0572a4e1dd4d60bc99516dc5d7d4d57fee8215e9 Mon Sep 17 00:00:00 2001 From: Florian Rival Date: Fri, 20 Aug 2021 12:40:09 +0200 Subject: [PATCH] Make objects effects updated just before the rendering (like layers) * Update method names to make this very obvious * Also fix wrong parameters --- .../Builtin/BaseObjectExtension.cpp | 6 +-- Extensions/Effects/adjustment-pixi-filter.ts | 2 +- .../Effects/advanced-bloom-pixi-filter.ts | 2 +- Extensions/Effects/ascii-pixi-filter.ts | 2 +- Extensions/Effects/bevel-pixi-filter.ts | 2 +- .../Effects/black-and-white-pixi-filter.ts | 2 +- .../Effects/blending-mode-pixi-filter.ts | 2 +- Extensions/Effects/blur-pixi-filter.ts | 2 +- Extensions/Effects/brightness-pixi-filter.ts | 2 +- Extensions/Effects/bulge-pinch-pixi-filter.ts | 2 +- Extensions/Effects/color-map-pixi-filter.ts | 2 +- .../Effects/color-replace-pixi-filter.ts | 2 +- Extensions/Effects/crt-pixi-filter.ts | 2 +- .../Effects/displacement-pixi-filter.ts | 2 +- Extensions/Effects/dot-pixi-filter.ts | 2 +- Extensions/Effects/drop-shadow-pixi-filter.ts | 2 +- Extensions/Effects/glitch-pixi-filter.ts | 2 +- Extensions/Effects/glow-pixi-filter.ts | 2 +- Extensions/Effects/godray-pixi-filter.ts | 2 +- Extensions/Effects/kawase-blur-pixi-filter.ts | 2 +- Extensions/Effects/light-night-pixi-filter.ts | 2 +- Extensions/Effects/night-pixi-filter.ts | 2 +- Extensions/Effects/noise-pixi-filter.ts | 2 +- Extensions/Effects/old-film-pixi-filter.ts | 2 +- Extensions/Effects/outline-pixi-filter.ts | 2 +- Extensions/Effects/pixelate-pixi-filter.ts | 2 +- Extensions/Effects/radial-blur-pixi-filter.ts | 2 +- Extensions/Effects/reflection-pixi-filter.ts | 2 +- Extensions/Effects/rgb-split-pixi-filter.ts | 2 +- Extensions/Effects/sepia-pixi-filter.ts | 2 +- Extensions/Effects/tilt-shift-pixi-filter.ts | 2 +- Extensions/Effects/twist-pixi-filter.ts | 2 +- Extensions/Effects/zoom-blur-pixi-filter.ts | 2 +- Extensions/ExampleJsExtension/dummyeffect.ts | 11 +++-- .../cocos-renderers/layer-cocos-renderer.ts | 2 +- GDJS/Runtime/layer.ts | 7 ++- .../pixi-renderers/layer-pixi-renderer.ts | 2 +- .../pixi-renderers/pixi-effects-manager.ts | 13 +++-- .../pixi-renderers/pixi-filters-tools.ts | 8 ++-- GDJS/Runtime/runtimescene.ts | 47 ++++++++++++------- 40 files changed, 89 insertions(+), 71 deletions(-) diff --git a/Core/GDCore/Extensions/Builtin/BaseObjectExtension.cpp b/Core/GDCore/Extensions/Builtin/BaseObjectExtension.cpp index b09f5f3ccc1f..0730cda2c7be 100644 --- a/Core/GDCore/Extensions/Builtin/BaseObjectExtension.cpp +++ b/Core/GDCore/Extensions/Builtin/BaseObjectExtension.cpp @@ -1089,7 +1089,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsBaseObjectExtension( _("Change the value of a parameter of an effect.") + "\n" + _("You can find the parameter names (and change the effect " "names) in the effects window."), - _("Set _PARAM2_ to _PARAM3_ for effect _PARAM3_ of _PARAM0_"), + _("Set _PARAM2_ to _PARAM3_ for effect _PARAM1_ of _PARAM0_"), _("Effects"), "res/actions/effect24.png", "res/actions/effect.png") @@ -1104,7 +1104,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsBaseObjectExtension( _("Change the value (string) of a parameter of an effect.") + "\n" + _("You can find the parameter names (and change the effect " "names) in the effects window."), - _("Set _PARAM2_ to _PARAM3_ for effect _PARAM3_ of _PARAM0_"), + _("Set _PARAM2_ to _PARAM3_ for effect _PARAM1_ of _PARAM0_"), _("Effects"), "res/actions/effect24.png", "res/actions/effect.png") @@ -1132,7 +1132,7 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsBaseObjectExtension( obj.AddCondition("IsEffectEnabled", _("Effect is enabled"), _("Check if the effect on an object is enabled."), - _("Effect _PARAM2_ on _PARAM1_ is enabled"), + _("Effect _PARAM1_ of _PARAM0_ is enabled"), _("Effects"), "res/actions/effect24.png", "res/actions/effect.png") diff --git a/Extensions/Effects/adjustment-pixi-filter.ts b/Extensions/Effects/adjustment-pixi-filter.ts index 701ab264724b..9fa37f6a4585 100644 --- a/Extensions/Effects/adjustment-pixi-filter.ts +++ b/Extensions/Effects/adjustment-pixi-filter.ts @@ -4,7 +4,7 @@ namespace gdjs { const adjustmentFilter = new PIXI.filters.AdjustmentFilter(); return adjustmentFilter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { const adjustmentFilter = (filter as unknown) as PIXI.filters.AdjustmentFilter; if (parameterName === 'gamma') { diff --git a/Extensions/Effects/advanced-bloom-pixi-filter.ts b/Extensions/Effects/advanced-bloom-pixi-filter.ts index 7804a16f184c..33d249773117 100644 --- a/Extensions/Effects/advanced-bloom-pixi-filter.ts +++ b/Extensions/Effects/advanced-bloom-pixi-filter.ts @@ -4,7 +4,7 @@ namespace gdjs { const advancedBloomFilter = new PIXI.filters.AdvancedBloomFilter(); return advancedBloomFilter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { const advancedBloomFilter = (filter as unknown) as PIXI.filters.AdvancedBloomFilter; if (parameterName === 'threshold') { diff --git a/Extensions/Effects/ascii-pixi-filter.ts b/Extensions/Effects/ascii-pixi-filter.ts index 7924e429b8ed..ff19558be52c 100644 --- a/Extensions/Effects/ascii-pixi-filter.ts +++ b/Extensions/Effects/ascii-pixi-filter.ts @@ -4,7 +4,7 @@ namespace gdjs { const asciiFilter = new PIXI.filters.AsciiFilter(); return asciiFilter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { const asciiFilter = (filter as unknown) as PIXI.filters.AsciiFilter; if (parameterName === 'size') { diff --git a/Extensions/Effects/bevel-pixi-filter.ts b/Extensions/Effects/bevel-pixi-filter.ts index 563b1ce167a0..ae213896f0c1 100644 --- a/Extensions/Effects/bevel-pixi-filter.ts +++ b/Extensions/Effects/bevel-pixi-filter.ts @@ -4,7 +4,7 @@ namespace gdjs { const bevelFilter = new PIXI.filters.BevelFilter(); return bevelFilter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { const bevelFilter = (filter as unknown) as PIXI.filters.BevelFilter; if (parameterName === 'rotation') { diff --git a/Extensions/Effects/black-and-white-pixi-filter.ts b/Extensions/Effects/black-and-white-pixi-filter.ts index 35dfbe5b182e..6d8460aaa4fc 100644 --- a/Extensions/Effects/black-and-white-pixi-filter.ts +++ b/Extensions/Effects/black-and-white-pixi-filter.ts @@ -6,7 +6,7 @@ namespace gdjs { colorMatrix.blackAndWhite(false); return colorMatrix; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { // @ts-ignore - unsure why PIXI.filters is not recognised. const colorMatrix = (filter as unknown) as PIXI.filters.ColorMatrixFilter; diff --git a/Extensions/Effects/blending-mode-pixi-filter.ts b/Extensions/Effects/blending-mode-pixi-filter.ts index 6c2134a71f3c..ef01f4182590 100644 --- a/Extensions/Effects/blending-mode-pixi-filter.ts +++ b/Extensions/Effects/blending-mode-pixi-filter.ts @@ -5,7 +5,7 @@ namespace gdjs { const blendingModeFilter = new PIXI.filters.AlphaFilter(); return blendingModeFilter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { // @ts-ignore - unsure why PIXI.filters is not recognised. const blendingModeFilter = (filter as unknown) as PIXI.filters.AlphaFilter; diff --git a/Extensions/Effects/blur-pixi-filter.ts b/Extensions/Effects/blur-pixi-filter.ts index c1ffaedfbb95..20ae38b50cc4 100644 --- a/Extensions/Effects/blur-pixi-filter.ts +++ b/Extensions/Effects/blur-pixi-filter.ts @@ -5,7 +5,7 @@ namespace gdjs { const blur = new PIXI.filters.BlurFilter(); return blur; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { if ( parameterName !== 'blur' && diff --git a/Extensions/Effects/brightness-pixi-filter.ts b/Extensions/Effects/brightness-pixi-filter.ts index 2587114ca0ab..0e177539502c 100644 --- a/Extensions/Effects/brightness-pixi-filter.ts +++ b/Extensions/Effects/brightness-pixi-filter.ts @@ -6,7 +6,7 @@ namespace gdjs { brightness.brightness(1, false); return brightness; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { // @ts-ignore - unsure why PIXI.filters is not recognised. const brightnessFilter = (filter as unknown) as PIXI.filters.ColorMatrixFilter; diff --git a/Extensions/Effects/bulge-pinch-pixi-filter.ts b/Extensions/Effects/bulge-pinch-pixi-filter.ts index e9f4ceacfe03..a2dd4adb1edc 100644 --- a/Extensions/Effects/bulge-pinch-pixi-filter.ts +++ b/Extensions/Effects/bulge-pinch-pixi-filter.ts @@ -4,7 +4,7 @@ namespace gdjs { const bulgePinchFilter = new PIXI.filters.BulgePinchFilter(); return bulgePinchFilter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { const bulgePinchFilter = (filter as unknown) as PIXI.filters.BulgePinchFilter; if (parameterName === 'centerX') { diff --git a/Extensions/Effects/color-map-pixi-filter.ts b/Extensions/Effects/color-map-pixi-filter.ts index 5c8b055c1dc4..deb43d402c72 100644 --- a/Extensions/Effects/color-map-pixi-filter.ts +++ b/Extensions/Effects/color-map-pixi-filter.ts @@ -17,7 +17,7 @@ namespace gdjs { ); return colorMapFilter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { const colorMapFilter = (filter as unknown) as PIXI.filters.ColorMapFilter; if (parameterName === 'mix') { diff --git a/Extensions/Effects/color-replace-pixi-filter.ts b/Extensions/Effects/color-replace-pixi-filter.ts index d6596e471773..d1ecca500c17 100644 --- a/Extensions/Effects/color-replace-pixi-filter.ts +++ b/Extensions/Effects/color-replace-pixi-filter.ts @@ -4,7 +4,7 @@ namespace gdjs { const colorReplaceFilter = new PIXI.filters.ColorReplaceFilter(); return colorReplaceFilter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { const colorReplaceFilter = (filter as unknown) as PIXI.filters.ColorReplaceFilter; if (parameterName === 'epsilon') { diff --git a/Extensions/Effects/crt-pixi-filter.ts b/Extensions/Effects/crt-pixi-filter.ts index 1865d3315098..fe8574b71558 100644 --- a/Extensions/Effects/crt-pixi-filter.ts +++ b/Extensions/Effects/crt-pixi-filter.ts @@ -7,7 +7,7 @@ namespace gdjs { crtFilter._animationTimer = 0; return crtFilter; }, - update: function (filter, target) { + updatePreRender: function (filter, target) { if (filter.animationSpeed !== 0) { // Multiply by 10 so that the default value is a sensible speed filter.time += diff --git a/Extensions/Effects/displacement-pixi-filter.ts b/Extensions/Effects/displacement-pixi-filter.ts index 342f8afb0cd1..06585538eaf0 100644 --- a/Extensions/Effects/displacement-pixi-filter.ts +++ b/Extensions/Effects/displacement-pixi-filter.ts @@ -14,7 +14,7 @@ namespace gdjs { ); return displacementFilter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { // @ts-ignore - unsure why PIXI.filters is not recognised. const displacementFilter = (filter as unknown) as PIXI.filters.DisplacementFilter; diff --git a/Extensions/Effects/dot-pixi-filter.ts b/Extensions/Effects/dot-pixi-filter.ts index 5b2e31223374..1486497f82fe 100644 --- a/Extensions/Effects/dot-pixi-filter.ts +++ b/Extensions/Effects/dot-pixi-filter.ts @@ -4,7 +4,7 @@ namespace gdjs { const dotFilter = new PIXI.filters.DotFilter(); return dotFilter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { const dotFilter = (filter as unknown) as PIXI.filters.DotFilter; if (parameterName === 'scale') { diff --git a/Extensions/Effects/drop-shadow-pixi-filter.ts b/Extensions/Effects/drop-shadow-pixi-filter.ts index 55f730cfbf7e..9ef270975c67 100644 --- a/Extensions/Effects/drop-shadow-pixi-filter.ts +++ b/Extensions/Effects/drop-shadow-pixi-filter.ts @@ -4,7 +4,7 @@ namespace gdjs { const dropShadowFilter = new PIXI.filters.DropShadowFilter(); return dropShadowFilter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { const dropShadowFilter = (filter as unknown) as PIXI.filters.DropShadowFilter; if (parameterName === 'blur') { diff --git a/Extensions/Effects/glitch-pixi-filter.ts b/Extensions/Effects/glitch-pixi-filter.ts index e0e8b6084cd1..62b54b5d3460 100644 --- a/Extensions/Effects/glitch-pixi-filter.ts +++ b/Extensions/Effects/glitch-pixi-filter.ts @@ -7,7 +7,7 @@ namespace gdjs { glitchFilter._animationTimer = 0; return glitchFilter; }, - update: function (filter, target) { + updatePreRender: function (filter, target) { if (filter.animationFrequency !== 0) { filter._animationTimer += target.getElapsedTime() / 1000; if (filter._animationTimer >= 1 / filter.animationFrequency) { diff --git a/Extensions/Effects/glow-pixi-filter.ts b/Extensions/Effects/glow-pixi-filter.ts index 9354698b0c7b..7a8ba75e222e 100644 --- a/Extensions/Effects/glow-pixi-filter.ts +++ b/Extensions/Effects/glow-pixi-filter.ts @@ -4,7 +4,7 @@ namespace gdjs { const glowFilter = new PIXI.filters.GlowFilter(); return glowFilter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { const glowFilter = (filter as unknown) as PIXI.filters.GlowFilter; if (parameterName === 'innerStrength') { diff --git a/Extensions/Effects/godray-pixi-filter.ts b/Extensions/Effects/godray-pixi-filter.ts index fe785a64446e..a7cc1215fb4e 100644 --- a/Extensions/Effects/godray-pixi-filter.ts +++ b/Extensions/Effects/godray-pixi-filter.ts @@ -6,7 +6,7 @@ namespace gdjs { const godrayFilter = new PIXI.filters.GodrayFilter(); return godrayFilter; }, - update: function (filter, target) { + updatePreRender: function (filter, target) { if (filter.animationSpeed !== 0) { filter.time += (target.getElapsedTime() / 1000) * filter.animationSpeed; } diff --git a/Extensions/Effects/kawase-blur-pixi-filter.ts b/Extensions/Effects/kawase-blur-pixi-filter.ts index 0fb0814b574c..3d0f50c1dd08 100644 --- a/Extensions/Effects/kawase-blur-pixi-filter.ts +++ b/Extensions/Effects/kawase-blur-pixi-filter.ts @@ -4,7 +4,7 @@ namespace gdjs { const kawaseBlurFilter = new PIXI.filters.KawaseBlurFilter(); return kawaseBlurFilter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { const kawaseBlurFilter = (filter as unknown) as PIXI.filters.KawaseBlurFilter; if (parameterName === 'pixelizeX') { diff --git a/Extensions/Effects/light-night-pixi-filter.ts b/Extensions/Effects/light-night-pixi-filter.ts index 59e1a6e059c3..5aec36c65f80 100644 --- a/Extensions/Effects/light-night-pixi-filter.ts +++ b/Extensions/Effects/light-night-pixi-filter.ts @@ -27,7 +27,7 @@ namespace gdjs { const filter = new gdjs.LightNightPixiFilter(); return filter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { if (parameterName !== 'opacity') { return; diff --git a/Extensions/Effects/night-pixi-filter.ts b/Extensions/Effects/night-pixi-filter.ts index 888f123be65d..ee258d017aa6 100644 --- a/Extensions/Effects/night-pixi-filter.ts +++ b/Extensions/Effects/night-pixi-filter.ts @@ -31,7 +31,7 @@ namespace gdjs { const filter = new gdjs.NightPixiFilter(); return filter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { if (parameterName !== 'intensity' && parameterName !== 'opacity') { return; diff --git a/Extensions/Effects/noise-pixi-filter.ts b/Extensions/Effects/noise-pixi-filter.ts index 355c7572fbac..ff6bbed76938 100644 --- a/Extensions/Effects/noise-pixi-filter.ts +++ b/Extensions/Effects/noise-pixi-filter.ts @@ -5,7 +5,7 @@ namespace gdjs { const noiseFilter = new PIXI.filters.NoiseFilter(); return noiseFilter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { // @ts-ignore - unsure why PIXI.filters is not recognised. const noiseFilter = (filter as unknown) as PIXI.filters.NoiseFilter; diff --git a/Extensions/Effects/old-film-pixi-filter.ts b/Extensions/Effects/old-film-pixi-filter.ts index dbf710c3858a..6353382188f7 100644 --- a/Extensions/Effects/old-film-pixi-filter.ts +++ b/Extensions/Effects/old-film-pixi-filter.ts @@ -7,7 +7,7 @@ namespace gdjs { oldFilmFilter._animationTimer = 0; return oldFilmFilter; }, - update: function (filter, target) { + updatePreRender: function (filter, target) { if (filter.animationFrequency !== 0) { filter._animationTimer += target.getElapsedTime() / 1000; if (filter._animationTimer >= 1 / filter.animationFrequency) { diff --git a/Extensions/Effects/outline-pixi-filter.ts b/Extensions/Effects/outline-pixi-filter.ts index f4b0d4f1782c..d129b9d5c514 100644 --- a/Extensions/Effects/outline-pixi-filter.ts +++ b/Extensions/Effects/outline-pixi-filter.ts @@ -4,7 +4,7 @@ namespace gdjs { const outlineFilter = new PIXI.filters.OutlineFilter(); return outlineFilter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { const outlineFilter = (filter as unknown) as PIXI.filters.OutlineFilter; if (parameterName === 'thickness') { diff --git a/Extensions/Effects/pixelate-pixi-filter.ts b/Extensions/Effects/pixelate-pixi-filter.ts index ef24ba0ee7cc..0c464b22fe80 100644 --- a/Extensions/Effects/pixelate-pixi-filter.ts +++ b/Extensions/Effects/pixelate-pixi-filter.ts @@ -6,7 +6,7 @@ namespace gdjs { ); return pixelateFilter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { const pixelateFilter = (filter as unknown) as PIXI.filters.PixelateFilter; if (parameterName === 'size') { diff --git a/Extensions/Effects/radial-blur-pixi-filter.ts b/Extensions/Effects/radial-blur-pixi-filter.ts index 20da7033acbf..681310b5547e 100644 --- a/Extensions/Effects/radial-blur-pixi-filter.ts +++ b/Extensions/Effects/radial-blur-pixi-filter.ts @@ -4,7 +4,7 @@ namespace gdjs { const radialBlurFilter = new PIXI.filters.RadialBlurFilter(); return radialBlurFilter; }, - update: function (filter, target) { + updatePreRender: function (filter, target) { const radialBlurFilter = (filter as unknown) as PIXI.filters.RadialBlurFilter; radialBlurFilter.center[0] = Math.round( // @ts-ignore - extra properties are stored on the filter. diff --git a/Extensions/Effects/reflection-pixi-filter.ts b/Extensions/Effects/reflection-pixi-filter.ts index 9884552df9ee..1330f9d9cabc 100644 --- a/Extensions/Effects/reflection-pixi-filter.ts +++ b/Extensions/Effects/reflection-pixi-filter.ts @@ -23,7 +23,7 @@ namespace gdjs { ); return reflectionFilter; }, - update: function (filter, target) { + updatePreRender: function (filter, target) { if (filter.animationSpeed !== 0) { filter.time += (target.getElapsedTime() / 1000) * filter.animationSpeed; } diff --git a/Extensions/Effects/rgb-split-pixi-filter.ts b/Extensions/Effects/rgb-split-pixi-filter.ts index 13cbb2134d83..f176d7d6c34a 100644 --- a/Extensions/Effects/rgb-split-pixi-filter.ts +++ b/Extensions/Effects/rgb-split-pixi-filter.ts @@ -4,7 +4,7 @@ namespace gdjs { const rgbSplitFilter = new PIXI.filters.RGBSplitFilter(); return rgbSplitFilter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { const rgbSplitFilter = (filter as unknown) as PIXI.filters.RGBSplitFilter; if (parameterName === 'redX') { diff --git a/Extensions/Effects/sepia-pixi-filter.ts b/Extensions/Effects/sepia-pixi-filter.ts index fbe11ce691b4..bba31e1823e9 100644 --- a/Extensions/Effects/sepia-pixi-filter.ts +++ b/Extensions/Effects/sepia-pixi-filter.ts @@ -6,7 +6,7 @@ namespace gdjs { colorMatrixFilter.sepia(false); return colorMatrixFilter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { // @ts-ignore - unsure why PIXI.filters is not recognised. const colorMatrixFilter = (filter as unknown) as PIXI.filters.ColorMatrixFilter; diff --git a/Extensions/Effects/tilt-shift-pixi-filter.ts b/Extensions/Effects/tilt-shift-pixi-filter.ts index 3e46b3b9bd05..83f3c45aaf2d 100644 --- a/Extensions/Effects/tilt-shift-pixi-filter.ts +++ b/Extensions/Effects/tilt-shift-pixi-filter.ts @@ -4,7 +4,7 @@ namespace gdjs { const tiltShiftFilter = new PIXI.filters.TiltShiftFilter(); return tiltShiftFilter; }, - update: function (filter, target) {}, + updatePreRender: function (filter, target) {}, updateDoubleParameter: function (filter, parameterName, value) { const tiltShiftFilter = (filter as unknown) as PIXI.filters.TiltShiftFilter; if (parameterName === 'blur') { diff --git a/Extensions/Effects/twist-pixi-filter.ts b/Extensions/Effects/twist-pixi-filter.ts index 4be2610e7ad3..8569ec9c0d44 100644 --- a/Extensions/Effects/twist-pixi-filter.ts +++ b/Extensions/Effects/twist-pixi-filter.ts @@ -10,7 +10,7 @@ namespace gdjs { twistFilter.offset = new PIXI_.Point(0, 0); return twistFilter; }, - update: function (filter, target) { + updatePreRender: function (filter, target) { const twistFilter = (filter as unknown) as PIXI.filters.TwistFilter; twistFilter.offset.x = Math.round( // @ts-ignore - extra properties are stored on the filter. diff --git a/Extensions/Effects/zoom-blur-pixi-filter.ts b/Extensions/Effects/zoom-blur-pixi-filter.ts index 2e40dfe4ce5f..ef9ae39591f5 100644 --- a/Extensions/Effects/zoom-blur-pixi-filter.ts +++ b/Extensions/Effects/zoom-blur-pixi-filter.ts @@ -4,7 +4,7 @@ namespace gdjs { const zoomBlurFilter = new PIXI.filters.ZoomBlurFilter(); return zoomBlurFilter; }, - update: function (filter, target) { + updatePreRender: function (filter, target) { const zoomBlurFilter = (filter as unknown) as PIXI.filters.ZoomBlurFilter; zoomBlurFilter.center[0] = Math.round( // @ts-ignore - extra properties are stored on the filter. diff --git a/Extensions/ExampleJsExtension/dummyeffect.ts b/Extensions/ExampleJsExtension/dummyeffect.ts index 403a7b7f92c2..acde7f0ba6bc 100644 --- a/Extensions/ExampleJsExtension/dummyeffect.ts +++ b/Extensions/ExampleJsExtension/dummyeffect.ts @@ -57,11 +57,12 @@ namespace gdjs { ); return filter; }, - // Function called at every frame rendered - update: function (filter, layer) {}, - // If your filter depends on the time, you can get the elapsed time - // with `layer.getElapsedTime()`. - // You can update the uniforms or other state of the filter. + // Function called at every frame, after events and before the frame is rendered. + updatePreRender: function (filter, layer) { + // If your filter depends on the time, you can get the elapsed time + // with `layer.getElapsedTime()`. + // You can update the uniforms or other state of the filter. + }, // Function that will be called to update a (number) parameter of the PIXI filter with a new value updateDoubleParameter: function (filter, parameterName, value) { if (parameterName === 'opacity') { diff --git a/GDJS/Runtime/cocos-renderers/layer-cocos-renderer.ts b/GDJS/Runtime/cocos-renderers/layer-cocos-renderer.ts index 6c5175551443..af8130c98fbf 100644 --- a/GDJS/Runtime/cocos-renderers/layer-cocos-renderer.ts +++ b/GDJS/Runtime/cocos-renderers/layer-cocos-renderer.ts @@ -140,7 +140,7 @@ namespace gdjs { this._cocosLayer.setVisible(visible); } - update(): void {} + updatePreRender(): void {} // Unimplemented updateClearColor(): void {} diff --git a/GDJS/Runtime/layer.ts b/GDJS/Runtime/layer.ts index eb9bddb8601a..d4b706f5ade9 100644 --- a/GDJS/Runtime/layer.ts +++ b/GDJS/Runtime/layer.ts @@ -124,14 +124,13 @@ namespace gdjs { /** * Called at each frame, after events are run and before rendering. - * @param [runtimeScene] The scene the layer belongs to. */ - update(runtimeScene?: gdjs.RuntimeScene): void { + updatePreRender(runtimeScene?: gdjs.RuntimeScene): void { if (this._followBaseLayerCamera) { this.followBaseLayer(); } - this._renderer.update(); - this._effectsManager.update(this._rendererEffects, this); + this._renderer.updatePreRender(); + this._effectsManager.updatePreRender(this._rendererEffects, this); } /** diff --git a/GDJS/Runtime/pixi-renderers/layer-pixi-renderer.ts b/GDJS/Runtime/pixi-renderers/layer-pixi-renderer.ts index caca7e3ae4d9..d0291e3a657f 100644 --- a/GDJS/Runtime/pixi-renderers/layer-pixi-renderer.ts +++ b/GDJS/Runtime/pixi-renderers/layer-pixi-renderer.ts @@ -82,7 +82,7 @@ namespace gdjs { this._pixiContainer.visible = !!visible; } - update(): void { + updatePreRender(): void { if (this._renderTexture) { this._updateRenderTexture(); } diff --git a/GDJS/Runtime/pixi-renderers/pixi-effects-manager.ts b/GDJS/Runtime/pixi-renderers/pixi-effects-manager.ts index 7c8fe9b78c84..0459f2197ce2 100644 --- a/GDJS/Runtime/pixi-renderers/pixi-effects-manager.ts +++ b/GDJS/Runtime/pixi-renderers/pixi-effects-manager.ts @@ -52,7 +52,7 @@ namespace gdjs { updateDoubleParameter: filterCreator.updateDoubleParameter, updateStringParameter: filterCreator.updateStringParameter, updateBooleanParameter: filterCreator.updateBooleanParameter, - update: filterCreator.update, + updatePreRender: filterCreator.updatePreRender, }; if (target.isLightingLayer && target.isLightingLayer()) { @@ -81,13 +81,16 @@ namespace gdjs { /** * Update the filters applied on a PixiJS DisplayObject. - * @param runtimeObject - * @param target + * This must be called after the events and before the rendering. + * + * This allows effects to be sure that they are up to date and ready + * to render. This is not called on objects that are not rendered on screen + * ("culling"). This is always called on layers. */ - update(rendererEffects: RendererEffects, target: EffectsTarget) { + updatePreRender(rendererEffects: RendererEffects, target: EffectsTarget) { for (const filterName in rendererEffects) { const filter = rendererEffects[filterName]; - filter.update(filter.pixiFilter, target); + filter.updatePreRender(filter.pixiFilter, target); } } diff --git a/GDJS/Runtime/pixi-renderers/pixi-filters-tools.ts b/GDJS/Runtime/pixi-renderers/pixi-filters-tools.ts index 099579d69546..492c0587f71f 100644 --- a/GDJS/Runtime/pixi-renderers/pixi-filters-tools.ts +++ b/GDJS/Runtime/pixi-renderers/pixi-filters-tools.ts @@ -90,8 +90,8 @@ namespace gdjs { export type FilterCreator = { /** Function to call to create the filter */ makePIXIFilter: (target: EffectsTarget, effectData: EffectData) => any; - /** The function to be called to update the filter at every frame */ - update: (filter: PIXI.Filter, target: gdjs.EffectsTarget) => any; + /** The function to be called to update the filter at every frame before the rendering. */ + updatePreRender: (filter: PIXI.Filter, target: gdjs.EffectsTarget) => any; /** The function to be called to update a parameter (with a number) */ updateDoubleParameter: ( filter: PIXI.Filter, @@ -116,8 +116,8 @@ namespace gdjs { export type Filter = { /** The PIXI filter */ pixiFilter: PIXI.Filter; - /** The function to be called to update the filter at every frame */ - update: (filter: PIXI.Filter, target: gdjs.EffectsTarget) => any; + /** The function to be called to update the filter at every frame before the rendering. */ + updatePreRender: (filter: PIXI.Filter, target: gdjs.EffectsTarget) => any; /** The function to be called to update a parameter (with a number) */ updateDoubleParameter: ( filter: PIXI.Filter, diff --git a/GDJS/Runtime/runtimescene.ts b/GDJS/Runtime/runtimescene.ts index b8dbd76a3c02..5ba914632fd4 100644 --- a/GDJS/Runtime/runtimescene.ts +++ b/GDJS/Runtime/runtimescene.ts @@ -509,16 +509,16 @@ namespace gdjs { this._profiler.end('callbacks and extensions (post-events)'); } if (this._profiler) { - this._profiler.begin('objects (pre-render)'); + this._profiler.begin('objects (pre-render, effects update)'); } this._updateObjectsPreRender(); if (this._profiler) { - this._profiler.end('objects (pre-render)'); + this._profiler.end('objects (pre-render, effects update)'); } if (this._profiler) { this._profiler.begin('layers (effects update)'); } - this._updateLayers(); + this._updateLayersPreRender(); if (this._profiler) { this._profiler.end('layers (effects update)'); } @@ -577,19 +577,22 @@ namespace gdjs { } } - _updateLayers() { + /** + * Called to update effects of layers before rendering. + */ + _updateLayersPreRender() { for (const name in this._layers.items) { if (this._layers.items.hasOwnProperty(name)) { - /** @type gdjs.Layer */ - const theLayer: gdjs.Layer = this._layers.items[name]; - theLayer.update(this); + const layer = this._layers.items[name]; + layer.updatePreRender(this); } } } /** * Called to update visibility of the renderers of objects - * rendered on the scene and give a last chance for objects to update before rendering. + * rendered on the scene ("culling"), update effects (of visible objects) + * and give a last chance for objects to update before rendering. * * Visibility is set to false if object is hidden, or if * object is too far from the camera of its layer ("culling"). @@ -601,8 +604,16 @@ namespace gdjs { const object = this._allInstancesList[i]; const rendererObject = object.getRendererObject(); if (rendererObject) { - object.getRendererObject().visible = !object.isHidden(); + rendererObject.visible = !object.isHidden(); + + // Update effects, only for visible objects. + if (rendererObject.visible) { + this._runtimeGame + .getEffectsManager() + .updatePreRender(object.getRendererEffects(), object); + } } + // Perform pre-render update. object.updatePreRender(this); } @@ -613,9 +624,11 @@ namespace gdjs { // TODO: For compatibility, pass a scale of `2`, // meaning that size of cameras will be multiplied by 2 and so objects // will be hidden if they are outside of this *larger* camera area. - // Useful for objects not properly reporting their visibility AABB, + // This is useful for: + // - objects not properly reporting their visibility AABB, // (so we have a "safety margin") but these objects should be fixed // instead. + // - objects having effects rendering outside of their visibility AABB. this._updateLayersCameraCoordinates(2); this._constructListOfAllInstances(); for (let i = 0, len = this._allInstancesList.length; i < len; ++i) { @@ -642,6 +655,14 @@ namespace gdjs { rendererObject.visible = true; } } + + // Update effects, only for visible objects. + if (rendererObject.visible) { + this._runtimeGame + .getEffectsManager() + .updatePreRender(object.getRendererEffects(), object); + } + // Perform pre-render update. object.updatePreRender(this); } @@ -710,15 +731,9 @@ namespace gdjs { const elapsedTimeInSeconds = elapsedTime / 1000; obj.setX(obj.getX() + averageForce.getX() * elapsedTimeInSeconds); obj.setY(obj.getY() + averageForce.getY() * elapsedTimeInSeconds); - this._runtimeGame - .getEffectsManager() - .update(obj.getRendererEffects(), obj); obj.update(this); obj.updateForces(elapsedTimeInSeconds); } else { - this._runtimeGame - .getEffectsManager() - .update(obj.getRendererEffects(), obj); obj.update(this); } obj.updateTimers(elapsedTime);