How to apply shader based prefiltering on a texture?

I’m trying to prefilter a texture through a fragment shader, as in the flow goes like this:

  • Load texture: const texture = new Texture(url...);
  • Apply glsl based custom filter to the texture: const filteredTexture = ?? (Render to rendertarget, create new texture from it)
  • And then dispose original texture and pass filtered texture to be used by a material.

With my attempts so far I have came across EffectRenderer and EffectWrapper etc. but it seems like I’m getting deeper into Babylon.js internals and it still isn’t quite working yet. So I’m wondering if I’m either missing an existing util to do this or maybe there is a Playground example somewhere to use as reference?

cc @Evgeni_Popov @sebavan

I got it working. Here is a Playground link in case someone is looking for similar solution in the future: https://www.babylonjs-playground.com/#IMDVID#1

2 Likes

Is this the confirmed solution? I am looking at processing a video stream using a list of filters and using the modified texture in a shader. The ImageFilter type seems designed for this purpose, but I would like to understand the cost of either.

r

@sebavan our filter king :slight_smile: