#! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'Doc/Guide/preface.tex' <<'END_OF_FILE' X\chapter*{Preface} X\addcontentsline{toc}{chapter}{Preface} X X{\em Rayshade} is a program for creating ray-traced images. XIt reads a description of a scene to be Xrendered and produces a color image corresponding to the Xdescription. X{\em Rayshade} was designed to make it easy to Xcreate nice pictures. XIt was also meant to be flexible, easy to modify, Xand relatively fast. X XThe first version of \rayshade was written in 1987-1998 at XPrinceton University with help and encouragement from David Dobkin Xand David Hoffman. That version was heavily based on a public-domain X``introductory'' ray tracer written by Roman Kuchkuda. XChanges to \rayshade from that point until version 4.0 were Xevolutionary in nature. XThe current version is to a large extent a re-write, Xand an attempt has been made to remove some of the fundamental Xproblems present in previous incarnations. X XI wish to thank the many people who have made Xcontributions to the development of {\em rayshade} during the past four years. XThanks to Marc Andreessen, Ray Bellis, Dominique Boisvert, William Bouma, XAllen Braunsdorf, Jeff Butterworth, Nick Carriero, Nancy Everson, Tom Friedel, XRobert Funchess, David Gelernter, Mike Gigante, Ed Herderick, John Knuston, XRaphael Manfredi, Lee Moore, Dietmar Saupe, Brian Wyvill, Xand everybody else for their bug-fixes, suggestions, input files, Xencouragement, support, and other feedback. X XDavid Dobkin first suggested that an extensible Xray tracer would be a worthwhile project. Gavin Bell, David XHoffman, Lefteris Koutsofios, and Steven North Xwere the first users of the original \rayshade, and their feedback Xshowed that the project might indeed have a future. XIn the Fall of 1988, XPrzemyslaw Prusinkiewicz encouraged me Xto develop \rayshade further, and was, as always, full of ``insanely Xgreat'' ideas. The resulting version of \rayshade was released Xon UseNet in 1989. Allan Snider was particularly helpful in Xfinding bugs in version 3.0 and in making valuable suggestions Xas to how the program might be improved. X X{\em Rashade} version 4.0 Xwas written by Craig Kolb and Rod Bogart during 1990-1991, with contributions Xof ideas and code made by many others. XPat Hanrahan's {\em OOGL} provided the spirit, if not the letter, of the Xmodularity of the version 4.0. Thanks to Pat and to Mark VandeWettering Xfor the ``net tracer'' conversations and for the inspiration to do something Xto clean up {\em rayshade}. XEric Haines saved the day on more than one occasion by suggesting Ximprovements, finding bugs, and saying nice things about \rayshade Xwhen I was all but ready to throw in the towel. XRobert Skinner was kind enough to provide the {\em Noise()}, {\em DNoise()}, Xand other texturing functions and to allow them to be redistributed. XMark Podlipec provided the blob object and torus object, which uses XJochen Schwarze's cubic and quartic root-finding functions. XMajor Thanks to Rod Bogart for being willing to take the plunge and Xplay such a large role in the development of version 4.0. XI am most grateful to Benoit Mandelbrot for his Xcontinued support and inspiration. X X\begin{flushright} X\parbox[t]{1.5in}{ XC. Kolb \\ XFebruary 13, 1991 X} X\end{flushright} END_OF_FILE if test 3168 -ne `wc -c <'Doc/Guide/preface.tex'`; then echo shar: \"'Doc/Guide/preface.tex'\" unpacked with wrong size! fi # end of 'Doc/Guide/preface.tex' fi if test -f 'Examples/pool.ray' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Examples/pool.ray'\" else echo shar: Extracting \"'Examples/pool.ray'\" \(3791 characters\) sed "s/^X//" >'Examples/pool.ray' <<'END_OF_FILE' X/* Converted by rsconvert */ X/* X * Example rayshade input file X * X * pool table from "Reds' Nightmare" X * X * C. Kolb 2/88 X * X * $Id: pool.ray,v 4.0 91/07/17 14:26:36 kolb Exp Locker: kolb $ X * X * $Log: pool.ray,v $ X * Revision 4.0 91/07/17 14:26:36 kolb X * Initial version. X * X */ Xup 0 0 1 Xfov 45 Xscreen 512 512 Xmaxdepth 2 Xbackground 0 0 0 Xlight 1.4 point 20 0 66 Xsurface blacktile X ambient 0.01 0.01 0.01 X diffuse 0.01 0.01 0.01 Xsurface s0 X ambient 0.862745 0.862745 0.862745 X diffuse 0.039216 0.039216 0.039216 Xsurface s1 X X ambient 0.470588 0.156863 0.392157 X diffuse 0.470588 0.156863 0.392157 X specular 1 1 1 Xsurface s2 X X ambient 0.117647 0.117647 0.392157 X diffuse 0.117647 0.117647 0.392157 Xsurface s3 X X ambient 0.784314 0.078431 0.078431 X diffuse 0.470588 0.039216 0.039216 Xsurface s4 X ambient 0 0.2235 0.145 X diffuse 0 0.2235 0.145 Xsurface mirror X ambient 0.04 0.04 0.04 X diffuse 0.05 0.05 0.05 X specular .8 .8 .8 X specpow 60 X reflect 1. Xsurface s5 X ambient 0.196078 0.392157 0.117647 X diffuse 0.196078 0.392157 0.117647 X specular 0.156863 0.156863 0.156863 X specpow 7 X reflect 1. Xsurface s6 X X ambient 0.588235 0.392157 0.117647 X diffuse 0.196078 0.392157 0.117647 X specular 0.156863 0.156863 0.156863 X specpow 7 X reflect 1. Xsurface s7 X ambient 0.196078 0.392157 0.509804 X diffuse 0.196078 0.392157 0.117647 X specular 0.156863 0.156863 0.156863 X specpow 7 X reflect 1. Xsurface s8 X ambient 0.980392 0.196078 0.117647 X diffuse 0.196078 0.392157 0.117647 X specular 0.156863 0.156863 0.156863 X specpow 7 X reflect 1. Xsurface s9 X X ambient 0.196078 0.392157 0.901961 X diffuse 0.196078 0 0.117647 X specular 0.156863 0.156863 0.156863 X specpow 7 X reflect 1. Xsurface s10 X ambient 0.411765 0.411765 0.176471 X diffuse 0.411765 0.411765 0.176471 Xsurface floor X ambient 0.1 0.1 0.1 X diffuse 0.5 0.5 0.45 X specular 0.8 0.8 0.8 X specpow 18 Xsurface s12 X ambient 0.313725 0.313725 0.313725 X diffuse 0.745098 0.745098 0.745098 Xsurface s13 X ambient 0.078431 0.862745 0.078431 X diffuse 0.039216 0.039216 0.039216 X specular 0.156863 0.156863 0.156863 X specpow 7 Xsurface s14 X ambient 0.784314 0.078431 0.078431 X diffuse 0.470588 0.039216 0.039216 Xsurface s15 X ambient 0.392157 0.098039 0.047059 X diffuse 0.392157 0.098039 0.047059 X specular 0.039216 0.039216 0.039216 X specpow 3 Xsurface s16 X ambient 0.509804 0.509804 0.509804 X diffuse 0.509804 0.509804 0.509804 X specular 0.156863 0.156863 0.156863 X specpow 7 X reflect 1. Xsphere s5 1.5 0 -21 1.5 X sphere s6 1.5 1.5 -23.598 1.5 X sphere s7 1.5 -1.5 -23.598 1.5 X sphere s8 1.5 3 -26.1962 1.5 X sphere s9 1.5 0 -26.1962 1.5 X sphere s5 1.5 -3 -26.1962 1.5 X sphere s6 1.5 4.5 -28.7942 1.5 X sphere s7 1.5 1.5 -28.7942 1.5 X sphere s8 1.5 -1.5 -28.7942 1.5 X sphere s9 1.5 -4.5 -28.7942 1.5 X sphere s5 1.5 6 -31.3923 1.5 X sphere s6 1.5 3 -31.3923 1.5 X sphere s7 1.5 0 -31.3923 1.5 X sphere s8 1.5 -3 -31.3923 1.5 X sphere s9 1.5 -6 -31.3923 1.5 X X box s4 -30 -57 -2 30 57 0 X box s15 27 -54 -1.5 33 54 1.5 texture wood scale 15 10 15 X box s15 -33 -54 -1.5 -27 54 1.5 texture wood scale 15 10 15 X box s15 -33 54 -1.5 33 60 1.5 texture wood scale 10 15 15 X box s15 -33 -60 -1.5 33 -54 1.5 texture wood scale 10 15 15 X sphere s16 1.5 0 0 0 translate 0 21 1.5 X box mirror -11.3333 -144.1 10 31.3333 -143.9 50 /* was 40. -144 30. */ X /* X * Walls X */ X plane s10 0 -144 0 0 1 0 X plane s10 -180 0 0 1 0 0 X plane s10 180 0 0 -1 0 0 X plane s10 0 144 0 0 -1 0 X /* X * Floor X */ X plane floor 0 0 -30 0 0 1 X texture marble scale 6 6 6 rotate 1 0 0 90 X translate 0 0 -4.376 X texture checker blacktile scale 12.3 12.3 12.3 X /* X * Ceiling X */ X plane s12 0 0 72 0 0 -1 X Xeyep 38 100 43 Xlookp 0 0 0 END_OF_FILE if test 3791 -ne `wc -c <'Examples/pool.ray'`; then echo shar: \"'Examples/pool.ray'\" unpacked with wrong size! fi # end of 'Examples/pool.ray' fi if test -f 'etc/nff2shade.awk' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'etc/nff2shade.awk'\" else echo shar: Extracting \"'etc/nff2shade.awk'\" \(3477 characters\) sed "s/^X//" >'etc/nff2shade.awk' <<'END_OF_FILE' X# X# This awk script will convert an NFF-format input file (as output by X# Eric Haines' SPD) to something rayshade can understand. X# The World object will be enclosed in a single grid of 22*22*22 voxels. X# X# Example usage: X# mount | awk -f sped2shade.awk | rayshade > mountains.rle X# X# For best results, one should modify the output for all but the tetra X# and mountain databases to provide a tighter bounding box around the X# object of interest (tree, gears, etc.). This is done by moving X# ground polygons and the like outside of the topmost grid object. X# This will decrease ray-tracing time dramatically. X# X# Note that we have to make sure that the viewing paramters are output X# outside of the object definition block. We do this by printing X# the eye position, etc., at the very end of the output. X# XBEGIN{ X init = 0; X lights = 0; X print "maxdepth 4" X print "sample 1 nojitter" X print "cutoff 0." X print "report verbose" X} Xsubstr($1, 1, 1) == "#" { print "/* " $0 " */"; next;} X$1 == "v" { next;} X$1 == "from" { eyex = $2; eyey = $3; eyez = $4; next;} X$1 == "at" { atx = $2; aty = $3; atz = $4; next;} X$1 == "up" { upx = $2; upy = $3; upz = $4; next;} X$1 == "angle" { fov = $2; next;} X$1 == "hither" {next;} X$1 == "resolution" {screenx = $2; screeny = $3; next;} X X$1 == "l" { lightd[lights] = $2 " "$3 " "$4; lights++; next; } X$1 == "b" {print "background " $2 " "$3 " "$4; next; } X$1 == "f" { X if (init == 0) { X print "grid 22 22 22"; X init = 1; X } X printf("applysurf "); X if (lights != 0) X aintens = sqrt(lights) / (4*lights); X else X aintens = .1; X dr = $2*$5; X dg = $3*$5; X db = $4*$5; X# this is a good guess.... X ar = aintens*dr; X ag = aintens*dg; X ab = aintens*db; X if (ar != 0 || ag != 0 || ab != 0) X printf("\tambient %f %f %f\n", ar, ag, ab); X if (dr != 0 || dg != 0 || db != 0) X printf("\tdiffuse %f %f %f\n", dr, dg, db); X# X# This gets a little strange. We're given a color, Ks, and T. X# We need a specular color, a specular reflectivity (for reflected X# rays), and a transparency (for transmitted rays). X# In rayshade, reflected rays have intensity proportional to X# specular_color*reflectivity, transmitted proportaional to X# specular_color*transparency, and specular hilights to X# specular_color. Also, Ks + T >1 for some SPDs. X# X if ($6) { X sr = $2*$6; X sg = $3*$6; X sb = $4*$6; X printf("\tspecular %f %f %f specpow %f\n", sr, sg, sb, $7); X } X if ($6 < 1. - $8) X printf("\treflect 1.0\n"); X else X printf("\treflect %f\n", 1. - $8); X X if ($8 || $9) X printf("\ttransp %f index %f\n", $8, $9); X next; X} X X$1 == "c" { X getline; X x1 = $1; X y1 = $2; X z1 = $3; X br = $4; X getline; X printf("cone %f %f %f %f %f %f %f %f\n", \ X br, x1, y1, z1, $4, $1, $2, $3); X next; X} X$1 == "s" { X print "sphere "$5 " "$2 " "$3 " "$4; X next; X} X$1 == "pp" { X if ($2 == 3) X print "triangle "; X else X print "poly "; X next; X} X$1 == "p" { X# X# Polygon -- the vertices will print out in the default statement. X# If there are three vertices, make it a triangle. X# X if ($2 == 3) X print "triangle "; X else X print "poly "; X next; X} X{ X# Matched nothing (or is a vertex data) -- print it. X print; X next; X} XEND{ X print "end" X# X# Output light definitions. X# X intens = sqrt(lights) / (lights); X for (i = 0; i < lights; i++) { X print "light " intens " point " lightd[i] X } X printf("eyep %g %g %g\n", eyex, eyey, eyez); X printf("lookp %g %g %g\n", atx, aty, atz); X printf("up %g %g %g\n", upx, upy, upz); X printf("fov %g\n", fov); X printf("screen %d %d\n", screenx, screeny); X} END_OF_FILE if test 3477 -ne `wc -c <'etc/nff2shade.awk'`; then echo shar: \"'etc/nff2shade.awk'\" unpacked with wrong size! fi # end of 'etc/nff2shade.awk' fi if test -f 'libray/libcommon/sampling.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'libray/libcommon/sampling.c'\" else echo shar: Extracting \"'libray/libcommon/sampling.c'\" \(3298 characters\) sed "s/^X//" >'libray/libcommon/sampling.c' <<'END_OF_FILE' X/* X * sampling.c X * X * Copyright (C) 1989, 1991, Craig E. Kolb, Rod G. Bogart X * All rights reserved. X * X * This software may be freely copied, modified, and redistributed X * provided that this copyright notice is preserved on all copies. X * X * You may not distribute this software, in whole or in part, as part of X * any commercial product without the express consent of the authors. X * X * There is no warranty or other guarantee of fitness of this software X * for any purpose. It is provided solely "as is". X * X * $Id: sampling.c,v 4.0 91/07/17 14:31:55 kolb Exp Locker: kolb $ X * X * $Log: sampling.c,v $ X * Revision 4.0 91/07/17 14:31:55 kolb X * Initial version. X * X */ X#include "common.h" X#include "sampling.h" X XSampleInfo Sampling; /* sampling information */ X X/* X * Set sampling options. X */ Xvoid XSamplingSetOptions(n, gaussian, width) Xint n, gaussian; XFloat width; X{ X Float norm, u, v; X int x, y; X X Sampling.sidesamples = n; X Sampling.totsamples = n*n; X Sampling.weight = 1. / (Float)Sampling.totsamples; X Sampling.spacing = 1. / (Float)Sampling.sidesamples; X Sampling.filterwidth = width; X Sampling.filterdelta = Sampling.filterwidth * Sampling.spacing; X Sampling.gaussian = gaussian; X X Sampling.filter = (Float **)Malloc(Sampling.sidesamples X *sizeof(Float *)); X for (y = 0; y < Sampling.sidesamples; y++) { X Sampling.filter[y] = (Float *)Malloc(Sampling.sidesamples * X sizeof(Float)); X } X if (Sampling.gaussian) { X norm = 0.; X u = -0.5*Sampling.filterwidth + X 0.5*Sampling.filterwidth*Sampling.spacing; X for (x = 0; x < Sampling.sidesamples; x++) { X v = -0.5*Sampling.filterwidth + X 0.5*Sampling.filterwidth*Sampling.spacing; X for (y = 0; y < Sampling.sidesamples; y++) { X Sampling.filter[x][y] = exp(-0.5*(u*u+v*v)); X norm += Sampling.filter[x][y]; X v += Sampling.spacing * X Sampling.filterwidth; X } X u += Sampling.spacing * Sampling.filterwidth; X } X X for (x = 0; x < Sampling.sidesamples; x++) X for (y = 0; y < Sampling.sidesamples; y++) X Sampling.filter[x][y] /= norm; X } else { X /* Box filter. Yawn. */ X for (x = 0; x < Sampling.sidesamples; x++) X for (y = 0; y < Sampling.sidesamples; y++) X Sampling.filter[x][y] = Sampling.weight; X } X} X X/* X * Set start time and duration of frame. X */ Xvoid XSamplingSetTime(starttime, shutter, frame) XFloat starttime, shutter; Xint frame; X{ X Sampling.starttime = starttime; X Sampling.shutter = shutter; X Sampling.framenum = frame; X TimeSet(Sampling.starttime); X FrameSet((Float)frame); X} X X/* X * Find a point on a unit circle that is separated from other random X * points by some jitter spacing. X * X * It should do the above, but the temporary hack below just finds a X * jittered point in a unit square. X */ Xvoid XUnitCirclePoint(pnt, sample) XVector *pnt; X{ X /* X * This picks a random point on a -1 to 1 square. The jitter stuff X * is correct enough to avoid excessive noise. An extremely blurry X * bright highlight will look squarish, not roundish. Sorry. X */ X Float jit; X X if (sample >= 0) { X jit = 2. * Sampling.spacing; X X pnt->x = nrand()*jit - 1.0 + X (sample % Sampling.sidesamples) * jit; X pnt->y = nrand()*jit - 1.0 + X (sample / Sampling.sidesamples) * jit; X pnt->z = 0.0; X } else { X pnt->x = nrand() * 2.0 - 1.0; X pnt->y = nrand() * 2.0 - 1.0; X pnt->z = 0.0; X } X} END_OF_FILE if test 3298 -ne `wc -c <'libray/libcommon/sampling.c'`; then echo shar: \"'libray/libcommon/sampling.c'\" unpacked with wrong size! fi # end of 'libray/libcommon/sampling.c' fi if test -f 'libray/libcommon/vecmath.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'libray/libcommon/vecmath.c'\" else echo shar: Extracting \"'libray/libcommon/vecmath.c'\" \(3640 characters\) sed "s/^X//" >'libray/libcommon/vecmath.c' <<'END_OF_FILE' X/* X * vecmath.c X * X * Copyright (C) 1989, 1991, Craig E. Kolb X * All rights reserved. X * X * This software may be freely copied, modified, and redistributed X * provided that this copyright notice is preserved on all copies. X * X * You may not distribute this software, in whole or in part, as part of X * any commercial product without the express consent of the authors. X * X * There is no warranty or other guarantee of fitness of this software X * for any purpose. It is provided solely "as is". X * X * $Id: vecmath.c,v 4.0 91/07/17 14:33:02 kolb Exp Locker: kolb $ X * X * $Log: vecmath.c,v $ X * Revision 4.0 91/07/17 14:33:02 kolb X * Initial version. X * X */ X#include "common.h" X X/* X * Normalize a vector, return original length. X */ XFloat XVecNormalize(a) Xregister Vector *a; X{ X Float d; X X d = sqrt(a->x*a->x + a->y*a->y + a->z*a->z); X if(d == 0.) X return 0.; X a->x /= d; X a->y /= d; X a->z /= d; X#ifdef CRAY X /* X * The Cray Research Inc. math functional units don't work in the IEEE X * standard way, so when we get here, we just might have an x,y or z X * that is not in the range -1.0 <= J <= 1.0 Yes, I know that that X * can't happen, but it does. So since we know we just normalized this X * vector, we'll just force x,y and z into the range -1.0 to 1.0 O.K? X */ X if (a->x >= 1.0) a->x = 1.0; X else if (a->x <= -1.0) a->x = -1.0; X if (a->y >= 1.0) a->y = 1.0; X else if (a->y <= -1.0) a->y = -1.0; X if (a->z >= 1.0) a->z = 1.0; X else if (a->z <= -1.0) a->z = -1.0; X#endif /* CRAY */ X X return d; X} X X/* X * Compute cross-product of a and b, place normalized result in o. Returns X * length of result before normalization. X */ XFloat XVecNormCross(a, b, r) XVector *a, *b, *r; X{ X VecCross(a, b, r); X return VecNormalize(r); X} X X/* X * Compute cross-product of a and b, place result in o. X */ Xvoid XVecCross(a, b, r) XVector *a, *b, *r; X{ X r->x = (a->y * b->z) - (a->z * b->y); X r->y = (a->z * b->x) - (a->x * b->z); X r->z = (a->x * b->y) - (a->y * b->x); X} X X/* X * Calculate direction of refracted ray using Heckbert's formula. Returns TRUE X * if a total internal reflection occurs. X */ Xint XRefract(dir, from_index, to_index, I, N, cos1) XFloat from_index, to_index, cos1; XVector *dir, *I, *N; X{ X Float kn, cos2, k; X Vector nrm; X X if (cos1 < 0.) { X /* X * Hit the 'backside' of a surface -- flip the normal. X */ X nrm.x = -N->x; X nrm.y = -N->y; X nrm.z = -N->z; X cos1 = -cos1; X } else X nrm = *N; X X kn = from_index / to_index; X cos2 = 1. - kn*kn*(1. - cos1*cos1); X if (cos2 < 0.) X return TRUE; /* Total internal reflection. */ X k = kn * cos1 - sqrt(cos2); X VecComb(kn, *I, k, nrm, dir); X return FALSE; X} X X/* X * Given a vector, find two additional vectors such that all three X * are mutually perpendicular and uaxis X vaxis = vector. The given X * vector need not be normalized. uaxis and vaxis are normalized. X */ Xvoid XVecCoordSys(vector, uaxis, vaxis) XVector *vector, *uaxis, *vaxis; X{ X uaxis->x = -vector->y; X uaxis->y = vector->x; X uaxis->z = 0.; X if (VecNormalize(uaxis) == 0.) { X uaxis->x = vector->z; X uaxis->y = 0.; X uaxis->z = -vector->x; X if (VecNormalize(uaxis) == 0.) X RLerror(RL_WARN, X "VecCoordSys passed degenerate vector.\n"); X } X (void)VecNormCross(vector, uaxis, vaxis); X} X X/* X * Modify given normal by "bumping" it. X */ Xvoid XMakeBump(norm, dpdu, dpdv, fu, fv) XVector *norm, *dpdu, *dpdv; /* normal, surface derivatives */ XFloat fu, fv; /* bump function partial derivatives in uv */ X{ X Vector tmp1, tmp2; X X VecCross(norm, dpdv, &tmp1); X VecScale(fu, tmp1, &tmp1); X VecCross(norm, dpdu, &tmp2); X VecScale(fv, tmp2, &tmp2); X VecSub(tmp1, tmp2, &tmp1); X VecAdd(*norm, tmp1, norm); X (void)VecNormalize(norm); X} END_OF_FILE if test 3640 -ne `wc -c <'libray/libcommon/vecmath.c'`; then echo shar: \"'libray/libcommon/vecmath.c'\" unpacked with wrong size! fi # end of 'libray/libcommon/vecmath.c' fi if test -f 'libray/liblight/spot.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'libray/liblight/spot.c'\" else echo shar: Extracting \"'libray/liblight/spot.c'\" \(3312 characters\) sed "s/^X//" >'libray/liblight/spot.c' <<'END_OF_FILE' X/* X * spot.c X * X * Copyright (C) 1989, 1991, Craig E. Kolb X * All rights reserved. X * X * This software may be freely copied, modified, and redistributed X * provided that this copyright notice is preserved on all copies. X * X * You may not distribute this software, in whole or in part, as part of X * any commercial product without the express consent of the authors. X * X * There is no warranty or other guarantee of fitness of this software X * for any purpose. It is provided solely "as is". X * X * $Id: spot.c,v 4.0 91/07/17 14:35:42 kolb Exp Locker: kolb $ X * X * $Log: spot.c,v $ X * Revision 4.0 91/07/17 14:35:42 kolb X * Initial version. X * X */ X#include "light.h" X#include "spot.h" X Xstatic LightMethods *iSpotMethods = NULL; X XSpotlight * XSpotCreate(from, to, coef, in, out) XVector *from, *to; XFloat coef, in, out; X{ X Spotlight *spot; X X spot = (Spotlight *)share_malloc(sizeof(Spotlight)); X spot->pos = *from; X VecSub(*to, *from, &spot->dir); X if (VecNormalize(&spot->dir) == 0. || in > out) { X RLerror(RL_ABORT,"Invalid spotlight specification.\n"); X return (Spotlight *)NULL; X } X spot->coef = coef; X spot->radius = cos(deg2rad(in)); X spot->falloff = cos(deg2rad(out)); X X return spot; X} X XLightMethods * XSpotMethods() X{ X if (iSpotMethods == (LightMethods *)NULL) { X iSpotMethods = LightMethodsCreate(); X iSpotMethods->intens = SpotIntens; X iSpotMethods->dir = SpotDirection; X } X return iSpotMethods; X} X X/* X * Calculate intensity ('color') of light reaching 'pos' from light 'lp'. X * The spotlight is 'dist' units from 'pos' along 'dir'. X * X * Returns TRUE if non-zero illumination, FALSE otherwise. X */ Xint XSpotIntens(spot, lcolor, cache, ray, dist, noshadow, color) XSpotlight *spot; XShadowCache *cache; XRay *ray; XColor *lcolor, *color; Xint noshadow; XFloat dist; X{ X Float atten; X extern Float SpotAtten(); X X /* X * Compute spotlight color X */ X atten = SpotAtten(spot, &ray->dir); X /* X * If outside of spot, return FALSE. X */ X if (atten == 0.) X return FALSE; X if (Shadowed(color, lcolor, cache, ray, dist, noshadow)) X return FALSE; X ColorScale(atten, *color, color); X return TRUE; X} X X/* X * Compute intensity of spotlight along 'dir'. X */ XFloat XSpotAtten(lp, dir) XSpotlight *lp; XVector *dir; X{ X Float costheta, atten; X extern Float rampup(); X X costheta = -dotp(dir, &lp->dir); X /* X * Behind spotlight. X */ X if (costheta <= 0.) X return 0.; X /* X * Intensity is the product of costheta raised to lp->coef and X * a function that smoothly interpolates from 0 at X * costheta=lp->falloff to 1 at costheta=lp->radius. X */ X atten = pow(costheta, lp->coef); X if (lp->radius > 0.) X atten *= rampup(lp->falloff, lp->radius, costheta); X return atten; X} X X/* X * Cubic interpolation between 0 at left and 1 at right, sampled at 'at' X * It is assumed that right >= left. X */ XFloat Xrampup(left, right, at) XFloat left, right, at; X{ X if (at < left) X return 0.; X else if (at > right) X return 1.; X X if (right == left) X return 0.; X X at = (at - left) / (right - left); X return (3 - 2*at)*at*at; X} X Xvoid XSpotDirection(lp, pos, dir, dist) XSpotlight *lp; XVector *pos, *dir; XFloat *dist; X{ X /* X * Calculate dir from position to center of light source. X */ X VecSub(lp->pos, *pos, dir); X *dist = VecNormalize(dir); X} X XSpotMethodRegister(meth) XUserMethodType meth; X{ X if (iSpotMethods) X iSpotMethods->user = meth; X} END_OF_FILE if test 3312 -ne `wc -c <'libray/liblight/spot.c'`; then echo shar: \"'libray/liblight/spot.c'\" unpacked with wrong size! fi # end of 'libray/liblight/spot.c' fi if test -f 'libray/libobj/box.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'libray/libobj/box.c'\" else echo shar: Extracting \"'libray/libobj/box.c'\" \(3201 characters\) sed "s/^X//" >'libray/libobj/box.c' <<'END_OF_FILE' X/* X * box.c X * X * Copyright (C) 1989, 1991, Craig E. Kolb X * All rights reserved. X * X * This software may be freely copied, modified, and redistributed X * provided that this copyright notice is preserved on all copies. X * X * You may not distribute this software, in whole or in part, as part of X * any commercial product without the express consent of the authors. X * X * There is no warranty or other guarantee of fitness of this software X * for any purpose. It is provided solely "as is". X * X * $Id: box.c,v 4.0 91/07/17 14:36:32 kolb Exp Locker: kolb $ X * X * $Log: box.c,v $ X * Revision 4.0 91/07/17 14:36:32 kolb X * Initial version. X * X */ X#include "geom.h" X#include "box.h" X Xstatic Methods *iBoxMethods = NULL; Xstatic char boxName[] = "box"; X Xunsigned long BoxTests, BoxHits; X XBox * XBoxCreate(v1, v2) XVector *v1, *v2; X{ X Box *box; X Vector size; X X VecSub(*v1, *v2, &size); X X if (equal(size.x, 0.) || equal(size.y, 0.) || equal(size.z, 0.)) { X RLerror(RL_WARN, "Degenerate box.\n"); X return (Box *)NULL; X } X X box = (Box *)share_malloc(sizeof(Box)); X box->bounds[LOW][X] = min(v1->x, v2->x); X box->bounds[HIGH][X] = max(v1->x, v2->x); X box->bounds[LOW][Y] = min(v1->y, v2->y); X box->bounds[HIGH][Y] = max(v1->y, v2->y); X box->bounds[LOW][Z] = min(v1->z, v2->z); X box->bounds[HIGH][Z] = max(v1->z, v2->z); X return box; X} X XMethods * XBoxMethods() X{ X if (iBoxMethods == (Methods *)NULL) { X iBoxMethods = MethodsCreate(); X iBoxMethods->create = (GeomCreateFunc *)BoxCreate; X iBoxMethods->methods = BoxMethods; X iBoxMethods->name = BoxName; X iBoxMethods->intersect = BoxIntersect; X iBoxMethods->normal = BoxNormal; X iBoxMethods->enter = BoxEnter; X iBoxMethods->bounds = BoxBounds; X iBoxMethods->stats = BoxStats; X iBoxMethods->checkbounds = FALSE; X iBoxMethods->closed = TRUE; X } X return iBoxMethods; X} X Xint XBoxIntersect(box, ray, mindist, maxdist) XBox *box; XRay *ray; XFloat mindist, *maxdist; X{ X BoxTests++; X if (BoundsIntersect(ray, box->bounds, mindist, maxdist)) { X BoxHits++; X return TRUE; X } X return FALSE; X} X Xint XBoxNormal(box, pos, nrm, gnrm) XVector *pos, *nrm, *gnrm; /* point of intersection */ XBox *box; X{ X nrm->x = nrm->y = nrm->z = 0.; X X if (equal(pos->x, box->bounds[HIGH][X])) X nrm->x = 1.; X else if (equal(pos->x, box->bounds[LOW][X])) X nrm->x = -1.; X else if (equal(pos->y, box->bounds[HIGH][Y])) X nrm->y = 1.; X else if (equal(pos->y, box->bounds[LOW][Y])) X nrm->y = -1.; X else if (equal(pos->z, box->bounds[HIGH][Z])) X nrm->z = 1.; X else if (equal(pos->z, box->bounds[LOW][Z])) X nrm->z = -1.; X else X RLerror(RL_WARN, "Confusion in nrmbox!\n"); X *gnrm = *nrm; X return FALSE; X} X X/* X * Determine if ray enters (TRUE) or leaves (FALSE) box at pos X */ Xint XBoxEnter(box, ray, mind, hitd) XBox *box; XRay *ray; XFloat mind, hitd; X{ X Vector pos; X X VecAddScaled(ray->pos, mind, ray->dir, &pos); X return OutOfBounds(&pos, box->bounds); X} X Xvoid XBoxBounds(box, bounds) XBox *box; XFloat bounds[2][3]; X{ X BoundsCopy(box->bounds, bounds); X} X Xchar * XBoxName() X{ X return boxName; X} X Xvoid XBoxStats(tests, hits) Xunsigned long *tests, *hits; X{ X *tests = BoxTests; X *hits = BoxHits; X} X Xvoid XBoxMethodRegister(meth) XUserMethodType meth; X{ X if (iBoxMethods) X iBoxMethods->user = meth; X} END_OF_FILE if test 3201 -ne `wc -c <'libray/libobj/box.c'`; then echo shar: \"'libray/libobj/box.c'\" unpacked with wrong size! fi # end of 'libray/libobj/box.c' fi if test -f 'libray/libobj/geom.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'libray/libobj/geom.h'\" else echo shar: Extracting \"'libray/libobj/geom.h'\" \(3949 characters\) sed "s/^X//" >'libray/libobj/geom.h' <<'END_OF_FILE' X/* X * geom.h X * X * Copyright (C) 1989, 1991, Craig E. Kolb X * All rights reserved. X * X * This software may be freely copied, modified, and redistributed X * provided that this copyright notice is preserved on all copies. X * X * You may not distribute this software, in whole or in part, as part of X * any commercial product without the express consent of the authors. X * X * There is no warranty or other guarantee of fitness of this software X * for any purpose. It is provided solely "as is". X * X * $Id: geom.h,v 4.0 91/07/17 14:37:52 kolb Exp Locker: kolb $ X * X * $Log: geom.h,v $ X * Revision 4.0 91/07/17 14:37:52 kolb X * Initial version. X * X */ X#ifndef OBJECT_H X#define OBJECT_H X X#include "libcommon/common.h" X#include "libcommon/transform.h" X#include "bounds.h" X X/* X * Constants for enter flag in HitNode. X */ X#define EXITING 1 X#define ENTERING 2 X X#define MAXMODELDEPTH 128 /* Maximum height of DAG. */ X Xtypedef char * GeomRef; Xtypedef GeomRef GeomCreateFunc(); X X/* X * If the object has a normal method, it's a primitive X * otherwise it's an aggregate (or an instance) X */ X#define IsAggregate(o) ((o)->methods->normal == NULL) X X/* X * Geom methods. X * (p) means applies only to primitive objects X * (a) means applies only to aggregate objects X */ Xtypedef struct Methods { X char *(*name)(); /* Geom name */ X GeomRef (*create)(); /* Create and return ref */ X int (*intersect)(), /* Ray/obj intersection */ X (*normal)(), /* Geom normal (p) */ X (*enter)(), /* Ray enter or exit? (p) */ X (*convert)(); /* Convert from list (a) */ X void (*uv)(), /* 2D mapping (p) */ X (*stats)(), /* Statistics */ X (*bounds)(), /* Bounding volume */ X (*user)(); /* User-defined method */ X struct Methods *(*methods)(); /* object methods func. */ X char checkbounds, /* check bbox before int.? */ X closed; /* properly closed? */ X} Methods; X Xtypedef void (*UserMethodType)(); X X/* X * Geom definition X */ Xtypedef struct Geom { X char *name; /* Geom name, if any. */ X GeomRef obj; /* Pointer to object info. */ X Methods *methods; X unsigned long prims; /* sum of # primitive objects */ X Float bounds[2][3]; /* Bounding box */ X Float timenow; /* Geom's idea of what time it is */ X short int animtrans; /* transformation is animated */ X short int frame; /* frame for which obj is inited */ X struct Surface *surf; /* surface, if any */ X struct Trans *trans; /* Transformation information */ X struct Trans *transtail; /* Double linked list end */ X struct Texture *texture; /* Texture mapping info. */ X#ifdef SHAREDMEM X unsigned long *counter; /* Geoms are shared, counters aren't */ X#else X unsigned long counter; /* "mailbox" for grid intersection */ X#endif X struct Geom *next; /* Next object. */ X} Geom; X X/* X * Linked list of pointers to objects. X */ Xtypedef struct GeomList { X Geom *obj; X struct GeomList *next; X} GeomList; X X/* X * Array of hit information. Stores a path through an object DAG, X * as well as the ray in 'model' (object) space and the distance from X * the ray origin to the point of intersection. X */ Xtypedef struct HitNode { X Geom *obj; /* Geom hit */ X Ray ray; /* Ray */ X Float mindist; /* Amount of ray to ignore */ X Float dist; /* Distance from ray origin to hit */ X short enter, /* Enter (TRUE) or Leave (FALSE) obj */ X dotrans; /* transformations non-identity? */ X Trans trans; /* parent-->obj and inverse trans */ X} HitNode; X X/* X * Structure holding a list of HitNodes. A maximum of MAXMODELDEPTH X * nodes can be referenced. X */ Xtypedef struct HitList { X int nodes; X HitNode data[MAXMODELDEPTH]; X} HitList; X Xextern char *GeomName(); X Xextern Geom *GeomCreate(), *GeomCopy(), *GeomCopyNamed(), X *GeomComputeAggregateBounds(); X X Xextern GeomList *GeomStackPush(), *GeomStackPop(); X Xextern void PrimUV(), AggregatePrintInfo(), X IntersectStats(); X Xextern int AggregateConvert(), PrimNormal(), X TraceRay(); /* application-provided */ X Xextern Methods *MethodsCreate(); X X#endif /* OBJECT_H */ END_OF_FILE if test 3949 -ne `wc -c <'libray/libobj/geom.h'`; then echo shar: \"'libray/libobj/geom.h'\" unpacked with wrong size! fi # end of 'libray/libobj/geom.h' fi if test -f 'libray/libobj/intersect.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'libray/libobj/intersect.c'\" else echo shar: Extracting \"'libray/libobj/intersect.c'\" \(3980 characters\) sed "s/^X//" >'libray/libobj/intersect.c' <<'END_OF_FILE' X/* X * intersect.c X * X * Copyright (C) 1989, 1991, Craig E. Kolb X * All rights reserved. X * X * This software may be freely copied, modified, and redistributed X * provided that this copyright notice is preserved on all copies. X * X * You may not distribute this software, in whole or in part, as part of X * any commercial product without the express consent of the authors. X * X * There is no warranty or other guarantee of fitness of this software X * for any purpose. It is provided solely "as is". X * X * $Id: intersect.c,v 4.0 91/07/17 14:38:37 kolb Exp Locker: kolb $ X * X * $Log: intersect.c,v $ X * Revision 4.0 91/07/17 14:38:37 kolb X * Initial version. X * X */ X#include "geom.h" X Xstatic void AddToHitList(); X/* X * Number of bounding volume tests. X * External modules have read access via IntersectStats(). X */ Xstatic unsigned long BVTests; X X/* X * Intersect object & ray. Return distance from "pos" along "ray" to X * intersection point. Return value <= 0 indicates no intersection. X */ Xint Xintersect(obj, ray, hitlist, mindist, maxdist) XGeom *obj; /* Geom to be tested. */ XRay *ray; /* Ray origin, direction. */ XHitList *hitlist; /* Intersection path */ XFloat mindist, *maxdist; X{ X Ray newray; X Vector vtmp; X Trans *curtrans; X Float distfact, nmindist, nmaxdist; X X /* X * Check ray/bounding volume intersection, if required. X */ X if (obj->methods->checkbounds) { X VecAddScaled(ray->pos, mindist, ray->dir, &vtmp); X if (OutOfBounds(&vtmp, obj->bounds)) { X nmaxdist = *maxdist; X BVTests++; X if (!BoundsIntersect(ray, obj->bounds, mindist, X &nmaxdist)) X return FALSE; X } X } X X newray = *ray; X nmindist = mindist; X nmaxdist = *maxdist; X X /* X * Transform the ray if necessary. X */ X if (obj->trans != (Trans *)0) { X /* X * If object's idea of the current time is wrong, X * update the transformations. X */ X if (obj->animtrans && !equal(obj->timenow, ray->time)) { X TransResolveAssoc(obj->trans); X } X X /* X * Transforming the ray can change the distance between X * the ray origin and the point of intersection. X * We save the amount the ray is "stretched" and later X * divide the computed distance by this amount. X */ X distfact = 1.; X for (curtrans = obj->transtail; curtrans; X curtrans = curtrans->prev) X distfact *= RayTransform(&newray, &curtrans->itrans); X nmindist *= distfact; X nmaxdist *= distfact; X } X /* X * Geom has been updated to current time. X */ X obj->timenow = ray->time; X X /* X * Call correct intersection routine. X */ X if (IsAggregate(obj)) { X /* X * Aggregate X */ X if (!(*obj->methods->intersect) X (obj->obj, &newray, hitlist, nmindist, &nmaxdist)) X return FALSE; X } else { X /* X * Primitive X */ X if (!(*obj->methods->intersect) X (obj->obj, &newray, nmindist, &nmaxdist)) X return FALSE; X hitlist->nodes = 0; X } X X /* X * Had a hit -- add ray, distance and object to tail of hitlist. X */ X AddToHitList(hitlist, &newray, nmindist, nmaxdist, obj); X X /* X * Set dist to distance to intersection point from the origin X * of the untransformed ray. X */ X if (obj->trans != (Trans *)0) X *maxdist = nmaxdist / distfact; X else X *maxdist = nmaxdist; X X return TRUE; X} X Xstatic void XAddToHitList(hitlist, ray, mind, dist, obj) XHitList *hitlist; XRay *ray; XFloat mind, dist; XGeom *obj; X{ X HitNode *np; X Trans *list; X X np = &hitlist->data[hitlist->nodes++]; X X np->ray = *ray; X np->obj = obj; X np->mindist = mind; X np->dist = dist; X np->enter = 0; X X if (obj->trans) { X /* X * Compute total transformation, forward and inverse, X * for this object, and store in hitlist for use later. X */ X TransCopy(obj->trans, &np->trans); X for (list = obj->trans->next; list; list = list->next) X TransCompose(&np->trans, list, &np->trans); X np->dotrans = TRUE; X } else X np->dotrans = FALSE; X} X X/* X * Return intersection statistics. X * Currently, this is limited to the # of bounding volume test performed. X */ Xvoid XIntersectStats(bvtests) Xunsigned long *bvtests; X{ X *bvtests = BVTests; X} END_OF_FILE if test 3980 -ne `wc -c <'libray/libobj/intersect.c'`; then echo shar: \"'libray/libobj/intersect.c'\" unpacked with wrong size! fi # end of 'libray/libobj/intersect.c' fi if test -f 'libray/libsurf/surface.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'libray/libsurf/surface.c'\" else echo shar: Extracting \"'libray/libsurf/surface.c'\" \(3304 characters\) sed "s/^X//" >'libray/libsurf/surface.c' <<'END_OF_FILE' X/* X * surface.c X * X * Copyright (C) 1989, 1991, Craig E. Kolb X * All rights reserved. X * X * This software may be freely copied, modified, and redistributed X * provided that this copyright notice is preserved on all copies. X * X * You may not distribute this software, in whole or in part, as part of X * any commercial product without the express consent of the authors. X * X * There is no warranty or other guarantee of fitness of this software X * for any purpose. It is provided solely "as is". X * X * $Id: surface.c,v 4.0 91/07/17 14:40:55 kolb Exp Locker: kolb $ X * X * $Log: surface.c,v $ X * Revision 4.0 91/07/17 14:40:55 kolb X * Initial version. X * X */ X#include "atmosphere.h" X#include "surface.h" X X#define blend(a, b, p, q) (a * p + b * q) X XColor Black = {0., 0., 0.}, X White = {1., 1., 1.}; X X/* X * Create and return pointer to surface with given properties. X */ XSurface * XSurfaceCreate() X{ X Surface *stmp; X X stmp = (Surface *)Malloc(sizeof(Surface)); X X stmp->amb = stmp->diff = stmp->spec = X stmp->translu = Black; X X stmp->body = White; X X stmp->srexp = stmp->stexp = DEFAULT_PHONGPOW; X stmp->statten = 1.; /* No attenuation by default */ X X stmp->reflect = stmp->transp = 0.; X X stmp->noshadow = FALSE; X X stmp->index = DEFAULT_INDEX; X X stmp->name = (char *)NULL; X stmp->next = (Surface *)NULL; X X return stmp; X} X XSurface * XSurfaceCopy(surf) XSurface *surf; X{ X Surface *res; X X if (!surf) X return (Surface *)NULL; X X res = SurfaceCreate(); X *res = *surf; X res->next = (Surface *)NULL; X res->name = (char *)NULL; X return res; X} X X/* X * Compute combination of two surfaces. Resulting surface is copied into surf1. X */ Xvoid XSurfaceBlend(surf1, surf2, p, q) XSurface *surf1, *surf2; XFloat p, q; X{ X /* X * P is weight of surf1. q is weight of surf2. X * Result is placed in surf1. X */ X if (q < EPSILON) X return; /* keep surf1 as-is */ X X ColorBlend(&surf1->amb, &surf2->amb, p, q); X ColorBlend(&surf1->diff, &surf2->diff, p, q); X ColorBlend(&surf1->spec, &surf2->spec, p, q); X ColorBlend(&surf1->translu, &surf2->translu, p, q); X ColorBlend(&surf1->body, &surf2->body, p, q); X X surf1->srexp = blend(surf1->srexp, surf2->srexp, p, q); X surf1->stexp = blend(surf1->stexp, surf2->stexp, p, q); X X surf1->reflect = blend(surf1->reflect, surf2->reflect, p, q); X surf1->transp = blend(surf1->transp, surf2->transp, p, q); X surf1->translucency = blend(surf1->translucency, surf2->translucency, X p, q); X /* X * Questionable... X */ X surf1->statten = blend(surf1->statten, surf2->statten, p, q); X surf1->index = blend(surf1->index, surf2->index, p, q); X X if (p < EPSILON) { X surf1->noshadow = surf2->noshadow; X } else { X /* else there's a blend of some kind... */ X surf1->noshadow = (surf1->noshadow && surf2->noshadow); X } X} X X/* X * Blend two colors. Result is placed in color1. X */ Xvoid XColorBlend(color1, color2, p, q) XColor *color1, *color2; XFloat p, q; X{ X color1->r = blend(color1->r, color2->r, p, q); X color1->g = blend(color1->g, color2->g, p, q); X color1->b = blend(color1->b, color2->b, p, q); X} X XSurfList * XSurfPop(list) XSurfList *list; X{ X SurfList *stmp = list->next; X X free((voidstar)list); X return stmp; X} X XSurfList * XSurfPush(surf, list) XSurface *surf; XSurfList *list; X{ X SurfList *stmp; X X stmp = (SurfList *)Malloc(sizeof(SurfList)); X stmp->surf = surf; X stmp->next = list; X return stmp; X} END_OF_FILE if test 3304 -ne `wc -c <'libray/libsurf/surface.c'`; then echo shar: \"'libray/libsurf/surface.c'\" unpacked with wrong size! fi # end of 'libray/libsurf/surface.c' fi if test -f 'libshade/lightdef.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'libshade/lightdef.c'\" else echo shar: Extracting \"'libshade/lightdef.c'\" \(3547 characters\) sed "s/^X//" >'libshade/lightdef.c' <<'END_OF_FILE' X/* X * lightdef.c X * X * Copyright (C) 1989, 1991, Craig E. Kolb X * All rights reserved. X * X * This software may be freely copied, modified, and redistributed X * provided that this copyright notice is preserved on all copies. X * X * You may not distribute this software, in whole or in part, as part of X * any commercial product without the express consent of the authors. X * X * There is no warranty or other guarantee of fitness of this software X * for any purpose. It is provided solely "as is". X * X * $Id: lightdef.c,v 4.0 91/07/17 14:46:25 kolb Exp Locker: kolb $ X * X * $Log: lightdef.c,v $ X * Revision 4.0 91/07/17 14:46:25 kolb X * Initial version. X * X */ X#include "rayshade.h" X#include "options.h" X#include "liblight/light.h" X#include "liblight/infinite.h" /* to create default infinite light */ X#include "liblight/jittered.h" /* to create jittered light sources */ X XLight *Lights = NULL; /* Linked list of defined lights */ X Xvoid XLightAddToDefined(light) XLight *light; X{ X if (light) { X light->next = Lights; X Lights = light; X } X} X Xvoid XLightSetup() X{ X long shadowopts; X Light *ltmp; X X /* X * Set shadowing options. X */ X shadowopts = 0; X if (Options.no_shadows) X shadowopts |= SHADOW_NONE; X if (Options.shadowtransp) X shadowopts |= SHADOW_TRANSP; X if (Options.csg) X shadowopts |= SHADOW_CSG; X if (Options.cache) X shadowopts |= SHADOW_CACHE; X if (Options.shutterspeed > 0.) X shadowopts |= SHADOW_BLUR; X ShadowSetOptions(shadowopts); X X /* X * If no light sources were defined, add a default. X */ X if (Lights == (Light *)NULL) { X Color ctmp; X Vector vtmp; X vtmp.x = vtmp.z = 1.; X vtmp.y = -1; X ctmp.r = ctmp.g = ctmp.b = 1.; X X LightAddToDefined(LightInfiniteCreate(&ctmp, &vtmp)); X } X /* X * Now that we've parsed the input file, we know what X * maxlevel is, and we can allocate the correct amount of X * space for each light source's cache. X */ X for (ltmp = Lights; ltmp; ltmp = ltmp->next) { X ltmp->cache = (ShadowCache *)Calloc( X (unsigned)Options.maxdepth + 1, sizeof(ShadowCache)); X } X} X Xvoid XAreaLightCreate(color, corner, u, usamp, v, vsamp, shadow) XColor *color; XVector *corner, *u, *v; Xint usamp, vsamp, shadow; X{ X Vector vpos, curpos; X int i, j, numlight; X Float ulen, vlen; X Color intens; X Light *ltmp; X X if (usamp < 1 || vsamp < 1) X RLerror(RL_ABORT, "Invalid area light specification.\n"); X X numlight = usamp * vsamp; /* Total number of jittered sources */ X X /* X * Sum of all intensities is equal to specified intensity. X */ X intens.r = color->r / (Float)numlight; X intens.g = color->g / (Float)numlight; X intens.b = color->b / (Float)numlight; X X VecSub(*u, *corner, u); X VecSub(*v, *corner, v); X /* X * Make sure that u and v are not degenerate. X */ X ulen = VecNormalize(u); X vlen = VecNormalize(v); X if (ulen < EPSILON || vlen < EPSILON) X RLerror(RL_ABORT, "Degenerate area light source.\n"); X /* X * Scale u and v such that they define the area covered by a X * single sample. X */ X VecScale(ulen / (Float)usamp, *u, u); X VecScale(vlen / (Float)vsamp, *v, v); X /* X * For each sample... X */ X vpos = *corner; X for (i = 0; i < vsamp; i++) { X curpos = vpos; X for (j = 0; j < usamp; j++) { X /* X * current pos is the "corner" of a new light X * source. A jittered position based on X * the "corner" and the two edge vectors X * is used as the position for the X * light source in lighting calculations. X */ X ltmp = LightJitteredCreate(&intens, &curpos, u, v); X ltmp->shadow = shadow; X LightAddToDefined(ltmp); X VecAdd(curpos, *u, &curpos); X } X VecAdd(vpos, *v, &vpos); X } X} END_OF_FILE if test 3547 -ne `wc -c <'libshade/lightdef.c'`; then echo shar: \"'libshade/lightdef.c'\" unpacked with wrong size! fi # end of 'libshade/lightdef.c' fi if test -f 'libshade/options.h' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'libshade/options.h'\" else echo shar: Extracting \"'libshade/options.h'\" \(3167 characters\) sed "s/^X//" >'libshade/options.h' <<'END_OF_FILE' X/* X * options.h X * X * Copyright (C) 1989, 1991, Craig E. Kolb X * All rights reserved. X * X * This software may be freely copied, modified, and redistributed X * provided that this copyright notice is preserved on all copies. X * X * You may not distribute this software, in whole or in part, as part of X * any commercial product without the express consent of the authors. X * X * There is no warranty or other guarantee of fitness of this software X * for any purpose. It is provided solely "as is". X * X * $Id: options.h,v 4.0 91/07/17 14:46:54 kolb Exp Locker: kolb $ X * X * $Log: options.h,v $ X * Revision 4.0 91/07/17 14:46:54 kolb X * Initial version. X * X */ X#ifndef OPTIONS_H X#define OPTIONS_H X X/* X * Constants for Stereo mode X */ X#define LEFT 1 X#define RIGHT 2 X X/* X * Options X */ Xtypedef struct RSOptions { X int stereo, /* Stereo mode? */ X verbose, /* Babbling mode? */ X quiet, /* Don't complain? */ X jitter, /* use jittered sampling? */ X samples, /* Sqrt of # of samples */ X maxdepth, /* Maximum ray tree depth */ X report_freq, /* Frequency, in lines, of report */ X no_shadows, /* Trace shadow rays? */ X shadowtransp, /* ... through transparent objects? */ X cache, /* Cache shadowing info? */ X appending, /* Append to image file? */ X resolution_set, /* resolution set on command line */ X contrast_set, /* contrast overridden ... */ X samples_set, /* samples overridden ... */ X cutoff_set, /* cutoff ... */ X maxdepth_set, /* adaptive depth ... */ X window_set, /* window ... */ X freq_set, /* report frequency ... */ X jitter_set, /* use jittering */ X eyesep_set, /* eye separation ... */ X csg, /* CSG object someplace in world */ X flipnorm, /* flip normals of polygonal objs */ X samplemap, /* output sample map? */ X gaussian, /* Use gaussian pixel filter? */ X framenum, /* current frame number */ X startframe, /* Starting frame number. */ X endframe, /* ending frame number */ X totalframes, /* total # of frames */ X totalframes_set; /* set on command line? */ X#ifdef URT X int alpha; /* Write alpha channel? */ X int exp_output; /* Write exponential RLE file? */ X#endif X Float eyesep, /* Eye separation (for Stereo mode) */ X gamma, /* Gamma value (0 == no correction) */ X xmin, xmax, ymin, ymax, /* Window range */ X starttime, /* Think about it ... */ X shutterspeed, /* time shutter is open */ X framestart, /* start time of the current frame */ X framelength, /* length of the current frame */ X filterwidth; /* Pixel filter width. */ X Color contrast, /* Max. allowable contrast */ X cutoff, /* Ray tree depth control */ X ambient; /* Ambient light multiplier */ X char *progname, /* argv[0] */ X *statsname, /* Name of stats file. */ X *imgname, /* Name of output image file */ X *inputname, /* Name of input file, NULL == stdin */ X *cppargs; /* arguments to pass to cpp */ X#ifdef LINDA X int workers, /* # of worker processes */ X workernum, /* worker #, 0 == supervisor */ X verbose_worker; /* Babble while you work? */ X#endif X FILE *pictfile; /* output file pointer */ X} RSOptions; X Xextern RSOptions Options; Xextern void OptionsList(), OptionsSet(); X X#endif /* OPTIONS_H */ END_OF_FILE if test 3167 -ne `wc -c <'libshade/options.h'`; then echo shar: \"'libshade/options.h'\" unpacked with wrong size! fi # end of 'libshade/options.h' fi if test -f 'libshade/symtab.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'libshade/symtab.c'\" else echo shar: Extracting \"'libshade/symtab.c'\" \(3608 characters\) sed "s/^X//" >'libshade/symtab.c' <<'END_OF_FILE' X/* X * symtab.c X * X * Copyright (C) 1989, 1991, Craig E. Kolb, Rod G. Bogart X * All rights reserved. X * X * This software may be freely copied, modified, and redistributed X * provided that this copyright notice is preserved on all copies. X * X * You may not distribute this software, in whole or in part, as part of X * any commercial product without the express consent of the authors. X * X * There is no warranty or other guarantee of fitness of this software X * for any purpose. It is provided solely "as is". X * X * $Id: symtab.c,v 4.0 91/07/17 14:48:02 kolb Exp Locker: kolb $ X * X * $Log: symtab.c,v $ X * Revision 4.0 91/07/17 14:48:02 kolb X * Initial version. X * X */ X X#include "rayshade.h" X#include "symtab.h" X#include "builtin.h" X Xstatic struct SymtabPredefinedEntry SymtabPredefined[] = { X {"pi", 3.141592, NULL, FLOAT_EXPR, FALSE, 0}, X {"dtor", 0.017453, NULL, FLOAT_EXPR, FALSE, 0}, X {"rtod", 57.29578, NULL, FLOAT_EXPR, FALSE, 0}, X {"cos", 0.0, cos, BUILTIN_EXPR, FALSE, 1}, X {"sin", 0.0, sin, BUILTIN_EXPR, FALSE, 1}, X {"tan", 0.0, tan, BUILTIN_EXPR, FALSE, 1}, X {"sqrt", 0.0, sqrt, BUILTIN_EXPR, FALSE, 1}, X {"acos", 0.0, acos, BUILTIN_EXPR, FALSE, 1}, X {"asin", 0.0, asin, BUILTIN_EXPR, FALSE, 1}, X {"atan", 0.0, atan, BUILTIN_EXPR, FALSE, 1}, X {"hypot", 0.0, hypot, BUILTIN_EXPR, FALSE, 2}, X {"time", 0.0, NULL, FLOAT_EXPR, TRUE, 0}, X {"frame", 0.0, NULL, FLOAT_EXPR, TRUE, 0}, X {"linear", 0.0, LinearTime, BUILTIN_EXPR, TRUE, 4}, X {NULL, 0.0, NULL, 0, 0} X}; X XSymtabEntry *Symtab = (SymtabEntry *) NULL; X Xvoid SymtabAddEntry(); X Xvoid XSymtabInit() X{ X int i; X X for(i=0; SymtabPredefined[i].name; i++) { X if (SymtabPredefined[i].type == BUILTIN_EXPR) X SymtabAddEntry(SymtabPredefined[i].name, X SymtabPredefined[i].type, X NULL, X SymtabPredefined[i].fp, X SymtabPredefined[i].timevary, X SymtabPredefined[i].params); X else X SymtabAddEntry(SymtabPredefined[i].name, X SymtabPredefined[i].type, X ExprFloatCreate(SymtabPredefined[i].f, X SymtabPredefined[i].timevary), X NULL, SymtabPredefined[i].timevary, 0); X } X TimeExpr = ExprFloatSymtabFind("time"); X FrameExpr = ExprFloatSymtabFind("frame"); X} X Xvoid XSymtabAddEntry(name, type, expr, fp, timevary, params) Xchar *name; XExpr *expr; XFloat (*fp)(); Xint type, timevary, params; X{ X SymtabEntry *res; X X if (SymtabFind(name) != (SymtabEntry *)NULL) X RLerror(RL_ABORT, "Symbol %s redefined.\n", name); X X res = (SymtabEntry *) Malloc( sizeof(SymtabEntry)); X res->name = strsave(name); X res->type = type; X res->timevary = timevary; X switch (type) { X case FLOAT_EXPR: X res->value.expr = expr; X expr->symtab = TRUE; X break; X case BUILTIN_EXPR: X res->value.fp = fp; X break; X default: X RLerror(RL_WARN, X "Type %d not implemented!!!",type); X } X res->params = params; X res->next = Symtab; X Symtab = res; X} X XSymtabEntry * XSymtabFind(name) Xchar *name; X{ X SymtabEntry *res; X for(res=Symtab; res; res=res->next) { X if (!strcmp(res->name,name)) X return res; X } X /*error*/ X return NULL; X} X XExpr * XExprFloatSymtabFind(name) Xchar *name; X{ X SymtabEntry *res; X X if ((res = SymtabFind(name)) == NULL) X RLerror(RL_PANIC, X "Symbol %s not defined!\n", name); X if (res->type != FLOAT_EXPR) X RLerror(RL_PANIC, X "Symbol %s is not a float expression!\n", name); X return res->value.expr; X} X X XSymtabEntry * XSymtabBuiltinFind(name) Xchar *name; X{ X SymtabEntry *res; X X if ((res = SymtabFind(name)) == NULL) X RLerror(RL_PANIC, X "Symbol %s not defined!\n", name); X if (res->type != BUILTIN_EXPR) X RLerror(RL_PANIC, X "Symbol %s is not a built in function!\n", name); X return res; X} END_OF_FILE if test 3608 -ne `wc -c <'libshade/symtab.c'`; then echo shar: \"'libshade/symtab.c'\" unpacked with wrong size! fi # end of 'libshade/symtab.c' fi echo shar: End of archive 7 \(of 19\). cp /dev/null ark7isdone MISSING="" for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 19 archives. rm -f ark[1-9]isdone ark[1-9][0-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0