5.54. ShaderSource (property)

<shader-source> ‐ A shader source that defines shader parameters

5.54.1. Attributes

NameTypeDefaults
idIDNone (required)
typeSTRINGNone (required)
beginFLOATNone (required for shader_source_loop)
endFLOATNone (required for shader_source_loop)
durFLOATNone (required for shader_source_loop)
periodFLOATNone (required for shader_source_loop)
nb_texturesINTEGERNone (required)
cg_vp_*FLOATNone (user defined)
cg_fs_*FLOATNone (user defined)

5.54.2. Description

This element defines a shader source.

The string value of the type attribute is equal to shader_source_finite in the case of a non-repeated shader and to shader_source_loop in the case of a periodic shader.

In the case of an periodic shader, the float values begin and end of the begin and end attributes define the maximal time interval during which the shader is active. Shading begins at begin time and is stops at end time. The float value period of the period attribute is used to define the intervals at which shading is restarted. Shading is periodically restarted at begin+n×period for n in 1, 2,...,N. N is the the largest integer smaller than or equal to (end-begin)/period. The float value duration of the duration attribute must be smaller than or equal to period; it defines the shading time during each period (see Figure 5-19).

Figure 5-19. Periodical Shading

The user can define float parameters that will be passed to the vertex and fragment shaders. The naming convention is that vertex shader parameters must be prefixed cg_vp_ and fragment shader parameters must be prefixed cg_fs_. The sample shader_source described below has two vertex shader parameters and two fragment shader parameters. All the shader parameters declared in the shader_source must be provided by the corresponding shaders as uniform float input parameters.

The value of the nb_textures attribute is used to define the number of textures used by the shader.

This element can have as many shader_source_textures shader_source_videos in its scope as the value n of the nb_textures attribute. These textures must be indexed from 1 to n. The fragment shader must have n uniform sampler2D parameters named lookupTable1, lookupTable2... lookupTablen.

So that the lights defined in the scene graph can be accessed in the vertex program, the vertex program can have as many uniform float input parameters as the number of lights in the scene graph. These parameters should be named auxLghitDir1, auxLightDir2... auxLightDirn. At run time, these parameters will be dynamically assigned the light position in the observer's coordinates.

5.54.3. Expected children

The following elements must occur in light: as many shader_source_textures or shader_source_videos as the value n of the nb_textures attribute and indexed from 1 to n.

5.54.4. Example

The example below defines a finite shader source that begins at time 0.0 and terminates at time 100.0. The shader has three textures: two bitmaps and one video. The user has defined two vertex shader parameters cg_vp_widthRatio and cg_vp_heightRatio and two fragment shader parameters cg_fs_blend0 and cg_fs_blur.

<shader_source id="bump_#1"  type="shaderfinite"
             nb_textures="3"  
             begin="0.0" end="100.0" dur="100.0" period="100.0"
             cg_vp_widthRatio="(320/512)" 
             cg_vp_heightRatio="(240/256)" 
             cg_fs_blend0="0.0" 
             cg_fs_blur="150.0" >
  <shader_source_texture index="1" encoding="pnga" 
             xlink:href="textures/sky_wallday.png" id="hand"/>
  <shader_source_texture index="2" encoding="pnga" 
             xlink:href="textures/hemispherical2.png" id="hand"/>
  <shader_source_video index="3" xlink:href="Video/wall.avi" id="Wall" 
             type="videoloop" begin="0.0" end="1000000.0"   
             dur="1000000.0" period="1000000.0" />
</shader_source>