EGR 199:
Fundamentals of Engineering

3D Modeling and Ray Tracing

Prabhaker Mateti
   

by Anto Matkovic

Table of Contents

Executive Summary
Background Information

3D Modeling
What is Ray Tracing?
Radiosity
What is POV?
sPatch

Procedures
Appendix A: Acronyms
Appendix B: Further Reading Links
Achievement Test

 Executive Summary

This article introduces 3D modeling, and ray tracing.  It assumes that the student is already familiar with Web, HTML authoring. and VRML.

Background Information

3D Modeling

Suppose you have the following problem.  You have a real-world scene whose still pictures you are shooting.  You want to see it from different angles, with different light sources, and placed at different positions.  You could do what the old-world movie makers did.  Spend a lot of money and energy, hire a lot of people, construct elaborate sets, and take pictures.  Or ...

camera {
  location <0, 80, -200>
  right <4/3, 0, 0>
  up <0, 1, 0>
  sky <0, 1, 0>
  direction <0, 0, 1.8>
  look_at <0, 15, 0>
}
You can describe the shapes of a real-world scene with 3D geometry.  Apply textures.  Position the light sources.  You may do this using an interactive modeling system, like a CAD package, or by creating a text file that has a programming language-like syntax to describe the elements. In the 3D format knowns as .POV, a particular camera is described at left.

CSG modeling

-=

The Constructive Solid Geometry consists in building objects by using solid primitives and Boolean operators. Each primitive represent a real volume. It means that a CSG modeler can determine whether a point is outside or inside a solid object and combine them to create complex shapes. This modeling technique is very powerful and generate accurate representations than can be used in engineering or manufacturing. 

 

Surface modeling 

In surface modeling, object geometry is not completely expressed like in CSG. Surface modeling is only concerned in building the outside shell of an object. We use points placed in a 3D space to form curves and combine several curves to generate surfaces (with no thickness).

 

What is Ray Tracing?

In the physical world, rays of light are emitted from a light source and illuminate objects. The light reflects off of the objects or passes through transparent objects. This reflected light hits our eyes or perhaps a camera lens. A light source emits rays in all directions.  Only a very small percentage of these rays hit an observer.  If a computer program were to literally do this,  it would take forever to trace a scene.

Ray casting traces a ray from the eye through a point on the object being viewed, and find intersections with all the obejects in the scene.  The intersection that has the smallest z value determines the color of the pixel (picture element) on the screen.  Ray tracing goes further by reflecting the ray off the object and tracing it further, which may get reflected, and so on until it exits the scene or reaches the light source.  If the surface were tranparent, and additional refracted ray is traced.  Ray tracing is a rendering technique that calculates an image of a 3D real world scene by simulating the way rays of light travel. 

Ray tracing algorithms  start with their simulated camera and trace rays backwards out into the scene. The user specifies the location of the camera, light sources, and objects as well as the surface texture properties of objects, their interiors (if transparent) and any atmospheric media such as fog, haze, or fire.  For every pixel in the final image one or more viewing rays are shot from the camera, into the scene to see if it intersects with any of the objects in the scene. These viewing rays originate from the viewer (the camera), and pass through the viewing window (containing the final image).

Every time an object is hit by a ray, the color of the surface at that point is calculated. For this purpose rays are sent backwards to each light source to determine the amount of light coming from the source.  Shadow rays determine if a surface point lies in shadow or not. If the surface is reflective or transparent, new rays are set up and traced in order to determine the contribution of the reflected and refracted light to the final surface color.

Here is a Poser head with the sun as the light source.

The same head with one white spot light.

This head has a spot and a radial light to lighten up the shadows.

Now the head has colored lights. The main spot is a warm color and the radial light is a cool color.


Radiosity

Radiosity is an extra calculation that computes the diffuse interreflection of light more  realistically. This diffuse interreflection can be seen if you place a white chair in a room full of blue carpet, blue walls and blue curtains. The chair will pick up a blue tint from light reflecting off of other parts of the room. Also notice that the shadowed areas of your surroundings are not totally dark even if no light source shines directly on the surface. Diffuse light reflecting off of other objects fills in the shadows. Typically ray-tracing uses a trick called ambient light to simulate such effects but it is not very accurate.  Radiosity is more accurate than simplistic ambient light but it takes much longer to compute. For this reason, POV-Ray does not use radiosity by default. Radiosity is turned on using the Radiosity INI file option or the +QR command line switch.

What is POV?

POV is a 3-dimensional ray tracing engine. It takes your 3D model and simulates the way light interacts with the objects you have defined.  It can create stunning 3D pictures and animation. In addition to ray tracing,  POV uses radiosity to add greater realism to scenes containing diffuse light sources such as the fluorescent lighting.  POV can simulate many atmospheric and volumetric effects (such as smoke and haze).

The coordinate system for POV-Ray has the positive Y axis pointing up, the positive X axis pointing to the right, and the positive Z axis pointing into the screen.  The X, Y, Z coordinates of a location is specified with a 3-part vector of 3 numeric values, between  angle brackets and separating the values with commas.

 In a previous lab, you have seen examples of VRML scenes.    The syntax of the .wrl VRML files is different from .pov files.

POV is a rendering engine only, it does not include a modeler.  A modeler is a program which uses graphics to make the job of creating 3D objects simpler. Using a modeler you can arrange structures by visually interacting.

sPatch

sPatch Screen ShotsPatch is freeware.  It is a Bezier patch based modeler that exports POV, DXF and VRML on Windows 95/NT. It can build models for VRML browsers and  POV-Ray.  Because it is spline based it especially good for bio shapes and curvy objects.

 

 

 

Procedures

The machines in 141 RC have POV version 3.0x, and sPatch installed.

1. POV:  Play with Ready Made Examples

1.0 Running POV-Ray

  1. Double click on the Desktop icon for POV-Ray.  It will bring up a window with a text file in it.  The  files whose names end with .pov are the models written in the POV language.
  2. Note that POV has excellent Help menu.  Familiarize yourself with it.  You will find that it is not overwhelming.
  3. Run the demo (select Render/Run Demo).You will see POV-Ray start up a Render Window and generate a sample scene line by line.
  4. Study the code in the text window.  Answer the following questions.
  5. Q1.1
  6. Q1.2
  7. Q1.3
  8. Q1.4 

1.1  Have a look at the details of this rendering: Alien.jpg.   Note that this is a 174KB file.

1.2

2. POV: Creating your own POV Model

2.1 A Simple Model

Create a new file from within POV.  File/New.  Copy and Paste pieces of the following the text file -- an example of a POV model --, one piece at a time.   After each paste, Render it to see the effect you produced.  When all of the contents are in, it will render as a blue ball sitting on a patterned gray  reflective table top.

Note that lower case Upper Case distinction is made in .pov files.

 
  1. Suppose we move the light_source line to the bottom of the file.  Will the scene render differently?
  2. Raise (in the +Y direction) the sphere by 2 units.  Render it, and verify that the sphere is raised.  Explain how you did this.  Explain what happened to the reflections.
  3. Play with the settings of finish{} of plane.  Report your findings.
  4. Add a texture.  Insert the line

    #include "textures.inc"

    so we can use the textures defined in the file textures.inc.  Add
    sphere { <0,0,0>,1
    	texture { Jade }}
#include "colors.inc"

camera {
  location <0,0.5,-7>
  look_at <0,0,0>
}

light_source {<100,140,-300> color White}

plane {
  <0,1,0>,-1
  texture {
    pigment {color Silver}
    normal {bumps 0.5 scale .8}
    finish {
     phong 1 reflection .5
     ambient 0.4 diffuse 0.
} } }

sphere { <0,0,0>,1
  texture { 
    pigment { color Blue }
    finish {
     reflection 0.2 diffuse 0.1
     ambient 0.8 phong .8
} } }

3. sPatch: Model a Bottle of Coke

Shape the Bottle 
 
  1. Open a new document under sPatch.  
  2. Set a value between 0.250 or 0.100 for the grid .  
    Then I enable the grid. 
  3. Now using the add tool  (pressing A key to gain time), draw a rough profile of the bottle in the XY plan. The XY plan is important because we will use the lathe function later. For this bottle we use a closed profile because we want to be able to vary the apparent thickness of the glass. This profile need not to be extremely accurate but let us make sure that the two points making the middle of the base are on the same Y coordinate. This is because the lathe is made around the Y axis and we want a seamless junction.  To avoid our lathed surface self intersect, we use the peak tool to alter the profile near the Y axis. Now my profile follows exactly the lathing axis so my surface will be OK.
 
Refine the Shape
 
  1. Disable the grid. 
  2. Use the translate tool  to place the points forming the
    profile curve. Use the XYZ switches to make sure you don't move the selected point in an unwanted direction. For instance,  disable the X axis when moving the two points that should remain on the sameY axis.
  3. If necessary  use the add tool  again to include new points in the profile curve. Use the group tool  to select multiple points and move that selection around.  When happy with the shape of the neck, move it around as a whole.
 
Turn the Lathe ON 
 
  1. Change the lathe setting to a fairly high and even value (something like 30 or 32). Use the lathe tool  to generate the bottle from the closed profile. Notice on the left that the shape obtained doesn't have the right proportions. 
  2. Select all the points (press Ctrl-A) and use the scale tool   (with the Y switched off) to make the bottle thicker or thinner. I also use the scale tool  and the translate tool  on group selections  to obtain a satisfying shape.
  3. Try shaded previews to see how your bottle looks, as shown here.  Adjust shape as above. bad but is still too smooth.

    As of now, it lacks the characteristic grooves of the classic coke bottle. 

  4. Use the view tool present on top of each view frame to navigate between views and to switch between the shaded and wireframe mode. 

 
Create the relief on the bottle surface.
 
 
  1. Apply the scale tool  to specially selected points. These points are on the outside on the widest section. Select every other point around bottle as shown on the left.   See Tip below.
  2. Switch off the Y axis and scale down this selection slightly to obtained the wanted grooves. Make sure the scaling is small enough to avoid the inner surface to intersect with the outer surface. 

    The shaded preview now show a much more convincing coke bottle with grooves that catch the light and create nice highlight and reflections.
 
Tip: Selecting these points is the only difficult part of this exercise. You can select all the points at first (Ctrl-A) then use the group tool  to deselect all the unwanted nodes. Splitting the window into 4 views can help as you can use the easiest view for each point.
  
Melt the Bottle!
 
  1. Select only the neck of the bottle with the group tool .
  2. Use the rotate tool  and the translate tool  on that selection.
  3. Then, using the group tool  add the circumference just underneath the neck to the current selection and re-apply translate  and rotate 
  4. Repeat these three operation till the selection includes the entire bottle except the base. At this stage the coke bottle look quite melted but still a tad too regular. While checking that you didn't create an intersection between inner and outer surfaces, use the noise tool  on the current selection to add some more natural variation to the curves. Do this until the shaded preview looks good.  Now, render it  with POV.
 

Appendix A: Acronyms

CSG Constructive Solid Geometry
PNG Portable Network Graphics
POV Persistence of Vision
VRML Virtual Reality Modeling Language
A few acronyms and their expansions are collected in the table here. If you are curious about an acronym or term not listed, type it in the input box below, and then press


 the button to look it up in the TechEncyclopedia.

Appendix B: Further  Links

Achievement Test

  1.  Answer the questions of Running POV section.
 
pmateti@cs.wright.edu