TUTORIAL: Photo-realism Techniques in Ray Tracing

  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

Introduction


It will be obvious (from the title if nothing else) that this tutorial was completely inspired by digitalMedia's superb tutorial on Photo-realism Techniques in Vectors. Similar to Chris's tutorial, this isn't necessarily a step-by-step how to, but rather an example of what can be done. Giving credit where credit is due, the example presented below was not self generated but rather an example given from the individual who wrote the includes used in this POVRay creation, specifically, Jaime Vives Piqueres - http://www.ignorancia.org . It's my hope that this tutorial will generate some interest in the possibilities available from Ray Tracing.

Tools Used


POVRay 3.6 (Persistence of Vision Ray Tracing)
Fruit Texturing II Include Files obtained from here

Code Example


As noted the code below is not mine, and I've left the credit intact. Basically, inspired by dM's work, I wanted to find out if I could do something similar with POVRay and generate a photo-realistic apple. Didn't take but a few searches to find the includes linked to above.

I'll start with the end result - the apple.
Attachments:
test_apple.jpg


Here is the code used to generate the apple, the marble table and background.
POVRAY Code: [ Select ]
                                  /*
 
 /*
 
   Fruit texturing example: fuji apple
 
   --
   Jaime Vives Piqueres, Jun-2002.
   
   jaime@ignorancia.org
   http://www.ignorancia.org
 
   --
   
   This is a demonstration scene for my fruit texturing macros. The trick
   consists on using a radial pattern to distribute rotated copies of another
   pigment, wich uses also rotated copies of a third pigment, following the
   slope y pattern.
   
   This complex pigment is used as the second layer of a multilayer texture,
   to give the typical apple skin stripe, with some transparency to show a
   lower base layer. Another third layer on top of these helps to integrate
   (soft/hide) the "longitudinal stripe" (in this example this third layer is
   also a two-layer texture, to add the finish and little speckles).
   
   See "i_fruitext.inc" for the details...
   
*/
 
// *** global ***
#version 3.5;
global_settings{
 noise_generator 2
 max_trace_level 8
 assumed_gamma 1.0
 ambient_light 0.0
 radiosity{
//  nearest_count 10 error_bound .5  
 }
}
 
// *** standard ***
#include "colors.inc"
#include "textures.inc"
#include "woods.inc"
#include "stones.inc"
 
// *** common and control variables ***
#declare use_table=1;
#declare use_blur=3;    //(x8 = samples)
#declare hf_res=1;     
#declare r1=seed(930);  // apple seed
#declare r_l=seed(1003);  // light pos. seed
 
 
// *** fuji apple colors, pigments and textures ***
// basic pigments
#declare p1=Firebrick*.5+OrangeRed*.1;
#declare p2=Yellow*.8+White*.1;
#declare p3=YellowGreen*.8+White*.1;
// base texture (bottom layer)
#declare t_base=
texture{
 pigment{
  cylindrical
  turbulence .25
  color_map{
   [0.0 p1]
   [0.2 p1]
   [0.7 p3]
   [1.0 p2]
  }
  scale 5
  translate 1
 }
}
// pìgment for the radial-slope texture ("stripes", second layer)
#declare p_stripes=
pigment{
 pigment_pattern{
  bumps
  turbulence .5
  lambda 2
  scale <1,7,1>*.15
 }
 color_map{
  [0.0 p1]
  [0.45 p1]
  [0.45 p1 transmit .9]
  [1.0 p1 transmit .9]
 }
}
// *** "soft/hide" texture (third layer), with additional "dirty" layer ***
#declare t_upper=
texture{
 pigment{
  cylindrical
  turbulence .25
  color_map{
   [0.0 p1 transmit .8]
   [0.2 p1 transmit .6]
   [0.7 p3 transmit .1]
   [1.0 p3 transmit .0]
  }
  scale 4
  translate 1
 }
}
texture{
 pigment{
  granite
  turbulence .5
  lambda 3
  color_map{
   [0.00 DarkGreen*.5 transmit .1]
   [0.1 DarkTan transmit .5]
   [0.20 DarkGreen transmit .8]
   [1.00 DarkTan transmit .9]
  }
 }
 normal{
  granite .1
  turbulence .5
  lambda 3
  scale .01
 }
 finish{
  phong .3 phong_size 40
  reflection {0,.01}
 }
 scale 4
}
 
// *** create the final texture ***
#include "i_fruitext.inc"  // fruit texturing macros
#local t_apple=m_radial_sloped(t_base,p_stripes,t_upper,r1)
 
// *** apply the texture to the apple ***
#include "i_apple.inc"     // apple object
#declare o_apple=object{apple(seed(11),t_apple)}
object{o_apple rotate 360*rand(r1)*y translate <0,82.5,1>}
 
 
 
// *** testing scenario ***
// marble table
#if (use_table)
#declare p_base_marble1=
pigment{granite turbulence .05 scale .5 translate 33}
#declare p_base_marble2=
pigment{crackle turbulence .1 scale 1 translate 333}
#declare p_marble=
pigment{
 bozo turbulence 1
 pigment_map{
  [0.00 p_base_marble1]
  [1.00 p_base_marble2]
 }
 scale .2
}
#declare t_marble=
texture{
 T_Stone26
 scale 4
 finish{
  reflection{.01,.1}
 }
}
height_field{
 function 512*hf_res,512*hf_res{
  pigment{p_marble}
 }
 texture{t_marble}
 translate -.5
 scale <30,.05,30>
 translate <1,80.2,4>
}
// room
box{-.5,.5
 hollow
 scale 500
 pigment{
  checker color SummerSky color White
  scale 15
 }
}
plane{y,249 pigment{White}}
plane{y,-249 pigment{Gray}}
#end
 
 
 
// *** lights ***
light_source{
 <50,230,-100>
 White*30000
 fade_distance 1
 fade_power 2
}
box{-.5,.5
 material{
  texture{
   pigment { color rgbf<1, 1, 1, 1> }
   finish {  diffuse 0 }
  }
  interior{
   media {
    method 1
    emission 10
    intervals 10
    samples 1, 10
    confidence 0.9999
    variance 1/1000
   }
  }
 }
 hollow
 no_shadow
 scale <50,10,50>
 translate <50,231,-100>
}
 
 
// **************
// *** camera ***
// **************
#declare desde=<-10,80+31,-55>;
camera{
 location desde
 direction 3.2
 look_at <.1,84.5,0>
 #if (use_blur)
 focal_point <.1,83.9,0>
 aperture 2
 blur_samples 8*use_blur
 variance 0
 #end
}
 
 
 
 
  1.                                   /*
  2.  
  3.  /*
  4.  
  5.    Fruit texturing example: fuji apple
  6.  
  7.    --
  8.    Jaime Vives Piqueres, Jun-2002.
  9.    
  10.    jaime@ignorancia.org
  11.    http://www.ignorancia.org
  12.  
  13.    --
  14.    
  15.    This is a demonstration scene for my fruit texturing macros. The trick
  16.    consists on using a radial pattern to distribute rotated copies of another
  17.    pigment, wich uses also rotated copies of a third pigment, following the
  18.    slope y pattern.
  19.    
  20.    This complex pigment is used as the second layer of a multilayer texture,
  21.    to give the typical apple skin stripe, with some transparency to show a
  22.    lower base layer. Another third layer on top of these helps to integrate
  23.    (soft/hide) the "longitudinal stripe" (in this example this third layer is
  24.    also a two-layer texture, to add the finish and little speckles).
  25.    
  26.    See "i_fruitext.inc" for the details...
  27.    
  28. */
  29.  
  30. // *** global ***
  31. #version 3.5;
  32. global_settings{
  33.  noise_generator 2
  34.  max_trace_level 8
  35.  assumed_gamma 1.0
  36.  ambient_light 0.0
  37.  radiosity{
  38. //  nearest_count 10 error_bound .5  
  39.  }
  40. }
  41.  
  42. // *** standard ***
  43. #include "colors.inc"
  44. #include "textures.inc"
  45. #include "woods.inc"
  46. #include "stones.inc"
  47.  
  48. // *** common and control variables ***
  49. #declare use_table=1;
  50. #declare use_blur=3;    //(x8 = samples)
  51. #declare hf_res=1;     
  52. #declare r1=seed(930);  // apple seed
  53. #declare r_l=seed(1003);  // light pos. seed
  54.  
  55.  
  56. // *** fuji apple colors, pigments and textures ***
  57. // basic pigments
  58. #declare p1=Firebrick*.5+OrangeRed*.1;
  59. #declare p2=Yellow*.8+White*.1;
  60. #declare p3=YellowGreen*.8+White*.1;
  61. // base texture (bottom layer)
  62. #declare t_base=
  63. texture{
  64.  pigment{
  65.   cylindrical
  66.   turbulence .25
  67.   color_map{
  68.    [0.0 p1]
  69.    [0.2 p1]
  70.    [0.7 p3]
  71.    [1.0 p2]
  72.   }
  73.   scale 5
  74.   translate 1
  75.  }
  76. }
  77. // pìgment for the radial-slope texture ("stripes", second layer)
  78. #declare p_stripes=
  79. pigment{
  80.  pigment_pattern{
  81.   bumps
  82.   turbulence .5
  83.   lambda 2
  84.   scale <1,7,1>*.15
  85.  }
  86.  color_map{
  87.   [0.0 p1]
  88.   [0.45 p1]
  89.   [0.45 p1 transmit .9]
  90.   [1.0 p1 transmit .9]
  91.  }
  92. }
  93. // *** "soft/hide" texture (third layer), with additional "dirty" layer ***
  94. #declare t_upper=
  95. texture{
  96.  pigment{
  97.   cylindrical
  98.   turbulence .25
  99.   color_map{
  100.    [0.0 p1 transmit .8]
  101.    [0.2 p1 transmit .6]
  102.    [0.7 p3 transmit .1]
  103.    [1.0 p3 transmit .0]
  104.   }
  105.   scale 4
  106.   translate 1
  107.  }
  108. }
  109. texture{
  110.  pigment{
  111.   granite
  112.   turbulence .5
  113.   lambda 3
  114.   color_map{
  115.    [0.00 DarkGreen*.5 transmit .1]
  116.    [0.1 DarkTan transmit .5]
  117.    [0.20 DarkGreen transmit .8]
  118.    [1.00 DarkTan transmit .9]
  119.   }
  120.  }
  121.  normal{
  122.   granite .1
  123.   turbulence .5
  124.   lambda 3
  125.   scale .01
  126.  }
  127.  finish{
  128.   phong .3 phong_size 40
  129.   reflection {0,.01}
  130.  }
  131.  scale 4
  132. }
  133.  
  134. // *** create the final texture ***
  135. #include "i_fruitext.inc"  // fruit texturing macros
  136. #local t_apple=m_radial_sloped(t_base,p_stripes,t_upper,r1)
  137.  
  138. // *** apply the texture to the apple ***
  139. #include "i_apple.inc"     // apple object
  140. #declare o_apple=object{apple(seed(11),t_apple)}
  141. object{o_apple rotate 360*rand(r1)*y translate <0,82.5,1>}
  142.  
  143.  
  144.  
  145. // *** testing scenario ***
  146. // marble table
  147. #if (use_table)
  148. #declare p_base_marble1=
  149. pigment{granite turbulence .05 scale .5 translate 33}
  150. #declare p_base_marble2=
  151. pigment{crackle turbulence .1 scale 1 translate 333}
  152. #declare p_marble=
  153. pigment{
  154.  bozo turbulence 1
  155.  pigment_map{
  156.   [0.00 p_base_marble1]
  157.   [1.00 p_base_marble2]
  158.  }
  159.  scale .2
  160. }
  161. #declare t_marble=
  162. texture{
  163.  T_Stone26
  164.  scale 4
  165.  finish{
  166.   reflection{.01,.1}
  167.  }
  168. }
  169. height_field{
  170.  function 512*hf_res,512*hf_res{
  171.   pigment{p_marble}
  172.  }
  173.  texture{t_marble}
  174.  translate -.5
  175.  scale <30,.05,30>
  176.  translate <1,80.2,4>
  177. }
  178. // room
  179. box{-.5,.5
  180.  hollow
  181.  scale 500
  182.  pigment{
  183.   checker color SummerSky color White
  184.   scale 15
  185.  }
  186. }
  187. plane{y,249 pigment{White}}
  188. plane{y,-249 pigment{Gray}}
  189. #end
  190.  
  191.  
  192.  
  193. // *** lights ***
  194. light_source{
  195.  <50,230,-100>
  196.  White*30000
  197.  fade_distance 1
  198.  fade_power 2
  199. }
  200. box{-.5,.5
  201.  material{
  202.   texture{
  203.    pigment { color rgbf<1, 1, 1, 1> }
  204.    finish {  diffuse 0 }
  205.   }
  206.   interior{
  207.    media {
  208.     method 1
  209.     emission 10
  210.     intervals 10
  211.     samples 1, 10
  212.     confidence 0.9999
  213.     variance 1/1000
  214.    }
  215.   }
  216.  }
  217.  hollow
  218.  no_shadow
  219.  scale <50,10,50>
  220.  translate <50,231,-100>
  221. }
  222.  
  223.  
  224. // **************
  225. // *** camera ***
  226. // **************
  227. #declare desde=<-10,80+31,-55>;
  228. camera{
  229.  location desde
  230.  direction 3.2
  231.  look_at <.1,84.5,0>
  232.  #if (use_blur)
  233.  focal_point <.1,83.9,0>
  234.  aperture 2
  235.  blur_samples 8*use_blur
  236.  variance 0
  237.  #end
  238. }
  239.  
  240.  
  241.  
  242.  



What Exactly Is Happening In the Code


For those who've never used POVRay, in a nutshell the images are generated with programming code. It looks a little intimidating at first, however, anyone familiar with any kind of programming language can pretty much figure out intuitively what is going on. POVRay code can use a variety of include files (.inc). Essentially you can relate them to "classes" - simply reusable code. For example you'll notice in this application that several common include files are included to create various colors, textures, woods and stones -- all defined in the respective include files (these particular include files are included with the POVRay application. Experienced users can also write their own include files, but others can be found, in most cases free, on the internet).

POVRAY Code: [ Select ]
// *** standard ***
#include "colors.inc"
#include "textures.inc"
#include "woods.inc"
#include "stones.inc"
  1. // *** standard ***
  2. #include "colors.inc"
  3. #include "textures.inc"
  4. #include "woods.inc"
  5. #include "stones.inc"


For the generation of the apple, two other include files are used (linked to in Tools Used) -- i_fruitext.inc and i_apple.inc. These two includes contain three macros designed by the author that essentially define the attributes used to create the apple object.

Altering The Code to Produce Variants


Personally, I prefer green apples to red, so I made some modifications to demonstrate how altering the code, alters the image. In POVRay often times images can be altered by various random "seeds" In this case there are two seeds that can be altered -- the apple seed itself (930 different seeds) and the light position (1003 seeds):

POVRAY Code: [ Select ]
#declare r1=seed(930);  // apple seed
#declare r_l=seed(1003);  // light pos. seed
  1. #declare r1=seed(930);  // apple seed
  2. #declare r_l=seed(1003);  // light pos. seed

In the original he used seed 11. I changed that to seed 800 to alter the shape of the apple. I didn't change the light position.

I also altered the pigments used from:
POVRAY Code: [ Select ]
// basic pigments
#declare p1=Firebrick*.5+OrangeRed*.1;
#declare p2=Yellow*.8+White*.1;
#declare p3=YellowGreen*.8+White*.1;
  1. // basic pigments
  2. #declare p1=Firebrick*.5+OrangeRed*.1;
  3. #declare p2=Yellow*.8+White*.1;
  4. #declare p3=YellowGreen*.8+White*.1;


to:
POVRAY Code: [ Select ]
// basic pigments
#declare p1=YellowGreen*.5+OrangeRed*.1;
#declare p2=GreenYellow*.8+White*.1;
#declare p3=MediumSpringGreen*.8+White*.1;
  1. // basic pigments
  2. #declare p1=YellowGreen*.5+OrangeRed*.1;
  3. #declare p2=GreenYellow*.8+White*.1;
  4. #declare p3=MediumSpringGreen*.8+White*.1;

Obviously changing the reddish-yellow color of the apple to a green color

Finally, I changed the texture of the marble table from T_Stone26 to T_Stone18:
POVRAY Code: [ Select ]
#declare t_marble=
texture{
 T_Stone26
 scale 4
 finish{
  reflection{.01,.1}
 }
}
  1. #declare t_marble=
  2. texture{
  3.  T_Stone26
  4.  scale 4
  5.  finish{
  6.   reflection{.01,.1}
  7.  }
  8. }

to:
POVRAY Code: [ Select ]
#declare t_marble=
texture{
 T_Stone18
 scale 4
 finish{
  reflection{.01,.1}
 }
}
  1. #declare t_marble=
  2. texture{
  3.  T_Stone18
  4.  scale 4
  5.  finish{
  6.   reflection{.01,.1}
  7.  }
  8. }


Other than that, I made no other alterations to the code, although obviously the possibility for changes is endless. I will make one last note on the code for those new to POVRay that in all cases, you have to define your camera. Anyone familiar with photography can figure out intuitively what this code does.

POVRAY Code: [ Select ]
// **************
// *** camera ***
// **************
#declare desde=<-10,80+31,-55>;
camera{
 location desde
 direction 3.2
 look_at <.1,84.5,0>
 #if (use_blur)
 focal_point <.1,83.9,0>
 aperture 2
 blur_samples 8*use_blur
 variance 0
 #end
}
  1. // **************
  2. // *** camera ***
  3. // **************
  4. #declare desde=<-10,80+31,-55>;
  5. camera{
  6.  location desde
  7.  direction 3.2
  8.  look_at <.1,84.5,0>
  9.  #if (use_blur)
  10.  focal_point <.1,83.9,0>
  11.  aperture 2
  12.  blur_samples 8*use_blur
  13.  variance 0
  14.  #end
  15. }


And the end result -- my green apple:

Attachments:
myApple.jpg




Conclusion


I simply hope that this motivates some of you to look into the incredible world of ray tracing.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • digitalMedia
  • a.k.a. dM
  • Genius
  • User avatar
  • Posts: 5149
  • Loc: SC-USA

Post 3+ Months Ago

Well, I've got it installed. Now I just need to sort out the Greek. :)
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

There's a ton of good tutes on it.
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

Wow nice result Mark, I haven't touched POVRay in years. You wouldn't happen to know if POVRay supports Global Illumination would you? Softened shadow edges, light refraction, etc go a really long way toward realism.

For anyone who doesn't want to be a "visual" programmer. There are several free modeling programs that will allow you to use POVRay as your render solution without all the code. My favorite a long time ago was Moray although Bishop3D is looking kind of cool.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

Don't think POVRay does, but MegaPOV might. It has HDR support. I didn't read through the documentation

http://megapov.inetart.net/features.html
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

ATNO/TW wrote:
...but MegaPOV might. It has HDR support.


Yeah being able to use HDR for lighting would mean at least a partial radiosity solver. Its worth finding out though. Since I really think that makes the biggest difference in terms of realism.

Here are two examples of the same environment, 1st one using raytracing and the second using radiosity (GI) Notice the difuse shadows and the color spill in the second one that isn't there in the first.
Attachments:
renders.jpg
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

HDR is something I'd really like to learn more about.
  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

Radiosity capabilities and process very greatly between apps. Are you mostly interested in HDR lighting solutions or would a broader overview of Radiosity (refraction, caustics, sub surface scattering, etc) be more helpful? I might try to come up with a tutorial but its a broad subject so some idea of the interest would help.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

I would really like to see a few tutes from you gb. Especially on HDR and Flash

Post Information

  • Total Posts in this topic: 9 posts
  • Moderator: Tutorial Writers
  • Users browsing this forum: No registered users and 1 guest
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.