I just released v0.5.0 this weekend which includes signature changes to a number of the BVH functions to help simplify function arguments and make the results more consistent and the ability to use SharedArrayBuffers so the same BVH memory can be used across multiple WebWorkers. The functions will log a warning if you’re using the old signature so it should hopefully make the transition easy if you’re using a function that’s changed. If you’ve just been using three-mesh-bvh to override and accelerate Mesh.raycast then no changes will be needed!
Release notes here:
And for fun a couple more path traced images made with the code from the new demo!
This library is awesome. I downloaded it for some collision detection, but once I’d tried the demos…
I make room/product configurators, and it would be fantastic to offer some browser based raytracing. At the moment I download a scene and take it through Blender/Cycles.
This is the most realistic lighting I’ve ever seen in threejs. Props gkjohnson!
@Peter_Devine this is awesome! And what a clever approach to getting color working without full material support. Thanks for sharing. After a few more changes the raycasting shader code will be available to use in the next release and I’m pretty excited about the possibilities of raytracing in a shader.
What is the name of the example with the rabbit? Could you share the link?
If you take a look at the list of demos it’s listed as the lasso selection example. The demo uses a torus knot geometry instead, though.
In example PointCloudIntersection, is that just Intersection with the point?
As explained above the point intersection example is just using degenerate triangles to emulate point queries. The demo shows raycasting but with the shapecast function you can implement any kind of spatial query you want.
@gkjohnson Cheers! Looking forward very much to the next release.
I couldn’t work out a way to reduce the “intensity” of the shadows, so I ended up boosting the ambient light when rendering. Must admit I still couldn’t work out quite how it worked, but was blown away by the results. Shame we don’t have AI noise reduction in the browser yet, but I suppose it’s only a matter of time
couldn’t work out a way to reduce the “intensity” of the shadows
The throughput *= 1.0 / PI; is what attenuates the intensity after a light bounce for the Lambertian model. You can change it to fit what you want stylistically but I believe 1 / PI is what is physically correct and the reason shadows and corners get dark after multiple bounces.
Shame we don’t have AI noise reduction in the browser yet, but I suppose it’s only a matter of time
There’s probably some kind of noise reduction that can be done without AI but that’s beyond the scope of the small demo, though. Possible a future project.
It certainly looks correct
It’s obviously the lighting pass which it missing.
I’ll try the cpu version, which I can see includes lighting.
I just couldn’t get the workers to function from the demo.
Version 0.5.1 of three-mesh-bvh has been released! As Peter found early the newest release includes some helpers and shader functions for raycasting against the BVH in a shader which can be used for things like path tracing, runtime lightmap generation, and other gpgpu applications! The release also includes new typescript definition files.
Here’s the latest demo for path tracing on the GPU which renders a simple Lambertian material. Perhaps at some point I’ll create a more robust gpu path tracing project:
For those interested the BVH and associated geometry vertex buffer attributes are packed into the textures so they can be sampled in the fragment shader. The shader coder for performing a raycast query is pretty simple, as well. Check out the example code for a full demonstration of how set the shader up! Looking forward to seeing what people make!
It’s best to come up with an algorithm for achieving the effect you’re looking for without the BVH first. With or without the BVH the results for your chart will have to be sorted based on the domain of the overhead lines you’ve drawn for the cross section chart. Once that’s been figured out you can use the BVH to accelerate the generation of the cross section.
The “clipped edges” or “selection” examples should provide a good start for how to the BVH and “shapecast” function to accelerate the intersections.
function getNearestPointIndex(point, points){
let index = 0;
for (let i = 0; i < points.length; i++){
let p = points[i];
if (p.checked == false && p.equals(point, tolerance)){
index = i;
break;
}
}
return index;
}
which would be very slow for a large number of points but Im guessing I could use BVH raycast to point cloud example to find the coincident points to greatly speed this up but it means creating a new point cloud with each point becoming a face. Is there a better way?
I’ve put together a separate repo with a demo Lambertian GPU Path Tracer using three-mesh-bvh that includes support for basic material properties, textures, an environment map, tiled renderer, and mroe. Check out the project page here!
Thanks! It’s using a technique called “raytracing” or “path tracing”. There are some resources at the bottom of the README in the three-gpu-pathtracing repo.
Yes you can use the “shapecast” function to determine which triangles are hit, save the indices of the triangles, and then adjust the vertices accordingly. The sculpting example does something similar if you’d like to take a look there. Just keep in mind that the BVH must be rebuilt or adjusted after the vertices have been moved so the bounds include the shifted vertices.
Here’s the function in the sculpting example that finds and adjusts the vertices.