Prev | Next



RenderMan Artist Tools

PhotoRealistic RenderMan
Application Note #6


Appendix A: A C Program that Generates a Scene

May, 1990
#include <stdio.h>
#include <ri.h>

#define ASPECT_RATIO	1.33333    /* define as 1.33333 for usual 4:3 image */
#define TEXTURE_ROWS	256        /* a power of two */
#define IMAGE_ROWS	300

main()
{
    RiBegin(RI_NULL);
    SetupOptions();

    RiFrameBegin(0);
    SetupCamera();

    RiWorldBegin();
    SetupModel();
    RiWorldEnd();

    RiFrameEnd();
    RiEnd();
}

/*
 * Set RenderMan options for medium quality/speed tradeoff.
 */

SetupOptions()
{
    static RtInt gsz = 32;
    static RtInt bktsz[2] = {12, 12};
    RtInt splits = 5;

    RiOption("limits", "gridsize", (RtPointer) &gsz,
		"eyesplits", (RtPointer) &splits,
		"bucketsize", (RtPointer) bktsz, RI_NULL);
    RiShadingRate(2.);
    RiPixelSamples(2., 2.);
    RiPixelFilter(RiBoxFilter, 1., 1.);

#ifdef REFLECTION
    RiDisplay("refl.tif", RI_FILE, RI_RGBA, RI_NULL);
    RiFormat(TEXTURE_ROWS, TEXTURE_ROWS, ASPECT_RATIO);
#else
    RiDisplay("foo", RI_FRAMEBUFFER, RI_RGBA, RI_NULL);
    RiFormat((RtInt)(IMAGE_ROWS*ASPECT_RATIO), IMAGE_ROWS, 1.0);
#endif
}

/*
 * Set RenderMan camera parameters.
 */

SetupCamera()

{
    static RtMatrix m = {		/* an arbitrary viewing matrix */
	.970143, -0.004705, -.24249, 0,
	0, .999812, -0.0193992, 0,
	.242536, 0.01882, .96996, 0,
	-7.27607, -1.96434, 53.406, 1
    };
    RtFloat fov = 25.;

    RiProjection(RI_PERSPECTIVE, (RtToken) "fov", (RtPointer) &fov, RI_NULL);
    RiTransform(m);

#ifdef REFLECTION
    /* Transform z=0 plane to coincide with reflection plane. */
    RiTranslate(0., 0., -0.05);

    /* Reflect camera through the reflection plane z=0. */
    RiScale(1., 1., -1.);

    /* Transform reflection plane back to z=0. */
    RiTranslate(0., 0., 0.05);
#endif
}

/*
 * The model consists of three "walls" of a room (actually two
 * walls and the floor) with a mirror on one of the walls.
 * When rendering the REFLECTION image, the mirror
 * and the wall it is hanging on are both removed so that
 * the camera can see into the room from the other side of
 * the wall.
 */

SetupModel()
{
    static RtColor c[4] = { 		/* various colors */
	{ 0.5, 0.4, 0.1}, { 0.3, 0.5, 0.5},
	{ 1, 1, 1}, { 0.4, 0.2, 0.7}
    };
    int i;
#ifdef REFLECTION
#define NWALLS	2		/* Just do two walls. */
    static RtPoint walls[NWALLS][4] = {
	{ 0, 0, -100}, { 0, 0, 0}, { 100, 0, -100}, {100, 0, 0},
	{ 0, 100, -100}, {0, 100, 0}, { 0, 0, -100}, { 0, 0, 0},
    };
#else
#define NWALLS	3		/* Do three walls and mirror. */
    static RtPoint walls[NWALLS][4] = {
	{ 0, 0, -100}, { 0, 0, 0}, { 100, 0, -100}, {100, 0, 0},
	{ 0, 100, -100}, {0, 100, 0}, { 0, 0, -100}, { 0, 0, 0},
	{ 0, 100, 0}, { 100, 100, 0}, { 0, 0, 0 }, { 100, 0, 0}
    };
    static RtPoint mirror[4] = {
	{ 5, 10.5, -.05}, { 10, 10.5, -.05},
	{5, 0.5, -.05}, { 10, 0.5, -.05}
    };


    RiAttributeBegin();
    RiColor(c[2]);
    RiSurface("refl", RI_NULL);
    RiPatch(RI_BILINEAR, RI_P, (RtPointer) mirror, RI_NULL);
    RiAttributeEnd();
#endif

    RiColor(c[0]);
    for (i = 0; i < NWALLS; i++) {
	RiPatch(RI_BILINEAR, RI_P, (RtPointer) walls[i], RI_NULL);
	RiColor(c[1]);
    }

    /* Put a teapot in the room. */
    RiColor(c[3]);
    RiTransformBegin();
	RiTranslate(5., 1., -2.);
	RiRotate(90., 0., 1., 0.);
	RiRotate(-90., 1., 0., 0.);
	RiGeometry("teapot", RI_NULL);
    RiTransformEnd();
}

Prev | Next


Pixar Animation Studios
Copyright© Pixar. All rights reserved.
Pixar® and RenderMan® are registered trademarks of Pixar.
All other trademarks are the properties of their respective holders.