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
WebGL is a complicated API, and it's often not obvious what the recommended ways to use it are. This page tackles recommendations across the spectrum of expertise, and not only highlights dos and don'ts, but also details why. You can rely on this...
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
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
Thanks.
I’ve also pinged him in the associated PR.
BabylonJS:master
← MiiBond:mbond/ibl-shadows
opened 03:26PM - 15 May 24 UTC
This PR adds an `IblShadowsRenderPipeline` that adds shadowing for image-based l… ighting (IBL). It's applied as a post process after rendering your scene. You must assign an HDR environment with `setIblTexture` to enable the shadowing. Both cubemaps and equirectangular IBL's work.
This pipeline builds a voxel grid for all the meshes in the scene that you want to cast shadows. You can exclude meshes (e.g. the skybox, ground plane, etc.) by calling `addExcludedMesh` on the pipeline. The voxel grid needs to be re-generated every time something in the scene moves and this can be an expensive operation (depending on the voxel resolution) so **it's most suitable for static scenes** in its current form. Note that the camera can move and the IBL environment is free to rotate or change completely without having to rebuild the voxel grid.
Using this voxel grid, shadows are generated by sampling the IBL and then applied to the scene as a greyscale approximation. In combination with this, we can also calculate screen-space shadows to handle shadowing of small details.
Here's a PG to test with:
https://playground.babylonjs.com/#8R5SSE#165
**Some important exposed settings:**
* voxel resolution - the dimension of the voxel grid, in voxels. Directly affects how sharp the shadows are. Must be power-of-two.
* sample directions - how many samples of the voxel grid per pixel. Increasing this results in less noise but adds significantly to the per-frame cost of shadows
* toggling screen-space shadows - SS shadows add small shadow detail close to the shadow caster but may not be needed in all scenes so this is togglable and has various settings to control how they behave.
**Updating the voxel grid:**
* When a mesh is added or removed from a scene, the voxelization of the scene is automatically rebuilt.
* When a mesh moves in the scene, you must call `updateSceneBounds` to get the shadows to rebuild. Is there some place that I could do this automatically for users?
**Things that still need work:**
* The voxel tracing is currently done in an extremely naïve way and tends to miss voxels, especially at higher voxel resolutions. I have an algorithm using octrees mostly implemented that will be significantly better quality but I wanted to get this PR in sooner.
* The shadows are greyscale and are an approximation of the light intensity blocked by an object. They often over-darken surfaces because of this. I have plans to improve this and also add better support for coloured lighting.
* IBL shadows don't currently work with multiple cameras (mostly due to this issue https://forum.babylonjs.com/t/viewport-issue-when-using-prepassrenderer/51276)
* WebGPU is not yet fully supported.
* When WebGPU is working, I should be able to make use of compute shaders to significantly speed up voxel grid generation.
* Various performance and quality tweaks. e.g. support downsizing the buffers for faster speed.
![IBL Shadows](https://github.com/BabylonJS/Babylon.js/assets/1069125/7fb09b3f-93f2-40c2-aa8a-3e5161bed46e)
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
Feel the same mate:) I did not think about it either ;D
sebavan
August 10, 2024, 12:01am
14
ahah It is way easier when you did not work on it This is the kind of stuff only another pair of eyes can spot.