v21i008: A ray tracing program, Part01/08

Rich Salz rsalz at uunet.uu.net
Thu Feb 8 07:48:59 AEST 1990


Submitted-by: Craig Kolb <craig at weedeater.math.yale.edu>
Posting-number: Volume 21, Issue 8
Archive-name: rayshade/part01

This is version 3.0 of rayshade, a raytracing program.  Rayshade reads
a multi-line ASCII file describing a scene to be rendered and produces
a Utah Raster RLE format file of the raytraced image.

Rayshade features:

	Eight types of primitives (box, cone, cylinder, height field,
	polygon, sphere, superquadric, flat- and Phong-shaded triangle)

	Composite objects

	Point, directional, and extended (area) light sources

	Solid procedural texturing and bump mapping of primitives, objects,
		and individual instances of objects

	Antialiasing through adaptive supersampling or "jittered" sampling

	Arbitrary linear transformations on primitives,
		instances of objects, and texture/bump maps

	Use of uniform spatial subdivision or hierarchy of bounding
		volumes to speed rendering

	Options to facilitate rendering of stereo pairs

	Support for the C-Linda parallel programming language

Rayshade has been tested on many different UNIX-based computers.  If your
machine has a C compiler and enough memory (at least 2Mb), rayshade should
be fairly easy to port.  Be warned that rayshade uses yacc and lex to
process input files.  If you do not have lex and yacc, try to get flex and
bison from the Free Software Foundation folks (ftp to prep.ai.mit.edu).


Thanks,
Craig
kolb at yale.edu

#! /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 <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 8)."
# Contents:  Changes Copyright Examples Examples/balls.ray
#   Examples/planet.map Examples/planet.ray Examples/solids.ray
#   MANIFEST README References TODO doc src src/atmosphere.c src/box.c
#   src/constants.h src/defaults.h src/input_lex.l src/memory.c
#   src/patchlevel.h src/plane.c src/raymath.c src/raytrace.h
#   src/texture.h src/typedefs.h src/version.c src/viewing.c
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Changes' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Changes'\"
else
echo shar: Extracting \"'Changes'\" \(1251 characters\)
sed "s/^X//" >'Changes' <<'END_OF_FILE'
XBugfixes
X--------
X
XWas possible to divide by zero in main.c and intersect.c.
XSuperquadric normals were sometimes unnecessarily flipped.
XFog and mist should be applied after shading calculations.
XReading colormap file with > 256 entries dumped core.
XCouldn't comment out slashes.
XRemoved check of dotp(ray, norm) in shade().
XAdded check for s < lightdist in inshadow().
XVarious problems in grid.c.
X
XPortability Changes
X-------------------
X
XCalculation of index in poly.c and triangle.c was non-portable.
XSome code in intersect.c was apparently non-portable.
XModified functions to no longer return structures.
X
XMisc. Changes
X-------------
X
XNo longer need use "endfile" keyword at the end of input files.
XAdded adaptive ray tree pruning and -T option.
XCombined -R, -G and -B options into -C option.
XAdded -R option.
XOptimization of IntBounds().
XMerged int_grid() and DDA().
XAdded "samples", "jittered", "cutoff", "contrast" and "adaptive" keywords.
XFlat-shaded triangles now require less storage space.
XShadow caching is now the default.
XThe number of shadow cache hits are reported.
XShadow cache hits are counted as "shadow rays".
XShadow hits are counted as "intersecting rays".
XThe number of shadow hits is reported.
XVarious cleanups courtesy of lint.
END_OF_FILE
if test 1251 -ne `wc -c <'Changes'`; then
    echo shar: \"'Changes'\" unpacked with wrong size!
fi
# end of 'Changes'
fi
if test -f 'Copyright' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Copyright'\"
else
echo shar: Extracting \"'Copyright'\" \(806 characters\)
sed "s/^X//" >'Copyright' <<'END_OF_FILE'
X/*
X * Copyright (C) 1989, Craig E. Kolb
X *
X * This software may be freely copied, modified, and redistributed,
X * provided that this copyright notice is preserved on all copies.
X * 
X * There is no warranty or other guarantee of fitness for this software,
X * it is provided solely "as is".  Bug reports or fixes may be sent
X * to the author, who may or may not act on them as he desires.
X *
X * You may not include this software in a program or other software product
X * without supplying the source, or without informing the end-user that the 
X * source is available for no extra charge.
X *
X * If you modify this software, you should include a notice giving the
X * name of the person performing the modification, the date of modification,
X * and the reason for such modification.
X *
X * $Id$
X *
X * $Log$
X */
END_OF_FILE
if test 806 -ne `wc -c <'Copyright'`; then
    echo shar: \"'Copyright'\" unpacked with wrong size!
fi
# end of 'Copyright'
fi
if test ! -d 'Examples' ; then
    echo shar: Creating directory \"'Examples'\"
    mkdir 'Examples'
fi
if test -f 'Examples/balls.ray' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Examples/balls.ray'\"
else
echo shar: Extracting \"'Examples/balls.ray'\" \(915 characters\)
sed "s/^X//" >'Examples/balls.ray' <<'END_OF_FILE'
X/*
X * This file is the result of feeding "balls" from Eric Haines'
X * SPD through nff2shade.awk and then hand-tweaking things.
X */
Xmaxdepth 3
Xeyep 2.1 1.3 1.7
Xlookp 0 0 0
Xup 0 0 1
Xfov 45
Xscreen 256 256
Xbackground 0.078 0.361 0.753
Xsurface s1  0.15 0.1 0.045  1. 0.75 0.33  0. 0. 0.  0. 0. 0. 0.
Xplane s1 0 0 1 0 0 -.5
Xsurface s2  0.035 0.0325 0.025  0.5 0.45 0.35  0.8 0.8 0.8  3. 0.5 0. 0.
Xsphere s2 0.5 0 0 0 texture bump 0.3 scale 0.04 0.04 0.04
Xsphere s2 0.166667 0.272166 0.272166 0.544331
Xsphere s2 0.166667 0.643951 0.172546 0
Xsphere s2 0.166667 0.172546 0.643951 0
Xsphere s2 0.166667 -0.371785 0.0996195 0.544331
Xsphere s2 0.166667 -0.471405 0.471405 0
Xsphere s2 0.166667 -0.643951 -0.172546 0
Xsphere s2 0.166667 0.0996195 -0.371785 0.544331
Xsphere s2 0.166667 -0.172546 -0.643951 0
Xsphere s2 0.166667 0.471405 -0.471405 0 
Xlight 0.288675 point 4 3 2
Xlight 0.288675 point 1 -4 4
Xlight 0.288675 point -3 1 5
END_OF_FILE
if test 915 -ne `wc -c <'Examples/balls.ray'`; then
    echo shar: \"'Examples/balls.ray'\" unpacked with wrong size!
fi
# end of 'Examples/balls.ray'
fi
if test -f 'Examples/planet.map' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Examples/planet.map'\"
else
echo shar: Extracting \"'Examples/planet.map'\" \(2551 characters\)
sed "s/^X//" >'Examples/planet.map' <<'END_OF_FILE'
X40 128 200
X40 128 200
X41 129 201
X42 130 202
X43 131 202
X44 132 203
X45 133 204
X46 134 204
X47 135 205
X48 136 206
X48 136 206
X49 137 207
X50 138 208
X51 139 209
X52 140 209
X53 141 210
X54 142 211
X55 143 211
X56 144 212
X57 145 213
X57 145 213
X58 146 214
X59 147 215
X60 148 216
X61 149 216
X62 150 217
X63 151 218
X64 152 218
X65 153 219
X66 154 220
X66 154 220
X67 155 221
X68 156 222
X69 157 222
X70 158 223
X71 159 224
X72 160 225
X73 161 225
X74 162 226
X75 163 227
X75 163 227
X76 164 228
X77 165 229
X78 166 229
X79 167 230
X80 168 231
X81 169 232
X82 170 232
X83 171 233
X84 172 234
X84 172 234
X85 173 235
X86 174 236
X87 175 236
X88 176 237
X89 177 238
X90 178 238
X91 179 239
X92 180 240
X93 181 241
X93 181 241
X94 182 242
X95 183 243
X96 184 243
X97 185 244
X98 186 245
X99 187 245
X100 188 246
X101 189 247
X102 190 248
X102 190 248
X103 191 249
X104 192 250
X105 193 250
X106 194 251
X107 195 252
X108 196 252
X109 197 253
X110 198 254
X111 199 255
X244 211 1
X240 211 1
X237 211 1
X234 211 1
X231 211 1
X228 211 1
X224 211 1
X221 211 1
X218 211 1
X215 211 1
X212 211 1
X209 211 1
X205 211 1
X202 211 1
X199 211 1
X196 211 1
X193 211 1
X190 211 1
X186 211 1
X183 211 1
X180 211 1
X177 211 1
X174 211 1
X171 211 1
X132 208 1
X129 206 1
X125 204 1
X122 201 1
X119 199 1
X115 197 1
X112 194 1
X108 192 1
X105 190 1
X102 187 1
X98 185 1
X95 183 1
X91 180 1
X88 178 1
X84 176 1
X81 173 1
X78 171 1
X74 169 1
X71 166 1
X67 164 1
X64 162 1
X61 159 1
X57 157 1
X54 155 1
X50 152 1
X47 150 1
X44 148 1
X40 145 1
X37 143 1
X33 141 1
X30 138 1
X27 136 1
X23 134 1
X20 131 1
X16 129 1
X13 127 1
X10 124 1
X6 122 1
X3 120 1
X0 118 1
X3 116 1
X6 115 1
X9 113 1
X12 112 1
X15 110 1
X18 109 1
X21 107 1
X25 106 1
X28 104 1
X31 103 1
X34 101 1
X37 100 1
X40 98 1
X43 97 1
X46 96 1
X50 94 1
X53 93 1
X56 91 1
X59 90 1
X62 88 1
X65 87 1
X68 85 1
X71 84 1
X75 82 1
X78 81 1
X81 79 1
X84 78 1
X87 77 1
X90 75 1
X93 74 1
X96 72 1
X100 71 1
X103 69 1
X106 68 1
X109 66 1
X112 65 1
X115 63 1
X118 62 1
X122 61 1
X121 61 1
X120 61 1
X118 60 1
X117 60 1
X115 59 1
X114 59 1
X113 59 1
X111 58 1
X110 58 1
X109 58 1
X111 59 1
X114 60 1
X116 62 1
X119 63 1
X121 65 1
X124 66 1
X126 68 1
X129 69 1
X131 71 1
X134 72 1
X136 74 1
X139 75 1
X141 77 1
X144 78 1
X147 80 1
X149 81 1
X152 83 1
X154 84 1
X157 86 1
X159 87 1
X162 89 1
X164 90 1
X167 92 1
X169 93 1
X172 95 1
X174 96 1
X177 98 1
X180 99 1
X182 101 1
X185 102 1
X187 104 1
X190 105 1
X192 107 1
X195 108 1
X197 110 1
X200 111 1
X202 113 1
X205 114 1
X207 116 1
X210 117 1
X213 119 2
X210 120 9
X208 122 16
X205 124 23
X203 126 30
X200 128 37
X198 129 44
X195 131 51
X193 133 59
X190 135 66
X188 137 73
X186 138 80
X183 140 87
X181 142 94
X178 144 101
X176 146 109
X173 148 116
X254 255 255
X254 255 254
X254 255 254
X254 255 253
X254 255 253
X254 255 253
END_OF_FILE
if test 2551 -ne `wc -c <'Examples/planet.map'`; then
    echo shar: \"'Examples/planet.map'\" unpacked with wrong size!
fi
# end of 'Examples/planet.map'
fi
if test -f 'Examples/planet.ray' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Examples/planet.ray'\"
else
echo shar: Extracting \"'Examples/planet.ray'\" \(427 characters\)
sed "s/^X//" >'Examples/planet.ray' <<'END_OF_FILE'
X/*
X * Example rayshade input file describing a single texture-mapped sphere.
X *
X * C. Kolb 9/89
X */
Xscreen 256 256
Xlight 1.0 0.9 0.8 directional 1. -1. 1.
Xeyep 0. -4. 0.
Xsurface basesurf .16 .15 .14 .8 .75 .7 0 0 0 0 0 0 0
Xsphere basesurf 1.0 0 0 0
X	texture fbm 	0.		/* offset */
X			1.		/* scale */
X			0.3		/* h */
X			2.0		/* lambda */
X			6		/* octaves */
X			-.2		/* thresh */
X			planet.map 	/* mapname */
X		scale 0.7 0.7 0.7 
END_OF_FILE
if test 427 -ne `wc -c <'Examples/planet.ray'`; then
    echo shar: \"'Examples/planet.ray'\" unpacked with wrong size!
fi
# end of 'Examples/planet.ray'
fi
if test -f 'Examples/solids.ray' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Examples/solids.ray'\"
else
echo shar: Extracting \"'Examples/solids.ray'\" \(856 characters\)
sed "s/^X//" >'Examples/solids.ray' <<'END_OF_FILE'
X/*
X * solids.ray
X *
X * Example rayshade input file.
X *
X * Render using:
X *	rayshade solids.ray > solids.rle
X *
X * For previewing purposes, you may wish to use the -P option.
X * Craig Kolb 9/89
X */
Xeyep 0. 25. 7.
Xscreen 128 128
Xjittered
Xlight 1.4 extended -15. 20. 15. 1.4
Xsurface red .02 0 0 .5 0 0 .2 .2 .2 32. 0.5 0 0
Xsurface blacktile 0.01 0.015 0.01 0.02 0.03 0.02 0.3 0.35 0.3 30 0.33 0 0
Xsurface white .02 .02 .008 .5 .5 .25 0.8 0.8 0.8 18 0.2 0 0
Xsurface glass 0.02 0.02 0.02  0. 0. 0.  0.8 0.8 0.8  25 0.2 .3 1.15
X
Xsphere red 4. 3 0 0
X/*
X * Cone actually sticks through ground plane.  This solves problems
X * that arise when the bottom of the cone and the plane are coincident.
X */
Xcone glass -5. 3 -4.1 -5. 3. 4. 4. 0.
X
Xplane white 0. 0. 1. 0. 0. -4. 
X		texture marble scale 4. 4. 4.
X		texture checker blacktile translate 0. 0. 0.3 scale 4. 4. 4.
END_OF_FILE
if test 856 -ne `wc -c <'Examples/solids.ray'`; then
    echo shar: \"'Examples/solids.ray'\" unpacked with wrong size!
fi
# end of 'Examples/solids.ray'
fi
if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'MANIFEST'\"
else
echo shar: Extracting \"'MANIFEST'\" \(3432 characters\)
sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
X   File Name		Archive #	Description
X-----------------------------------------------------------
X BLURB.UTAH                 3	Blurb from Utah Raster Toolkit
X Changes                    1	List of recent changes
X Copyright                  1	Copyright information	
X Examples                   1	Example input files	
X Examples/balls.ray         1	Tweaked output from Eric Haines' SPD
X Examples/planet.map        1	Colormap for planet image
X Examples/planet.ray        1	Simple planet example
X Examples/pool.ray          2	Pool table example
X Examples/solids.ray        1	Transparency/reflectivity example
X MANIFEST                   1	This shipping list
X README                     1	General information
X References                 1	Publications of interest
X TODO                       1	List of suggested extensions	
X doc                        1	Documentation directory
X doc/primitive.ms           7	Tutorial on adding primitives
X doc/rayshade.1             8	Rayshade man page
X doc/texture.ms             5	Tutorial on adding textures
X nff2shade.awk              2	Awk script to convert NFF-->rayshade
X src                        1	Source directory
X src/Makefile               4	Make control file
X src/atmosphere.c           1	Atmospheric effects
X src/bounds.c               3	Bounding box routines
X src/box.c                  1	Box primitive
X src/cone.c                 3	Cone primitive
X src/constants.h            1	Various constants
X src/cylinder.c             3	Cylinder primitive
X src/datatypes.h            2	Datatype definitions
X src/defaults.h             1	Default values
X src/funcdefs.h             2	Function declarations
X src/grid.c                 5	Ray/grid intersection
X src/hf.c                   6	Heightfield primitive
X src/input.c                2	Routines to handle #include
X src/input_lex.l            1	Lexical analysis
X src/input_yacc.y           6	Parsing	
X src/intersect.c            3	Top-level intersection routines
X src/light.c                3	Shadow generation
X src/list.c                 2	Ray/list intersection
X src/main.c                 2	Driving routine
X src/malloc.c               4	A fast storage allocator
X src/matrix.c               5	Matrix manipulation
X src/memory.c               1	Memory management
X src/noise.c                4	Perlin-style Noise and DNoise()
X src/object.c               3	Misc. object functions
X src/outputp.c              2	Image file interface
X src/patchlevel.h           1	Patchlevel information
X src/plane.c                1	Plane primitive
X src/poly.c                 4	Polygon primitive
X src/primobj.h              2	Primitive object definitions
X src/ray_options.c          3	Command line parsing
X src/raymath.c              1	Vector functions
X src/raytrace.c             6	Sampling/antialiasing
X src/raytrace.h             1	Sampling patters
X src/setup.c                2	Initialization
X src/shade.c                5	Lighting calculations
X src/sphere.c               2	Sphere primitive
X src/superq.c               2	Superquadric primitive
X src/surface.c              2	Surface & color functions
X src/texture.c              4	Texturing & bump mapping
X src/texture.h              1	Texture definitions
X src/triangle.c             4	Triangle primitive
X src/typedefs.h             1	Misc. typedefs
X src/version.c              1	Version information
X src/viewing.c              1	Viewing transformations
X src/voxels.c               3	Voxel allocation & initialization
END_OF_FILE
if test 3432 -ne `wc -c <'MANIFEST'`; then
    echo shar: \"'MANIFEST'\" unpacked with wrong size!
fi
# end of 'MANIFEST'
fi
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(5201 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
XThis is version 3.0 of rayshade, a raytracing program.  Rayshade reads
Xa multi-line ASCII file describing a scene to be rendered and produces
Xa Utah Raster RLE format file of the raytraced image.
X
XRayshade features:
X
X	Eight types of primitives (box, cone, cylinder, height field,
X	polygon, sphere, superquadric, flat- and Phong-shaded triangle)
X
X	Composite objects
X
X	Point, directional, and extended (area) light sources
X
X	Solid procedural texturing and bump mapping of primitives, objects,
X		and individual instances of objects
X
X	Antialiasing through adaptive supersampling or "jittered" sampling
X
X	Arbitrary linear transformations on primitives,
X		instances of objects, and texture/bump maps
X
X	Use of uniform spatial subdivision or hierarchy of bounding
X		volumes to speed rendering
X
X	Options to facilitate rendering of stereo pairs
X
X	Support for the C-Linda parallel programming language
X
X
XThis version supersedes all previous versions, and it is to this release
Xthat subsequent patches should be applied.
X
XRayshade has been tested on many different UNIX-based computers.  If your
Xmachine has a C compiler and enough memory (at least 2Mb), rayshade should
Xbe fairly easy to port.  Be warned that rayshade uses yacc and lex to
Xprocess input files.  If you do not have lex and yacc, try to get flex and
Xbison from the Free Software Foundation folks (ftp to prep.ai.mit.edu).
X
XNormally, rayshade makes use of the Utah Raster toolkit.  I strongly
Xsuggest you get a copy of the toolkit, as it provides a host of useful tools
Xfor image manipulation and a library for reading/reading the toolkit's
X"RLE" format image files.  UTAH.BLURB is the "blurb" file from the latest
Xdistribution of the toolkit, which can be obtained via anonymous ftp from
Xcs.utah.edu (128.110.4.21), weedeater.math.yale.edu (192.26.88.42),
Xnl.cs.cmu.edu (128.22.222.56), and uunet.uu.net.  Also of interest is the
X"fbm" library, available from nl.cs.cmu.edu:/usr/mlm/ftp/fbm.tar.Z, which
Xprovides tools for converting Utah Raster RLE format images to/from other
Xformats.
X
XIf you do not want to or cannot use the Utah Raster toolkit, compile-time
Xswitches are provided to create image files using a generic format very
Xsimilar to that used by Mark VandeWettering's raytracer.  See the Makefile
Xand src/outputp.c for details.
X
XThe directory "src" contains the source to rayshade.  To compile, edit the
XMakefile in that directory and change include file and library paths and set
XCFLAGS and LIBS to whatever is appropriate for your particular hardware/
Xsoftware configuration.
X
XThe file doc/rayshade.1 contains a brief manual page which covers most things
Xa casual user will need to know in order to produce raytraced images.
XA tutorial on adding new textures on rayshade is included in doc/texture.ms.
XA similar document on adding new primitives to rayshade is in
Xdoc/primitive.ms.  Unfortunately, there is as yet no technical documentation.
X
XOnce you've compiled rayshade, you can test it using the example input
Xfiles in the Examples directory.  You can also run the output of
XEric Haines' Standard Procedural Database through awk using the
X"nff2shade.awk" script, and feed the results to rayshade.  Note that for
Xseveral of the databases, you will need to tweak the data a bit to achieve
Xoptimal runtimes.  See nff2shade.awk for details.
X
XRayshade was not designed to be, nor is it, the be-all and end-all of
Xraytracers.  It was meant to be reasonably fast, portable, and easy to 
Xmodify.  It has some nice features which allow you to produce
Xpretty pictures, but there are countless extensions, modifications,
Xand improvements which could be made.  There are many routines which may be
Xoptimized and many features which could be added.  For a list of suggested
Ximprovements and projects see "TODO".  You are encouraged to modify the
Xsource code left and right.
X
XRayshade had its start as an "introductory" public domain raytracer written
Xby Roman Kuchkuda.  During 1987-88 the first version of rayshade was written
Xby Craig Kolb, David P. Dobkin (the original cylinder, cone and extinct torus-
Xtracing code), and David C. Hoffman (the original octree code).  Craig Kolb
Xwrote the current version of rayshade during the fall of 1988 and has made a
Xlarge number of changes since then.
X
XThe current version of rayshade owes much to a number of people who have
Xmade suggestions, fixed bugs, and who have been all-around good sports about
Xthe whole thing.  Thanks to David Dobkin, Eric Haines, Lefteris Koutsofios,
XKen Musgrave, Przemek Prusinkiewicz, and Allan Snider for their encouragement,
Xcomments, and willingness to be on the Front Lines.  Thanks also to Roman
XKuchkuda for providing a base upon which to build.  Special thanks to Robert
XSkinner for providing the Noise(), DNoise(), and other texturing functions
Xand allowing them to be redistributed.
X
XIf you find any bugs, make any useful extensions, have a nice input
Xfile, port rayshade to a new environment, or need assistance understanding a
Xparticularly braindamaged section of code, please let me know.  I can be most
Xeasily reached by email.
X
XCraig Kolb 10/27/89
Xkolb at yale.edu
X
XYale University Dept. of Mathematics
XP.O. Box 2155 Yale Station
XNew Haven, CT  06520-2155
END_OF_FILE
if test 5201 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'References' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'References'\"
else
echo shar: Extracting \"'References'\" \(2965 characters\)
sed "s/^X//" >'References' <<'END_OF_FILE'
X#
X# Publications of particular interest to rayshade-hackers.
X#
X# Mostly snipped from the Ray Tracing Bibliography assembled by
X# Paul Heckbert and Eric Haines.
X#
X%A Robert L. Cook
X%A Thomas Porter
X%A Loren Carpenter
X%T Distributed Ray Tracing
X%J Computer Graphics
X(SIGGRAPH '84 Proceedings)
X%V 18
X%N 3
X%D July 1984
X%P 137-145
X%Z Monte Carlo distribution of rays to get
Xgloss, translucency, penumbras, depth of field, motion blur
X%K probabilistic ray tracing, monte carlo, motion blur, stochastic sampling
X
X%A Robert L. Cook
X%T Stochastic Sampling in Computer Graphics
X%J ACM Transactions on Graphics
X%V 5
X%N 1
X%D Jan. 1986
X%P 51-72
X
X%A Akira Fujimoto
X%A Takayuki Tanaka
X%A Kansei Iwata
X%T ARTS: Accelerated Ray-Tracing System
X%J IEEE Computer Graphics and Applications
X%D Apr. 1986
X%P 16-26
X%K octree
X
X%A Andrew S. Glassner
X%A Jim Arvo
X%A Robert L. Cook
X%A Eric Haines
X%A Pat Hanrahan
X%A Paul Heckbert
X%A David B. Kirk
X%B An Introduction to Ray Tracing
X%I Academic Press
X%C London
X%D 1989
X
X%A Eric Haines
X%T A Proposal for Standard Graphics Environments
X%J IEEE Computer Graphics and Applications
X%V 7
X%N 11
X%D Nov. 1987
X%P 3-5
X%K benchmark
X%Z renderer benchmarking environments and how to obtain them
X
X%A Roy Hall
X%B Illumination and Color in Computer Generated Imagery
X%C New York
X%D 1989
X%I Springer-Verlag
X
X%A Timothy L. Kay
X%A James T. Kajiya
X%T Ray Tracing Complex Scenes
X%J Computer Graphics
X(SIGGRAPH '86 Proceedings)
X%V 20
X%N 4
X%D Aug. 1986
X%P 269-278
X%K bounding volume
X
X%A Roman Kuchkuda
X%T An Introduction to Ray Tracing
X%B Theoretical Foundations of Computer Graphics and CAD
X%E R.A. Earnshaw
X%I Springer-Verlag
X%C Berlin
X%D 1988
X%P 1039-1060
X
X%A J. P. Lewis
X%T Algorithms for Solid Noise Synthesis
X%J Computer Graphics
X(SIGGRAPH '89 Proceedings)
X%V 23
X%N 3
X%D August 1989
X%P 263-270
X
X%A Don P. Mitchell
X%T Generating Antialiased Images at Low Sampling Densities
X%J Computer Graphics
X(SIGGRAPH '87 Proceedings)
X%V 21
X%N 4
X%D July 1987
X%P 65-72
X
X%A F. Kenton Musgrave
X%A Craig E. Kolb
X%A Robert S. Mace
X%T The Synthesis and Rendering of Eroded Fractal Terrains
X%J Computer Graphics
X(SIGGRAPH '89 Proceedings)
X%V 23
X%N 3
X%D July 1989
X%P 41-50
X%Z info on efficiently ray tracing height fields
X%K fractal, height fields
X
X%A Ken Perlin
X%T An Image Synthesizer
X%J Computer Graphics
X(SIGGRAPH '85 Proceedings)
X%V 19
X%N 3
X%D July 1985
X%P 287-296
X
X%A David F. Rogers
X%B Procedural Elements for Computer Graphics
X%I McGraw-Hill
X%C New York
X%D 1985
X%Z the only book on image synthesis, good summary of ray tracing
X
X%A John M. Snyder
X%A Alan H. Barr
X%T Ray Tracing Complex Models Containing Surface Tessellations
X%J Computer Graphics
X(SIGGRAPH '87 Proceedings)
X%V 21
X%N 4
X%D July 1987
X%P 119-128
X%Z If you only read one paper before modifying rayshade, make it this one.
X%K parametric surface, tessellation, 3D grid
X
X%A Turner Whitted
X%T An Improved Illumination Model for Shaded Display
X%J CACM
X%V 23
X%N 6
X%D June 1980
X%P 343-349
X%Z the classic ray tracing paper
END_OF_FILE
if test 2965 -ne `wc -c <'References'`; then
    echo shar: \"'References'\" unpacked with wrong size!
fi
# end of 'References'
fi
if test -f 'TODO' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'TODO'\"
else
echo shar: Extracting \"'TODO'\" \(1259 characters\)
sed "s/^X//" >'TODO' <<'END_OF_FILE'
XAdd CSG.
X
XMake "distributed ray tracing" implementation more complete.  Sample for
Xdepth of field, gloss, etc.
X
XKeep track of maxt for a given ray and pass it to the various
Xintersection routines.  For example, we can stop traversing a height
Xfield grid if the ray hasn't hit the height field by the time we're
X"maxt" along the ray.
X
XKeep track of the primitives hit for (at least a portion of) the ray
Xtree.  When spawaning a new ray, check for intersection with the primitive
Xlast hit by the corresponding ray in the saved tree.  If it hits, you have a
Xvalue for "maxt" for the above.
X
XMake heightfields be stored in fixed-point, and take care of byte-ordering
Xproblems so that height fields are transportable from machine to machine.
X
XImplement something similar to Jevans & Wyvill's adaptive subdivision scheme.
X
XAdd better antialiasing (e.g., Mitchell's paper).
X
XAdd a better way to do continue an interrupted trace.  There should be code
Xin rayshade to find the number of the last line traced and start from
Xthere.
X
XAdd an option to perform sorting during ray/List intersection tests so
Xwe test objects roughly in order.
X
XImprove handling of input files (error messages, #include directives, etc.).
X
XHave workers pass statistics back to the supervisor.
END_OF_FILE
if test 1259 -ne `wc -c <'TODO'`; then
    echo shar: \"'TODO'\" unpacked with wrong size!
fi
# end of 'TODO'
fi
if test ! -d 'doc' ; then
    echo shar: Creating directory \"'doc'\"
    mkdir 'doc'
fi
if test ! -d 'src' ; then
    echo shar: Creating directory \"'src'\"
    mkdir 'src'
fi
if test -f 'src/atmosphere.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/atmosphere.c'\"
else
echo shar: Extracting \"'src/atmosphere.c'\" \(2223 characters\)
sed "s/^X//" >'src/atmosphere.c' <<'END_OF_FILE'
X/*
X * atmosphere.c
X *
X * Copyright (C) 1989, Craig E. Kolb
X *
X * This software may be freely copied, modified, and redistributed,
X * provided that this copyright notice is preserved on all copies.
X *
X * There is no warranty or other guarantee of fitness for this software,
X * it is provided solely .  Bug reports or fixes may be sent
X * to the author, who may or may not act on them as he desires.
X *
X * You may not include this software in a program or other software product
X * without supplying the source, or without informing the end-user that the
X * source is available for no extra charge.
X *
X * If you modify this software, you should include a notice giving the
X * name of the person performing the modification, the date of modification,
X * and the reason for such modification.
X *
X * $Id: atmosphere.c,v 3.0 89/10/27 02:05:46 craig Exp $
X *
X * $Log:	atmosphere.c,v $
X * Revision 3.0  89/10/27  02:05:46  craig
X * Baseline for first official release.
X * 
X */
X#include <stdio.h>
X#include <math.h>
X#include "typedefs.h"
X#include "constants.h"
X#include "funcdefs.h"
X
XFog *GlobalFog;
XMist *GlobalMist;
X
X/*
X * Add fog to the given color.
X */
XComputeFog(fog, dist, color)
XFog *fog;
Xdouble dist;
XColor *color;
X{
X	double atten;
X
X	atten = LNHALF * dist * fog->trans;
X	if (atten < -10.)
X		atten = 0.;
X	else
X		atten = exp(atten);
X	blend_color(color, &fog->color, atten, 1. - atten);
X}
X
X/*
X * Add low-altitude mist to the given color.
X */
XComputeMist(mist, origin, hit, dist, color)
XMist *mist;
XVector *origin, *hit;
Xdouble dist;
XColor *color;
X{
X	double deltaZ, d, atten;
X
X	deltaZ = mist->scale * (hit->z - origin->z);
X	if (abs(deltaZ) > EPSILON)
X		d = (exp(-origin->z*mist->scale + mist->zero) -
X			    exp(-hit->z*mist->scale + mist->zero)) / deltaZ;
X	else
X		d = exp(-hit->z*mist->scale + mist->zero);
X	d *= LNHALF * dist;
X	atten =  d /  mist->trans.r;
X	atten = (atten < -10. ? (0.) : exp(atten));
X	color->r = atten*color->r + (1. - atten)*mist->color.r;
X
X	atten =  d /  mist->trans.g;
X	atten = (atten < -10. ? (0.) : exp(atten));
X	color->g = atten*color->g + (1. - atten)*mist->color.g;
X
X	atten =  d /  mist->trans.b;
X	atten = (atten < -10. ? (0.) : exp(atten));
X	color->b = atten*color->b + (1. - atten)*mist->color.b;
X}
END_OF_FILE
if test 2223 -ne `wc -c <'src/atmosphere.c'`; then
    echo shar: \"'src/atmosphere.c'\" unpacked with wrong size!
fi
# end of 'src/atmosphere.c'
fi
if test -f 'src/box.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/box.c'\"
else
echo shar: Extracting \"'src/box.c'\" \(3148 characters\)
sed "s/^X//" >'src/box.c' <<'END_OF_FILE'
X/*
X * box.c
X *
X * Copyright (C) 1989, Craig E. Kolb
X *
X * This software may be freely copied, modified, and redistributed,
X * provided that this copyright notice is preserved on all copies.
X *
X * There is no warranty or other guarantee of fitness for this software,
X * it is provided solely .  Bug reports or fixes may be sent
X * to the author, who may or may not act on them as he desires.
X *
X * You may not include this software in a program or other software product
X * without supplying the source, or without informing the end-user that the
X * source is available for no extra charge.
X *
X * If you modify this software, you should include a notice giving the
X * name of the person performing the modification, the date of modification,
X * and the reason for such modification.
X *
X * $Id: box.c,v 3.0 89/10/27 02:05:47 craig Exp $
X *
X * $Log:	box.c,v $
X * Revision 3.0  89/10/27  02:05:47  craig
X * Baseline for first official release.
X * 
X */
X#include <math.h>
X#include <stdio.h>
X#include "constants.h"
X#include "typedefs.h"
X#include "funcdefs.h"
X
XObject *
Xmakbox(surf, x, y, z, xs, ys, zs)
Xchar *surf;
Xdouble x, y, z, xs, ys, zs;
X{
X	Box          *box;
X	Primitive *prim;
X	Object *newobj;
X	extern int Quiet, yylineno;
X
X	if (xs < EPSILON || ys < EPSILON || zs < EPSILON) {
X		if (!Quiet)
X			fprintf(stderr,"Degenerate box (line %d)\n",yylineno);
X		return (Object *)0;
X	}
X	prim = mallocprim();
X	prim->surf = find_surface(surf);
X	newobj = new_object(NULL, BOX, (char *)prim, (Trans *)NULL);
X	prim->type = BOX;
X	box = (Box *)Malloc(sizeof(Box));
X	prim->objpnt.p_box = box;
X	box->bounds[LOW][X] = x - xs;
X	box->bounds[HIGH][X] = x + xs;
X	box->bounds[LOW][Y] = y - ys;
X	box->bounds[HIGH][Y] = y + ys;
X	box->bounds[LOW][Z] = z - zs;
X	box->bounds[HIGH][Z] = z + zs;
X	return newobj;
X}
X
Xdouble
Xintbox(pos, ray, obj)
XVector *ray;	/* ray vector */
XVector *pos;	/* origin of ray */
XPrimitive *obj;	/* box description */
X{
X	Ray tmpray;
X	extern unsigned long BVTests, primtests[];
X
X	/*
X	 * IntBounds will increment BVTests, even though we're
X	 * not really doing a BV intersection test.
X	 */
X	primtests[BOX]++;
X	BVTests--;
X	tmpray.pos = *pos;
X	tmpray.dir = *ray;
X	return IntBounds(&tmpray, obj->objpnt.p_box->bounds);
X}
X
Xnrmbox(pos, obj, nrm)
XVector           *pos, *nrm;	/* point of intersection */
XPrimitive       *obj;	/* box description */
X{
X	Box          *box;
X
X	box = obj->objpnt.p_box;
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		fprintf(stderr,"Nrmbox: confusion!\n");
X}
X
Xboxextent(o, bounds)
XPrimitive *o;
Xdouble bounds[2][3];
X{
X	Box *b = o->objpnt.p_box;
X
X	bounds[LOW][X] = b->bounds[LOW][X];
X	bounds[HIGH][X] = b->bounds[HIGH][X];
X	bounds[LOW][Y] = b->bounds[LOW][Y];
X	bounds[HIGH][Y] = b->bounds[HIGH][Y];
X	bounds[LOW][Z] = b->bounds[LOW][Z];
X	bounds[HIGH][Z] = b->bounds[HIGH][Z];
X}
END_OF_FILE
if test 3148 -ne `wc -c <'src/box.c'`; then
    echo shar: \"'src/box.c'\" unpacked with wrong size!
fi
# end of 'src/box.c'
fi
if test -f 'src/constants.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/constants.h'\"
else
echo shar: Extracting \"'src/constants.h'\" \(2403 characters\)
sed "s/^X//" >'src/constants.h' <<'END_OF_FILE'
X/*
X * constants.h
X *
X * Copyright (C) 1989, Craig E. Kolb
X *
X * This software may be freely copied, modified, and redistributed,
X * provided that this copyright notice is preserved on all copies.
X *
X * There is no warranty or other guarantee of fitness for this software,
X * it is provided solely .  Bug reports or fixes may be sent
X * to the author, who may or may not act on them as he desires.
X *
X * You may not include this software in a program or other software product
X * without supplying the source, or without informing the end-user that the
X * source is available for no extra charge.
X *
X * If you modify this software, you should include a notice giving the
X * name of the person performing the modification, the date of modification,
X * and the reason for such modification.
X *
X * $Id: constants.h,v 3.0 89/10/27 02:05:48 craig Exp $
X *
X * $Log:	constants.h,v $
X * Revision 3.0  89/10/27  02:05:48  craig
X * Baseline for first official release.
X * 
X */
X
X#define LIGHTS		10		/* Max # of lights */
X
X/*
X * Primitive type constants.  When adding primitives, insert *before*
X * "LIST" and increment LIST and GRID values, otherwise arrays of
X * intersection/normal/extent routines in intersect.c won't be indexed
X * correctly.
X */
X#define SPHERE		0
X#define BOX		1
X#define TRIANGLE	2
X#define SUPERQ		3
X#define PLANE		4
X#define CYL		5
X#define POLY		6
X#define PHONGTRI	7
X#define CONE		8
X#define HF		9
X#define LIST		10
X#define GRID		11
X
X#define PRIMTYPES	10	/* # of types of primitives */
X
X#define TRUE		1
X#define FALSE		0
X
X/*
X * Used to make indices into bounding box arrays more readable.
X */
X#define X	0
X#define Y	1
X#define Z	2
X#define LOW	0
X#define HIGH	1
X
X/*
X * Light source types
X */
X#define LOCAL		(char)1
X#define DIRECTIONAL	(char)2
X#define EXTENDED	(char)3
X
X/*
X * Various useful constants and macros.
X */
X#define	PI		3.14159265358979323846
X#define deg2rad(x)	(double)(PI * x / 180.)
X#define LNHALF		(-.69314718)
X/*
X * Minimum vector length
X */
X#define EPSILON		(double)0.00001
X
X/*
X * Maximum intersection-point distance.  (Making the "world" a sphere of radius
X * FAR_AWAY centered at eyep.)
X */
X#define FAR_AWAY		1.0E+14
X
X/*
X * Constants used in triangle & polygon intersection tests.
X */
X#define XNORMAL		(char)0
X#define YNORMAL		(char)1
X#define ZNORMAL		(char)2
X
X/*
X * Constants for Stereo mode
X */
X#define LEFT		1
X#define RIGHT		2
X
X#ifndef NULL
X#	define NULL 0
X#endif
X
X#define UNSET		-1
END_OF_FILE
if test 2403 -ne `wc -c <'src/constants.h'`; then
    echo shar: \"'src/constants.h'\" unpacked with wrong size!
fi
# end of 'src/constants.h'
fi
if test -f 'src/defaults.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/defaults.h'\"
else
echo shar: Extracting \"'src/defaults.h'\" \(1642 characters\)
sed "s/^X//" >'src/defaults.h' <<'END_OF_FILE'
X/*
X * defaults.h
X *
X * Copyright (C) 1989, Craig E. Kolb
X *
X * This software may be freely copied, modified, and redistributed,
X * provided that this copyright notice is preserved on all copies.
X *
X * There is no warranty or other guarantee of fitness for this software,
X * it is provided solely .  Bug reports or fixes may be sent
X * to the author, who may or may not act on them as he desires.
X *
X * You may not include this software in a program or other software product
X * without supplying the source, or without informing the end-user that the
X * source is available for no extra charge.
X *
X * If you modify this software, you should include a notice giving the
X * name of the person performing the modification, the date of modification,
X * and the reason for such modification.
X *
X * $Id: defaults.h,v 3.0 89/10/27 02:05:49 craig Exp $
X *
X * $Log:	defaults.h,v $
X * Revision 3.0  89/10/27  02:05:49  craig
X * Baseline for first official release.
X * 
X */
X
X#define DEFLIGHTSAMPLES	4	/* sqrt of number of shadow rays per pixel */
X
X#define XRESOLUTION	512		/* Default screen size (pixels) */
X#define YRESOLUTION	512
X#define DEFCUTOFF	0.001		/* Default tree cutoff value */
X#define MAXLEVEL	3		/* Maximum ray tree depth. */
X#define PIXEL_DIV	1		/* Maximum pixel subdivision factor */
X#define HFOV		45		/* Field-of-view */
X#define EYEX		0		/* Eye position */
X#define EYEY		20
X#define EYEZ		0
X#define LOOKX		0		/* Look point */
X#define LOOKY		0
X#define LOOKZ		0
X#define UPX		0		/* Up vector */
X#define UPY		0
X#define UPZ		1
X
X#define DEFREDCONT	0.25		/* Default contrast threshold values. */
X#define DEFGREENCONT	0.2
X#define DEFBLUECONT	0.4
END_OF_FILE
if test 1642 -ne `wc -c <'src/defaults.h'`; then
    echo shar: \"'src/defaults.h'\" unpacked with wrong size!
fi
# end of 'src/defaults.h'
fi
if test -f 'src/input_lex.l' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/input_lex.l'\"
else
echo shar: Extracting \"'src/input_lex.l'\" \(2960 characters\)
sed "s/^X//" >'src/input_lex.l' <<'END_OF_FILE'
X/* input_lex.l								    */
X/*									    */
X/* Copyright (C) 1989, Craig E. Kolb					    */
X/*									    */
X/* This software may be freely copied, modified, and redistributed,	    */
X/* provided that this copyright notice is preserved on all copies.	    */
X/* 									    */
X/* There is no warranty or other guarantee of fitness for this software,    */
X/* it is provided solely "as is".  Bug reports or fixes may be sent	    */
X/* to the author, who may or may not act on them as he desires.		    */
X/*									    */
X/* You may not include this software in a program or other software product */
X/* without supplying the source, or without informing the end-user that the */
X/* source is available for no extra charge.				    */
X/*									    */
X/* $Id: input_lex.l,v 3.0 89/10/27 02:05:52 craig Exp $ */
X%{
X#include <stdio.h>
X#ifdef SYSV
X#include <string.h>
X#else
X#include <strings.h>
X#endif
X#include "typedefs.h"
X#include "y.tab.h"
Xdouble atof();
Xchar *strsave();
X%}
Xalpha	[a-zA-Z]
Xspecial	[\.\_-]
Xdigit	[0-9]
Xexp	[Ee][-+]?{digit}+
Xstring	({alpha}|"/")({alpha}|{digit}|{special}|"/")*
X%p 3000
X%%
X" "			;
X\t			;
X\n			;
X"/*"			{skipcomments();}
Xadaptive		{return(tADAPTIVE);}
Xbackground		{return(tBACKGROUND);}
Xblotch			{return(tBLOTCH);}
Xbox			{return(tBOX);}
Xbump			{return(tBUMP);}
Xchecker			{return(tCHECKER);}
Xcone			{return(tCONE);}
Xcontrast		{return(tCONTRAST);}
Xcutoff			{return(tCUTOFF);}
Xcylinder		{return(tCYL);}
Xdefend			{return(tENDDEF);}
Xdefine			{return(tSTARTDEF);}
Xdirectional		{return(tDIRECTIONAL);}
Xendfile			{return(tENDFILE);}
Xextended		{return(tEXTENDED);}
Xeyep			{return(tEYEP);}
Xfbm			{return(tFBM);}
Xfbmbump			{return(tFBMBUMP);}
Xfog			{return(tFOG);}
Xfov			{return(tFOV);}
Xgrid			{return(tGRID);}
Xheightfield		{return(tHEIGHTFIELD);}
Xjittered		{return(tJITTERED);}
Xlight			{return(tLIGHT);}
Xlist			{return(tLIST);}
Xlookp			{return(tLOOKP);}
Xmarble			{return(tMARBLE);}
Xmaxdepth		{return(tMAXDEPTH);}
Xmist			{return(tMIST);}
Xobject			{return(tOBJECT);}
Xoutfile			{return(tOUTFILE);}
Xplane			{return(tPLANE);}
Xpoint			{return(tPOINT);}
Xpoly			{return(tPOLY);}
Xresolution		{return(tRESOLUTION);}
Xrotate			{return(tROTATE);}
Xsamples			{return(tSAMPLES);}
Xscale			{return(tSCALE);}
Xscreen			{return(tSCREEN);}
Xsphere			{return(tSPHERE);}
Xsuperq			{return(tSUPERQ);}
Xsurface			{return(tSURFACE);}
Xtexture			{return(tTEXTURE);}
Xtransform		{return(tTRANSFORM);}
Xtranslate		{return(tTRANSLATE);}
Xtriangle		{return(tTRIANGLE);}
Xup			{return(tUP);}
Xwood			{return(tWOOD);}
X{string}		{yylval.c = strsave(yytext);
X				return(tSTRING);}
X[+-]?{digit}+		{yylval.i = atoi(yytext);
X				return(tINT);}
X
X[+-]?{digit}+"."{digit}*({exp})? |
X[+-]?{digit}*"."{digit}+({exp})? |
X[+-]?{digit}+{exp}		{yylval.d = atof(yytext); return(tFLOAT);}
X
X.			{return yytext[0];}
X
X%%
Xyywrap() {return(1);}
X/*
X * Skip over comments.
X */
Xskipcomments()
X{
X	char c;
X
X	while (1) {
X		while (input() != '*')
X			;
X		if ((c = input()) == '/')
X			return;
X		unput(c);
X	}
X}
END_OF_FILE
if test 2960 -ne `wc -c <'src/input_lex.l'`; then
    echo shar: \"'src/input_lex.l'\" unpacked with wrong size!
fi
# end of 'src/input_lex.l'
fi
if test -f 'src/memory.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/memory.c'\"
else
echo shar: Extracting \"'src/memory.c'\" \(1596 characters\)
sed "s/^X//" >'src/memory.c' <<'END_OF_FILE'
X/*
X * memory.c
X *
X * Copyright (C) 1989, Craig E. Kolb
X *
X * This software may be freely copied, modified, and redistributed,
X * provided that this copyright notice is preserved on all copies.
X *
X * There is no warranty or other guarantee of fitness for this software,
X * it is provided solely .  Bug reports or fixes may be sent
X * to the author, who may or may not act on them as he desires.
X *
X * You may not include this software in a program or other software product
X * without supplying the source, or without informing the end-user that the
X * source is available for no extra charge.
X *
X * If you modify this software, you should include a notice giving the
X * name of the person performing the modification, the date of modification,
X * and the reason for such modification.
X *
X * $Id: memory.c,v 3.0 89/10/27 02:05:56 craig Exp $
X *
X * $Log:	memory.c,v $
X * Revision 3.0  89/10/27  02:05:56  craig
X * Baseline for first official release.
X * 
X */
X#include <stdio.h>
X#include "typedefs.h"
X#include "funcdefs.h"
X
Xunsigned long TotalAllocated;
X
Xchar *
XMalloc(bytes)
Xunsigned bytes;
X{
X	char *res, *malloc();
X
X	TotalAllocated += bytes;
X
X	res = malloc(bytes);
X	if (res == (char *)0) {
X		fprintf(stderr,"Out of memory trying to allocate %d bytes.\n");
X		exit(0);
X	}
X	return res;
X}
X
Xchar *
XCalloc(nelem, elen)
Xunsigned nelem, elen;
X{
X	char *res;
X
X	res = Malloc(nelem*elen);
X#ifdef SYSV
X	memset(res, (char)0, nelem*elen);
X#else
X	bzero(res, nelem*elen);
X#endif
X	return res;
X}
X
XPrintMemoryStats()
X{
X	extern FILE *fstats;
X
X	fprintf(fstats,"Total memory allocated:\t\t%d bytes\n",TotalAllocated);
X}
END_OF_FILE
if test 1596 -ne `wc -c <'src/memory.c'`; then
    echo shar: \"'src/memory.c'\" unpacked with wrong size!
fi
# end of 'src/memory.c'
fi
if test -f 'src/patchlevel.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/patchlevel.h'\"
else
echo shar: Extracting \"'src/patchlevel.h'\" \(21 characters\)
sed "s/^X//" >'src/patchlevel.h' <<'END_OF_FILE'
X#define PATCHLEVEL 0
END_OF_FILE
if test 21 -ne `wc -c <'src/patchlevel.h'`; then
    echo shar: \"'src/patchlevel.h'\" unpacked with wrong size!
fi
# end of 'src/patchlevel.h'
fi
if test -f 'src/plane.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/plane.c'\"
else
echo shar: Extracting \"'src/plane.c'\" \(2370 characters\)
sed "s/^X//" >'src/plane.c' <<'END_OF_FILE'
X/*
X * plane.c
X *
X * Copyright (C) 1989, Craig E. Kolb
X *
X * This software may be freely copied, modified, and redistributed,
X * provided that this copyright notice is preserved on all copies.
X *
X * There is no warranty or other guarantee of fitness for this software,
X * it is provided solely .  Bug reports or fixes may be sent
X * to the author, who may or may not act on them as he desires.
X *
X * You may not include this software in a program or other software product
X * without supplying the source, or without informing the end-user that the
X * source is available for no extra charge.
X *
X * If you modify this software, you should include a notice giving the
X * name of the person performing the modification, the date of modification,
X * and the reason for such modification.
X *
X * $Id: plane.c,v 3.0 89/10/27 02:05:59 craig Exp $
X *
X * $Log:	plane.c,v $
X * Revision 3.0  89/10/27  02:05:59  craig
X * Baseline for first official release.
X * 
X */
X#include <stdio.h>
X#include "constants.h"
X#include "typedefs.h"
X#include "funcdefs.h"
X
X/*
X * create plane Primitive
X */
XObject *
Xmakplane(surf, norm, pos)
Xchar *surf;
XVector *norm, *pos;
X{
X	Plane	*plane;
X	Vector tmpnrm;
X	Object *newobj;
X	Primitive *prim;
X	extern int Quiet, yylineno;
X
X	tmpnrm = *norm;
X	if (normalize(&tmpnrm) == 0.) {
X		if (!Quiet)
X			fprintf(stderr, "Degenerate plane normal (line %d)\n",
X							yylineno);
X		return (Object *)0;
X	}
X	prim = mallocprim();
X	prim->surf = find_surface(surf);
X	prim->type = PLANE;
X	newobj = new_object(NULL, PLANE, (char *)prim, (Trans *)NULL);
X	plane = (Plane *)Malloc(sizeof(Plane));
X	prim->objpnt.p_plane = plane;
X	plane->norm = tmpnrm;
X	plane->d = dotp(&plane->norm, pos);
X
X	return newobj;
X}
X
Xdouble
Xintplane(pos, ray, obj)
XVector *pos;
XVector *ray;
XPrimitive *obj;
X{
X	Plane *plane;
X	double denom, dist;
X	extern unsigned long primtests[];
X
X	primtests[PLANE]++;
X	plane = obj->objpnt.p_plane;
X
X	denom = dotp(&plane->norm, ray);
X	if (denom == 0.)
X		return 0.;
X	dist = (plane->d - dotp(&plane->norm, pos)) / denom;
X	return (dist > FAR_AWAY ? 0. : dist);
X}
X
X/*ARGSUSED*/
Xnrmplane(pos, obj, nrm)
XVector *pos, *nrm;
XPrimitive *obj;
X{
X	*nrm = obj->objpnt.p_plane->norm;
X}
X
X/*ARGSUSED*/
Xplaneextent(o, bounds)
XPrimitive *o;
Xdouble bounds[2][3];
X{
X	/*
X	 * Planes are unbounded by nature.  minx > maxx signifies
X	 * this.
X	 */
X	bounds[LOW][X] = 1.0;
X	bounds[HIGH][X] = -1.0;
X}
END_OF_FILE
if test 2370 -ne `wc -c <'src/plane.c'`; then
    echo shar: \"'src/plane.c'\" unpacked with wrong size!
fi
# end of 'src/plane.c'
fi
if test -f 'src/raymath.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/raymath.c'\"
else
echo shar: Extracting \"'src/raymath.c'\" \(3147 characters\)
sed "s/^X//" >'src/raymath.c' <<'END_OF_FILE'
X/*
X * raymath.c
X *
X * Copyright (C) 1989, Craig E. Kolb
X *
X * This software may be freely copied, modified, and redistributed,
X * provided that this copyright notice is preserved on all copies.
X *
X * There is no warranty or other guarantee of fitness for this software,
X * it is provided solely .  Bug reports or fixes may be sent
X * to the author, who may or may not act on them as he desires.
X *
X * You may not include this software in a program or other software product
X * without supplying the source, or without informing the end-user that the
X * source is available for no extra charge.
X *
X * If you modify this software, you should include a notice giving the
X * name of the person performing the modification, the date of modification,
X * and the reason for such modification.
X *
X * $Id: raymath.c,v 3.0 89/10/27 02:06:01 craig Exp $
X *
X * $Log:	raymath.c,v $
X * Revision 3.0  89/10/27  02:06:01  craig
X * Baseline for first official release.
X * 
X */
X#include <math.h>
X#include "typedefs.h"
X#include "constants.h"
X#include "funcdefs.h"
X
X/*
X * Normalize a vector, return original length.
X */
Xdouble
Xnormalize(a)
Xregister Vector *a;
X{
X	double 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	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 */
Xdouble
Xcrossp(o, a, b)
XVector *o, *a, *b;
X{
X	rawcrossp(o, a, b);
X	return normalize(o);
X}
X
X/*
X * Compute cross-product of a and b, place result in o.
X */
Xrawcrossp(o, a, b)
XVector *o, *a, *b;
X{
X	o->x = (a->y * b->z) - (a->z * b->y);
X	o->y = (a->z * b->x) - (a->x * b->z);
X	o->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 */
Xrefract(dir, from_index, to_index, I, N, cos1)
Xdouble from_index, to_index, cos1;
XVector *dir, I, N;
X{
X	double kn, cos2, k;
X
X	if (cos1 < 0.) {
X		/*
X		 * Hit the 'backside' of a surface -- flip the
X		 * normal.
X		 */
X		N.x = -N.x;
X		N.y = -N.y;
X		N.z = -N.z;
X		cos1 = -cos1;
X	}
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, N, dir);
X	return FALSE;
X}
X
X#ifdef DUMB_CPP
X/*
X * Return difference between two vectors.
X */
Xvecsub(a, b, res)
XVector a, b, *res;
X{
X	res->x = a.x - b.x;
X	res->y = a.y - b.y;
X	res->z = a.z - b.z;
X}
X
X/*
X * Return sum of two vectors.
X */
Xvecadd(a, b, res)
XVector a, b, *res;
X{
X	res->x = a.x + b.x;
X	res->y = a.y + b.y;
X	res->z = a.z + b.z;
X}
X
X/*
X * Compute scalar product of a vector.
X */
Xscalar_prod(scale, vec, res)
Xdouble scale;
XVector vec, *res;
X{
X	res->x = vec.x * scale;
X	res->y = vec.y * scale;
X	res->z = vec.z * scale;
X}
X
Xveccomb(s1, v1, s2, v2, res)
Xdouble s1, s2;
XVector v1, v2, *res;
X{
X	res->x = s1 * v1.x + s2 * v2.x;
X	res->y = s1 * v1.y + s2 * v2.y;
X	res->z = s1 * v1.z + s2 * v2.z;
X}
X
Xaddscaledvec(v1, s, v2, res)
XVector v1, v2, *res;
Xdouble s;
X{
X	res->x = v1.x + s * v2.x;
X	res->y = v1.y + s * v2.y;
X	res->z = v1.z + s * v2.z;
X}
X#endif
END_OF_FILE
if test 3147 -ne `wc -c <'src/raymath.c'`; then
    echo shar: \"'src/raymath.c'\" unpacked with wrong size!
fi
# end of 'src/raymath.c'
fi
if test -f 'src/raytrace.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/raytrace.h'\"
else
echo shar: Extracting \"'src/raytrace.h'\" \(1649 characters\)
sed "s/^X//" >'src/raytrace.h' <<'END_OF_FILE'
X/*
X * raytrace.h
X *
X * Copyright (C) 1989, Craig E. Kolb
X *
X * This software may be freely copied, modified, and redistributed,
X * provided that this copyright notice is preserved on all copies.
X *
X * There is no warranty or other guarantee of fitness for this software,
X * it is provided solely .  Bug reports or fixes may be sent
X * to the author, who may or may not act on them as he desires.
X *
X * You may not include this software in a program or other software product
X * without supplying the source, or without informing the end-user that the
X * source is available for no extra charge.
X *
X * If you modify this software, you should include a notice giving the
X * name of the person performing the modification, the date of modification,
X * and the reason for such modification.
X *
X * $Id: raytrace.h,v 3.0 89/10/27 02:06:03 craig Exp $
X *
X * $Log:	raytrace.h,v $
X * Revision 3.0  89/10/27  02:06:03  craig
X * Baseline for first official release.
X * 
X */
Xtypedef struct {
X	float x, y, size;	/* location and size */
X	Color ul, ur, ll, lr;	/* Color values of four corners */
X} pixel_square;
X
Xpixel_square *SquareStack;
Xdouble Minsquare;
X
X/*
X * "Dither matrices" used to encode the 'number' of a ray that samples a
X * particular portion of a pixel.  Hand-coding is ugly, but...
X */
Xint OneSample[1] = 	{0};
Xint TwoSamples[4] =	{0, 2,
X			 3, 1};
Xint ThreeSamples[9]= 	{0, 2, 7,
X			 6, 5, 1,
X			 3, 8, 4};
Xint FourSamples[16] =	{ 0,  8,  2, 10,
X			 12,  4, 14,  6,
X			  3, 11,  1,  9,
X			 15,  7, 13,  5};
Xint FiveSamples[25] =	{ 0,  8, 23, 17,  2,
X			 19, 12,  4, 20, 15,
X			  3, 21, 16,  9,  6,
X			 14, 10, 24,  1, 13,
X			 22,  7, 18, 11,  5};
END_OF_FILE
if test 1649 -ne `wc -c <'src/raytrace.h'`; then
    echo shar: \"'src/raytrace.h'\" unpacked with wrong size!
fi
# end of 'src/raytrace.h'
fi
if test -f 'src/texture.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/texture.h'\"
else
echo shar: Extracting \"'src/texture.h'\" \(1474 characters\)
sed "s/^X//" >'src/texture.h' <<'END_OF_FILE'
X/*
X * texture.h
X *
X * Copyright (C) 1989, Craig E. Kolb
X *
X * This software may be freely copied, modified, and redistributed,
X * provided that this copyright notice is preserved on all copies.
X *
X * There is no warranty or other guarantee of fitness for this software,
X * it is provided solely .  Bug reports or fixes may be sent
X * to the author, who may or may not act on them as he desires.
X *
X * You may not include this software in a program or other software product
X * without supplying the source, or without informing the end-user that the
X * source is available for no extra charge.
X *
X * If you modify this software, you should include a notice giving the
X * name of the person performing the modification, the date of modification,
X * and the reason for such modification.
X *
X * $Id: texture.h,v 3.0 89/10/27 02:06:06 craig Exp $
X *
X * $Log:	texture.h,v $
X * Revision 3.0  89/10/27  02:06:06  craig
X * Baseline for first official release.
X * 
X */
X
X#define CHECKER		0	/* Checkerboard */
X#define BLOTCH		1	/* Color blotches */
X#define BUMP		2	/* Bump mapping */
X#define MARBLE		3	/* marble texture */
X#define FBM		4	/* fBm texture */
X#define FBMBUMP		5	/* fBm bump map */
X#define WOOD		6
X
XTexture *NewCheckText(), *NewBlotchText(), *NewBumpText(), *NewMarbleText();
XTexture *NewfBmText(), *NewfBmBumpText();
XTexture *NewWoodText();
X/*
X * Texturing routines.
X */
Xint	CheckerText(), BlotchText(), BumpText(), MarbleText(), fBmText();
Xint	fBmBumpText(), WoodText();
END_OF_FILE
if test 1474 -ne `wc -c <'src/texture.h'`; then
    echo shar: \"'src/texture.h'\" unpacked with wrong size!
fi
# end of 'src/texture.h'
fi
if test -f 'src/typedefs.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/typedefs.h'\"
else
echo shar: Extracting \"'src/typedefs.h'\" \(1750 characters\)
sed "s/^X//" >'src/typedefs.h' <<'END_OF_FILE'
X/*
X * typedefs.h
X *
X * Copyright (C) 1989, Craig E. Kolb
X *
X * This software may be freely copied, modified, and redistributed,
X * provided that this copyright notice is preserved on all copies.
X *
X * There is no warranty or other guarantee of fitness for this software,
X * it is provided solely .  Bug reports or fixes may be sent
X * to the author, who may or may not act on them as he desires.
X *
X * You may not include this software in a program or other software product
X * without supplying the source, or without informing the end-user that the
X * source is available for no extra charge.
X *
X * If you modify this software, you should include a notice giving the
X * name of the person performing the modification, the date of modification,
X * and the reason for such modification.
X *
X * $Id: typedefs.h,v 3.0 89/10/27 02:06:07 craig Exp $
X *
X * $Log:	typedefs.h,v $
X * Revision 3.0  89/10/27  02:06:07  craig
X * Baseline for first official release.
X * 
X */
X#include "datatypes.h"
X#include "primobj.h"
X
X/*
X * Light definition.
X */
Xtypedef struct {
X	char type;		/* Light source type */
X	Vector pos;		/* Position / direction */
X	Color color;		/* Color (always normalized) */
X	double radius;		/* Radius (for extended sources) */
X	Primitive **cache;
X	TransInfo *trans;
X} Light;
X
X/*
X * Object node definition
X */
Xtypedef struct Object {
X	char *name;		/* Object name, if any. */
X	char type;		/* Type (grid, list, sphere, cone...) */
X	char *data;		/* Pointer to list/grid/primitive */
X	Trans *trans;		/* Transformation information */
X	double bounds[2][3];	/* Bounding box */
X#ifdef LINDA
X	unsigned long *counter;
X#else
X	unsigned long counter;		/* # of last grid checked against */
X#endif
X	struct Texture *texture;	/* Texture mapping info. */
X} Object;
END_OF_FILE
if test 1750 -ne `wc -c <'src/typedefs.h'`; then
    echo shar: \"'src/typedefs.h'\" unpacked with wrong size!
fi
# end of 'src/typedefs.h'
fi
if test -f 'src/version.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/version.c'\"
else
echo shar: Extracting \"'src/version.c'\" \(1138 characters\)
sed "s/^X//" >'src/version.c' <<'END_OF_FILE'
X/*
X * version.c
X *
X * Copyright (C) 1989, Craig E. Kolb
X *
X * This software may be freely copied, modified, and redistributed,
X * provided that this copyright notice is preserved on all copies.
X *
X * There is no warranty or other guarantee of fitness for this software,
X * it is provided solely .  Bug reports or fixes may be sent
X * to the author, who may or may not act on them as he desires.
X *
X * You may not include this software in a program or other software product
X * without supplying the source, or without informing the end-user that the
X * source is available for no extra charge.
X *
X * If you modify this software, you should include a notice giving the
X * name of the person performing the modification, the date of modification,
X * and the reason for such modification.
X *
X * $Id: version.c,v 3.0 89/10/27 02:06:08 craig Exp $
X *
X * $Log:	version.c,v $
X * Revision 3.0  89/10/27  02:06:08  craig
X * Baseline for first official release.
X * 
X */
X#include <stdio.h>
X#include "patchlevel.h"
X
Xprint_version()
X{
X	extern char rcsid[];
X	extern FILE *fstats;
X
X	fprintf(fstats,"rayshade: %s\nPatch level %d\n",rcsid, PATCHLEVEL);
X}
END_OF_FILE
if test 1138 -ne `wc -c <'src/version.c'`; then
    echo shar: \"'src/version.c'\" unpacked with wrong size!
fi
# end of 'src/version.c'
fi
if test -f 'src/viewing.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/viewing.c'\"
else
echo shar: Extracting \"'src/viewing.c'\" \(2211 characters\)
sed "s/^X//" >'src/viewing.c' <<'END_OF_FILE'
X/*
X * viewing.c
X *
X * Copyright (C) 1989, Craig E. Kolb
X *
X * This software may be freely copied, modified, and redistributed,
X * provided that this copyright notice is preserved on all copies.
X *
X * There is no warranty or other guarantee of fitness for this software,
X * it is provided solely .  Bug reports or fixes may be sent
X * to the author, who may or may not act on them as he desires.
X *
X * You may not include this software in a program or other software product
X * without supplying the source, or without informing the end-user that the
X * source is available for no extra charge.
X *
X * If you modify this software, you should include a notice giving the
X * name of the person performing the modification, the date of modification,
X * and the reason for such modification.
X *
X * $Id: viewing.c,v 3.0 89/10/27 02:06:08 craig Exp $
X *
X * $Log:	viewing.c,v $
X * Revision 3.0  89/10/27  02:06:08  craig
X * Baseline for first official release.
X * 
X */
X#include <math.h>
X#include <stdio.h>
X#include "constants.h"
X#include "typedefs.h"
X#include "funcdefs.h"
X
XVector lookp, eyep, up, firstray, scrnx, scrny;
Xdouble vfov, hfov, Separation;
Xint Xres = UNSET, Yres = UNSET, Stereo;
Xviewing()
X{
X	Vector gaze;
X	double dist, magnitude;
X
X	vecsub(lookp, eyep, &gaze);
X	firstray = gaze;
X
X	dist = normalize(&gaze);
X	(void)crossp(&scrnx, &gaze, &up);
X	(void)crossp(&scrny, &scrnx, &gaze);
X	dist *= 2.0;
X
X	/*
X	 * Add stereo separation if desired.
X	 */
X	if (Stereo) {
X		if (Stereo == LEFT)
X			magnitude = -.5 * Separation;
X		else
X			magnitude = .5 * Separation;
X		eyep.x += magnitude * scrnx.x;
X		eyep.y += magnitude * scrnx.y;
X		eyep.z += magnitude * scrnx.z;
X		vecsub(lookp, eyep, &firstray);
X		gaze = firstray;
X		dist = normalize(&gaze);
X		(void)crossp(&scrnx, &gaze, &up);
X		(void)crossp(&scrny, &scrnx, &gaze);
X	}
X
X	magnitude = dist * tan(deg2rad(0.5*hfov)) / Xres;
X	scrnx.x *= magnitude;
X	scrnx.y *= magnitude;
X	scrnx.z *= magnitude;
X	magnitude = dist * tan(deg2rad(0.5*vfov)) / Yres;
X	scrny.x *= magnitude;
X	scrny.y *= magnitude;
X	scrny.z *= magnitude;
X
X	firstray.x += 0.5*Yres*scrny.x - 0.5*Xres*scrnx.x;
X	firstray.y += 0.5*Yres*scrny.y - 0.5*Xres*scrnx.y;
X	firstray.z += 0.5*Yres*scrny.z - 0.5*Xres*scrnx.z;
X}
END_OF_FILE
if test 2211 -ne `wc -c <'src/viewing.c'`; then
    echo shar: \"'src/viewing.c'\" unpacked with wrong size!
fi
# end of 'src/viewing.c'
fi
echo shar: End of archive 1 \(of 8\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 8 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0


-- 
Please send comp.sources.unix-related mail to rsalz at uunet.uu.net.
Use a domain-based address or give alternate paths, or you may lose out.



More information about the Comp.sources.unix mailing list