POV-Ray : Newsgroups : povray.newusers : Cube in different colors ? : Re: Cube in different colors ? Server Time
4 Sep 2024 18:14:19 EDT (-0400)
  Re: Cube in different colors ?  
From: Warp
Date: 11 Sep 2002 07:50:32
Message: <3d7f2e08@news.povray.org>
Rafal 'Raf256' Maj <raf### [at] raf256com> wrote:
> so finaly - with method is the fastest ?
> maybe some union/merge/intersection of planes ?

  I made a test with boxes made of planes, polygons and a mesh (with
differently colored sides) and compared their rendering speed
(-w800 -h600 +a0.1) by randomly placing 500 of them in the scene.
The render times were:

Planes:   75 s
Polygons: 80 s
Mesh:     63 s

  Seems like the mesh wins.

  This is the scene:


// 1: Planes
// 2: Polygons
// 3: Mesh
#declare BoxType = 1;
#declare Amount = 500;


#macro FixCorners(Corner1, Corner2)
  #local X1 = Corner1.x; #local X2 = Corner2.x;
  #local Y1 = Corner1.y; #local Y2 = Corner2.y;
  #local Z1 = Corner1.z; #local Z2 = Corner2.z;
  #if(X1 > X2) #local tmp = X1; #local X1 = X2; #local X2 = tmp; #end
  #if(Y1 > Y2) #local tmp = Y1; #local Y1 = Y2; #local Y2 = tmp; #end
  #if(Z1 > Z2) #local tmp = Z1; #local Z1 = Z2; #local Z2 = tmp; #end
  #local Corner1 = <X1, Y1, Z1>;
  #local Corner2 = <X2, Y2, Z2>;
#end

#macro PlaneBox(Corner1, Corner2, T1, T2, T3, T4, T5, T6)
  #local C1 = Corner1+<0,0,0>;
  #local C2 = Corner2+<0,0,0>;
  FixCorners(C1, C2)
  intersection
  {
    plane { -x, -C1.x texture { T1 } }
    plane {  x,  C2.x texture { T2 } }
    plane { -y, -C1.y texture { T3 } }
    plane {  y,  C2.y texture { T4 } }
    plane { -z, -C1.z texture { T5 } }
    plane {  z,  C2.z texture { T6 } }
    bounded_by { box { C1, C2 } }
  }
#end

#macro PolygonBox(Corner1, Corner2, T1, T2, T3, T4, T5, T6)
  #local C1 = Corner1+<0,0,0>;
  #local C2 = Corner2+<0,0,0>;
  FixCorners(C1, C2)
  union
  {
    polygon
    { 5, C1, <C1.x, C1.y, C2.z>, <C1.x, C2.y, C2.z>, <C1.x, C2.y, C1.z>, C1
      texture { T1 }
    }
    polygon
    { 5, C2, <C2.x, C2.y, C1.z>, <C2.x, C1.y, C1.z>, <C2.x, C1.y, C2.z>, C2
      texture { T2 }
    }
    polygon
    { 5, C1, <C2.x, C1.y, C1.z>, <C2.x, C1.y, C2.z>, <C1.x, C1.y, C2.z>, C1
      texture { T3 }
    }
    polygon
    { 5, C2, <C1.x, C2.y, C2.z>, <C1.x, C2.x, C1.z>, <C2.x, C2.y, C1.z>, C2
      texture { T4 }
    }
    polygon
    { 5, C1, <C2.x, C1.y, C1.z>, <C2.x, C2.y, C1.z>, <C1.x, C2.y, C1.z>, C1
      texture { T5 }
    }
    polygon
    { 5, C2, <C1.x, C2.y, C2.z>, <C1.x, C1.y, C2.z>, <C2.x, C1.y, C2.z>, C2
      texture { T6 }
    }
  }
#end

#macro MeshBox(Corner1, Corner2, T1, T2, T3, T4, T5, T6)
  #local C1 = Corner1+<0,0,0>;
  #local C2 = Corner2+<0,0,0>;
  FixCorners(C1, C2)
  mesh2
  {
    vertex_vectors
    { 8,
      C1, <C2.x, C1.y, C1.z>, <C2.x, C1.y, C2.z>, <C1.x, C1.y, C2.z>,
      <C1.x, C2.x, C1.z>, <C2.x, C2.y, C1.z>, C2, <C1.x, C2.y, C2.z>
    }
    texture_list
    { 6,
      texture { T1 }, texture { T2 }, texture { T3 },
      texture { T4 }, texture { T5 }, texture { T6 }
    }
    face_indices
    { 6*2,
      <0, 3, 7>, 0, <0, 7, 4>, 0,
      <1, 5, 6>, 1, <1, 6, 2>, 1,
      <0, 1, 2>, 2, <0, 2, 3>, 2,
      <4, 7, 6>, 3, <4, 6, 5>, 3,
      <0, 4, 5>, 4, <0, 5, 1>, 4,
      <3, 2, 6>, 5, <3, 6, 7>, 5
    }
  }
#end

camera { location <4,10,-20>*2 look_at 0 angle 35 }
light_source { <100,200,-150>, 1 }

#declare T = array[6]
{
  pigment { rgb 1 },
  pigment { rgb x },
  pigment { rgb y },
  pigment { rgb z },
  pigment { rgb x+y },
  pigment { rgb y+z },
}

#declare Box =
  #switch(BoxType)
    #case(1)
      PlaneBox(-1, 1, T[0], T[1], T[2], T[3], T[4], T[5])
    #break
    #case(2)
      PolygonBox(-1, 1, T[0], T[1], T[2], T[3], T[4], T[5])
    #break
    #case(3)
      MeshBox(-1, 1, T[0], T[1], T[2], T[3], T[4], T[5])
    #break
  #end

#declare S = seed(1);
#declare Ind = 0;
#while(Ind < Amount)
  object
  { Box
    rotate <rand(S)*360, rand(S)*360, rand(S)*360>
    translate (<rand(S),.5,rand(S)>-.5)*50
  }
  #declare Ind = Ind+1;
#end


-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

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