Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ACG::ShaderModifier Class Reference

#include <ACG/GL/ShaderGenerator.hh>

Inheritance diagram for ACG::ShaderModifier:
ACG::IRenderer::DepthMapPass ACG::ShaderModifierFile CelShadingModifier NormalFragmentModifier PeelDualInitModifier PeelDualLayerModifier PeelInitModifier PeelLayerModifier

Public Member Functions

virtual void modifyVertexIO (ShaderGenerator *_shader)
 Add your own inputs/outputs to the vertex shader. More...
 
virtual void modifyVertexBeginCode (QStringList *_code)
 Append code the the vertex shader. More...
 
virtual void modifyVertexEndCode (QStringList *_code)
 Append code the the vertex shader. More...
 
virtual void modifyGeometryIO (ShaderGenerator *_shader)
 Add your own inputs/outputs to the geometry shader. More...
 
virtual void modifyTessControlIO (ShaderGenerator *_shader)
 Add your own inputs/outputs to the tessellation control shader. More...
 
virtual void modifyTessEvalIO (ShaderGenerator *_shader)
 Add your own inputs/outputs to the tessellation evaluation shader. More...
 
virtual void modifyFragmentIO (ShaderGenerator *_shader)
 Add your own inputs/outputs to the fragment shader. More...
 
virtual void modifyFragmentBeginCode (QStringList *_code)
 Append code the the fragment shader. More...
 
virtual void modifyFragmentEndCode (QStringList *_code)
 Append code the the fragment shader. More...
 
virtual void modifyLightingCode (QStringList *_code, int _lightId, ShaderGenLightType _lightType)
 Modify the default lighting code of the shader generator. More...
 
virtual bool replaceDefaultLightingCode ()
 Specify whether this modifier replaces or extends the default lighting code. More...
 
unsigned int getID ()
 Returns the modifier ID. More...
 
 operator std::vector< unsigned int > () const
 
std::vector< unsigned int > operator| (const std::vector< unsigned int > &_v) const
 

Static Public Member Functions

static ShaderModifierloadFromFile (QString _filename)
 Load a modifier from file. More...
 

Private Attributes

unsigned int modifierID_
 

Friends

class ShaderProgGenerator
 

Detailed Description

A shader modifier can modify uniforms, in/outputs and glsl code of vertex and fragment shaders. This is useful for global effects like shadow mapping and depth peeling, where only little changes in code are necessary.

Usage:

  1. Derive a new subclass of ShaderModifier and implement necessary modify functions.
  2. Allocate a static instance of your modifier and register it to ShaderProgGenerator to get it's modifier-ID
  3. Create ShaderProgGenerator with a bitwise combination of modifier IDs to activate them.

Example:

// First modifier
class VertexShaderModifier1 : public ACG::ShaderModifier {
public:
void modifyVertexEndCode(QStringList* _code) {
_code->push_back("// Vertex End Code Modifier begin");
_code->push_back("< Some glsl code > ");
_code->push_back("// Vertex End Code Modifier end");
}
static VertexShaderModifier1 instance;
};
// Static instance required!
VertexShaderModifier YarnVertexShaderModifier::instance;
class VertexShaderModifier2 : public ACG::ShaderModifier {
public:
void modifyVertexEndCode(QStringList* _code) {
_code->push_back("// Vertex End Code Modifier 2 begin");
_code->push_back("< Some glsl code > ");
_code->push_back("// Vertex End Code Modifier 2 end");
}
static VertexShaderModifier2 instance;
};
VertexShaderModifier2 VertexShaderModifier2::instance;

To use the modifiers, you have to register them to the shader generator:

// Register the modifiers
ACG::ShaderProgGenerator::registerModifier(&VertexShaderModifier::instance);
ACG::ShaderProgGenerator::registerModifier(&VertexShaderModifier2::instance);
// Use them via the shader cache
GLSL::Program* prog = ACG::ShaderCache::getInstance()->getProgram(&shDesc,(VertexShaderModifier::instance.getID() | VertexShaderModifier2::instance.getID() ));

Definition at line 703 of file ShaderGenerator.hh.

Member Function Documentation

unsigned int ACG::ShaderModifier::getID ( )
inline

Returns the modifier ID.

Returns
Id of the modifier

Definition at line 866 of file ShaderGenerator.hh.

ShaderModifier * ACG::ShaderModifier::loadFromFile ( QString  _filename)
static

Load a modifier from file.

Shader Mod text file format:

The file can begin with a glsl version directive (optionally): #version glsl_version

The rest of the file contains glsl code blocks, which are separated by keywords. Each keyword must be at the beginning of a line. Furthermore they end on a colon ':'. The keyword defines the meaning of the following code block.

IO code blocks are specified by the keywords: VertexIO:, TessControlIO:, TessEvalIO:, GeometryIO: and FragmentIO:

example

VertexIO: in vec3 customInputName; out vec3 custumOutputName; uniform vec4 param0;

Shader code modifications are done via the keywords: VertexBeginCode:, VertexEndCode:, FragmentBeginCode: and FragmentEndCode:

The returned modifier should not be deleted manually.

Parameters
_filenameabsolute or relative (from shaderdir) file name
Returns
pointer to shader modifier, 0 if loading failed

Definition at line 2454 of file ShaderGenerator.cc.

virtual void ACG::ShaderModifier::modifyFragmentBeginCode ( QStringList *  _code)
inlinevirtual

Append code the the fragment shader.

Refer to the generation structure (Shader Generator ) to see where your code is added and which variables you can modify. Use

_code->push_back("...");

to insert your code here

Parameters
_codestring list of shader code.

Reimplemented in ACG::ShaderModifierFile, PeelDualLayerModifier, and PeelLayerModifier.

Definition at line 819 of file ShaderGenerator.hh.

virtual void ACG::ShaderModifier::modifyFragmentEndCode ( QStringList *  _code)
inlinevirtual

Append code the the fragment shader.

Refer to the generation structure (Shader Generator ) to see where your code is added and which variables you can modify. Use

_code->push_back("...");

to insert your code here.

Parameters
_codestring list of shader code.

Reimplemented in ACG::ShaderModifierFile, ACG::IRenderer::DepthMapPass, PeelDualInitModifier, PeelDualLayerModifier, CelShadingModifier, NormalFragmentModifier, PeelInitModifier, and PeelLayerModifier.

Definition at line 835 of file ShaderGenerator.hh.

virtual void ACG::ShaderModifier::modifyFragmentIO ( ShaderGenerator _shader)
inlinevirtual

Add your own inputs/outputs to the fragment shader.

your implementation may look like this:

_shader->addInput("sampler2D depthSampler");
_shader->addUniform("vec4 shaderParam");
Parameters
_shadershader interface

Reimplemented in ACG::ShaderModifierFile, PeelDualLayerModifier, CelShadingModifier, PeelInitModifier, and PeelLayerModifier.

Definition at line 803 of file ShaderGenerator.hh.

virtual void ACG::ShaderModifier::modifyGeometryIO ( ShaderGenerator _shader)
inlinevirtual

Add your own inputs/outputs to the geometry shader.

your implementation may look like this:

_shader->addInput("sampler2D depthSampler");
_shader->addUniform("vec4 shaderParam");
Parameters
_shadershader interface

Reimplemented in ACG::ShaderModifierFile.

Definition at line 764 of file ShaderGenerator.hh.

virtual void ACG::ShaderModifier::modifyLightingCode ( QStringList *  _code,
int  _lightId,
ShaderGenLightType  _lightType 
)
inlinevirtual

Modify the default lighting code of the shader generator.

Refer to the generation structure (Shader Generator ) to see where your code is added and which variables you can modify.

Use

_code->push_back("...");

to insert your code here.

Parameters
_codestring list of shader code.
_lightIdlight index, use g_vLightDir__{_lightId}, etc. in shader code to use light parameters
_lightTypelight type: point, spot or directional light

Reimplemented in CelShadingModifier.

Definition at line 854 of file ShaderGenerator.hh.

virtual void ACG::ShaderModifier::modifyTessControlIO ( ShaderGenerator _shader)
inlinevirtual

Add your own inputs/outputs to the tessellation control shader.

your implementation may look like this:

_shader->addInput("sampler2D depthSampler");
_shader->addUniform("vec4 shaderParam");
Parameters
_shadershader interface

Reimplemented in ACG::ShaderModifierFile.

Definition at line 777 of file ShaderGenerator.hh.

virtual void ACG::ShaderModifier::modifyTessEvalIO ( ShaderGenerator _shader)
inlinevirtual

Add your own inputs/outputs to the tessellation evaluation shader.

your implementation may look like this:

_shader->addInput("sampler2D depthSampler");
_shader->addUniform("vec4 shaderParam");
Parameters
_shadershader interface

Reimplemented in ACG::ShaderModifierFile.

Definition at line 790 of file ShaderGenerator.hh.

virtual void ACG::ShaderModifier::modifyVertexBeginCode ( QStringList *  _code)
inlinevirtual

Append code the the vertex shader.

Refer to the generation structure (Shader Generator ) to see where your code is added and which variables you can modify. Use

_code->push_back("...");

to insert your code here.

Parameters
_codestring list of shader code.

Reimplemented in ACG::ShaderModifierFile.

Definition at line 736 of file ShaderGenerator.hh.

virtual void ACG::ShaderModifier::modifyVertexEndCode ( QStringList *  _code)
inlinevirtual

Append code the the vertex shader.

Refer to the generation structure (Shader Generator ) to see where your code is added and which variables you can modify. Use

_code->push_back("...");

to insert your code here

Parameters
_codestring list of shader code.

Reimplemented in ACG::ShaderModifierFile.

Definition at line 751 of file ShaderGenerator.hh.

virtual void ACG::ShaderModifier::modifyVertexIO ( ShaderGenerator _shader)
inlinevirtual

Add your own inputs/outputs to the vertex shader.

Your implementation may look like this:

_shader->addInput("vec4 inTangent");
_shader->addUniform("vec4 shaderParam");
Parameters
_shadershader interface

Reimplemented in ACG::ShaderModifierFile, CelShadingModifier, and NormalFragmentModifier.

Definition at line 722 of file ShaderGenerator.hh.

virtual bool ACG::ShaderModifier::replaceDefaultLightingCode ( )
inlinevirtual

Specify whether this modifier replaces or extends the default lighting code.

Returns
return false if this modifier modifies an already computed lighting color, return true if this modifier replaces the default lighting color

Reimplemented in CelShadingModifier.

Definition at line 860 of file ShaderGenerator.hh.


The documentation for this class was generated from the following files: