POV-Ray : Newsgroups : povray.newusers : <no subject> : Re: <no subject> Server Time
26 Mar 2023 23:56:42 EDT (-0400)
  Re: <no subject>  
From: green
Date: 25 Nov 2018 10:25:01
Message: <web.5bfabe296f92e85688dbe9e30@news.povray.org>
"j13r" <buc### [at] gmxat> wrote:
> Hi all,
>
> I would like to make a image of magnetic field loops (similar to these:
>
https://ichef.bbci.co.uk/news/304/media/images/58947000/jpg/_58947314_162169main_trace_solar_flare_lg-1.jpg
> https://martianchronicles.files.wordpress.com/2010/05/loops.gif
> http://www.space.com/images/i/000/015/747/original/sun-as-art-swirls.jpg
> more information here: https://en.wikipedia.org/wiki/Coronal_loop
> )
> The only difference is that I want them on a disk.
>
> So far I tried to make the loops with multiple "torus" elements,
> which are light sources at the same time.
> I added more of these in larger sizes to give it a glow/halo effect.
> This is all very similar to the lightsabre object example.
>
> However, already with a few of these (8, see code below), the rendering is
> getting slow. I think the reason is that the ~130 torus objects are overlapping
> each other. This leads to a lot of root tests (742109138, see output below).
> I was wondering if you could suggest a smarter technique?
>
> It would also be good to be more flexible than with the torus.
> I attached my code below.
>
> Cheers,
>        Johannes
>
> $ povray +W400 +H400 -V +Olightarc.png +WT4 -d lightarc.pov
> .....
> ----------------------------------------------------------------------------
> Render Statistics
> Image Resolution 400 x 400
> ----------------------------------------------------------------------------
> Pixels:           160000   Samples:               0   Smpls/Pxl: 0.00
> Rays:             301581   Saved:                 0   Max Level: 1/5
> ----------------------------------------------------------------------------
> Ray->Shape Intersection          Tests       Succeeded  Percentage
> ----------------------------------------------------------------------------
> Box                          401896791          652287      0.16
> Cone/Cylinder                    89831           70491     78.47
> CSG Intersection             401896791       120763539     30.05
> Torus                        401896791       129236959     32.16
> Torus Bound                  401896791       141316940     35.16
> Bounding Box                 742109138       532510992     71.76
> ----------------------------------------------------------------------------
> Roots tested:             141316940   eliminated:             16711239
> Media Intervals:             125201   Media Samples:           1627613 (13.00)
> Shadow Ray Tests:          17116032   Succeeded:              16027193
> Shadow Cache Hits:              363
> Transmitted Rays:            141581
> ----------------------------------------------------------------------------
> ----------------------------------------------------------------------------
> Render Time:
>   Photon Time:      No photons
>   Radiosity Time:   No radiosity
>   Trace Time:       0 hours  3 minutes 56 seconds (236.095 seconds)
>               using 4 thread(s) with 781.471 CPU-seconds total
>
>
>
> Code:
>
> // Magnetic field on a disk
> //
> #include "colors.inc"
> #include "rand.inc"
>
> // options of this script
> #declare number_of_subarcs=8;
> #declare number_of_arcs=8;
> #declare disk_radius=4;
>
> camera {
>  location <4,1,4>
>  look_at <0,0,0>
> }
> background {color Black}
>
> // set up disk
> cylinder {
>  <0,0,0>
>  <0,-0.04,0>
>  disk_radius
>  pigment { color White }
>  finish { phong 0 diffuse 0.2 ambient 0 }
> }
>
> // a single arc is a thin half-torus
> #declare arc=
> difference {
>  torus {
>   5, 0.04           // major and minor radius
>   rotate -90*x      // make vertical
>  }
>  box {<-6,-6,-1>, <6,0,1>}
> }
> // this thicker torus is used to make a halo glow around the thing arcs
> #declare thickarc=
> difference {
>  torus {
>   5, 0.5
>   rotate -90*x
>  }
>  box {<-6,-6,-1>, <6,0,1>}
> }
>
> #declare r1=seed(5); // defines the shape
> // now comes the combination of objects
> #declare glowarc= union {
> light_source { <0, 5, 0> color rgb <0,0,.5> }
> // bright white arc
> object {arc pigment{Clear} hollow
>  interior { media{ emission <1,1,1>*100 } }
> }
> /*object {
>  thickarc pigment{Clear} hollow
>  interior { media{emission <.01,.01,1>*2 density { spherical scale <5,100,100> }
> } }
>  translate <0,0.01,0>
> }*/
> // fainter blue arcs
> #declare i=0;
> #while (i<number_of_subarcs)
>  #declare i = i + 1;
>  // we jitter them slightly
>  #declare myscale = 1/Rand_Normal(1,0.05,r1);
>  #declare xrot = Rand_Normal(0, 7, r1);
>  #declare yrot = Rand_Normal(0, 3, r1);
>  #declare zrot = 0;
>  object {
>   arc pigment{Clear} hollow
>   scale myscale
>   rotate <xrot,yrot,zrot>
>   interior { media{
>    emission <0,0,1>*pow(10,1+1*rand(r1))
>   } }
>  }
>  // make fuzzy, weak halos with thickarc objects
>  object {
>   thickarc pigment{Clear} hollow
>   scale myscale
>   rotate <xrot,yrot,zrot>
>   interior { media{emission <.01,.01,1>*(0.4/number_of_subarcs)} }
>  }
> #end
> }
>
> #declare r2=seed(2); // defines the locations
>
> // now we can create a couple of these
> #declare i=0;
> #while (i<number_of_arcs)
>  // find a uniform location on the disk to put it
>  #declare myx = (rand(r2)-0.5)*3*2;
>  #declare myy = (rand(r2)-0.5)*3*2;
>  #declare d = sqrt(pow(myx,2)+pow(myy,2));
>  #declare phi = atan2(myy,myx);
>  // make sure the radius is not outside the disk
>  #if (d < disk_radius-1)
>
>  // orient the arc so it tends to point to the disk center
>  #declare phi2 = phi + 45*(rand(r2)-0.5)/180*3.14;
>  object{ glowarc
>   scale 0.05+0.1*rand(r2)
>   rotate y*(phi2/3.14*180+90)
>   translate <d*sin(phi),0,d*cos(phi)>
>  }
>  #declare i = i + 1;
>  #end
> #end

the slow-down is the light_source in the union.  comment it out and there is an
approximately fifty-fold speedup (with my first guess, using whole tori, same as
b.eagle's 'difference' suspicion, which was a ~25% speed-up.)


Post a reply to this message

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