Clipping Solids (SDF functions)

shaders
points
clipping

#1

Hi community!

Here is a picture:

And there is a working example:

This topic is an evolving of the previous one

Just had a thought, what if there’s a shorter way to check, if a point is inside of a solid body.
And I’ve remembered about the distance functions from some good articles of Inigo Quilez.
So, why not give those functions a try?
The result, as you can see, looks promising. You can set primitives by formulas, then translate, rotate or distort them, thus you set the area of visibility. The more flexibilty, the more funny stuff you can do :slight_smile:

Update #1

Update #2
Another approach

Update #3
Approach #2 coloured by indices


Collection of sphere definitions
📕 Three.js Bookshelf
#2

This is fantastic!

Have you found a way to determine whether the points are inside any arbitrary geometry? Or does it have to be defined by a mathematical equation, like the twisted cube? I was working on an identical “volumetric display” project to show models through particles, but haven’t been able to figure out how to calculate when the particle is inside the geometry :frowning_face:. The best I’ve been able to do so far is to find the geometry faces via depthMap render.

Check it out: http://dyadstudios.com/playground/volumetric/


#3

Yes, the box is defined in the shader:

// http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
float udBox( vec3 p, vec3 b )
{
  return length(max(abs(p)-b,0.0));
}

Unfortunately, I have no idea of how to do that stuff with arbitrary geometries.

The only way I can imagine is that you can model complex solids by combining the primitives described with the distance functions. But the more complex the model, the more complex shaders you get :thinking:

Just have a look at the source code of the raymarching shader, there you can find all the functions for primitives:
https://www.shadertoy.com/view/Xds3zN

Very cool idea! :+1:


#4

Not sure if someone needs this technique at all :thinking: , but I’ve made some additional examples and put them as updates in the main post.