1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
|
\
.\" This man page was generated by the Netpbm tool 'makeman' from HTML source.
.\" Do not hand-hack it! If you have bug fixes or improvements, please find
.\" the corresponding HTML page on the Netpbm website, generate a patch
.\" against that, and send it to the Netpbm maintainer.
.TH "Pamtris User Manual" 1 "15 April 2021" "netpbm documentation"
.PP
.SH NAME
pamtris - triangle rasterizer featuring perspective-correct
interpolation of generic vertex attributes and depth buffering
.UN synopsis
.SH SYNOPSIS
\fBpamtris\fP
\fB-width=\fP\fIwidth\fP
\fB-height=\fP\fIheight\fP
{\ \fB-num_attribs=\fP\fIattributes_per_vertex\fP
[\ \fB-tupletype=\fP\fItupletype\fP\ ]
| \fB-rgb\fP
| \fB-grayscale\fP\ }
[\ \fB-maxval=\fP\fImaxval\fP\ ]
.PP
All options can be abbreviated to their shortest unique prefix.
You may use two hyphens instead of one to designate an option. You
may use either white space or an equals sign between an option name
and its value.
.UN description
.SH DESCRIPTION
.PP
This program is part of
.BR "Netpbm" (1)\c
\&.
.PP
\fBpamtris\fP can be used to draw a great variety of 2D and 3D graphics by
composing arbitrarily complex pictures out of separate triangles, triangle
strips and triangle fans. The program reads instructions written in a simple
command script notation from Standard Input and outputs its results
as a (potentially multi-image) PAM stream on Standard Output.
.PP
For example, the following input
.nf
\f(CW
mode fan
attribs 0 128 0
vertex 0 0 1
attribs 0 0 128
vertex 200 0 1
attribs 50 20 103
vertex 190 61 1
attribs 100 40 78
vertex 161 117 1
attribs 150 60 53
vertex 117 161 1
attribs 200 80 28
vertex 61 190 1
attribs 250 100 3
vertex 0 200 1
print
\fP
.fi
.PP
produces this:
.PP
.B Example pamtris output for FAN mode
.IMG -C pamtris_fan.png
.PP
The input file gives triangle data by setting the appropriate drawing mode,
if necessary, and then providing a list of vertices. Each vertex is also
associated with a list of up to 20 "attributes," which are integer
values between 0 and a given maxval. In the most common usage, you use
\fBpamtris\fP to draw a visual image and a vertex has three attributes, which
are an RGB specification of a color. Such attribute lists may be provided on
a per-vertex basis.
.PP
Prior to effectively writing a PAM image to Standard Output, \fBpamtris\fP
first rasterizes it onto an internal frame buffer, which consists of an
"image buffer" and a "depth buffer." The image buffer consists of a sequence
of \fIheight\fP rows containing a sequence of \fIwidth\fP tuples. There is
one sample for each vertex attribute in every tuple plus an opacity (alpha)
sample. Each tuple in the image buffer is also associated with an integer
depth in the depth buffer, which determines whether subsequent drawing
operations affect that particular tuple or not. This provides a way of
depth-sorting graphical objects which is adequate for many purposes in 2D
and 3D computer graphics. One prominent shortcoming of such an approach
to depth-sorting, however, is that it does not automatically work with
objects which are intended to appear "translucent," therefore requiring
more elaborate strategies to incorporate said objects into pictures
generated using this technique.
.PP
The opacity sample is the last sample of the tuple. \fBpamtris\fP
manipulates opacity internally and for any tuple it is always either 0 or the
maxval. The program does not provide the user direct control over the alpha
image plane.
.PP
\fBpamtris\fP rasterizes triangles by approximating their visible area as
a collection of tuples at particular positions in the frame buffer, and to
each sample of every such tuple it assigns a value which is a
perspective-correct interpolation between the values of the corresponding
attribute for each vertex of the triangle. Whenever a tuple within the area
of the frame buffer is produced, it is written to the corresponding position
in the frame buffer if and only if it passes a depth test. This test works
as follows: the depth value of every incoming tuple (which is itself an
interpolation between the Z-coordinates of the vertices of the
corresponding triangle) is compared against the value in the corresponding
position in the depth buffer. If the depth value of the incoming tuple
equals or is smaller than the depth value already present in said position in
the depth buffer, the following happens.
.IP \(bu
Every sample \fIi\fP, where 0 ≤ \fIi\fP < \fInum_attribs\fP,
of the tuple in the corresponding position in the image buffer is set to equal
the value of the respective sample of the incoming tuple; and the alpha
sample (the last one) is updated to the \fImaxval\fP;
.IP \(bu
The depth value in the corresponding position in the depth buffer is
updated to a depth value directly proportional to that of the incoming
tuple.
.PP
Otherwise, that particular tuple effects no change at all in the frame
buffer.
.PP
The frame buffer is initially set so that all samples in every tuple of the
image buffer contain the value 0, and all entries in the depth buffer contain
the maximum permitted depth value.
.PP
The attributes' values, and therefore the samples in the output
PAM images, have no fixed interpretation ascribed to them (except for the
last image plane, which is deliberately supposed to represent tuple opacity
information); one may ascribe any suitable meaning to them, such as that of
colors, texture coordinates, surface normals, light interaction
characteristics, texture influence coefficients for multi-texturing, etc.
.UN examples
.SH EXAMPLES
.UN examples_fan
.SS Fan Mode
.PP
The following command generates the image from the fan mode example at the
top of the
.UR #description
DESCRIPTION
.UE
\& section. If the file
\fBfan.tris\fP contains that code, you could process it with:
.nf
\f(CW
$ pamtris -height=200 -width=200 -rgb <fan.tris >fan.pam
\fP
.fi
.UN examples_strip
.SS Strip Mode
.PP
The following is an example of strip mode:
.nf
\f(CW
mode strip
attribs 255 0 0 # red
vertex 0 200 1
vertex 50 0 1
attribs 0 0 0 # black
vertex 100 200 1
attribs 0 205 205 # cyan
vertex 150 0 1
attribs 0 0 255 # blue
vertex 200 200 1
vertex 250 0 1
print
\fP
.fi
.PP
Save the above code in a file named \fBstrip.tris\fP (for instance)
and process it with:
.nf
\f(CW
$ pamtris -height=200 -width=200 -rgb <strip.tris >strip.pam
\fP
.fi
to yield:
.PP
.B Example pamtris output for STRIP mode
.IMG -C pamtris_strip.png
.UN examples_triangles
.SS Triangle Mode
.PP
The following is an example of triangle mode:
.nf
\f(CW
# yellow square
mode strip
attrib 155 155 0
vertex 50 50 100
vertex 50 200 100
vertex 200 50 100
vertex 200 200 100
# blue triangle
mode triangles
attrib 0 205 205
vertex 20 125 70
attrib 0 0 140
vertex 230 70 120 # Change "120" and see what happens
vertex 230 180 120 #
print
\fP
.fi
.PP
Save the above code in a file named \fBpierce.tris\fP (for instance)
and process it with:
.nf
\f(CW
$ pamtris -height=200 -width=200 -rgb <pierce.tris >pierce.pam
\fP
.fi
to yield:
.PP
.B Example pamtris output for TRIANGLES mode
.IMG -C pamtris_pierce.png
.UN pamtris_c
.SS Meta-programming
.PP
The \fBpamtris\fP command language is much too rudimentary to be used
directly for any serious drawing; you will probably want to use a general
purpose programming language to generate a temporary \fBpamtris\fP command
file.
.PP
For example, the \fBdraw_polygon\fP procedure in the C program below
outputs \fBpamtris\fP instructions to draw a regular polygon. It does this
by generating a number of \fBvertex\fP instructions tracing around the
perimeter of the corresponding circumscribed circle. (Note: The PAM image
produced by piping the output of the below program into \fBpamtris\fP was
subsequently downscaled through
\fBpamscale\ -linear\ -xscale\ 0.25\ -yscale\ 0.25\fP
to achieve an
.UR #antialias
anti-aliased
.UE
\& effect.)
.PP
.B Regular Polygons
.IMG -C pamtris_polygons.png
.nf
\f(CW
/* ----------------------- *
* width = 512 *
* height = 512 *
* num_attribs = 3 *
* tupletype = RGB_ALPHA *
* ----------------------- */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define PI 3.14159265358979323844
void draw_polygon
(int const center_x, int const center_y, int const radius, int const sides)
{
printf("mode fan\en"
"vertex %d %d 0\en", center_x, center_y);
for(int i = 0; i <= sides; i++)
{
int const x = round(center_x + radius * cos(i*2.0*PI / sides));
int const y = round(center_y - radius * sin(i*2.0*PI / sides));
printf("vertex %d %d 0\en", x, y);
}
}
int main(void)
{
puts("attribs 0 185 80"); /* color: green */
draw_polygon(300, 210, 150, 5); /* draws pentagon */
puts("attribs 255 15 240"); /* color: magenta */
draw_polygon(150, 320, 100, 7); /* draws heptagon */
puts("!");
}
\fP
.fi
.UN options
.SH OPTIONS
.PP
In addition to the options common to all programs based on libnetpbm
(most notably \fB-quiet\fP, see
.UR index.html#commonoptions
Common Options
.UE
\&), \fBpamtris\fP recognizes the following
command line options:
<dl compact="compact">
.TP
\fB-width=\fP\fIwidth\fP
Sets the width of the internal frame buffer and, by extension, of the
output PAM images, given in number of columns. This must be an integer in the
closed range [1, 8192].
.sp
This option is mandatory.
.TP
\fB-height=\fP\fIheight\fP
This is the height of the internal frame buffer and, by extension, of the
output PAM images, given in number of rows. This must be an integer in
the closed range [1, 8192].
.sp
This option is mandatory.
.TP
\fB-num_attribs=\fP\fIattributes_per_vertex\fP
This is the number of attributes per vertex. The depth of the output
PAM images equals this value plus one (to accomodate the alpha plane). The
argument must be an integer in the closed range [1, 20].
.sp
The input instruction stream may override this with a \fBreset\fP
command.
.sp
You must specify exactly one of \fB-num_attribs\fP, \fB-rgb\fP,
and \fB-grayscale\fP.
.TP
\fB-tupletype=\fP\fItupletype\fP
This is the tuple type for the output PAM images. The argument is a string
which may be no longer than 255 characters.
.sp
The input instruction stream may override this with a \fBreset\fP
command.
.sp
The default is a null string.
.sp
This option cannot be specified together with \fB-rgb\fP or
\fB-grayscale\fP.
.TP
\fB-rgb\fP
This is a convenience option which simply serves as an alias for
\fB-num_attribs=\fP3 \fB-tupletype=\fPRGB_ALPHA. In other words, this option
is a quick way to specify that you are going to use \fBpamtris\fP to draw
RGB(_ALPHA) color images directly, and the three vertex attributes are the
red, green and blue levels of the color associated with the vertex, in that
order.
.sp
The input instruction stream may override this with a \fBreset\fP
command.
.sp
You must specify exactly one of \fB-num_attribs\fP, \fB-rgb\fP,
and \fB-grayscale\fP.
.sp
This option was new in Netpbm 10.85 (December 2018).
.TP
\fB-grayscale\fP
Another convenience option, similar to \fB-rgb\fP; except this one is an
alias for \fB-num_attribs=\fP1 \fB-tupletype=GRAYSCALE_ALPHA\fP. The one
vertex attribute is the gray level associated with the vertex.
.sp
The input instruction stream may override this with a \fBreset\fP
command.
.sp
You must specify exactly one of \fB-num_attribs\fP, \fB-rgb\fP,
and \fB-grayscale\fP.
.sp
This option was new in Netpbm 10.85 (December 2018).
.TP
\fB-maxval=\fP\fImaxval\fP
Sets the maxval of the output PAM images, which is also the maximum
permitted value for each vertex attribute. This must be an integer in the
closed range [1, 65535].
.sp
The default value is 255.
.sp
The input instruction stream may override this with a
\fBreset\fP command.
.UN instruction_code
.SH INSTRUCTION CODE
.PP
The input for \fBpamtris\fP consists of a stream of text lines read from
Standard Input.
.PP
Empty lines or lines that contain only white space characters are called
blank lines and are ignored.
.PP
When a \fB#\fP occurs anywhere in a line, \fBpamtris\fP ignores it
along with every character after it. In other words, everything from the
\fB#\fP until the end of the line receives the same treatment as white
space.
.PP
Lines which are not blank must contain a sequence of strings, called
tokens, separated by white space. The first such token must be one of the
commands recognized by \fBpamtris\fP, and all further tokens are interpreted
as the arguments for that command, if it takes any. When an insufficient
number of arguments is provided for a command, the line is considered invalid
and is given the same treatment as a blank line. The same happens when an out
of range argument or one of a kind different of what is expected is given (for
example, when you give a string of letters where a numerical value is
expected), or when an unrecognized command/argument is found. When a number of
arguments greater than that required for a particular command is provided,
only the portion of the line up to the last required argument is considered
and any further tokens are ignored.
.PP
\fBpamtris\fP is case-insensitive. That is, \fBmode\fP, \fBMODE\fP,
\fBmODe\fP, etc. are all treated the same way.
.PP
The commands recognized by \fBpamtris\fP are:
.TP
\fBmode\fP
.TP
\fBattribs\fP
.TP
\fBvertex\fP
.TP
\fBprint\fP
.TP
\fBclear\fP
.TP
\fBreset\fP
.TP
\fBquit\fP
.PP
You may use a minimum unique abbreviation of a command name. You may use
an exclamation mark (\fB!\fP) in place of the \fBprint\fP command name and an
asterisk (\fB*\fP) in place of \fBclear\fP.
.PP
The functions of the commands are as follows.
.TP
\fBmode\fP { triangles | strip | fan }
.sp
This makes \fBpamtris\fP enter a new drawing mode. The argument is a word
which specifies the mode to change to. Instead of a full argument name, it is
permissible to provide a minimum unique abbreviation, which has the same
effect. The drawing mode will remain the same until the next \fBmode\fP
command is given.
.sp
This command also resets the current vertex list, which is
(re)initialized to an empty state after the command is executed. One may add
new vertices to this list through successive invocations of the \fBvertex\fP
command (see below). You do not have to worry about providing "too many"
vertices, since the vertex list is virtualized: \fBpamtris\fP maintains only
the state pertaining to three vertices at any one time. The current vertex
list is initially empty.
.sp
It is permissible to give \fBpamtris\fP a \fBmode\fP command which
instructs it to enter a drawing mode it is currently already in. One might
use this approach to reset the current vertex list without changing the
current drawing mode.
.sp
Regardless of the current drawing mode, the program immediately rasterizes
a new triangle into the frame buffer as soon as you provide the necessary
vertices for it through the current vertex list. (If you reset the vertex list
before giving all the vertices necessary to draw a new triangle, the program
effectively discards from the list any vertices that might have been pushed
into the vertex list up to that point without using them to draw any new
triangles.)
.sp
In the following descriptions of each drawing mode, triangles' and
vertices' indices (ordinal numbers) are 0-based.
.sp
The \fBtriangles\fP argument instructs \fBpamtris\fP to enter the
"TRIANGLES" drawing mode. While in this mode, a series of separate triangles
is constructed. Every three vertices pushed into the current vertex list
specify a new triangle. Formally, this means that every
\fIN\uth\d\fP triangle is specified by vertices 3*\fIN\fP,
3*\fIN\fP\ +\ 1, and 3*\fIN\fP\ +\ 2. This is the default
initial mode and is therefore not required to be set explicitly before
drawing any triangles.
.sp
The \fBstrip\fP argument instructs \fBpamtris\fP to enter the "STRIP"
drawing mode. While in this mode, \fBpamtris\fP constructs a "triangle
strip." That is, the first three vertices pushed into the current vertex
list specify the first triangle, and every new vertex pushed after that
specifies, together with the previous two, the next triangle. Formally, this
means that every \fIN\fP\uth\d triangle is specified by vertices
\fIN\fP, \fIN\fP\ +\ 1, and \fIN\fP\ +\ 2.
.sp
The \fBfan\fP argument instructs \fBpamtris\fP to enter the "FAN"
drawing mode. While in this mode, a so-called "triangle fan" is constructed.
That is, the first three vertices pushed into the current vertex list specify
the first triangle, and every new vertex pushed after that specifies, together
with the previous vertex and the first one, the next triangle. Formally, this
means that every \fIN\fP\uth\d triangle is specified by vertices
\fI0\fP, \fIN\fP\ +\ 1, and \fIN\fP\ +\ 2.
.TP
\fBattribs\fP \fIa<sub>0\fP \fIa<sub>1\fP
\fIa<sub>2\fP ... \fIa<sub>num_attribs - 1\fP
.sp
This updates the current attribute values list. This command takes as
arguments a sequence of \fInum_attribs\fP integers which represent the
values of the attributes to be associated with the next vertex. This
sequence of values is the just mentioned "current attribute values list."
.sp
Each \fIi\uth\d\fP argument, where 0 ≤ \fIi\fP <
\fInum_attribs\fP, indicates the value to be assigned to the
\fIi\fP\uth\d attribute of the current attribute values list. All
arguments must be integer values in the closed range [0, \fImaxval\fP].
If a number of arguments less than the current value of \fInum_attribs\fP
is given, the command is considered invalid and is therefore ignored.
.sp
The current attribute values list remains unchanged until the next valid
\fBattribs\fP or \fBreset\fP command is given. The \fBattribs\fP command
allows one to change the values of each attribute individually, while the
\fBreset\fP command is not specifically designed for that function, but it
has the side effect of setting all values in the current attribute values
list to the \fImaxval\fP (see below).
.sp
All values in the current attribute values list are initially set to the
\fImaxval\fP.
<dt id="cmd_vertex">\fBvertex\fP \fIx\fP \fIy\fP \fIz\fP [\fIw\fP]
.sp
Adds a new vertex to the current vertex list (see the \fBmode\fP
command above), assigning the values of the arguments to its respective
coordinates, and the values in the current attribute values list (see the
\fBattribs\fP command above) to the respective entries in the
attribute list associated with the vertex.
.sp
\fIx\fP, \fIy\fP and \fIz\fP
must be integer values in the closed range [-32767, 32767].
\fIx\fP and \fIy\fP represent, respectively, the column and row of the
tuple which corresponds to the location of the vertex. Such values may
correspond to tuples outside the limits of the frame buffer. The origin of
the coordinate system is at the top-left tuple of the frame buffer. The
X-axis goes from left to right, and the Y-axis from top to bottom. A
negative value for \fIx\fP indicates a column that many tuples to the
left of the leftmost column of the frame buffer. Likewise, a negative
value for \fIy\fP indicates a row that many tuples above the uppermost
row of the frame buffer. Observe that those coordinates correspond
directly to a particular point in the coordinate system delineated
above, regardless of whether you are trying to draw an image which is
supposed to look as if viewed "in perspective" or not; \fBpamtris\fP
does \fInot\fP "warp" the coordinates you give in any way.
Therefore, if you want to draw images in perspective, you must compute
values for \fIx\fP and \fIy\fP already projected into \fBpamtris\fP'
coordinate system yourself, using an external perspective projection
method, prior to giving them to the program.
.sp
The \fIz\fP parameter represents the Z-coordinate of the vertex, which
is used to compute depth values for tuples within the areas of rasterized
triangles. Intuitively, smaller values for \fIz\fP mean "closer to
the viewer," and larger ones mean "farther away from the viewer" (but
remember: as said above, the \fIx\fP and \fIy\fP coordinates are not
warped in any way, which implies that they are not affected by \fIz\fP;
neither by the next parameter, for that matter).
.sp
Optionally, you may provide a \fIw\fP parameter which represents a
"perspective correction factor" used to properly interpolate vertex attributes
across the area of the corresponding triangle. This must be an integer value
in the closed range [1, 1048575]. If you don't provide a value for it, the
default value of 1 is used (hence, if you want to nullify the effects of
perspective correction on a triangle so the output samples are computed as if
just linearly interpolated, simply do not provide a value for \fIw\fP for any
vertex of the triangle). If, however, you intend to draw 3D geometry in
perspective, you must provide an appropriate value for this parameter,
otherwise the output images might look very wrong. \fIw\fP was new in Netpbm
10.85 (December 2018).
.sp
Consider the
.UR https://en.wikipedia.org/wiki/Viewing_frustum
typical model
.UE
\& of the so-called "viewing frustum" used to project vertices
in 3D "world space" onto a planar "image space." If we adopt the convention
that a "z-plane" means any plane parallel to the view-plane (a.k.a. picture
plane, a.k.a. near plane), the value of \fIw\fP for a vertex should then be
the (smallest/euclidean/orthogonal) distance in pixels between the projection
reference point (PRP, or "eye") and the z-plane containing the vertex. One
way to compute this value amounts to simply taking the dot product between
the 3D vector \fBr\fP and the 3D unit vector \fBn\fP, where \fBr\fP is
the vector which goes from the projection reference point (PRP, or "eye") to
the vertex, and \fBn\fP is a view-plane normal (VPN) of unit length which
points away from the PRP. In other words, this is equal to the length of the
orthogonal projection of \fBr\fP on the line "determined" by \fBn\fP.
.sp
(Note: For any two 3D vectors \fBa\fP and \fBb\fP, with respective real
scalar components a<sub>x, a<sub>y, a<sub>z and
b<sub>x, b<sub>y, b<sub>z, the dot product between \fBa\fP
and \fBb\fP is simply
a<sub>x*b<sub>x\ +\ a<sub>y*b<sub>y\ +\ a<sub>z*b<sub>z.)
.TP
\fBprint\fP
.sp
This writes a PAM image to Standard Output whose raster is a copy of the
current contents of the image buffer. The values of the WIDTH and HEIGHT
fields are the same as the width and height, respectively, of the frame
buffer, which were given on the command line during program invocation. The
MAXVAL field is equal to the current maxval; the DEPTH field is equal to
the current value of \fInum_attribs\fP + 1; and the TUPLTYPE field is
equal to the current tupletype.
.sp
This command has no effect upon the current drawing state. E. g. it does
not modify the current drawing mode, the current vertex list, etc.
.sp
One may issue an arbitrary number of \fBprint\fP commands at different
positions in the input instruction sequence to produce a multi-image PAM
stream.
.TP
\fBclear\fP [ image | depth ]
.sp
Clears the frame buffer. That is, all samples in the image buffer are once
again set to 0, and all entries in the depth buffer are once again set to the
maximum permitted depth value.
.sp
Optionally, one may provide an argument to only clear either the image
buffer or the depth buffer individually, while leaving the other intact. With
the \fBimage\fP argument, only the image buffer is cleared; with the
\fBdepth\fP argument, only the depth buffer is cleared. Instead of full
argument names, one may provide a minimum unique abbreviation, which has the
same effect. The single character \fBz\fP is also accepted as an alias for
\fBdepth\fP.
.sp
Like the \fBprint\fP command, this command has no effect upon the
current drawing state either.
.TP
\fBreset\fP \fImaxval\fP \fInum_attribs\fP [\fItupletype\fP]
.sp
This updates the current maxval and number of attributes per vertex
(num_attribs), resetting the <u>image</u> buffer with a new maxval and number
of samples per tuple while at it. The parameter \fImaxval\fP must be an
integer in the closed range [1, 65535], and \fInum_attribs\fP must be an
integer in the closed range [1, 20].
.sp
Optionally, after the second argument, one may provide a string to be
assigned to the current \fItupletype\fP. The string goes from the first
character after the second argument which is not white space and continues
until (and including) the last character before the end of the line which is
not white space. If a new tupletype is not provided, or the provided string
is longer than 255 characters, the empty string is assigned to the current
\fItupletype\fP.
.sp
The side effects of running this command are
.IP \(bu
The new image buffer is completely cleared once the command is executed.
.IP \(bu
All values in the current attribute values list are set to the new maxval.
.IP \(bu
The current vertex list is reset.
.sp
However, it does not touch the depth buffer: it is left the same way as it
was found before the command. Also the drawing mode remains the same (e. g. if
\fBpamtris\fP was in FAN mode, it will continue in that same mode, etc.).
.sp
If this command is given with an invalid value for \fImaxval\fP or
\fInum_attribs\fP, it is ignored and therefore none of the above side
effects apply, nor do the current maxval, num_attribs or tupletype change at
all.
.sp
It is permissible to give a value for \fImaxval\fP and \fInum_attribs\fP
equal to the current maxval and num_attribs, respectively, although the above
side effects will still apply even in such cases.
.sp
Since this command deals with memory allocation, it may fail to execute
successfully. If that happens, no lines of input will be read anymore and
\fBpamtris\fP will be terminated as if the \fBquit\fP command was given.
.TP
\fBquit\fP
.sp
This terminates \fBpamtris\fP. It will not read any more lines of input
after this command.
.UN tips
.SH TIPS
.SS Texturing
.PP
It is possible to apply so-called "textures" to images produced with
\fBpamtris\fP by using a pair of vertex attributes as texture
coordinates, then using
.BR "\fBpamchannel\fP" (1)\c
\& to
select the appropriate channels in the output image(s), and finally
processing the result through
.BR "\fBpamlookup\fP" (1)\c
\&,
providing the desired texture file as a "lookup table." If you are drawing
pictures in perspective, make sure to provide adequate values for the
\fIw\fP parameter to your vertex commands
(
.UR #cmd_vertex
see above
.UE
\&) so that the resulting samples in
the images produced by \fBpamtris\fP are perspective-correct. You might
want to consider using
.BR "\fBpnmtile\fP" (1)\c
\& to make
textures which are inteded to be "repeated" along triangle meshes.
.PP
The animated GIF below is an example of what can be achieved using the
technique described above (Earth texture from
.UR https://visibleearth.nasa.gov/view.php?id=73580
nasa.gov
.UE
\&).
.PP
.B Rotating Earth
.IMG -C pamtris_earth.gif
.UN antialias
.SS Anti-aliased edges
.PP
\fBpamtris\fP performs no anti-aliasing on triangle edges by itself.
However, it is possible to obtain anti-aliased images through a
"super-sampling" approach: draw your image(s) at a size larger than
the desired final size, and then, when all postprocessing is done,
downscale the final image(s) to the desired size. Drawing images with
twice the desired width and height, then downscaling them to the intended
size while disregarding gamma (i.e. what \fBpamscale\ -linear\fP does)
often produces good enough results; but the larger the ratio \fI
"size\ of\ original\ image"\ /\ "size\ of\ downscaled\ image"
\fP, the better the quality of the anti-aliasing effect.
.UN seealso
.SH SEE ALSO
.BR "pampick" (1)\c
\&
.BR "pamchannel" (1)\c
\&
.BR "pamstack" (1)\c
\&
.BR "pamlookup" (1)\c
\&
.BR "pamarith" (1)\c
\&
.BR "pamscale" (1)\c
\&
.BR "pamdepth" (1)\c
\&
.BR "pamexec" (1)\c
\&
.BR "pam" (1)\c
\&
.UN history
.SH HISTORY
.PP
\fBpamtris\fP was new in Netpbm 10.84 (September 2018).
.SH DOCUMENT SOURCE
This manual page was generated by the Netpbm tool 'makeman' from HTML
source. The master documentation is at
.IP
.B http://netpbm.sourceforge.net/doc/pamtris.html
.PP
|