Comments (6)
Interesting topic here! drawIndirect is also part of my roadmap for achieving a new type of 'static' scene that I have in mind for threejs. I have started working on it here, with the support of the CAD software Plasticity.
Here is how I envision my roadmap:
- Add RenderBundle support with this pull request.
- Implement a single buffer pass with the pull request of @aardgoose #27388 to batch all the writeBuffer commands in one command, already bundled by a RenderBundle.
- Add a global UBO pipeline (UBO for the camera and scene elements such as fog, etc.) to update only a single UBO per frame, (instead of pre-calculating the
modelViewMatrix
on the CPU per mesh per frame) and multiply camera matrices by model matrices directly on the GPU instead of on the CPU. - Add frustum culling support via indirect draw calls and compute shading as described in Toji's article Render Bundles and Object Culling.
Each feature on this roadmap should be cherry-pickable once shipped to three.js.
I have never studied Unreal Nanite technology, but I believe all these features combined would be what's needed for this type of GPU rendering
from three.js.
I've been implementing that exactly, and you may take an interest to #28103 in lieu of indirect draw or some of my GPU driven experiments with meshlets and culling/visibility tests particularly https://twitter.com/Cody_J_Bennett/status/1736555185541886407, https://twitter.com/Cody_J_Bennett/status/1730911419707842973.
from three.js.
Hi @CodyJasonBennett I have came across your gpu-culling code before and if im understanding it only discards the fragment shader by setting the w value to 0 if not visible in the vertex shader. This is my issue with current solutions, same with BatchedMesh.
I have done some tests and discarding geometry in the vertex shader gives some performance boost but not a lot, specially considering that most meshlets won't be rendered. Also would be great to discard things on a geometry level and not on a geometry vertex level, if a whole meshlet is not visible I would like to just discard the whole thing in one go instead of discarding each vertex, wasting gpu.
With drawIndirect we can do something like (each is a compute pass):
- With meshlets AABB's and indices perform visibility culling
- Prefix sum
- Reindex
- Count visible meshlets
- Create indirect buffer based on above
After all done drawIndirect can be used with the GPU data to directly render the visible meshlets only, no need to go over invisible ones, also no gpu->cpu transfer is needed. Keep in mind that rendering the meshlets is not the issue, I have implemented something akin of an InstancedMesh for meshlets that can draw many instances in one draw call. The visibility culling is the problem, in non web environments this is easily solvable by using mesh shaders.
Offtopic but big fan of four, planning on using it as a base for what im trying to do above.
from three.js.
FWIW those experiments were as close as I could get to GPU driven rendering which is comparably trivial in WebGPU. The use of transform feedback performs culling at the instance or batch level and then the vertex shader will short circuit if the resulting instance buffer is zeroed. Doesn't work so great for virtualized geometry where you have a fixed number of vertices or vertex buffer memory; you want to move data and this can only be done with compute or carefully vectorized CPU code via WASM with GPU driver overhead from upload (introduces latency). May be the easiest path for you in the near term since you're already using METIS and Meshoptimizer.
On the topic of indirect drawing in WebGPU, or more specifically the WebGL compatibility side, my knee-jerk thought is to fallback to multi-draw (hence the backlink to my PR), but the data is different. WebGPU expects an interleaved buffer with draw arguments, but multi-draw expects separate buffers per argument, and they have to be consumed on the CPU. It may be best to consider this feature WebGPU only and consider compatibility only when proven feasible (cc @RenaudRohlinger, curious of your opinion here). This is one of the flagship features of WebGPU people migrate specifically for, alongside GPU shared memory, atomics, multisampled textures, etc. There is no WebGL 2 equivalent, even if it can be ported in a strictly worse fashion.
from three.js.
I'm not sure how that relates to this issue. What's described here is indirect drawing which would benefit from an interface with compute. That seems like a backlog of issues which affect WebGPURenderer
generally.
from three.js.
I won't hijack this issue any further, but I'm happy to explore this topic in WebGPU and later WebGL 2 (with expected latency). Today, I would lean with WASM + multi-draw which could use #28103. This is an area I've incidentally been studying which was the motivation behind all the prior work I linked. Awesome progress and great to see I'm not alone on the web, Bevy aside.
from three.js.
Related Issues (20)
- Editor: Missing `User Data` input in Geometry tab HOT 1
- readRenderTargetPixels() works for WebGLRenderTarget but is all 0 for WebGL3DRenderTarget HOT 21
- Please allow FBXLoader to use every non native texture that ThreeJS can load HOT 1
- It seems like there is an issue with outputNode in connection with depthNode HOT 1
- Rendering a scene including points with an override material causes inconsistent behavior HOT 2
- Target is not updated when panning the camera in ArcballControls HOT 1
- [WebGPU] Control Access Barriers HOT 1
- Suggestion of docs improvement. HOT 1
- ShaderMaterial for Hand breaks their motion tracking in WebXR (Quest3 tested) HOT 2
- [TSL] Invalid output, missing conversion of type in some cases HOT 1
- [TSL] Adding .label to a uniform prevent it from being updated through .value =
- TextureBinding includes writable usage and another usage in the same synchronisation scope HOT 7
- The download address for the homepage is still version 164, not version 165 HOT 1
- TSL: Missing While Support
- Please allow full testing on components by running CI/CD tests in real DOM environment and support loading assets from disk
- rotate-to-cursor on touch events HOT 1
- VolumeNodeMaterial only renders 1x1x1
- normal z-buffer #webgl_camera_logarithmicdepthbuffer rendering issues cross OS, gpu, browser HOT 3
- Uncaught (in promise) ReferenceError: Request is not defined HOT 2
- TSL: Unusual right associativeness of `sub` and `div`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from three.js.