Issues when copying custom mips into chain every frame

I’m running into an issue with copying custom mips into a mip chain in this playground:

In the playground, I get a lot of WebGL: INVALID_OPERATION: uniform1f: location is not from the associated program errors and the lodLevel uniform doesn’t appear to be set correctly for LOD0 (it’s coming through as 1 instead of 0).
If I don’t render every frame using scene.onBeforeRenderObservable, things work correctly and there are no WebGL errors.

Any ideas?

btw, #ifdef GL_ES is always true in WebGL, so you don’t need to use it

It is a race condition:

You cannot bind the render texture to a render path if it is used as a render target. So I changed the order of operation: Rendertarget, unbind from framebuffer then bind as a texture

Thanks, @Deltakosh. A race condition of some kind certainly makes sense.
However, your changed playground still exhibits the same behaviour. i.e. the WebGL error and incorrect uniform value for lodLevel == 0.

I think porting all these shaders to webgpu killed my brain :slight_smile:
Custom LOD rendering | Babylon.js Playground (babylonjs.com)

So the change I did was to see the lod value AFTER activating the effect. This ensures that the active shader is in place

Thank you.
Now, I have a follow-up question. This PR recreates an issue I’m having with my IBL shadowing branch.
I’m attempting to copy existing custom mips into the mip chain with the “pass” shader but it seems to be using the UI RT instead of the one I’m trying to assign.

pinging @sebavan as he is the mastermind behind the EffectWrapper :wink:

Thanks.
I’ve also pinged him in the associated PR.

1 Like

It seems that there is a conflict with the rendering of the Procedural Texture:
Custom LOD rendering | Babylon.js Playground (babylonjs.com)

Why do you need your render target to be a procedural texture if you generate the content ?

I generate the base mip using the ProceduralTexture because it’s an easy way to render a texture with just a fragment shader. i.e. without having to define a full-screen quad, etc.
I could create another RT and copy all mips into it, including the base mip but that’s another copy of the base mip, which is a 3D voxel grid and isn’t small (even a 256^3, single-byte texture is 16 MB).

As you read from a 3d texture, you need a 3d sampler and you can not use the default pass from babylon: https://playground.babylonjs.com/#T9J1HL#30

This would also probably need the layer as a parameter instead of hard coded.

1 Like

Boy, do I feel dim…
You’re exactly right and it’s working now :slight_smile:

Feel the same mate:) I did not think about it either ;D

ahah It is way easier when you did not work on it :slight_smile: This is the kind of stuff only another pair of eyes can spot.