shaders(3)
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 pro
- duces 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 de - scribes 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 de - scribes 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 differ
- ent 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 il
- lusion 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 sys
- tem 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 differ
- ent 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 differ
- ent 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 col
- or. 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 de
- scribed shaders.
- mask_shader()
- mask_shader() uses a decision function to mask be
- tween 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 descrip
- tion t_surface when masker() returns TRUE.
f_shader is used together with the surface descrip - tion f_surface when masker() returns FALSE. mask_data is a pointer to the data that the deci
- sion 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 sur
- face 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 conti
- nents. 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) - simple polygon processor, a 3d-graphics library
sipp_geometric - Vector and matrix functions for SIPP.
sipp_primitives(3) - a collection of geometric primitives - for SIPP.
sipp_pixmap(3) - 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.
- 3 December , 1990