Convex Editor
![](https://static.wixstatic.com/media/bd49bc_6f82ca1385684f68851f179a4395ec7ff000.jpg/v1/fill/w_866,h_487,al_c,q_85,usm_0.66_1.00_0.01,enc_avif,quality_auto/bd49bc_6f82ca1385684f68851f179a4395ec7ff000.jpg)
Project Overview
Building BVH
For each convex, I calculate it's bouding AABB when I generate it, and build Bouding Volume Hierachy of AABBs recursively to acceleration raycast intersection. To manage convex, I only make leaf node could own a vector of convex.
![](https://static.wixstatic.com/media/bd49bc_474cdc1f69f24709b6bdad67f1c09526f000.jpg/v1/fill/w_457,h_257,al_c,q_80,usm_0.66_1.00_0.01,enc_avif,quality_auto/bd49bc_474cdc1f69f24709b6bdad67f1c09526f000.jpg)
Building BVH for Convex
Code For Building BVH Recusively
In my scene,with BVH is at least 3 times faster than without BVH, if the attribution of random rays are less random. The performance improvement will be greater. It only takes 13 ms with 130k rays vs 8 convex.
![](https://static.wixstatic.com/media/bd49bc_9ef5855435bf4bc08ee1a2b2843354e5f000.jpg/v1/fill/w_457,h_257,al_c,q_80,usm_0.66_1.00_0.01,enc_avif,quality_auto/bd49bc_9ef5855435bf4bc08ee1a2b2843354e5f000.jpg)
How Much Dose BVH Acceleration Intersection
Raycast vs Convex
Red point means inward point, green point means outward point. The ray hits a convex only when the middle point of last red point and the first green point is inside the convex.
![](https://static.wixstatic.com/media/bd49bc_79b031d493204f4e96b363e68f588a53f000.jpg/v1/fill/w_457,h_257,al_c,q_80,usm_0.66_1.00_0.01,enc_avif,quality_auto/bd49bc_79b031d493204f4e96b363e68f588a53f000.jpg)
Raycast vs Convex and Debug Draw
Code for Raycast vs Convex
Screenshots
![](https://static.wixstatic.com/media/bd49bc_00b397e03b8f4d8faf9f51c824bdfe62~mv2.png/v1/fill/w_980,h_490,al_c,q_90,usm_0.66_1.00_0.01,enc_avif,quality_auto/bd49bc_00b397e03b8f4d8faf9f51c824bdfe62~mv2.png)
![](https://static.wixstatic.com/media/bd49bc_d733b4f1d8fb4b7bb1414977cc0e4eb1~mv2.png/v1/fill/w_980,h_487,al_c,q_90,usm_0.66_1.00_0.01,enc_avif,quality_auto/bd49bc_d733b4f1d8fb4b7bb1414977cc0e4eb1~mv2.png)
![](https://static.wixstatic.com/media/bd49bc_3da9a4c9818442758ffa2e4df6823034~mv2.png/v1/fill/w_980,h_488,al_c,q_90,usm_0.66_1.00_0.01,enc_avif,quality_auto/bd49bc_3da9a4c9818442758ffa2e4df6823034~mv2.png)
![](https://static.wixstatic.com/media/bd49bc_00b397e03b8f4d8faf9f51c824bdfe62~mv2.png/v1/fill/w_980,h_490,al_c,q_90,usm_0.66_1.00_0.01,enc_avif,quality_auto/bd49bc_00b397e03b8f4d8faf9f51c824bdfe62~mv2.png)