Title: Overlapping spheres? Post by: DarkBeam on September 28, 2011, 11:18:43 PM I am wondering on this concept. Take the normal 3d space in ortho coords. A sphere lies inside...
(x-x0)**2+(y-y0)**2+(z-z0)**2<=1 okay. think about 2 spheres. r is the distance from each origin as explained min(r1,r2)<=1 is the region where both spheres exist max(r1,r2)<=1 gives the intersection but i wanted to find an appropriate fun of r1 and r2 that . far from the intersection works as min(r1,r2) or almost like . near the intersection "melts" the spheres in some way what should I use as f? wondering of an exp smoothing but how? thanks Title: Re: Overlapping spheres? Post by: DarkBeam on September 28, 2011, 11:48:51 PM Like in this example www.shipbrook.com/jeff/raytrace/blobs.html :)
Title: Re: Overlapping spheres? Post by: marius on September 29, 2011, 01:03:18 AM Like in this example www.shipbrook.com/jeff/raytrace/blobs.html :) Have you seen http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm ? Distance estimation oriented but why would you want it any other way ;D Title: Re: Overlapping spheres? Post by: fractower on September 29, 2011, 03:16:35 AM I have played with a number of partition functions while trying to spatially combine two mandelbulbs separated in space. The parameter a controls the abruptness of the transition. It is also extendable to and many circles as you want.
r_min ~= (r1 * exp(-a*r1^2) + r2 * exp(-a*r2^2))/(exp(-a*r1^2) + exp(-a*r2^2)) Changing the sign in the exp will give you r_max. A couple of examples. No bulbs were hurt in the creation of these images. http://nocache-nocookies.digitalgott.com/gallery/6/2792_06_04_11_8_51_21.jpeg (http://nocache-nocookies.digitalgott.com/gallery/6/2792_06_04_11_8_51_21.jpeg) http://nocache-nocookies.digitalgott.com/gallery/6/2792_04_04_11_9_35_59.jpeg (http://nocache-nocookies.digitalgott.com/gallery/6/2792_04_04_11_9_35_59.jpeg) Title: Re: Overlapping spheres? Post by: DarkBeam on September 29, 2011, 12:08:43 PM Like in this example www.shipbrook.com/jeff/raytrace/blobs.html :) Have you seen http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm ? Distance estimation oriented but why would you want it any other way ;D Wooo!!!! GREAT find. :D but: Blend float opBlend( vec3 p ) { float d1 = primitiveA(p); float d2 = primitiveB(p); floar dd = smoothcurve(d1-d2); return mix(d1,d2,dd); } He forgot to tell what is mix() and smoothcurve() :hmh: :fiery: :fiery: Luca ^-^ Title: Re: Overlapping spheres? Post by: DarkBeam on September 29, 2011, 12:10:37 PM I have played with a number of partition functions while trying to spatially combine two mandelbulbs separated in space. The parameter a controls the abruptness of the transition. It is also extendable to and many circles as you want. r_min ~= (r1 * exp(-a*r1^2) + r2 * exp(-a*r2^2))/(exp(-a*r1^2) + exp(-a*r2^2)) Changing the sign in the exp will give you r_max. A couple of examples. No bulbs were hurt in the creation of these images. http://nocache-nocookies.digitalgott.com/gallery/6/2792_06_04_11_8_51_21.jpeg (http://nocache-nocookies.digitalgott.com/gallery/6/2792_06_04_11_8_51_21.jpeg) http://nocache-nocookies.digitalgott.com/gallery/6/2792_04_04_11_9_35_59.jpeg (http://nocache-nocookies.digitalgott.com/gallery/6/2792_04_04_11_9_35_59.jpeg) Fantastic! I will definitely try it! :-* Title: Re: Overlapping spheres? Post by: subblue on September 29, 2011, 05:16:18 PM He forgot to tell what is mix() and smoothcurve() mix(a, b, c): result =a when c <= 0 and =b when c >= 1 with a linear blend inbetween I'm guessing smoothcurve is like the smoothstep function in OpenGL, which (from the spec): Returns 0.0 if x <= edge0 and 1.0 if x >= edge1 and performs smooth Hermite interpolation between 0 and 1 when edge0 < x < edge1. This is useful in cases where you would want a threshold function with a smooth transition. This is equivalent to: t = clamp ((x – edge0) / (edge1 – edge0), 0, 1); return t * t * (3 – 2 * t); Title: Re: Overlapping spheres? Post by: DarkBeam on September 29, 2011, 05:39:19 PM He forgot to tell what is mix() and smoothcurve() mix(a, b, c): result =a when c <= 0 and =b when c >= 1 with a linear blend inbetween I'm guessing smoothcurve is like the smoothstep function in OpenGL, which (from the spec): Returns 0.0 if x <= edge0 and 1.0 if x >= edge1 and performs smooth Hermite interpolation between 0 and 1 when edge0 < x < edge1. This is useful in cases where you would want a threshold function with a smooth transition. This is equivalent to: t = clamp ((x – edge0) / (edge1 – edge0), 0, 1); return t * t * (3 – 2 * t); I found a very similar answer in google. :) tyty!!! Title: Re: Overlapping spheres? Post by: Syntopia on September 29, 2011, 11:33:26 PM I played around with this exact problem some weeks ago.
I never really understood Quilez's formula. If I use smoothcurve(d1-d2) = smoothstep(0,1,d1-d2), I get some very asymmetric objects, not very blobby (see the top of attached pictures). Also, if you look at slide 42 in his 'Rendering Worlds...' (http://www.iquilezles.org/www/material/nvscene2008/rwwtt.pdf), he uses a different formula - here he uses a global distance to interpolate: smoothstep(length(p),0,1) - notice the order of arguments?. And if you look at the Slisesix demo code, it seems he just mixes linearly ("float a = clamp( r*3.0, 0.0, 1.0 ); return c*a + d*(1.0-a);"). I came up with the following formula, which mixes linearly based on the distance from the center of each object (I could not find a good formula based on the ratios of the distance estimates, even though I would have preferred it). Fragmentarium code: Code: include "DE-Raytracer.frag" This produces the lower image. I also just tried fractowers formula, but it seems not very 'blobby' to me either - at least not if the r1 and r2 are distance estimates. It does, however, provide a nice controllable weighting if you mix the distance estimates by the distances to the center: Code: return (d1*exp(-A*r1*r1) + d2*exp(-A*r2*r2)) / (exp(-A*r1*r1) + exp(-A*r2*r2)); Title: Re: Overlapping spheres? Post by: Syntopia on September 30, 2011, 12:05:21 AM I just realized that there is a much simpler way:
Just take the union with the product of the distance estimates: Code: float DE( vec3 p ) This gives a nice symmetric blobby interpolation, and the blobbiness can be controlled by adjusting the 'n' factor. Besides that, it uses only distance estimates, and also works for unsigned distances. It also has the nice property that it will always add to volume, never remove from it. Title: Re: Overlapping spheres? Post by: DarkBeam on September 30, 2011, 12:20:20 AM Fantastic ... Thanks for those replies :)
Title: Re: Overlapping spheres? Post by: fractower on September 30, 2011, 12:47:25 AM The formula I originally provided returns a value with a lower bound of min(r1,r2). To get the blobby stuff you will need a formula the treates min(r1,r2) as an upper bound. This can be done by using a harmonic addition.
r_min ~= (exp(-a*r1^2) + exp(-a*r2^2))/((1/r1) * exp(-a*r1^2) + (1/r2) * exp(-a*r2^2)) or r_min = 1/(1/r1 + 1/r2). I usually protect against devide by zero with 1/(r+.00000001) Title: Re: Overlapping spheres? Post by: DarkBeam on September 30, 2011, 08:31:28 AM Anyway, reading the original blob article, I think that the accurate fmla shoul depend on a min and max radii.
under the min rad nothing should happen (so we can take safely min(r1,r2) over it we can start mangling. I think that syntopia's approach is good, edventually fixed with an exponential function? To emulate the "thin bridge" effect (the plasticity should be adjusted with a max/minrad factor in the original blob method). To see things clearly anyway I need more images and to test by myself. There is no hurry :D Title: Re: Overlapping spheres? Post by: KRAFTWERK on September 30, 2011, 09:24:43 AM Wow... This sounds tasty! O0 :beer:
Title: Re: Overlapping spheres? Post by: DarkBeam on September 30, 2011, 09:40:19 AM Wow... This sounds tasty! O0 :beer: Sure! Think about a blob-based folding or sphere inversion or decombine :DFor now decombines are "static" anyways Title: Re: Overlapping spheres? Post by: knighty on September 30, 2011, 10:52:21 PM You could also try:
Code: munion(a,b,alpha){I found those formulas some time ago in a document about implicit surface modeling and rendering. I will add the reference if I could retrive it. Title: Re: Overlapping spheres? Post by: knighty on September 30, 2011, 11:13:59 PM Ooops! These operations actually give smooth distance field. You will see the difference only when you add some value to the DE:
"munion(a,b,0)" will give the same result as "min(a,b)" but "munion(a,b,0)-0.5" is different from "min(a,b)-0.5". Title: Re: Overlapping spheres? Post by: Syntopia on September 30, 2011, 11:45:11 PM I realized that the method I posted earlier had some serious drawbacks. It is dependenT on the detail setting (minimum distance stopping treshold), so it is not a proper distance estimate. It also scales poorly for multiple objects (since you need to do all-pairwise distance products).
I did some Googling and found out that blending was actually already described in John Hart's original zeno paper: http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.48.3825 (Soft Metablobbies section) Hart's method is local meaning you can define a radius outside which nothing will be affected. It also scales nicely to multiple objects. Code: #include "DE-Raytracer.frag" Ooops! These operations actually give smooth distance field. You will see the difference only when you add some value to the DE: "munion(a,b,1)" will give the same result as "min(a,b)" but "munion(a,b,1)+0.5" is different from "min(a,b)+0.5". You want to subtract something from the 'munion', right? I tried your method - as might be seen on the picture below, it is a global method, so the sphere and box will change shapes also farther away from the melting point. Title: Re: Overlapping spheres? Post by: knighty on October 01, 2011, 04:22:08 PM You want to subtract something from the 'munion', right? I tried your method - as might be seen on the picture below, it is a global method, so the sphere and box will change shapes also farther away from the melting point. Yes, I was a little bit confused because it has been a long time since I've played with it. They are actually called R-functions. See for example this paper (http://le2i.cnrs.fr/IMG/publications/PG05.pdf) or this document (http://www.cs.princeton.edu/courses/archive/fall02/cs526/papers/course11sig96.pdf).(corrected the previous post :)) Title: Re: Overlapping spheres? Post by: Jesse on October 03, 2011, 05:19:02 PM Had some problems with a quick implementation of some of the suggested formulas, so i did some own tests and this is what i received so far for the min-combination of distance estimates:
delta1 = Min(0, DE1 - DEcombSmooth); delta2 = Min(0, DE2 - DEcombSmooth); DEtmp1 = DE1 + delta1 * (DEcombSmooth + delta2) / DEcombSmooth; DEtmp2 = DE2 + delta2 * (DEcombSmooth + delta1) / DEcombSmooth); DE = Min(DEtmp1, DEtmp2); And the pic: Title: Re: Overlapping spheres? Post by: Jesse on October 03, 2011, 05:21:09 PM And with a linear combination:
DEtmp1 = DE1 + Min(0, DE2 - DEcombSmooth); DEtmp2 = DE2 + Min(0, DE1 - DEcombSmooth); DE = Min(DEtmp1, DEtmp2); The non-linear method had a DEcombSmooth value of 3, so the effect is not very big compared to the linear one that had a value of 1... where DEcombSmooth is the absolute distance of the overlap. Title: Re: Overlapping spheres? Post by: DarkBeam on October 03, 2011, 08:37:34 PM What about the blobby method? :D :beer:
Title: Re: Overlapping spheres? Post by: Jesse on October 04, 2011, 08:05:12 PM What about the blobby method? :D :beer: The one and only one, ehmm lets see... dunno whats about it :dink: I just tried Hart's method like in Syntopias code, but have to figure out how to get a general working version with T and other parameters... by now i got only something that looked like my linear version, but it should get better than that. The non-linear version i posted is more like knighty's one, but it might be more easy to implement in a general way, at least for me. Doc, my bulb behaves blobby: Title: Re: Overlapping spheres? Post by: DarkBeam on October 04, 2011, 10:17:02 PM It looks really awesome as is! Ideal for crazy movies with semifluid fractals! lol :D
Title: Re: Overlapping spheres? Post by: hobold on October 04, 2011, 11:46:41 PM The trouble with "blobby" blending, regardless of the exact implementation, is that it is always a smoothing operation that tends to drown fractal detail (all small details, in fact, like sharp cusps and ridges and edges). So this kind of thing can only enrich fractal construction in the sense that it can selectively remove the "fractal-ness" in some places.
Title: Re: Overlapping spheres? Post by: fractower on October 05, 2011, 12:31:11 AM I have been playing with combining 2 or more escape time fractals which are spacially seperated. Assume the origins of the fractals are O1 and O2 respectively. The first step is to calculate the weight to be applied to each fractal. W1 = exp(-a1 * |z-O1|^2) / ( exp(-a1 * |z-O1|^2) + exp(-a2 * |z-O2|^2)) W2 = exp(-a2 * |z-O2|^2) / ( exp(-a1 * |z-O1|^2) + exp(-a2 * |z-O2|^2)) W1 + W2 =1. The a terms provide a zone of influence. A should be small enough so that the transition is not too abrupt. Calculate z1 and z2 for each fractal then combine z_new = W1*z1 + W2*z2. I have found it best to keep the fractals seperate by at least the escape shell. If the exp is too abrupt, 1/|z-O2|^n will work but n must be greater than the power term in the fractal. For example an 8th order mandelbulb will need an n of 9 or more. |