www.xbdev.net
xbdev - software development
Wednesday January 15, 2025
Home | Contact | Support | WebGPU Graphics and Compute ...
     
 

WebGPU/WGSL Tutorials and Articles

Graphics and Compute ...

 


Mesh to Spheres (Bounding Spheres)


Why convert a mesh to spheres?

Often the graphical mesh can be very detailed and complex - even simple meshes can be in the tens of thousands! Which is fine for `graphics` - but when we have to interact with these meshes we don't want to go cycling through all these triangles and checking for collisions.

We could calculate a bounding sphere or box - but we want something a bit more flexible and detailed!

Lots of Spheres

One solution is to use the GPU to calculate a simplified sphere grid - we want to do this on the GPU as these graphical meshes can be big - and we don't want to go looping over all of these triangles/vertices - it can be slow! The GPU however, can do this in parallel - distribute the calculations across multiple cores.



Example of high resolution mesh model (king chess character) converted to a grid of spheres.
Example of high resolution mesh model (king chess character) converted to a grid of spheres.



Algorithm Steps

Details about the algorithm (high-level overview)
1. Load the mesh (obviously)
2. Iterate over the mesh and find the `minimum` and `maximum`
3. Decide on a level of detail - granuarity (e.g., 16x16x16 cells)
4. Each of the 16x16x16 cells is run on a GPU thread
5. Each thread has access to all the triangles and the bounds
6. We use an atomic to keep track of which cells have been used avoid duplicating spheres
7. Each thead loops over the triangles and calculates the bounding box for each triangle - then it finds which cells (multiple cells) and adds a sphere to a list
8. That's it! We have a list of spheres that reresents the mesh

The algorithm can also use a Seperating Axis Test (SAT) for each triangle-cell (box) check - if the triangles are large (better fit).



Skull mesh with various grid resolutions (16, 32, 64).
Skull mesh with various grid resolutions (16, 32, 64).



The complete source code and various test versions/proof of concept (and other WebGPU examples) is provided in the resource section at the end.


Resources & Links


Code and interactive example (webgpulab)














WebGPU Development Pixels - coding fragment shaders from post processing to ray tracing! WebGPU by Example: Fractals, Image Effects, Ray-Tracing, Procedural Geometry, 2D/3D, Particles, Simulations WebGPU Games WGSL 2d 3d interactive web-based fun learning WebGPU Compute WebGPU API - Owners WebGPU Development Cookbook - coding recipes for all your webgpu needs! WebGPU & WGSL Essentials: A Hands-On Approach to Interactive Graphics, Games, 2D Interfaces, 3D Meshes, Animation, Security and Production Kenwright graphics and animations using the webgpu api 12 week course kenwright learn webgpu api kenwright programming compute and graphics applications with html5 and webgpu api kenwright real-time 3d graphics with webgpu kenwright webgpu for dummies kenwright webgpu api develompent a quick start guide kenwright webgpu by example 2022 kenwright webgpu gems kenwright webgpu interactive compute and graphics visualization cookbook kenwright wgsl webgpu shading language cookbook kenwright WebGPU Shader Language Development: Vertex, Fragment, Compute Shaders for Programmers Kenwright wgsl webgpugems shading language cookbook kenwright WGSL Fundamentals book kenwright WebGPU Data Visualization Cookbook kenwright Special Effects Programming with WebGPU kenwright WebGPU Programming Guide: Interactive Graphics and Compute Programming with WebGPU & WGSL kenwright Ray-Tracing with WebGPU kenwright



 
Advert (Support Website)

 
 Visitor:
Copyright (c) 2002-2024 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.