[lightDirection_VS]
// Direction TO the light
type   = igGfxShaderConstant
fields = _name,_parameterName,_elementIndex,_vectorWidth,_baseRegister
_name.value           = generic.vectors.value
_parameterName.value  = lightDirection
_elementIndex.value   = 9
_vectorWidth.value    = 4
_baseRegister.value   = -1

[treePosAndScale_VS]
// Position (in local quad tile coordinates) and scale of the tree.  The vector
// is set to represent float4(xyz position, scale).
type   = igGfxShaderConstant
fields = _name,_parameterName,_elementIndex,_vectorWidth,_baseRegister
_name.value           = generic.vectors.value
_parameterName.value  = treePosAndScale
_elementIndex.value   = 10
_vectorWidth.value    = 4
_baseRegister.value   = -1

[treeRotationVector_VS]
// Rotation of the tree along its z-axis and the interpolation value to use to
// transition between LoDs.  The vector is set to represent
// float4(-sin(angle), cos(angle), lod_value, 0).
// For lod_value, 1 refers to the highest and 0 refers to the lowest.
type   = igGfxShaderConstant
fields = _name,_parameterName,_elementIndex,_vectorWidth,_baseRegister
_name.value           = generic.vectors.value
_parameterName.value  = treeRotationVector
_elementIndex.value   = 11
_vectorWidth.value    = 4
_baseRegister.value   = -1

[materialAmbient_PS]
// rgb : Ambient material.
// a   : Material shininess.
type   = igGfxShaderConstant
fields = _name,_parameterName,_elementIndex,_vectorWidth,_baseRegister
_name.value           = generic.vectors.value
_parameterName.value  = materialAmbient
_elementIndex.value   = 14
_vectorWidth.value    = 4
_baseRegister.value   = -1

[materialDiffuse_PS]
// rgb : Diffuse material.
// a   : Alpha scalar used to transition 2D (billboards) to 3D.
type   = igGfxShaderConstant
fields = _name,_parameterName,_elementIndex,_vectorWidth,_baseRegister
_name.value           = generic.vectors.value
_parameterName.value  = materialDiffuse
_elementIndex.value   = 15
_vectorWidth.value    = 4
_baseRegister.value   = -1

[materialDiffuse_VS]
// The exact same object as materialDiffuse_PS but used for the vertex shader.
type   = igGfxShaderConstant
fields = _name,_parameterName,_elementIndex,_vectorWidth,_baseRegister
_name.value           = generic.vectors.value
_parameterName.value  = materialDiffuse
_elementIndex.value   = 15
_vectorWidth.value    = 4
_baseRegister.value   = -1

[lod_profile_VS]
// Distances for the transitions between LoDs:
// 0 high 3D LOD distance, at which LOD transition from highest 3D level begins
// 1 low 3D LOD distance, at which the lowest 3D level is sustained
// 2 billboard start distance, at which the billboard fades in and 3D fades out
// 3 billboard final distance at which only billboards are visible
type   = igGfxShaderConstant
fields = _name,_parameterName,_elementIndex,_vectorWidth,_baseRegister
_name.value           = generic.vectors.value
_parameterName.value  = lod_profile
_elementIndex.value   = 20
_vectorWidth.value    = 4
_baseRegister.value   = -1

// TODO(chrisco): rename batch_* variables.
[batch_camera_location_VS]
// When batching: Where the camera is with respect to the quad node's frame.
type   = igGfxShaderConstant
fields = _name,_parameterName,_elementIndex,_vectorWidth,_baseRegister
_name.value           = generic.vectors.value
_parameterName.value  = batch_camera_location
_elementIndex.value   = 21
_vectorWidth.value    = 4
_baseRegister.value   = -1

[batch_camera_direction_VS]
// The camera's view direction with respect to the quad node's frame.
type   = igGfxShaderConstant
fields = _name,_parameterName,_elementIndex,_vectorWidth,_baseRegister
_name.value           = generic.vectors.value
_parameterName.value  = batch_camera_direction
_elementIndex.value   = 22
_vectorWidth.value    = 4
_baseRegister.value   = -1

[batch_camera_params_VS]
// When batching, camera properties with respect to the quad node's frame.
// x : Camera azimuth in radians
// y : Camera zenith in radians
// z : Camera direction z-rotation angle in radians
// w : Camera direction y-rotation angle in radians
type   = igGfxShaderConstant
fields = _name,_parameterName,_elementIndex,_vectorWidth,_baseRegister
_name.value           = generic.vectors.value
_parameterName.value  = batch_camera_params
_elementIndex.value   = 23
_vectorWidth.value    = 4
_baseRegister.value   = -1

[hardware_shader_implementation]
passes    = single_pass
processor = defaultProcessor

[defaultProcessor]
type      = igShaderProcessor

[enableTextureStage0ATTR]
type              = igTextureStateAttr
fields            = _enabled,_unitID
_enabled.value    = true
_unitID.value     = 0

[enableTextureStage1ATTR]
type              = igTextureStateAttr
fields            = _enabled,_unitID
_enabled.value    = true
_unitID.value     = 1

[enableTextureStage2ATTR]
type              = igTextureStateAttr
fields            = _enabled,_unitID
_enabled.value    = true
_unitID.value     = 2

[enableTextureStage3ATTR]
type              = igTextureStateAttr
fields            = _enabled,_unitID
_enabled.value    = true
_unitID.value     = 3

[enableTextureStage4ATTR]
type              = igTextureStateAttr
fields            = _enabled,_unitID
_enabled.value    = true
_unitID.value     = 4

[disableTextureStage0ATTR]
type              = igTextureStateAttr
fields            = _enabled,_unitID
_enabled.value    = false
_unitID.value     = 0

[disableTextureStage1ATTR]
type              = igTextureStateAttr
fields            = _enabled,_unitID
_enabled.value    = false
_unitID.value     = 1

[disableTextureStage2ATTR]
type              = igTextureStateAttr
fields            = _enabled,_unitID
_enabled.value    = false
_unitID.value     = 2

[disableTextureStage3ATTR]
type              = igTextureStateAttr
fields            = _enabled,_unitID
_enabled.value    = false
_unitID.value     = 3

[disableTextureStage4ATTR]
type              = igTextureStateAttr
fields            = _enabled,_unitID
_enabled.value    = false
_unitID.value     = 4

[enableVertexShaderATTR]
type              = igVertexPipelineModeAttr
fields            = _mode
_mode.value       = IG_GFX_VERTEX_PIPELINE_MODE_SHADER

[disableVertexShaderATTR]
type              = igVertexPipelineModeAttr
fields            = _mode
_mode.value       = IG_GFX_VERTEX_PIPELINE_MODE_DEFAULT

[enablePixelShaderATTR]
type                = igPixelPipelineModeAttr
fields              = _pipelineMode
_pipelineMode.value = IG_GFX_PIXEL_PIPELINE_MODE_SHADER

[disablePixelShaderATTR]
type                = igPixelPipelineModeAttr
fields              = _pipelineMode
_pipelineMode.value = IG_GFX_PIXEL_PIPELINE_MODE_DEFAULT

[batch_model_view_proj_VS]
type   = igGfxShaderConstant
fields = _name,_parameterName,_baseRegister,_elementSize,_vectorWidth
_name.value          = matrix.mvp
_parameterName.value = batch_model_view_proj
_elementSize.value   = 4
_vectorWidth.value   = 4
_baseRegister.value  = -1
const                = false

[diffuseMap_PS]
type                 = igTextureSamplerSource
fields               = _name,_textureUnit,_samplerNumber
_name.value          = diffuseMap
_textureUnit.value   = 0
_samplerNumber.value = -1
const                = false

[normalMap_PS]
type                 = igTextureSamplerSource
fields               = _name,_textureUnit,_samplerNumber
_name.value          = normalMap
_textureUnit.value   = 1
_samplerNumber.value = -1
const                = false

[cullATTR]
type = igCullFaceAttr
fields = _enabled
_enabled.value = true

// Constants for the billboard shaders.  Each SpeedTree model comes with a set
// of shader constants that are the same for all of its instances.  Each model
// has a set of constants of the form:
// start_index + 0: float4(ambient.rgb, vertical_tex_offset)
//                  vertical_tex_offset is the offset from start_index where
//                  vertical billboard texture coordinates start.
// start_index + 1: float4(diffuse.rgb, light_scalar)
//                  light_scalar is multiplied against the diffuse color
//                  during lighting.
// start_index + 2: horizontal billboard texture extents (if available)
//                  float4(max s, max t, width s, height t)
//                  If there is no horizontal billboard, this element is the
//                  start of the vertical billboard texture extents.
// start_index + 3: 1st vertical billboard texture extents.
//                  float4(max s, max t, width s, height t)
// start_index + 4: 2nd vertical billboard texture extents.
//                  float4(max s, max t, width s, height t)
// start_index + 5: 3rd vertical billboard texture extents.
//                  float4(max s, max t, width s, height t)
// ...
// start_index + K: num_images-th vertical billboard texture extents.
//                  K -> vertical_tex_offset + (num_images - 1).
//
// 'num_images' is passed in the x-component of a vertical billboard's corner
// position.
//
// TODO(chrisco): optimize vertical billboard tex coord packing if the width
// and height are the same for all vertical billboards.  Things to consider:
// - this will make the shader longer.
// - we can fit more tree species in a single collection (batch).
//
// Each models' constants are gathered into the billboard_constants array.
//
// The number of actual float4 constants must never be greater than 64, or the
// shader won't be able to access them.  If _64_ is changed, update
// stbillboard.cg.
[billboard_constants_VS]
type   = igGfxShaderConstant
fields = _name,_parameterName,_elementCount,_baseRegister
_name.value            = speedtree.billboardconstants.value
_parameterName.value   = billboard_constants
_elementCount.value    = 64
_baseRegister.value    = -1
const                  = false
