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