RenderMan Introduction CS 551/645 Fall 2000

advertisement
RenderMan Introduction
CS 551/645
Fall 2000
Evaluate Me!
• Please visit the SEAS main website and use
the ‘Course Evaluations’ button to rate this
class.
Administrivia
• RenderMan assignment due 9:00 a.m. on
December 5th, one week from today
• Extra Credit assignment due 7:00 p.m. on
December 11th
– I have handouts to help explain the ray tracing
algorithm. Grab one after class.
Remember
• BMRT.org download is closed until Friday
– www.rhino3d.com has older Windows version
– www.tucows.com has recent Linux version
– My account on Small Hall has recent SGI version
Renderman Sites
• http://www.cgrg.ohiostate.edu/~smay/RManNotes/rmannotes.html
• http://www.renderman.org/RMR/
• http://home.earthlink.net/~satysharon/RMan/
• http://www.rendermania.com
• http://www.bmrt.org
• http://minerva.ca.scad.edu/faculty/kesson/CA301/b
ookindex.html
RenderMan
• Defines an interface between scene design
and scene rendering
– RenderMan Interface (Ri) is the formal spec
– BMRT and Pixar’s PRMan (aka RenderMan)
are two implementations of rendering software
that accept the RenderMan Interface input files
(RIB)
RenderMan Standards
• High-level object primitives
– Polygon, Quadric Surfaces, Parametric Surfaces
•
•
•
•
•
•
Hierarchical graphics state
Model and viewing transformations
Programmable shading language
Anti-aliasing
Texture Maps
Robust definition of image size and depth
RenderMan I/O
• Inputs
– RenderMan Interface Bytestream (RIB) files
• Scene description
– Shaders
• Programs that describe shading (lighting and coloring)
algorithms
– Maps
• Images, shadow regions, etc.
• Outputs
– Maps
• For use as inputs in future rendering stages
– Images
• The final product of the rendering
RIB Files
• You can write these by hand (ASCII or
binary)
• You can have them generated using C++
code and RenderMan C++ libraries
• Maya plugin - MTOR
• Roll your own RIB writer
Sample RIB File
##RenderMan RIB
version 3.03
Display "RenderMan" "framebuffer" "rgb"
Format 256 192 -1
LightSource "distantlight" 1
Translate 0 0 5
WorldBegin
Surface "metal"
Color [0.2 0.4 0.6]
Polygon "P" [0.5 0.5 0.5 0.5 -0.5 0.5 -0.5 -0.5
0.5 -0.5 0.5 0.5]
WorldEnd
Shaders
• Write from scratch
• Obtained from software app, Slim or
ShadeTree
• Must be compiled to object code
Sample Shader
surface metal (float Ka=1, Ks=1, roughness=.1)
{
normal Nf;
vector V;
Nf = faceforward(normalize(N), I) ;
V = normalize(-I) ;
Oi = Os;
Ci = Os * Cs * ( Ka*ambient() +
Ks*specular(Nf,V,roughness) );
} /* metal */
Shaders Examples
• There are a million shaders on the web
• It is amazing to see the complex effects
generated with simple functional
descriptions
• Shader writing is the bread and butter of
special effects houses (the fur on Stuart
Little, for example)
Shaders
• Many extra shaders are included with the
BMRT distribution
• Look in the shaders directory
• Read the .sl shaders and follow the structure
of the input parameters when using
• Remember, RenderMan graphics state
stores variables about camera position, light
positions, etc.
How To
• Generate this:
http://www.renderman.org/RMR/RIBS/bulb.rib
.rib Code
# bulb.rib
# Author: Scott Iverson
<jsiverso@midway.uchicago.edu>
# Date: 6/9/95
#
Display "bulb.tiff" "file" "rgb"
Projection "perspective" "fov" 25
Format 380 380 -1
Rotate 0 0 0 1
Rotate -0.570093918 1 0 0
Rotate 5.71059326 0 1 0
Translate -1 -2 10
Comments
Output to file (TIFF)
Perspective, 25 deg FOV
Image Size
Camera Rotation (NOOP)
Angle, X, Y, Z
Move Camera
.rib Code
WorldBegin
Light 1 is ambient with intensity .4
LightSource "ambientlight 1 "intensity" .4
Light 2 is distant with intensity .6 and direction (-.3, -.2, 1)
LightSource "distantlight" 2 "intensity" .6 "from"
[0 0 0] "to" [-.3 -.2 1]
AttributeBegin is like GL_PUSH
AttributeBegin
Rotate –90 degrees about x-axis
Rotate -90 1 0 0
Use interpolation to determine shading of pixels that fall
between sampled points. Could be “constant”
ShadingInterpolation "smooth"
.rib Code
# base
Apply the material “metal” to all future geometry
Surface "metal“
Apply the color “blue” to all future geometry
Color 0 0 1
Again, push to isolate the upcoming changes
AttributeBegin
Change the “handedness” of the coordinate system. Because
we’re about to draw a quadric surface, the handedness effects the
normal direction
Orientation "rh“
Create a quadric surface, a disk
Disk 0 .18 360
Pop the state (the handedness)
AttributeEnd
.rib Code
The Blue color remains and we draw a cylinder
Cylinder .18 0 .1 360
We move up a little (to the top of the cylinder)
Translate 0 0 .1
We change to another surface shader
Surface "matte”
We change to color “yellow”
Color 1 1 0
We draw a hyperboloid around base of bulb
Hyperboloid .18 0 0 .4 0 .15 360
.rib Code
Translate 0 0 .15
Surface "metal"
Color 1 .7 0
Translate 0 0 .05
Torus .4 .05 -90 90
Translate 0 0 0.10
Torus .4 .05 -90 90
Translate 0 0 0.10
Torus .4 .05 -90 90
Translate 0 0 0.10
Torus .4 .05 -90 90
Translate 0 0 0.10
Torus .4 .05 -90 90
Translate 0 0 0.10
Translate 0 0 -0.05
Move up a little
Change the surface shader
Change the color to be more red
360
Draw the torii for the threads
360
360
360
360
.rib Code
# the glass part
Change the shader
Surface "plastic" "roughness" .4
Change the color to “white”
Color 1 1 1
Here is the truncated call to generate the bulb surface
PatchMesh "bicubic" 13 "nowrap" 7 "nowrap" "P" [
0.40 0.00 0 0.40 0.220913867…]
Pop Stack
AttributeEnd
End of scene description
WorldEnd
Things to remember
• The default coordinate system is left-handed
• Camera initially at origin looking along positive-z
• All camera movements are defined before the
“World Begin” command
• Think backwards about camera movement.
You’re moving the world, not the camera
• Object transformations accumulate (note the torus
sequence) but for each object, the transformations
are applied last -> first
C++ Library
• Straightforward relationship to .rib file we
just reviewed
• Uses
– include/ri.h (for Rt data types and function
headers)
– lib/libribout.a (for function code)
C++ Library
• One weird thing about RenderMan Interface
– Shaders accept parameter list arguments
• token-value pairs
• Terminated by RI_NULL
– Explicit type casting
• RtToken, RtPointer
– Pass by address
parameter list
Define the name of the texture map file
Char *mytmap = “grid.tiff”
Create a new token name and define its type
tmap will now be of type uniform string
RiDeclare (“tmap”, ”uniform string”);
Use the shader, mytexture.sl, for the future geometry
Provide the input parameter, mytmap, for the location
of the texture map
RiSurface (”mytexture”, (RtToken) ”tmap”,
(RtPointer) &mytmap, RI_NULL);
What you need to do
• Create RiLookat()
– Arguments: eyePoint(xyz), lookatpoint(xyz),
upvector(xyz)
– Once this is created, remove the explicit rotate
and translate commands I have in the code
What you need to do
• Create an environment map
– Use the command in the class handout
• Apply the environment map to the surface
of the teapot
– Any surface shader that accepts a texture
argument will work (shinymetal, for example)
What you need to do
• Apply a marble or wood shader to the
pedestal
– It should look good
What you need to do
• Apply the images you used to generate the
environment map to texture map the walls
of the room
– If you wish, you can apply another kind of
shader to the floor of the room (even though
this would result in an unrealistic reflection on
the teapot)
Applying Texture Maps
• Again, a shader like paintedplastic will accept a
texturemap argument
– Just use it as an RiSurface before rendering the walls of
the room
– Make sure each wall gets a different texture
• However, polygons do not have simple ways to
adjust texture coordinates and texture may wrap or
tile
• Alternative: BILINEAR patch
RiPatch
• RiPatch (“bilinear”, RI_P, (RtPointer)
corners, RI_ST, (RtPointer) textcoords,
RI_NULL);
– RtPoint corners[4];
– static struct {RtFloat x,y} textcoords [4];
What you need to do
• Put 3 lights in the scene
– 1 point, 1 directional, 1 spot
• Forget about the shadows
– I’ll send out email with instructions for those
who are still interested
Download