POV-Ray : Newsgroups : povray.binaries.images : messing with bubbles (23k) Server Time
19 Nov 2024 00:35:33 EST (-0500)
  messing with bubbles (23k) (Message 1 to 6 of 6)  
From: Pete
Subject: messing with bubbles (23k)
Date: 16 Feb 2002 18:28:16
Message: <3c6eeb10@news.povray.org>
Hi,

I've been playing with some macros for generating bubble
CSG objects, the aim being to create a disk where two
bubbles meet, rather than simply two intersecting
spheres. It even seems to be working (though the macros
are still a bit sloppy) as you should be able to see
if you look closely at the parts where the bubbles intersect.

The macros take an array of bubble centers and radii as input,
and should work even for large numbers of bubbles (but rendering
will probably slow down a bit ;-)

I benefitted greatly by advice I read on this news server,
about making CSG differences more efficient, to the tune of
about a 1000% (literally!!) improvement in render time,
so thanks for that, whoever you were! :-)

This 800x600 image took about 1hr to render on my K6-3 450
w/ 250M with +A0.3 and +AM2 (but about 150M free, and I was
continuously browsing the web while it ran.)  

(I can only hope my primitive binary-posting technology will
work ok on this server, since I've never tried it before.
Apologies in advance, if it doesn't pan out...)

- Pete.


Post a reply to this message


Attachments:
Download 'bubbles.jpg' (23 KB)

Preview of image 'bubbles.jpg'
bubbles.jpg


 

From: Tim Nikias
Subject: Re: messing with bubbles (23k)
Date: 16 Feb 2002 19:51:42
Message: <3C6EFE9E.929C4C0B@gmx.de>
> I benefitted greatly by advice I read on this news server,
> about making CSG differences more efficient, to the tune of
> about a 1000% (literally!!) improvement in render time,
> so thanks for that, whoever you were! :-)
>

Thanks for making all of us a part of this!


I think it looks really nice, ever thought about making a bathtub
with foam?

--
Tim Nikias
Homepage: http://www.digitaltwilight.de/no_lights/index.html


Post a reply to this message

From: Ryan Mooney
Subject: Re: messing with bubbles (23k)
Date: 17 Feb 2002 01:32:00
Message: <3C6F4E5F.E911F3AC@earthlink.net>
have you or will you post the macro for public view... ???


Post a reply to this message

From: Pete
Subject: Re: messing with bubbles (23k)
Date: 17 Feb 2002 02:52:38
Message: <3c6f6146@news.povray.org>
Tim Nikias wrote:
> I think it looks really nice,

Thanks! :)

> ever thought about making a bathtub with foam?

Foam would be nice, but I'm not sure how quick it would
be :-) Still, the macro doesn't seem to hang up the render
outside the bubble areas.. I think perhaps the right way
to do it might be to generate a bunch of positions and
radii which form a sort of skin over where the foam is
to be, perhaps one or two layers of bubbles, and then
put some texture beneath that (which won't really be
seen in detail anyhow, hopefully) in order to cut down
on the max_trace_level setting needed (because that
would get really high with large solid chunks of foam
made of all these transparent bubbles.)

It would be necessary to work up something to generate
the positions and radii appropriately - but that shouldn't
be too hard. One problem is that the macro (currently) fails
to construct the appropriate disc between two bubbles if the
center of one bubble falls inside the other.

Ryan Mooney wrote:
> have you or will you post the macro for public view... ???

I thought I would wait a bit until I fixed up some uglinesses,
but since that may take a while, and since I have no shame about
my bad pov-code, and since it's even possible if I post that it
someone else will make it nicer ... here it is! 

As is, it requires version 3.5 (for conserve_energy in the
texture definition, and for a transform macro used at one
point, but neither of these are major problems to change.) 

You'll notice I have two pretty much identical macros bubchop
and bubchop2. They started off different ...

Also, I have been too lazy to find if there's a function which
will return the length of an array, so I include that as a
parameter, which kind of smells funny, IMHO, but never mind ;-)

It expects an array definition like this

#declare TheBubbles = array[12] {
	-2.5, 1.5, 0,  3.2
	 2.5, 1.5, 0,  3.5
	 0,    -1, 0,  3.4
}

where each four elements are center.x, center.y, center.z, radius,
and then you call it with

     bubs(TheBubbles,12)

To change the texture, just edit or re-declare the BubTex definition.

8<-----C-U-T---H-E-R-E-----
#include "shapes.inc"
#include "transforms.inc"

#macro bubchop(p1,r1,p2,r2) 
#local vl = vlength(p2 - p1);
#local iptscale = abs((r1^2 - r2^2 + vl^2)/(2*vl));
#local ipt = vnormalize(p2 - p1)* iptscale;
      cylinder {
         (r2+r1)*vnormalize(ipt),0,sqrt(abs(r1^2-iptscale^2))
         translate p1 + 999*ipt/1000
      }
#end

#macro bubchop2(p1,r1,p2,r2) 
#local vl = vlength(p2 - p1);
#local iptscale = abs((r1^2 - r2^2 + vl^2)/(2*vl));
#local ipt = vnormalize(p2 - p1)* iptscale;
      cylinder {
         (r2+r1)*vnormalize(ipt),0,abs(r1^2-iptscale^2)
         translate p1 + 999/1000*ipt
      }
#end

#macro bubring(p1,r1,p2,r2) 
#local vl = vlength(p2 - p1);
#local iptscale = abs((r1^2 - r2^2 + vl^2)/(2*vl));
#local ipt = vnormalize(p2 - p1)* iptscale;
object {
   torus { 
      sqrt(abs(r1^2-iptscale^2)),
      sqrt(abs(r1^2-iptscale^2))/55 
      Point_At_Trans(ipt)
      translate p1 + ipt
   }
}
#end

#macro bubdiff2(arr,arrlen,bubndx)
#local ndx = 0;
#while (ndx < arrlen-3)
   #if (ndx!=bubndx)
   //#if
(vlength(<arr[ndx],arr[ndx+1],arr[ndx+2]>-<arr[bubndx],arr[bubndx+1],arr[bubndx+2] >)
> arr[bubndx+3])
      #if
(vlength(<arr[ndx],arr[ndx+1],arr[ndx+2]>-<arr[bubndx],arr[bubndx+1],arr[bubndx+2] >)
< (arr[ndx+3]+arr[bubndx+3]))
//       #debug "\n2: adding one..."
         #local empty=0;
         bubchop2(
            < arr[bubndx],arr[bubndx+1],arr[bubndx+2] >,
            arr[bubndx+3],
            < arr[ndx],arr[ndx+1],arr[ndx+2] >,
            arr[ndx+3]
          )
      #end
   #end
   #local ndx = ndx + 4;
#end
#end


#macro bubrings(arr,arrlen,bubndx)
#local ndx = bubndx+4;
#local empty = 1;
#while (ndx < arrlen-3)
   #if (ndx!=bubndx)
      #if
(vlength(<arr[ndx],arr[ndx+1],arr[ndx+2]>-<arr[bubndx],arr[bubndx+1],arr[bubndx+2] >)
< (arr[ndx+3]+arr[bubndx+3]))
//       #debug "\nringing one..."
         #local empty=0;
         bubring(
            < arr[bubndx],arr[bubndx+1],arr[bubndx+2] >,
            arr[bubndx+3],
            < arr[ndx],arr[ndx+1],arr[ndx+2] >,
            arr[ndx+3]
         )
      #end
   #end
   #local ndx = ndx + 4;
#end
#if (empty)
   sphere {-10000,0.00001}
#end
#end

#macro bubdiff(arr,arrlen,bubndx)
difference {
   sphere {
      <arr[bubndx],arr[bubndx+1],arr[bubndx+2]>, arr[bubndx+3]*999/1000
   }
#local ndx = 0;
#local empty = 1;
#while (ndx < arrlen-3)
   #if (ndx!=bubndx)
      #if
(vlength(<arr[ndx],arr[ndx+1],arr[ndx+2]>-<arr[bubndx],arr[bubndx+1],arr[bubndx+2] >)
< (arr[ndx+3]+arr[bubndx+3]))
//       #debug "\nadding one..."
         #local empty=0;
         bubchop(
            < arr[bubndx],arr[bubndx+1],arr[bubndx+2] >,
            arr[bubndx+3],
            < arr[ndx],arr[ndx+1],arr[ndx+2] >,
            arr[ndx+3]
          )
      #end
   #end
   #local ndx = ndx + 4;

#end
#if (empty)
   sphere {-10000,0.00001}
#end
}
#end

#macro bubs(arr,arrlen)

#local ndx=0;
merge {
#while (ndx < arrlen-3)
   difference {
      merge {
         sphere {
            <arr[ndx],arr[ndx+1],arr[ndx+2]> arr[ndx+3]
         }
         bubrings(arr,arrlen,ndx)
      }
      bubdiff(arr,arrlen,ndx)
      bubdiff2(arr,arrlen,ndx)
      bounded_by {
         sphere {
            <arr[ndx],arr[ndx+1],arr[ndx+2]> arr[ndx+3]*1000/999
         }
      }
   }
   #local ndx = ndx+4;
#end
}
#end

#declare BubTex = texture {
   pigment {  
      bozo
      octaves 3
      turbulence 0.6
      color_map {
         [0.25 rgbft<1,0.7,0.9,0.13,0.83>]
         [0.3 rgbft<0.75,0.95,1,0.1,0.89>]
         [0.65 rgbft<0.69,1,0.96,0.01,0.99>]
         [0.9 rgbft<0.9,0.7,0.98,0.09,0.89>]
      }
      scale 5.6 
   }
   finish { ambient 0 diffuse 0  specular 0.7 roughness 0.001
      reflection { 0.2,0.285 fresnel on }
      irid {0.2 thickness 0.43 turbulence 0.15 }
      conserve_energy
   }
}
8<-----C-U-T---H-E-R-E-----

As I've implied, it's really not finished yet, and there are 
no doubt many fixes and improvements to be made... which anyone
is welcome to do (so long as they post them back to
news.povray.org! ;-)

- Pete.


Post a reply to this message

From: Shay
Subject: Re: messing with bubbles (23k)
Date: 18 Feb 2002 09:32:34
Message: <3c711082$1@news.povray.org>
Pete <pet### [at] somewhereinuk> wrote in message
news:3c6f6146@news.povray.org...
> One problem is that the macro (currently) fails
> to construct the appropriate disc between two bubbles if the
> center of one bubble falls inside the other.

It would be pretty simple to store all of your bubbles and radi in an array
and then check each bubble against the others to determine if that is the
case. A tub full of foam would probabaly take too long with that method,
however.

 -Shay


Post a reply to this message

From: Steve
Subject: Re: messing with bubbles (23k)
Date: 20 Feb 2002 20:43:49
Message: <slrna78ikt.mp3.steve@zero-pps.localdomain>
I like. 

--
sphere{z*5,1pigment{rgb.5}finish{reflection.3specular.5}}box{<-50,-3,-50>
<50,-2,50>pigment{checker/*\__\\__/  * \_\\__*/scale 2}finish{ambient.7}}
light_source/*__\\__\\__\\__\\__\(    ~ )\__\\__\\__\\__\\*/{<2,5,1>*4,1} 
/*\\__\\__\\__\\__\\__\\__\\__\\__\~  -/__\\__\\__\\__\\__\\*//* Steve */


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.