-
-
Notifications
You must be signed in to change notification settings - Fork 35.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebGLRenderer: Fix binding __webglFramebuffer when mipmaps are used. #30746
Conversation
Draft for now to get the ball rolling – I want to complete a working demo before I finish |
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
I can confirm this is good to go now! CC @Mugen87 |
@haxiomic Wow these look stunning! Are you planning to send a PR with these improvements too? |
Thanks @mrdoob! It would be great to get these improvements in, there's a few interesting pieces That demo relies on a some utilities which I've open sourced here: https://github.com/haxiomic/haxiomic-engine, might be a few bits three can benefit from – for example there's a fast gaussian blur implementation (uses the hardware bilinear sampling to reduce fetches and pre-computes texture coordinates to enable early fetch optimisations) For anyone looking to replicate, the pipeline looks like this bloomMipmapsMaterial = new BloomMipmapsMaterial();
...
// render scene to texture
Rendering.renderPass(renderer, {
target: mainTarget,
scene: scene,
camera: camera,
toneMapping: NoToneMapping,
});
// blur (linear color space) into the mipmap chain
generateBlurredMipmaps(renderer, {
target: mainTarget,
blurKernel_heightFraction: 0.0173, // size of mip 0 -> mip 1 blur radius relative to height
truncationSigma: 0.567,
});
// copy to screen (sRGB) while applying mipmap bloom
Rendering.shaderPass(renderer, {
target: null,
shader: bloomMipmapsMaterial,
toneMapping: ACESToneMapping,
uniforms: {
source: mainTarget.texture,
bloomFalloff: 0.386,
bloomStrength: 0.0328,
minLod: 1,
}
}); I will need to think how to use with EffectCompositor. I tend to use this Shader passes are such a common operation it's nice to have a primitive for this so we don't need to think about setting up a scene or camera |
AO is still in development but I can take a look at making three.js examples once that's done |
That would be great!🙏 |
@sunag FYI |
Closes #30745
Related issue: #29779
Description
It's possible render into specific mipmap levels when we set the target.texture.mipmaps array. This works great for color-only render targets, however if we give this target a depth buffer (either through depthBuffer: true or an explicit depthTexture), rendering will fail with a crash when rendering
The crash is caused by three.js assuming .__webglFramebuffer is a single framebuffer, however, when .mipmaps is set it becomes an array:
This causes a crash on this line
three.js/src/renderers/webgl/WebGLTextures.js
Line 1663 in fc4ef55
And
three.js/src/renderers/webgl/WebGLTextures.js
Line 1532 in fc4ef55
Maybe other places too
This PR resolves this by instead setting the depth attachment for only mipmap 0.
I will also think about setting a depth attachment for each mip level
I've tried to use idomatic three.js style which comes out quite verbose but let me know if we want something tidier!