---
name: "sipp_shaders"
section: "3"
platform: "linux"
package: "sipp-dev"
version: "3.1-11"
release: "Debian 4.0 (Etch)"
platforms: ["linux"]
url: "https://new.carta.tech/sipp_shaders"
---

# sipp\_shaders(3)

a collection of shaders for SIPP.

## NAME

shaders - a collection of shaders for SIPP.

## SYNOPSIS

*#include \<sipp.h\>*\
 *#include \<shaders.h\>*

\[g\]cc \[*flags*\] *files* -lsipp -lm \[ *libraries* \]

## DESCRIPTION

SIPP provides, as default, a simple shading model and a shading function called *basic\_shader()*. If this shader is not sufficient for a particular surface, the user can implement his/her own shading function and have SIPP call that one instead. SIPP also has a set of ready made shaders which provides other shading models or special effects.

This manual gives a short description the set of shaders beside *basic\_shader()* that are included in the library.  All shaders described here, except *strauss\_shader()* and *phong\_shader()* provide some kind of special effect on a surface and call *basic\_shader()* to do the actual shading calculations. See the user manual for a detailed description of the shaders.

## SHADERS AND SURFACE DESCRIPTORS

The following shader functions are provided with the SIPP library.

- *strauss\_shader()*

  *strauss\_shader()* is an implementation of a shader described by Paul Strauss in IEEE CG&A Nov. 1990. The shading model Strauss designed has parameters that is easy to grasp and have a reasonably deterministic effect on a surface, but yet produces very realistic results.

  The surface description used in *strauss\_shader()* is called *Strauss\_desc* and looks like this:\
   *typedef struct {*\
       *double  ambient;*\
       *double  smoothness;*\
       *double  metalness;*\
       *Color   color;*\
       *Color   opacity;*\
   *} Strauss\_desc;*

  *ambient* is a value between 0 and 1 which determines how much of the base color of a surface that is visible when it is not illuminated by any lightsource.\
   *smoothness* is a value between 0 and 1 that describes how smooth the surface is. This parameter controls both diffuse and specular reflections. 0 means a dull surface while 1 means a very smooth and shiny one.\
   *metalness* is alo a value between 0 and 1. It describes how metallic the material is. It controls among other things how much of the surface color should be mixed into the specular reflections at different angles. 0 means a non-metal while 1 means a very metallic surface.\
   *color* is (of course) the base color of the surface.\
   *opacity* specifies how opaque the surface is. This is stored as a color to allow different opacities for the different color bands.

- *wood\_shader()*

  *wood\_shader()* creates a simulated wood texture on a surface. It uses two colors, one as the base (often lighter) color of the wood and one as the color of the (often darker) rings in it. The rings are put into the base color about the x-axis and are then distorted  using *noise()* and *turbulence()*. A similar pattern is repeated at regular intervals to create an illusion of logs or boards.

  The surface description for a wood surface is called *Wood\_desc* and is defined as follows:\
   *typedef struct {*\
       *double   ambient;*\
       *double   specular;*\
       *double   c3;*\
       *double   scale;*\
       *Color    base;*\
       *Color    ring;*\
       *Color   opacity;*\
   *} Wood\_desc;*

  Except for the two colors and the field *scale*, *Wood\_desc* looks exactly like a *Surf\_desc* and the fields are used in the same way. \
   *scale* is a factor which determines the size of the wood pattern depending on the size of the texture coordinate system in relation to the world coordinate system. You will have to experiment some to get this right.\
   *base* is the color of the base material, and *ring* is the color of the darker rings.\
   *opacity* specifies how opaque the surface is. This is stored as a color to allow different opacities for the different color bands.

- *marble\_shader()*

  *marble\_shader()* creates a simulated marble texture on a surface. It uses two colors, one as the base material and one as the interspersed material. The interspersed material is put into the base material in strips that are distorted using *noise()* and *turbulence()*.

  The surface description for a marble surface is called *Marble\_desc* and is defined as follows:\
   *typedef struct {*\
       *double   ambient;*\
       *double   specular;*\
       *double   c3;*\
       *double   scale;*\
       *Color    base;*\
       *Color    strip;*\
       *Color   opacity;*\
   *} Marble\_desc;*

  Except for the two colors and the field *scale*, *Marble\_desc* looks exactly like a *Surf\_desc* and the fields are used in the same way. \
   *scale* is a factor which determines the size of the marble pattern depending on the size of the texture coordinate system in relation to the world coordinate system. \
   *base* is the color of the base material, and *strip* is the color of the interspersed material.\
   *opacity* specifies how opaque the surface is. This is stored as a color to allow different opacities for the different color bands.

- *granite\_shader()*

  *granite\_shader()* is very similar to *marble\_shader()* in that it also mixes two colors using *noise()* and *turbulence()*. The difference is in  how the mixing is done. The two colors are mixed whithout treating them separately in any way.

  The surface description used in *granite\_shader()* is called *Granite\_desc* and is defined as follows:\
   *typedef struct {*\
       *double   ambient;*\
       *double   specular;*\
       *double   c3;*\
       *double   scale;*\
       *Color    col1;*\
       *Color    col2;*\
       *Color   opacity;*\
   *} Granite\_desc;*

  The fields have the same meaning as in *Marble\_desc*.

- *bozo\_shader()*

  *bozo\_shader()* uses *noise()* to chose a color from a fixed set. The range of possible return value from *noise()* are divided into parts of equal size and each part is assigned a color. The size of the parts are dependent on the number of colors.

  The surface description is called *Bozo\_desc* and is defined as follows:\
   *typedef struct {*\
       *Color   \*colors;*\
       *int      no\_of\_cols;*\
       *double   ambient;*\
       *double   specular;*\
       *double   c3;*\
       *double   scale;*\
       *Color   opacity;*\
   *} Bozo\_desc;*

  *colors* is a pointer to an array of *Color* structs and *no\_of\_cols* defines the number of entries in this array. The other fields have the same function as in the prevoiusly described shaders.

- *mask\_shader()*

  *mask\_shader()* uses a decision function to mask between two different shaders. The user supplies a pointer to some data that the function need and a pointer to the function itself.

  The surface description is called *Mask\_desc* and has the following definition:\
   *typedef struct {*\
       *Shader \*t\_shader;*\
       *void   \*t\_surface;*\
       *Shader \*f\_shader;*\
       *void   \*f\_surface;*\
       *void   \*mask\_data;*\
       *bool  (\*masker)();*\
   *} Mask\_desc;*

  *t\_shader* is used together with the surface description *t\_surface* when *masker()* returns TRUE.\
   *f\_shader* is used together with the surface description *f\_surface* when *masker()* returns FALSE.\
   *mask\_data* is a pointer to the data that the decision function need.\
   *masker* is the decision function.

- *bumpy\_shader()*

  *bumpy\_shader()* is a function that perturbates the normal of a surface using *Dnoise()*. Any other shader can be used to do the final shading calculations.

  The surface description is called *Bumpy\_desc* and is defined as follows:\
   *typedef struct {*\
       *Shader \*shader;*\
       *void   \*surface;*\
       *double scale;*\
       *bool   bumpflag;*\
       *bool   holeflag;*\
   *} Bumpy\_desc;*

  *shader* and *surface* define the shader to be used for the final shading calculations. \
   *scale* has the same meaning as in previous shaders using *noise()*.\
   *bumpflag* and *holeflag* make it possible to flatten out half of the bumps. If only *bumpflag* is TRUE only bumps "standing out" from the surface are visible. The rest of the surface will be smooth. If, on the other hand, only *holeflag* is TRUE only bumps going "into" the surface will be visible, thus giving the surface an eroded look. If both flags are true, the whole surface will get a bumpy appearence, rather like an orange.

- *planet\_shader()*

  *planet\_shader()* is a somewhat specialized shader that produces a texture that resembles a planet surface. The planet is of the Tellus type with a mixture of oceans and continents. Some of the surface is covered by semi-transparent clouds which enhances the effect greatly. On the other hand, no polar caps are provided and this decreases the realism.

  The texture is 3-dimensional, so it is possible to create cube planets or even planets with cut-out parts that still have surfaces that resemble the earth surface. The texture is not scalable, and is designed to be used with texture coordinats in the range -1.0 to 1.0, e.g. a unit sphere. Of course the world coordinats need not have the same order of magnitude.

  *planet\_shader()* uses an ordinary *Surf\_desc* in which the *color* field is ignored.

## SEE ALSO

[sipp(3)](/sipp/3.md) - simple polygon processor, a 3d-graphics library\
 sipp\_geometric - Vector and matrix functions for SIPP.\
 [sipp\_primitives(3)](/sipp_primitives/3.md) - a collection of geometric primitives for SIPP.\
 [sipp\_pixmap(3)](/sipp_pixmap/3.md) - pixmap handling code for SIPP.\
 sipp\_bitmap(3) - bitmap handling code for SIPP.

## AUTHORS

Jonas Yngvesson		(jonas-y@isy.liu.se)\
 Inge Wallin		(ingwa@isy.liu.se)

## BUGS

The planet texture should be enhanced with polar caps and it should be possible to give parameters to control, among other factors, the ratio of ocean/land and the cloudiness.
