Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/interfaces/tachyon.py
8814 views
1
r"""
2
The Tachyon Ray Tracer
3
4
AUTHOR:
5
6
- John E. Stone
7
"""
8
9
#*****************************************************************************
10
# Copyright (C) 2006 John E. Stone
11
#
12
# Distributed under the terms of the GNU General Public License (GPL)
13
# as published by the Free Software Foundation; either version 2 of
14
# the License, or (at your option) any later version.
15
# http://www.gnu.org/licenses/
16
#*****************************************************************************
17
18
from sage.misc.pager import pager
19
from sage.misc.misc import tmp_filename
20
from sage.misc.sagedoc import format
21
import os
22
import sys
23
24
class TachyonRT:
25
"""
26
The Tachyon Ray Tracer
27
28
tachyon_rt(model, outfile='sage.png', verbose=1, block=True, extra_opts='')
29
30
INPUT:
31
32
- ``model`` - a string that describes a 3d model in
33
the Tachyon modeling format. Type tachyon_rt.help() for a
34
description of this format.
35
36
- ``outfile`` - (default: 'sage.png') output filename;
37
the extension of the filename determines the type. Supported types
38
include:
39
40
- ``tga`` - 24-bit (uncompressed)
41
42
- ``bmp`` - 24-bit Windows BMP (uncompressed)
43
44
- ``ppm`` - 24-bit PPM (uncompressed)
45
46
- ``rgb`` - 24-bit SGI RGB (uncompressed)
47
48
- ``png`` - 24-bit PNG (compressed, lossless)
49
50
- ``verbose`` - integer; (default: 1)
51
52
- ``0`` - silent
53
54
- ``1`` - some output
55
56
- ``2`` - very verbose output
57
58
- ``block`` - bool (default: True); if False, run the
59
rendering command in the background.
60
61
- ``extra_opts`` - passed directly to tachyon command
62
line. Use tachyon_rt.usage() to see some of the possibilities.
63
64
65
OUTPUT:
66
67
68
- Some text may be displayed onscreen.
69
70
- The file outfile is created.
71
72
73
EXAMPLES:
74
75
AUTHORS:
76
77
- John E. Stone
78
"""
79
def __repr__(self):
80
"""
81
Returns a brief description of this interface object (the Tachyon raytracer written by John Stone).
82
83
TESTS::
84
85
sage: from sage.interfaces.tachyon import TachyonRT
86
sage: t = TachyonRT()
87
sage: print t.__repr__()
88
John Stone's Tachyon Ray Tracer
89
"""
90
return "John Stone's Tachyon Ray Tracer"
91
92
def __call__(self, model, outfile='sage.png',
93
verbose=1, block=True, extra_opts=''):
94
"""
95
This executes the tachyon program, given a scene file input.
96
The default is to return the result as a PNG file called 'sage.png'.
97
98
TESTS::
99
100
sage: from sage.interfaces.tachyon import TachyonRT
101
sage: tgen = Tachyon()
102
sage: tgen.texture('t1')
103
sage: tgen.sphere((0,0,0),1,'t1')
104
sage: tgen.str()[30:40]
105
'resolution'
106
sage: t = TachyonRT()
107
sage: import os
108
sage: t(tgen.str(), outfile = os.devnull)
109
tachyon ...
110
Tachyon Parallel/Multiprocessor Ray Tracer...
111
"""
112
modelfile = tmp_filename(ext='.dat')
113
open(modelfile,'w').write(model)
114
opts = ''
115
ext = outfile[-4:].lower()
116
if ext == '.png':
117
opts += ' -format PNG '
118
elif ext == '.tga':
119
opts += ' -format TARGA '
120
elif ext == '.bmp':
121
opts += ' -format BMP '
122
elif ext == '.ppm':
123
opts += ' -format PPM '
124
elif ext == '.rgb':
125
opts += ' -format RGB '
126
127
opts += ' -o %s '%outfile
128
129
opts += ' ' + extra_opts + ' '
130
131
if verbose >= 2:
132
opts += ' +V '
133
elif verbose == 0:
134
opts += ' 1>/dev/null'
135
136
cmd = 'tachyon %s %s; rm -f "%s"'%(modelfile,opts, modelfile)
137
138
if not block:
139
cmd = '( ' + cmd + ' ) &'
140
141
if verbose:
142
print cmd
143
# One should always flush before system()
144
sys.stdout.flush()
145
sys.stderr.flush()
146
os.system(cmd)
147
148
def usage(self, use_pager=True):
149
"""
150
Returns the basic description of using the Tachyon raytracer (simply what is returned by running tachyon with no input). The output is paged unless use_pager=False.
151
152
TESTS::
153
154
sage: from sage.interfaces.tachyon import TachyonRT
155
sage: t = TachyonRT()
156
sage: t.usage(use_pager=False)
157
Tachyon Parallel/Multiprocessor Ray Tracer Version...
158
"""
159
r = os.popen('tachyon').read()
160
if use_pager == True:
161
pager()(r)
162
else:
163
print r
164
165
def help(self, use_pager=True):
166
"""
167
Prints (pages) the help file written by John Stone describing scene files for Tachyon. The output is paged unless use_pager=False.
168
169
TESTS::
170
171
sage: from sage.interfaces.tachyon import TachyonRT
172
sage: t = TachyonRT()
173
sage: t.help(use_pager=False)
174
This help, which was written by John Stone, describes ...
175
"""
176
s = r"""
177
This help, which was written by John Stone, describes how to create
178
scene files.
179
180
At the present time, scene description files are very simple.
181
The parser can't handle multiple file scene descriptions, although they
182
may be added in the future. Most of the objects and their scene description
183
are closely related to the RAY API
184
\emph{(See the API docs for additional info.)}
185
186
\subsection{Basic Scene Requirements}
187
Unlike some other ray tracers out there, RAY requires that you
188
specify most of the scene parameters in the scene description file itself.
189
If users would rather specify some of these parameters at the command line,
190
then I may add that feature in the future.
191
A scene description file contains keywords, and values associated or grouped
192
with a keyword. All keywords can be in caps, lower case, or mixed case
193
for the convenience of the user. File names and texture names are
194
normally case-sensitive, although the behavior for file names is
195
operating system-dependent. All values are either character strings, or
196
floating point numbers. In some cases, the presence of one keyword will
197
require additional keyword / value pairs.
198
199
At the moment there are several keywords with values,
200
that must appear in every scene description file.
201
Every scene description file must begin with the
202
{\bf BEGIN\_SCENE} keyword, and end with the {\bf END\_SCENE} keyword.
203
All definitions and declarations of any kind must be inside the
204
{\bf BEGIN\_SCENE}, {\bf END\_SCENE} pair.
205
The {\bf RESOLUTION} keyword is followed by an x resolution
206
and a y resolution in terms of pixels on each axis. There are currently
207
no limits placed on the resolution of an output image other than the
208
computer's available memory and reasonable execution time.
209
An example of a simple scene description skeleton is show below:
210
\begin{verbatim}
211
BEGIN_SCENE
212
RESOLUTION 1024 1024
213
...
214
... Camera definition..
215
...
216
... Other objects, etc..
217
...
218
219
END_SCENE
220
\end{verbatim}
221
222
\subsection{Camera and viewing parameters}
223
One of the most important parts of any scene, is the camera position and
224
orientation. Having a good angle on a scene can make the difference between
225
an average looking scene and a strikingly interesting one. There may be
226
multiple camera definitions in a scene file, but the last camera definition
227
overrides all previous definitions.
228
There are several parameters that control the camera in \RAY,
229
{\bf PROJECTION}, {\bf ZOOM}, {\bf ASPECTRATIO}, {\bf ANTIALIASING},
230
{\bf CENTER}, {\bf RAYDEPTH}, {\bf VIEWDIR}, and {\bf UPDIR}.
231
232
The first and last keywords required in the definition of a camera are the
233
{\bf CAMERA} and {\bf END\_CAMERA} keywords. The {\bf PROJECTION} keyword
234
is optional, the remaining camera keywords are required, and must be
235
written in the sequence they are listed in the examples in this section.
236
237
\subsubsection{Camera projection modes}
238
The {\bf PROJECTION} keyword must be followed by one of the supported
239
camera projection mode identifiers {\bf PERSPECTIVE}, {\bf PERSPECTIVE_DOF},
240
{\bf ORTHOGRAPHIC}, or {\bf FISHEYE}. The {\bf FISHEYE} projection mode
241
requires two extra parameters {\bf FOCALLENGTH} and {\bf APERTURE}
242
which precede the regular camera options.
243
244
\begin{verbatim}
245
Camera
246
projection perspective_dof
247
focallength 0.75
248
aperture 0.02
249
Zoom 0.666667
250
Aspectratio 1.000000
251
Antialiasing 128
252
Raydepth 30
253
Center 0.000000 0.000000 -2.000000
254
Viewdir -0.000000 -0.000000 2.000000
255
Updir 0.000000 1.000000 -0.000000
256
End_Camera
257
\end{verbatim}
258
259
\subsubsection{Common camera parameters}
260
The {\bf ZOOM} parameter controls the camera in a way similar to a
261
telephoto lens on a 35mm camera. A zoom value of 1.0 is standard,
262
with a 90 degree field of view. By changing the zoom factor to 2.0,
263
the relative size of any feature in the frame is twice as big, while
264
the field of view is decreased slightly. The zoom effect is
265
implemented as a scaling factor on the height and width of the image
266
plane relative to the world.
267
268
The {\bf ASPECRATIO} parameter controls the aspect ratio of the resulting
269
image. By using the aspect ratio parameter, one can produce images which
270
look correct on any screen. Aspect ratio alters the relative width of the
271
image plane, while keeping the height of the image plane constant. In
272
general, most workstation displays have an aspect ratio of 1.0. To see
273
what aspect ratio your display has, you can render a simple sphere, at
274
a resolution of 512x512 and measure the ratio of its width to its height.
275
276
The {\bf ANTIALIASING} parameter controls the maximum level of supersampling
277
used to obtain higher image quality. The parameter given sets the number of
278
additional rays to trace per-pixel to attain higher image quality.
279
280
The {\bf RAYDEPTH} parameter tells RAY what the maximum
281
level of reflections, refraction, or in general the maximum recursion
282
depth to trace rays to. A value between 4 and 12 is usually good. A
283
value of 1 will disable rendering of reflective or transmissive
284
objects (they'll be black).
285
286
The remaining three camera parameters are the most important, because
287
they define the coordinate system of the camera, and its position in the
288
scene. The {\bf CENTER} parameter is an X, Y, Z coordinate defining the
289
center of the camera \emph{(also known as the Center of Projection)}.
290
Once you have determined where the camera will be placed in the scene, you
291
need to tell RAY what the camera should be looking at. The
292
{\bf VIEWDIR} parameter is a vector indicating the direction the camera
293
is facing. It may be useful for me to add a "Look At" type keyword in
294
the future to make camera aiming easier. If people want or need the
295
"Look At" style camera, let me know. The last parameter needed to completely
296
define a camera is the "up" direction. The {\bf UPDIR} parameter is a vector
297
which points in the direction of the "sky". I wrote the camera so that
298
{\bf VIEWDIR} and {\bf UPDIR} don't have to be perpendicular, and there
299
shouldn't be a need for a "right" vector although some other ray tracers
300
require it. Here's a snippet of a camera definition:
301
\begin{verbatim}
302
CAMERA
303
ZOOM 1.0
304
ASPECTRATIO 1.0
305
ANTIALIASING 0
306
RAYDEPTH 12
307
CENTER 0.0 0.0 2.0
308
VIEWDIR 0 0 -1
309
UPDIR 0 1 0
310
END_CAMERA
311
\end{verbatim}
312
313
314
\subsubsection{Viewing frustum}
315
An optional {\bf FRUSTUM} parameter provides a means for rendering sub-images
316
in a larger frame, and correct stereoscopic images. The {\bf FRUSTUM}
317
keyword must be followed by four floating parameters, which indicate
318
the top, bottom, left and right coordinates of the image plane in
319
eye coordinates. When the projection mode is set to {\bf FISHEYE},
320
the frustum parameters correspond to spherical coordinates specified
321
in radians.
322
323
\begin{verbatim}
324
CAMERA
325
ZOOM 1.0
326
ASPECTRATIO 1.0
327
ANTIALIASING 0
328
RAYDEPTH 4
329
CENTER 0.0 0.0 -6.0
330
VIEWDIR 0.0 0.0 1.0
331
UPDIR 0.0 1.0 0.0
332
FRUSTUM -0.5 0.5 -0.5 0.5
333
END_CAMERA
334
\end{verbatim}
335
336
337
\subsection{Including Files}
338
The {\bf INCLUDE} keyword is used anywhere after the camera description,
339
and is immediately followed by a valid filename, for a file containing
340
additional scene description information. The included file is opened,
341
and processing continues as if it were part of the current file, until
342
the end of the included file is reached. Parsing of the current file
343
continues from where it left off prior to the included file.
344
345
\subsection{Scene File Comments}
346
The {\bf $\#$} keyword is used anywhere after the camera description, and
347
will cause RAY to ignore all characters from the {\bf $\#$} to the end
348
of the input line. The {\bf $\#$} character must be surrounded by whitespace
349
in order to be recognized. A sequence such as {\bf $\#\#\#$} will not be
350
recognized as a comment.
351
352
\subsection{Lights}
353
The most frequently used type of lights provided by RAY are positional
354
point light sources. The lights are actually small spheres, which are
355
visible. A point light is composed of three pieces of
356
information, a center, a radius (since its a sphere), and a color.
357
To define a light, simply write the {\bf LIGHT} keyword, followed by
358
its {\bf CENTER} (a X, Y, Z coordinate), its {\bf RAD} (radius, a scalar),
359
and its {\bf COLOR} (a Red Green Blue triple). The radius parameter will
360
accept any value of 0.0 or greater. Lights of radius 0.0 will not be
361
directly visible in the rendered scene, but contribute light to the scene
362
normally.
363
For a light, the color values
364
range from 0.0 to 1.0, any values outside this range may yield unpredictable
365
results. A simple light definition looks like this:
366
\begin{verbatim}
367
LIGHT CENTER 4.0 3.0 2.0
368
RAD 0.2
369
COLOR 0.5 0.5 0.5
370
\end{verbatim}
371
This light would be gray colored if seen directly, and would be 50\%
372
intensity in each RGB color component.
373
374
375
RAY supports simple directional lighting, commonly used in
376
CAD and scientific visualization programs for its performance
377
advantages over positional lights. Directional lights cannot be
378
seen directly in scenes rendered by \RAY, only their illumination
379
contributes to the final image.
380
381
\begin{verbatim}
382
DIRECTIONAL_LIGHT
383
DIRECTION 0.0 -1.0 0.0
384
COLOR 1.0 0.0 0.0
385
\end{verbatim}
386
387
RAY supports spotlights, which are described very similarly to a
388
point light, but they are attenuated by angle from the direction vector,
389
based on a ``falloff start'' angle and ``falloff end''angle. Between
390
the starting and ending angles, the illumination is attenuated linearly.
391
The syntax for a spotlight description in a scene file is as follows.
392
\begin{verbatim}
393
SPOTLIGHT
394
CENTER 0.0 3.0 17.0
395
RAD 0.2
396
DIRECTION 0.0 -1.0 0.0
397
FALLOFF_START 20.0
398
FALLOFF_END 45.0
399
COLOR 1.0 0.0 0.0
400
\end{verbatim}
401
402
The lighting system implemented by RAY provides various levels of
403
distance-based lighting attenuation. By default, a light is not attenuated
404
by distance. If the \emph{attenuation} keywords is present immediately
405
prior to the light's color, RAY will accept coefficients which are used
406
to calculate distance-based attenuation, which is applied the light by
407
multiplying with the resulting value. The attenuation factor is calculated
408
from the equation
409
$$
410
1/(K_c + K_l d + k_q d^2)
411
$$
412
413
This attenuation equation should be familiar to some as it
414
is the same lighting attenuation equation used by OpenGL.
415
The constant, linear, and quadratic terms are specified in a scene file
416
as shown in the following example.
417
\begin{verbatim}
418
LIGHT
419
CENTER -5.0 0.0 10.0
420
RAD 1.0
421
ATTENUATION CONSTANT 1.0 LINEAR 0.2 QUADRATIC 0.05
422
COLOR 1.0 0.0 0.0
423
\end{verbatim}
424
425
426
427
\subsection{Atmospheric effects}
428
RAY currently only implements one atmospheric effect,
429
simple distance-based fog.
430
431
\subsubsection{Fog}
432
RAY provides a simple distance-based fog effect intended to provide
433
functionality similar to that found in OpenGL, for compatibility with
434
software that requires an OpenGL-like fog implementation. Much like
435
OpenGL, RAY provides linear, exponential, and exponential-squared fog.
436
437
\begin{verbatim}
438
FOG
439
LINEAR START 0.0 END 50.0 DENSITY 1.0 COLOR 1.0 1.0 1.0
440
\end{verbatim}
441
442
\begin{verbatim}
443
FOG
444
EXP START 0.0 END 50.0 DENSITY 1.0 COLOR 1.0 1.0 1.0
445
\end{verbatim}
446
447
\begin{verbatim}
448
FOG
449
EXP2 START 0.0 END 50.0 DENSITY 1.0 COLOR 1.0 1.0 1.0
450
\end{verbatim}
451
452
453
\subsection{Objects}
454
455
\subsubsection{Spheres}
456
Spheres are the simplest object supported by RAY and they are
457
also the fastest object to render. Spheres are defined as one would expect,
458
with a {\bf CENTER}, {\bf RAD} (radius), and a texture. The texture may
459
be defined along with the object as discussed earlier, or it may be declared
460
and assigned a name.
461
Here's a sphere definition using a previously defined "NitrogenAtom" texture:
462
\begin{verbatim}
463
SPHERE CENTER 26.4 27.4 -2.4 RAD 1.0 NitrogenAtom
464
\end{verbatim}
465
A sphere with an inline texture definition is declared like this:
466
\begin{verbatim}
467
Sphere center 1.0 0.0 10.0
468
Rad 1.0
469
Texture Ambient 0.2 Diffuse 0.8 Specular 0.0 Opacity 1.0
470
Color 1.0 0.0 0.5
471
TexFunc 0
472
\end{verbatim}
473
Notice that in this example I used mixed case for the keywords, this is
474
allowable...
475
Review the section on textures if the texture definitions are confusing.
476
477
\subsubsection{Triangles}
478
Triangles are also fairly simple objects, constructed by listing the
479
three vertices of the triangle, and its texture. The order of the
480
vertices isn't important, the triangle object is "double sided", so the
481
surface normal is always pointing back in the direction of the incident ray.
482
The triangle vertices are listed as {\bf V1}, {\bf V2}, and {\bf V3} each one
483
is an X, Y, Z coordinate. An example of a triangle is shown below:
484
\begin{verbatim}
485
TRI
486
V0 0.0 -4.0 12.0
487
V1 4.0 -4.0 8.0
488
V2 -4.0 -4.0 8.0
489
TEXTURE
490
AMBIENT 0.1 DIFFUSE 0.2 SPECULAR 0.7 OPACITY 1.0
491
COLOR 1.0 1.0 1.0
492
TEXFUNC 0
493
\end{verbatim}
494
495
\subsubsection{Smoothed Triangles}
496
Smoothed triangles are just like regular triangles, except that the
497
surface normal for each of the three vertexes is used to determine the
498
surface normal across the triangle by linear interpolation.
499
Smoothed triangles yield curved looking objects and have nice
500
reflections.
501
\begin{verbatim}
502
STRI
503
V0 1.4 0.0 2.4
504
V1 1.35 -0.37 2.4
505
V2 1.36 -0.32 2.45
506
N0 -0.9 -0.0 -0.4
507
N1 -0.8 0.23 -0.4
508
N2 -0.9 0.27 -0.15
509
TEXTURE
510
AMBIENT 0.1 DIFFUSE 0.2 SPECULAR 0.7 OPACITY 1.0
511
COLOR 1.0 1.0 1.0
512
TEXFUNC 0
513
\end{verbatim}
514
515
\subsubsection{Infinite Planes}
516
517
Useful for things like desert floors, backgrounds, skies etc, the infinite
518
plane is pretty easy to use. An infinite plane only consists of two pieces
519
of information, the {\bf CENTER} of the plane, and a {\bf NORMAL} to the plane.
520
The center of the plane is just any point on the plane such that the point
521
combined with the surface normal define the equation for the plane.
522
As with triangles, planes are double sided. Here is an example of an
523
infinite plane:
524
\begin{verbatim}
525
PLANE
526
CENTER 0.0 -5.0 0.0
527
NORMAL 0.0 1.0 0.0
528
TEXTURE
529
AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
530
COLOR 1.0 1.0 1.0
531
TEXFUNC 1
532
CENTER 0.0 -5.0 0.0
533
ROTATE 0. 0.0 0.0
534
SCALE 1.0 1.0 1.0
535
\end{verbatim}
536
537
\subsubsection{Rings}
538
Rings are a simple object, they are really a not-so-infinite plane.
539
Rings are simply an infinite plane cut into a washer shaped ring, infinitely
540
thing just like a plane. A ring only requires two more pieces of information
541
than an infinite plane does, an inner and outer radius. Here's an example
542
of a ring:
543
\begin{verbatim}
544
Ring
545
Center 1.0 1.0 1.0
546
Normal 0.0 1.0 0.0
547
Inner 1.0
548
Outer 5.0
549
MyNewRedTexture
550
\end{verbatim}
551
552
\subsubsection{Infinite Cylinders}
553
Infinite cylinders are quite simple. They are defined by a center, an
554
axis, and a radius. An example of an infinite cylinder is:
555
\begin{verbatim}
556
Cylinder
557
Center 0.0 0.0 0.0
558
Axis 0.0 1.0 0.0
559
Rad 1.0
560
SomeRandomTexture
561
\end{verbatim}
562
563
\subsubsection{Finite Cylinders}
564
Finite cylinders are almost the same as infinite ones, but the
565
center and length of the axis determine the extents of the cylinder.
566
The finite cylinder is also really a shell, it doesn't have any
567
caps. If you need to close off the ends of the cylinder, use two
568
ring objects, with the inner radius set to 0.0 and the normal set
569
to be the axis of the cylinder. Finite cylinders are built this
570
way to enhance speed.
571
572
\begin{verbatim}
573
FCylinder
574
Center 0.0 0.0 0.0
575
Axis 0.0 9.0 0.0
576
Rad 1.0
577
SomeRandomTexture
578
\end{verbatim}
579
This defines a finite cylinder with radius 1.0, going from 0.0 0.0 0.0, to
580
0.0 9.0 0.0 along the Y axis. The main difference between an infinite cylinder
581
and a finite cylinder is in the interpretation of the {\bf AXIS} parameter.
582
In the case of the infinite cylinder, the length of the axis vector is
583
ignored. In the case of the finite cylinder, the axis parameter is used
584
to determine the length of the overall cylinder.
585
586
\subsubsection{Axis Aligned Boxes}
587
Axis aligned boxes are fast, but of limited usefulness. As such, I'm
588
not going to waste much time explaining 'em. An axis aligned box is
589
defined by a {\bf MIN} point, and a {\bf MAX} point. The volume between
590
the min and max points is the box. Here's a simple box:
591
\begin{verbatim}
592
BOX
593
MIN -1.0 -1.0 -1.0
594
MAX 1.0 1.0 1.0
595
Boxtexture1
596
\end{verbatim}
597
598
\subsubsection{Fractal Landscapes}
599
Currently fractal landscapes are a built-in function. In the near future
600
I'll allow the user to load an image map for use as a heightfield.
601
Fractal landscapes are currently forced to be axis aligned. Any suggestion
602
on how to make them more appealing to users is welcome. A fractal landscape
603
is defined by its "resolution" which is the number of grid points along
604
each axis, and by its scale and center. The "scale" is how large the
605
landscape is along the X, and Y axes in world coordinates. Here's a simple
606
landscape:
607
\begin{verbatim}
608
SCAPE
609
RES 30 30
610
SCALE 80.0 80.0
611
CENTER 0.0 -4.0 20.0
612
TEXTURE
613
AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
614
COLOR 1.0 1.0 1.0
615
TEXFUNC 0
616
\end{verbatim}
617
The landscape shown above generates a square landscape made of 1,800 triangles.
618
When time permits, the heightfield code will be rewritten to be more
619
general and to increase rendering speed.
620
621
\subsubsection{Arbitrary Quadric Surfaces}
622
Docs soon. I need to add these into the parser, must have forgotten
623
before ;-)
624
625
\subsubsection{Volume Rendered Scalar Voxels}
626
These are a little trickier than the average object :-)
627
These are likely to change substantially in the very near future so I'm not
628
going to get too detailed yet.
629
A volume rendered data set is described by its axis aligned bounding box, and
630
its resolution along each axis. The final parameter is the voxel data
631
file. If you are seriously interested in messing with these, get hold of
632
me and I'll give you more info. Here's a quick example:
633
\begin{verbatim}
634
SCALARVOL
635
MIN -1.0 -1.0 -0.4
636
MAX 1.0 1.0 0.4
637
DIM 256 256 100
638
FILE /cfs/johns/vol/engine.256x256x110
639
TEXTURE
640
AMBIENT 1.0 DIFFUSE 0.0 SPECULAR 0.0 OPACITY 8.1
641
COLOR 1.0 1.0 1.0
642
TEXFUNC 0
643
\end{verbatim}
644
645
\subsection{Texture and Color}
646
\subsubsection{Simple Texture Characteristics}
647
The surface textures applied to an object drastically alter its overall
648
appearance, making textures and color one of the most important topics in
649
this manual. As with many other renderers, textures can be declared and
650
associated with a name so that they may be used over and over again in
651
a scene definition with less typing. If a texture is only need once, or it
652
is unique to a particular object in the scene, then it may be declared along
653
with the object it is applied to, and does not need a name.
654
655
The simplest texture definition is a solid color with no image mapping
656
or procedural texture mapping. A solid color texture is defined by the
657
{\bf AMBIENT}, {\bf DIFFUSE}, {\bf SPECULAR}, {\bf OPACITY} and {\bf COLOR}
658
parameters. The {\bf AMBIENT} parameter defines the ambient lighting
659
coefficient to be used when shading the object. Similarly, the {\bf DIFFUSE}
660
parameter is the relative contribution of the diffuse shading to the surface
661
appearance. The {\bf SPECULAR} parameter is the contribution from perfectly
662
reflected rays, as if on a mirrored surface. {\bf OPACITY} defines how
663
transparent a surface is. An {\bf OPACITY} value of 0.0 renders the object
664
completely invisible. An {\bf OPACITY} value of 1.0 makes the object
665
completely solid, and non-transmissive. In general, the values for the
666
ambient, diffuse, and specular parameters should add up to 1.0, if they don't
667
then pixels may be over or underexposed quite easily. These parameters
668
function in a manner similar to that of other ray tracers. The {\bf COLOR}
669
parameter is an RGB triple with each value ranging from 0.0 to 1.0 inclusive.
670
If the RGB values stray from 0.0 to 1.0, results are undefined.
671
In the case of solid textures, a final parameter, {\bf TEXFUNC} is set to
672
zero (integer).
673
674
\subsubsection{Texture Declaration and Aliasing}
675
To define a simple texture for use on several objects in a scene, the
676
{\bf TEXDEF} keyword is used. The {\bf TEXDEF} keyword is followed by
677
a case sensitive texture name, which will subsequently be used while
678
defining objects. If many objects in a scene use the same texture through
679
texture definition, a significant amount of memory may be saved since only
680
one copy of the texture is present in memory, and its shared by all
681
of the objects. Here is an example of a solid texture definition:
682
\begin{verbatim}
683
TEXDEF MyNewRedTexture
684
AMBIENT 0.1 DIFFUSE 0.9 SPECULAR 0.0 OPACITY 1.0
685
COLOR 1.0 0.0 0.0 TEXFUNC 0
686
\end{verbatim}
687
When this texture is used in an object definition, it is referenced only by
688
name. Be careful not to use one of the other keywords as a defined texture,
689
this will probably cause the parser to explode, as I don't check for use
690
of keywords as texture names.
691
692
When a texture is declared within an object definition, it appears in
693
an identical format to the {\bf TEXDEF} declaration, but the {\bf TEXTURE}
694
keyword is used instead of {\bf TEXDEF}. If it is useful to have several
695
names for the same texture (when you are too lazy to actually finish defining
696
different variations of a wood texture for example, and just want to be
697
approximately correct for example) aliases can be constructed using the
698
{\bf TEXALIAS} keyword, along with the alias name, and the original name.
699
An example of a texture alias is:
700
\begin{verbatim}
701
TEXALIAS MyNewestRedTexture MyNewRedTexture
702
\end{verbatim}
703
This line would alias MyNewestRedTexture to be the same thing as the
704
previously declared MyNewRedTexture. Note that the source texture must
705
be declared before any aliases that use it.
706
707
\subsubsection{Image Maps and Procedural Textures} Image maps and
708
procedural textures very useful in making realistic looking scenes. A
709
good image map can do as much for the realism of a wooden table as any
710
amount of sophisticated geometry or lighting. Image maps are made by
711
wrapping an image on to an object in one of three ways, a spherical
712
map, a cylindrical map, and a planar map. Procedural textures are
713
used in a way similar to the image maps, but they are on the fly and
714
do not use much memory compared to the image maps. The main
715
disadvantage of the procedural maps is that they must be hard-coded
716
into RAY when it is compiled.
717
718
The syntax used for all texture maps is fairly simple to learn. The biggest
719
problem with the way that the parser is written now is that the different
720
mappings are selected by an integer, which is not very user friendly. I
721
expect to rewrite this section of the parser sometime in the near future to
722
alleviate this problem. When I rewrite the parser, I may also end up altering
723
the parameters that are used to describe a texture map, and some of them may
724
become optional rather than required.
725
726
\begin{center}
727
\begin{tabular}{|c|c|}
728
\multicolumn{2}{c}{Texture Mapping Functions} \\
729
\hline
730
{Value for TEXFUNC} & {Mapping and Texture Description}\\
731
\hline
732
{0} & {No special texture, plain shading} \\
733
{1} & {3D checkerboard function, like a Rubik's cube} \\
734
{2} & {Grit Texture, randomized surface color} \\
735
{3} & {3D marble texture, uses object's base color} \\
736
{4} & {3D wood texture, light and dark brown, not very good yet} \\
737
{5} & {3D gradient noise function (can't remember what it look like} \\
738
{6} & {Don't remember} \\
739
{7} & {Cylindrical Image Map, requires ppm filename} \\
740
{8} & {Spherical Image Map, requires ppm filename} \\
741
{9} & {Planar Image Map, requires ppm filename} \\
742
\hline
743
\end{tabular}
744
\end{center}
745
746
Here's an example of a sphere, with a spherical image map applied to its
747
surface:
748
\begin{verbatim}
749
SPHERE
750
CENTER 2.0 0.0 5.0
751
RAD 2.0
752
TEXTURE
753
AMBIENT 0.4 DIFFUSE 0.8 SPECULAR 0.0 OPACITY 1.0
754
COLOR 1.0 1.0 1.0
755
TEXFUNC 7 /cfs/johns/imaps/fire644.ppm
756
CENTER 2.0 0.0 5.0
757
ROTATE 0.0 0.0 0.0
758
SCALE 2.0 -2.0 1.0
759
\end{verbatim}
760
761
Basically, the image maps require the center, rotate and scale
762
parameters so that you can position the image map on the object
763
properly.
764
"""
765
f = format(s)
766
f = f.replace('{ ','').replace('}','').replace('{','')
767
if use_pager == True:
768
pager()(f)
769
else:
770
print(f)
771
772
tachyon_rt = TachyonRT()
773
774
775
776