1vpSetShadowLookupShader(3) Library Functions Manual vpSetShadowLookupShader(3)
2
3
4

NAME

6       vpSetShadowLookupShader  -  specify shading lookup tables for rendering
7       shadows
8

SYNOPSIS

10       #include <volpack.h>
11
12       vpResult
13       vpSetShadowLookupShader(vpc,       color_channels,       num_materials,
14               color_field,   color_table,   color_table_size,   weight_field,
15               weight_table,   weight_table_size,   shadow_table,   shadow_ta‐
16               ble_size)
17           vpContext *vpc;
18           int color_channels, num_materials;
19           int color_field;
20           float *color_table;
21           int color_table_size;
22           int weight_field;
23           float *weight_table;
24           int weight_table_size;
25           float *shadow_table;
26           int shadow_table_size;
27

ARGUMENTS

29       vpc    VolPack context from vpCreateContext.
30
31       color_channels
32              The number of color channels per pixel (1 or 3).
33
34       num_materials
35              The number of material types.
36
37       color_field
38              Field  number  for  voxel  field  containing  color lookup table
39              index.
40
41       color_table
42              Color lookup table.
43
44       color_table_size
45              Size of color lookup table in bytes.
46
47       weight_field
48              Field number for voxel field containing material  weight  lookup
49              table index.
50
51       weight_table
52              Material weight lookup table.
53
54       weight_table_size
55              Size of material weight lookup table in bytes.
56
57       shadow_table
58              Shadow color lookup table.
59
60       shadow_table_size
61              Size of shadow color lookup table in bytes.
62

DESCRIPTION

64       vpSetShadowLookupShader  is used to specify lookup tables that define a
65       shading function for rendering a volume with  shadows.   It  should  be
66       used instead of vpSetLookupShader when shadows are enabled.
67
68       VolPack supports a fast, one-pass shadow algorithm.  The algorithm com‐
69       putes the fraction of light from a given light source that reaches each
70       voxel.  The fraction is then used to attenuate the diffuse and specular
71       shading terms associated with  that  light  source,  producing  a  dark
72       shadow in areas that are hidden from the light source.  The implementa‐
73       tion uses lookup tables so that most of the shading calculation can  be
74       precomputed.
75
76       In order to compute the shadows in a single pass the algorithm places a
77       restriction on the direction of the light source: the light casting the
78       shadows  must  not  be more than 45 degrees from the viewing direction.
79       The quality of the shadows may  degrade  if  the  angle  approaches  45
80       degrees.   The  current  implementation  allows shadows to be cast only
81       from one light source.  Additional lights may be enabled, but they will
82       not cast shadows.
83
84       To  make  a  rendering  with  shadows, the following steps must be per‐
85       formed:
86
87              Call vpSetShadowLookupShader to define the  lookup  tables  (see
88              discussion below).
89
90              Call  vpSeti  with  the  VP_SHADOW_LIGHT option to specify which
91              light will cast shadows.  The current implementation only allows
92              one light to be specified.
93
94              Call  vpSeti  with  the  VP_SHADOW_BIAS option to set the shadow
95              bias value (see discussion below).
96
97              Call vpEnable with the VP_SHADOW option to enable shadows.
98
99              Call vpShadeTable as usual to initialize the lookup tables.
100
101              Call one of the rendering routines.
102
103       vpSetShadowLookupShader defines the  lookup  tables  required  for  the
104       shading  and shadowing algorithm.  The first nine arguments are identi‐
105       cal to the arguments for vpSetLookupShader (see the  corresponding  man
106       page).   The remaining two arguments specify an additional color lookup
107       table, shadow_table, with the same dimensions as color_table.  The con‐
108       tents of the table will be initialized by vpShadeTable.
109
110       The  call  to vpSeti with the VP_SHADOW_BIAS option specifies an offset
111       to eliminate self-shadowing.  Self-shadowing is  an  intrinsic  problem
112       when  implementing  shadow algorithms for volume rendering.  Consider a
113       single voxelized object consisting of an opaque core  surrounded  by  a
114       "halo" of lower-opacity voxels (necessary for the scene to be band-lim‐
115       ited).  As a light ray pierces the halo its strength is attenuated.  By
116       the  time the light reaches the high-opacity region a significant frac‐
117       tion of the light may be obscured, resulting in a general darkening  of
118       the  image  even  if  no shadows should be present.  The problem can be
119       corrected by moving the shadow a small distance along the direction  of
120       the  light  rays.  VP_SHADOW_BIAS specifies the distance of the bias in
121       units of voxels.  The optimal value depends on the data set.   Increase
122       the  bias  until it has no more effect on overall image brightness, but
123       do not increase it too far or small features in the data will no longer
124       produce correct shadows.
125
126       vpShadeTable  initializes  the shading lookup tables.  It operates dif‐
127       ferently when shadows are enabled.  Instead of computing one color  for
128       each  surface normal vector and storing the results in color_table, the
129       routine computes two colors terms.  The first term is  the  portion  of
130       the  voxel  color  due  to  the  diffuse and specular components of the
131       shadow light.  This value is stored in shadow_table.  The  second  term
132       contains  the  contribution  of  all other light source and the ambient
133       light term, and is stored in color_table.  During rendering  the  color
134       of  a  voxel is computed by extracting a surface normal from the voxel,
135       using the surface normal to index both  color_table  and  shadow_table,
136       attenuating  the  value  from shadow_table by the local strength of the
137       shadow light, and then  adding  the  two  terms  together.   The  local
138       strength  of  the  shadow light is found by extracting a value from the
139       shadow buffer, an internal data structure that is updated  during  ren‐
140       dering.
141
142       The  values  in  the shading lookup tables may be initialized before or
143       after calling  vpSetShadowLookupShader.   Typically  vpSetShadowLookup‐
144       Shader is called once at the beginning of a rendering session, and then
145       vpShadeTable is called whenever the user changes the lighting and shad‐
146       ing parameters or the viewing direction.
147
148       The shadow buffer is an internal 2D array used to maintain state during
149       rendering.  There are several state variables that can be used to query
150       its  current  size in pixels (VP_SHADOW_WIDTH and VP_SHADOW_HEIGHT) and
151       to suggest a  size  (VP_SHADOW_WIDTH_HINT  and  VP_SHADOW_HEIGHT_HINT).
152       The  required  size  depends  on the volume size and the shadow light's
153       direction.  Normally the buffer is automatically  resized  when  neces‐
154       sary.
155

STATE VARIABLES

157       Information about the current shading table parameters can be retrieved
158       with the following state variable codes (see vpGeti(3)): VP_COLOR_CHAN‐
159       NELS, VP_SHADE_COLOR_TABLE, VP_SHADE_COLOR_SIZE, VP_SHADE_WEIGHT_TABLE,
160       VP_SHADE_WEIGHT_SIZE,   VP_SHADE_COLOR_FIELD,    VP_SHADE_WEIGHT_FIELD,
161       VP_MATERIAL_COUNT,  VP_SHADOW,  VP_SHADOW_LIGHT,  VP_SHADOW_WIDTH_HINT,
162       VP_SHADOW_HEIGHT_HINT,        VP_SHADOW_WIDTH,        VP_SHADOW_HEIGHT,
163       VP_SHADOW_COLOR_TABLE, VP_SHADOW_COLOR_SIZE, VP_SHADOW_BIAS
164

ERRORS

166       The  normal  return  value is VP_OK.  The following error return values
167       are possible:
168
169       VPERROR_BAD_VALUE
170              One or more of the arguments has an invalid value or is  out  of
171              range.
172
173       VPERROR_LIMIT_EXCEEDED
174              The  num_materials  argument  has  exceeded  an  internal limit.
175              Change the value of VP_MAX_MATERIAL in volpack.h  and  recompile
176              the VolPack library.
177

SEE ALSO

179       VolPack(3), vpCreateContext(3), vpShadeTable(3), vpSetLookupShader(3)
180
181
182
183VolPack                                             vpSetShadowLookupShader(3)
Impressum