## Polygon Primitives

The RenderMan Interface supports two basic types of polygons:

• a convex polygon
• a general concave polygon with holes.

In both cases the polygon must be planar. Collections of polygons can be passed by giving a list of points and an array that indexes these points.

The geometric normal of the polygon is computed by computing the normal of the plane containing the polygon (unless it is explicitly specified). If the current orientation is left-handed, then a polygon whose vertices were specified in clockwise order (from the point of view of the camera) will be a front-facing polygon (that is, will have a normal vector which points toward the camera). If the current orientation is right-handed, then polygons whose vertices were specified in counterclockwise order will be front-facing. The shading normal is set to the geometric normal unless it is explicitly specified at the vertices.

The surface parameters of a polygon are its (x,y) coordinates. This is because the height z of a plane is naturally parameterized by its (x,y) coordinates, unless it is vertical. Texture coordinates are set equal to the surface parameters unless texture coordinates are given explicitly, one set per vertex. Polygons do not inherit texture coordinates from the graphics state.

The rules for primitive variable interpolation and texture coordinates are different for polygons than for all other geometric primitives. Uniform primitive variables are supplied for each polygon. Varying primitive variables are supplied for each polygon vertex, and are interpolated across the interior without regard to the artificial surface parameters defined above. Note that interpolating values across polygons is inherently ill-defined. However, linearly interpolating values across a triangle is always well defined. Thus, for the purposes of interpolation, polygons are always decomposed into triangles. However, the details of how this decomposition is done is implementation-dependent and may depend on the view.

```RiPolygon( nvertices, parameterlist )
RtInt	nvertices;
```

nvertices is the number of vertices in a single closed planar convex polygon. parameterlist is a list of token-array pairs where each token is one of the standard geometric primitive variables or a variable which has been defined with RiDeclare. The parameter list must include at least position ("P") information. If a primitive variable is varying, the array contains nvertices elements of the type corresponding to the token. If the variable is uniform, the array contains a single element.

No checking is done by the RenderMan Interface to ensure that polygons are planar, convex and nondegenerate. The rendering program will attempt to render invalid polygons but the results are unpredictable.

```RIB BINDING
Polygon parameterlist
```

The number of vertices in the polygon is determined implicitly by the number of elements in the required position array.

```EXAMPLE
RtPoint points[4] = ( 0.0, 1.0, 0.0,  0.0, 1.0, 1.0,
0.0, 0.0, 1.0,   0.0, 0.0, 0.0);

RiPolygon(4, RI_P, (RtPointer)points, RI_NULL);

```

A ``Phong-shaded'' polygon is given by:

```	RtPoint	points[4];
RtPoint	normals[4];

RiPolygon( 4, "P", (RtPointer)points, "N", (RtPointer)normals, RI_NULL );
```

A ``Phong-shaded'' polygon with a precomputed plane normal is:

```	RtPoint	points[4];
RtPoint	normals[4];
RtPoint	plane_normal;

RiPolygon( 4, "P", (RtPointer)points, "N", (RtPointer)normals,
"Np", (RtPointer)plane_normal, RI_NULL );```

```RiGeneralPolygon( nloops, nvertices, parameterlist )
RtInt	nloops;
RtInt	nvertices[];
```

Define a general planar concave polygon with holes. This polygon is specified by giving nloops lists of vertices. The first loop is the outer boundary of the polygon; all additional loops are holes. The array nvertices contains the number of vertices in each loop, and has length nloops. The vertices in all the loops are concatenated into a single vertex array. The length of this array, n, is equal to the sum of all the values in the array nvertices.

parameterlist is a list of token-array pairs where each token is one of the standard geometric primitive variables or a variable that has been defined with RiDeclare. The parameter list must include at least position ("P") information. If a primitive variable is varying, the array contains n elements of the type corresponding to the token. If the variable is uniform, there is a single element of that type. The number of floats associated with each type is given in, Standard Geometric Primitive Variables. The interpretation of these variables is the same as for a convex polygon.

No checking is done by the RenderMan Interface to ensure that polygons are planar and nondegenerate. The rendering program will attempt to render invalid polygons but the results are unpredictable.

```RIB BINDING

GeneralPolygon nvertices parameterlist
```

The number of loops in the general polygon is determined implicitly by the length of the nvertices array.

```EXAMPLE

GeneralPolygon [4 3] "P" [
0 0 0  0 1 0  0 1 1  0 0 1
0 0.25 0.5  0 0.75 0.75  0 0.75 0.25 ]

```

```RiPointsPolygons( npolys, nvertices, vertices, parameterlist )<
RtInt	npolys;<
RtInt	nvertices[];
RtInt	vertices[];
```

Define npolys planar convex polygons that share vertices. The array nvertices contains the number of vertices in each polygon and has length npolys. The array vertices contains, for each polygon vertex, an index into the varying primitive variable arrays. The varying arrays are 0-based. vertices has length equal to the sum of all of the values in the nvertices array. Individual vertices in the parameterlist are thus accessed indirectly through the indices in the array vertices

parameterlist is a list of token-array pairs where each token is one of the standard geometric primitive variables or a variable that has been defined with RiDeclare. The parameter list must include at least position ("P") information. If a primitive variable is varying, the array contains n elements of the type corresponding to the token, where the number n is equal to the maximum value in the array vertices plus one. If the variable is uniform, the array contains npolys elements of the associated type.

No checking is done by the RenderMan Interface to ensure that polygons are planar, convex and nondegenerate. The rendering program will attempt to render invalid polygons but the results are unpredictable.

```RIB BINDING

PointsPolygons nvertices vertices parameterlist
```

The number of polygons is determined implicitly by the length of the nvertices array.

```EXAMPLE

PointsPolygons [3 3 3] [0 3 2  0 1 3  1 4 3]
"P"   [0 1 1  0 3 1  0 0 0  0 2 0  0 4 0]
"Cs" [0 .3 .4  0 .3 .9  .2 .2 .2  .5 .2 0  .9 .8 0]

```

```RiPointsGeneralPolygons( npolys, nloops, nvertices, vertices, parameterlist )
RtInt	npolys;
RtInt	nloops[];
RtInt	nvertices[];
RtInt	vertices[];
```

Define npolys general planar concave polygons, with holes, that share vertices. The array nloops indicates the number of loops comprising each polygon and has a length npolys. The array nvertices contains the number of vertices in each loop and has a length equal to the sum of all the values in the array nloops. The array vertices contains, for each loop vertex, an index into the varying primitive variable arrays. All of the arrays are 0-based. vertices has a length equal to the sum of all the values in the array nvertices. Individual vertices in the parameterlist are thus accessed indirectly through the indices in the array vertices

parameterlist is a list of token-array pairs where each token is one of the standard geometric primitive variables or a variable that has been defined with RiDeclare. The parameter list must include at least position ("P") information. If a primitive variable is varying, the array contains n elements of the type corresponding to the token. The number n is equal to the maximum value in the array vertices plus one. If the variable is uniform, the array contains npolys elements of the associated type. . No checking is done by the RenderMan Interface to ensure that polygons are planar and nondegenerate. The rendering program will attempt to render invalid polygons but the results are unpredictable.

```RIB BINDING

PointsGeneralPolygons nloops nvertices vertices parameterlist
```

The number of polygons is determined implicitly by the length of the nloops array.

```EXAMPLE

PointsGeneralPolygons [2 2] [4 3 4 3] [0 1 3 4 6 7 8 1 2 5 4 9 10 11]
"P" [0 0 1  0 1 1  0 2 1  0 0 0  0 1 0  0 2 0
0 0.25 0.5  0 .75 .75  0 1.75 .25
0 1.25 0.5  0 1.75 .75  0 1.75 .25]

```

Copyright - Sudhir R Kaushik (sudhir@cs.wpi.edu)