VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
TerrainShader Class Reference

InstancedShader which does a multi-texture blend between up to three Textures, to render terrain meshes. More...

Inheritance diagram for TerrainShader:
InstancedShader Shader

Public Member Functions

 TerrainShader (const ShaderPtr &sharedShader)
 Construct a TerrainShader based on the given shared Shader. More...
 
const TexturePtrgetBaseTexture () const
 Returns the base Texture. More...
 
void setBaseTexture (const TexturePtr &value)
 Sets the base Texture. More...
 
const TexturePtrgetMaskTexture () const
 Returns the mask Texture. More...
 
void setMaskTexture (const TexturePtr &value)
 Sets the mask Texture. More...
 
const TexturePtrgetBlendTexture () const
 Returns the blend Texture. More...
 
void setBlendTexture (const TexturePtr &value)
 Sets the blend Texture. More...
 
void setTransform (const Matrix4 &matrix)
 Sets the transform to apply to vertices rendered with this Shader. More...
 
- Public Member Functions inherited from InstancedShader
 InstancedShader (const ShaderPtr &sharedShader)
 Create an InstancedShader which references a shader Shader. More...
 
const ShaderPtrgetSharedShader () const
 Returns the Shader that is shared among instances. More...
 
virtual bool isCurrent () const override
 Returns whether or not this instance is bound. More...
 
virtual bool isValid () const override
 Returns whether or not this shader is valid (compiled and linked) and can be used for rendering. More...
 
virtual bool isCompiled () const override
 Returns whether or not this shader has been processed for compilation. More...
 
virtual GLuint getProgramId () const override
 Returns the GL program id for this shader. More...
 
virtual void begin () override
 Binds this shader, and sets uniforms and other GL state associated with this instance. More...
 
virtual void end () override
 Unbinds this shader if bound by a corresponding call to begin(). More...
 
virtual void compile () override
 Compiles this shader, resulting in the compilation of the shared Shader if necessary. More...
 
virtual std::string getErrorLog () const override
 Retrieves the string describing compilation errors, if the call to compile() failed and isValid() is false. More...
 
virtual int getAttributeLocation (int index) const override
 Returns the location of an indexed Attribute. More...
 
virtual int getUniformLocation (int index) const override
 Returns the location of an indexed uniform. More...
 
void setIndexedTexture (int index, int stage, const TexturePtr &value, TexturePtr *stateValue)
 Set the indexed texture for this instance at the given index. More...
 
- Public Member Functions inherited from Shader
 Shader (const AttributeSetPtr &attributes, const std::vector< std::string > &uniformNames)
 Construct a Shader with the given list of attributes and uniforms. More...
 
const AttributeSetPtrgetAttributes () const
 Returns the list of indexed Attributes for this shader, as an AttributeSet. More...
 
const std::vector< std::string > & getUniformNames () const
 Returns the list of indexed uniforms. More...
 
void setIndexedUniform1f (int index, bool global, float value, float *stateValue)
 Set the value of a float scalar uniform at the given index. More...
 
void setIndexedUniform2f (int index, bool global, const Vector2 &value, Vector2 *stateValue)
 Set the value of a 2D float vector uniform at the given index. More...
 
void setIndexedUniform3f (int index, bool global, float value1, float value2, float value3, float *stateValue)
 Set the value of a 3D float vector uniform at the given index. More...
 
void setIndexedUniform4f (int index, bool global, float value1, float value2, float value3, float value4, float *stateValue)
 Set the value of a 4D float vector uniform at the given index. More...
 
void setIndexedUniform1i (int index, bool global, int value, int *stateValue)
 Set the value of an integer scalar uniform at the given index. More...
 
void setIndexedUniformMatrix4f (int index, bool global, bool transpose, const Matrix4 &value, Matrix4 *stateValue)
 Set the value of a 4x4 float matrix uniform at the given index. More...
 

Static Public Member Functions

static const ShaderPtrgetSharedShader (const TerrainShaderKey &shaderKey)
 Returns the uninstanced (shared) Shader which can render the traits in the specified TerrainShaderKey. More...
 

Protected Member Functions

virtual void updateState () override
 Implementation of InstancedShader::updateState(). More...
 

Detailed Description

InstancedShader which does a multi-texture blend between up to three Textures, to render terrain meshes.

As an InstancedShader, each instance is based on a shared Shader object. TerrainShader actually has multiple possible shared Shaders, each corresponding to a permutation of TerrainShaderKey. This allows the shader code for each permutation to be optimized. For example, if the part of terrain being rendered does not have a mask texture, then that shared Shader will avoid the extra texture sample, and will not blend in the mask alpha.

A TerrainShader instance for a given TerrainShaderKey is created by calling getSharedShader() with the shader key, and passing that to the TerrainShader constructor. This instance may then be used to specify exact textures to be applied to that terrain piece. This is managed by TerrainMeshRenderer.

The GLSL shader code is implemented in TerrainShader.vsh and TerrainShader.fsh.

Constructor & Destructor Documentation

TerrainShader::TerrainShader ( const ShaderPtr sharedShader)
explicit

Construct a TerrainShader based on the given shared Shader.

Parameters
sharedShaderShared shader to use, retrieved from getSharedShader()

Member Function Documentation

const TexturePtr& TerrainShader::getBaseTexture ( ) const
inline

Returns the base Texture.

const TexturePtr& TerrainShader::getBlendTexture ( ) const
inline

Returns the blend Texture.

const TexturePtr& TerrainShader::getMaskTexture ( ) const
inline

Returns the mask Texture.

static const ShaderPtr& TerrainShader::getSharedShader ( const TerrainShaderKey shaderKey)
static

Returns the uninstanced (shared) Shader which can render the traits in the specified TerrainShaderKey.

Note
The Shader for a key is only created once and then cached.
Parameters
shaderKeyTerrainShaderKey used to select the shader
Returns
Shared pointer to the Shader
void TerrainShader::setBaseTexture ( const TexturePtr value)

Sets the base Texture.

See also
TerrainMaterialDef
Parameters
valueShared pointer to the Texture to set
void TerrainShader::setBlendTexture ( const TexturePtr value)

Sets the blend Texture.

Note
This usually corresponds to the bevel texture.
See also
TerrainMaterialDef
Parameters
valueShared pointer to the Texture to set
void TerrainShader::setMaskTexture ( const TexturePtr value)

Sets the mask Texture.

Note
This usually corresponds to the mask texture.
See also
TerrainMaterialDef
Parameters
valueShared pointer to the Texture to set
void TerrainShader::setTransform ( const Matrix4 matrix)

Sets the transform to apply to vertices rendered with this Shader.

Parameters
matrixMatrix transform to set
virtual void TerrainShader::updateState ( )
overrideprotectedvirtual

Implementation of InstancedShader::updateState().

Reimplemented from InstancedShader.