ShukantPal / pixi-essentials

The best goodies for performant, enterprise-level applications built on PixiJS
https://api.pixijs.io
MIT License
285 stars 37 forks source link

[Question] How to trigger re-render (when filter changes)? #59

Closed Friksel closed 2 years ago

Friksel commented 2 years ago

I've set a displacementfilter on an SVGScene. When changing the displacement texture on a tick the SVGScene needs to update, but doesn't do that. I've tried setting _transformDirty = true; of the scene on each tick but it doesn't update the rendering.

How can we update the effect of filter(s) on the SVGScene?

Thanks in advance!

ShukantPal commented 2 years ago

Hmm you might need to wrap the scene in a container and apply the filter on the container. SVGScene doesn't support filtering directly

Friksel commented 2 years ago

Hmm you might need to wrap the scene in a container and apply the filter on the container. SVGScene doesn't support filtering directly

@ShukantPal thanks for your quick response. It happened to be something I missed; I needed to add the sprite used in the displacement filter to the stage too, even though the sprite shouldn't be visible and is only used for the displacement. After adding the sprite to the stage the filter is updating when changing the sprite's position.

SVGScene doesn't support filtering directly

No wrapper container was needed; I could just add the filter to the root element of the SVGScene and it worked out of the box. So looks supported to me.

On each tick the sprite is moving, causing the displacement to move, but guess the SVGScene is still cached and never needs to re-cache as basically only the filter shader changes?

ShukantPal commented 2 years ago

The SVGScene only caches the transforms of display object inside it. If the filter changes, those changes will be re rendered correctly

Friksel commented 2 years ago

The SVGScene only caches the transforms of display object inside it. If the filter changes, those changes will be re rendered correctly

Ah ok. I thought the SVGScene was cached as bitmap after each scale. So I understand that's not the case?

Only the sprite used as displacement map changes its position to move the displacement. I don't change the filter parameters themselves. Does this still mean a re-render of the SVGScene? If so, I'm not sure if I understand; the transforms don't change by just moving the texture used for a Displacement filter right? Isn't the displacement filter under water not just a shader used to filter a bitmap?

ShukantPal commented 2 years ago

No we don't cache the scene as a bitmap.

The SVG scene is re-rendered according to your render loop. So any changes other than to transforms should work well.