Render to mipmap level


Is there a way to directly render to individual mipmap levels of a render target texture via shaders or similar? I want to update the mipmap each frame with a custom function.

This is exactly what we do in our HDR filtering process

It requires mostly a manual setup of the renderTarget and so when rendering but you should be able to heavily inspire yourself from the code.

If not do not hesitate to share a playground with where you are at.

1 Like

This is exactly what I was looking for. Thanks for pointing me in the right direction.

So, I have tried to mimic the HDR filtering code you have linked but I cannot manage to get what I want. I have created a somewhat minimal example playground demonstrating my issue:

In this small example, I try to render the screen coordinates as colors into a render texture. The render texture is then displayed using a ShaderMaterial on the ground plane.

However, when I try to render into mip level 1, it instead seems to render into level 0 but at half the size. In the playground, you can see a colored square appear in the upper left quadrant of the ground plane. This is supported by the fact that texelFetch with an LOD of 1 doesn’t return any colored pixels.

Is there something I’m missing?

Rendering to a lod of a 2d texture is currently not supported.

I will try to address it ASAP

Will be working after Fix render to texture mips by sebavan · Pull Request #14418 · BabylonJS/Babylon.js · GitHub where an example of usage is available in the description.

1 Like

Amazing! Can confirm that it works on my end. Thanks for the fix.