Developer Documentation

Public Member Functions | Static Public Member Functions | Private Attributes | Friends | List of all members
ACG::ShaderModifier Class Reference

`#include <OpenFlipper/libs_required/ACG/GL/ShaderGenerator.hh>`

Inheritance diagram for ACG::ShaderModifier:

## 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 ShaderModifier * | loadFromFile (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 969 of file ShaderGenerator.hh.

## Member Function Documentation

## ◆ getID()

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

Returns the modifier ID.

Returns
  Id of the modifier

Definition at line 1132 of file ShaderGenerator.hh.

## ◆ loadFromFile()

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

  _filename | absolute or relative (from shaderdir) file name

Returns
  pointer to shader modifier, 0 if loading failed

Definition at line 2724 of file ShaderGenerator.cc.

## ◆ modifyFragmentBeginCode()

virtual void ACG::ShaderModifier::modifyFragmentBeginCode | ( | QStringList * | _code | ) |
| inline virtual

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

  _code | string list of shader code.

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

Definition at line 1085 of file ShaderGenerator.hh.

## ◆ modifyFragmentEndCode()

virtual void ACG::ShaderModifier::modifyFragmentEndCode | ( | QStringList * | _code | ) |
| inline virtual

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

  _code | string list of shader code.

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

Definition at line 1101 of file ShaderGenerator.hh.

## ◆ modifyFragmentIO()

virtual void ACG::ShaderModifier::modifyFragmentIO | ( | ShaderGenerator * | _shader | ) |
| inline virtual

Add your own inputs/outputs to the fragment shader.

your implementation may look like this:

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

Parameters

  _shader | shader interface

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

Definition at line 1069 of file ShaderGenerator.hh.

## ◆ modifyGeometryIO()

virtual void ACG::ShaderModifier::modifyGeometryIO | ( | ShaderGenerator * | _shader | ) |
| inline virtual

Add your own inputs/outputs to the geometry shader.

your implementation may look like this:

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

Parameters

  _shader | shader interface

Reimplemented in ACG::ShaderModifierFile.

Definition at line 1030 of file ShaderGenerator.hh.

## ◆ modifyLightingCode()

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

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

  _code | string list of shader code.
  _lightId | light index, use g_vLightDir__{_lightId}, etc. in shader code to use light parameters
  _lightType | light type: point, spot or directional light

Reimplemented in CelShadingModifier.

Definition at line 1120 of file ShaderGenerator.hh.

## ◆ modifyTessControlIO()

virtual void ACG::ShaderModifier::modifyTessControlIO | ( | ShaderGenerator * | _shader | ) |
| inline virtual

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

  _shader | shader interface

Reimplemented in ACG::ShaderModifierFile.

Definition at line 1043 of file ShaderGenerator.hh.

## ◆ modifyTessEvalIO()

virtual void ACG::ShaderModifier::modifyTessEvalIO | ( | ShaderGenerator * | _shader | ) |
| inline virtual

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

  _shader | shader interface

Reimplemented in ACG::ShaderModifierFile.

Definition at line 1056 of file ShaderGenerator.hh.

## ◆ modifyVertexBeginCode()

virtual void ACG::ShaderModifier::modifyVertexBeginCode | ( | QStringList * | _code | ) |
| inline virtual

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

  _code | string list of shader code.

Reimplemented in ACG::ShaderModifierFile, and ACG::SceneGraph::ClippingNode::ClippingShaderModifier.

Definition at line 1002 of file ShaderGenerator.hh.

## ◆ modifyVertexEndCode()

virtual void ACG::ShaderModifier::modifyVertexEndCode | ( | QStringList * | _code | ) |
| inline virtual

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

  _code | string list of shader code.

Reimplemented in ACG::ShaderModifierFile.

Definition at line 1017 of file ShaderGenerator.hh.

## ◆ modifyVertexIO()

virtual void ACG::ShaderModifier::modifyVertexIO | ( | ShaderGenerator * | _shader | ) |
| inline virtual

Add your own inputs/outputs to the vertex shader.

Your implementation may look like this:

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

Parameters

  _shader | shader interface

Reimplemented in ACG::ShaderModifierFile, ACG::SceneGraph::ClippingNode::ClippingShaderModifier, CelShadingModifier, and NormalFragmentModifier.

Definition at line 988 of file ShaderGenerator.hh.

## ◆ replaceDefaultLightingCode()

virtual bool ACG::ShaderModifier::replaceDefaultLightingCode | ( |  | ) |
| inline virtual

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 1126 of file ShaderGenerator.hh.

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

- OpenFlipper/libs_required/ACG/GL/ShaderGenerator.hh
- OpenFlipper/libs_required/ACG/GL/ShaderGenerator.cc