52 #include <QStringList> 59 #include <ACG/GL/gl.hh> 60 #include <ACG/Config/ACGDefines.hh> 70 #define SG_MAX_SHADER_LIGHTS 8 72 enum ShaderGenLightType
74 SG_LIGHT_DIRECTIONAL = 0,
77 SG_LIGHT_FORCE_DWORD = 0xFFFFFFFF
80 enum ShaderGenShadeMode
86 SG_SHADE_FORCE_DWORD = 0xFFFFFFFF
96 shadeMode(SG_SHADE_UNLIT),
98 vertexTemplateFile(
""),
99 tessControlTemplateFile(
""),
100 tessEvaluationTemplateFile(
""),
101 geometryTemplateFile(
""),
102 fragmentTemplateFile(
""),
104 colorMaterialMode(GL_AMBIENT_AND_DIFFUSE),
107 texGenMode(GL_EYE_LINEAR),
108 texGenPerFragment(
false)
110 for (
unsigned int i = 0 ; i < SG_MAX_SHADER_LIGHTS ; ++i)
111 lightTypes[i] = SG_LIGHT_DIRECTIONAL;
144 ShaderGenLightType lightTypes[SG_MAX_SHADER_LIGHTS];
146 ShaderGenShadeMode shadeMode;
151 QString vertexTemplateFile;
152 QString tessControlTemplateFile;
153 QString tessEvaluationTemplateFile;
154 QString geometryTemplateFile;
155 QString fragmentTemplateFile;
158 std::vector<unsigned int> shaderMods;
176 GLenum colorMaterialMode;
189 const std::map<size_t,TextureType>& textureTypes()
const {
return textureTypes_;}
199 textureTypes_[_stage] = t;
205 bool textured()
const {
return !textureTypes_.empty();}
220 bool texGenPerFragment;
222 void enableTexGenObjectLinear(
int _dim = 2)
224 texGenDim = std::max(std::min(_dim, 4), 0);
225 texGenMode = GL_OBJECT_LINEAR;
228 void enableTexGenEyeLinear(
int _dim = 2)
230 texGenDim = std::max(std::min(_dim, 4), 0);
231 texGenMode = GL_EYE_LINEAR;
234 void enableTexGenSphericalMap(
int _dim = 2)
236 texGenDim = std::max(std::min(_dim, 2), 0);
237 texGenMode = GL_SPHERE_MAP;
240 void enableTexGenNormalMap(
int _dim = 3)
242 texGenDim = std::max(std::min(_dim, 3), 0);
243 texGenMode = GL_NORMAL_MAP;
246 void enableTexGenReflectionMap(
int _dim = 3)
248 texGenDim = std::max(std::min(_dim, 3), 0);
249 texGenMode = GL_REFLECTION_MAP;
252 void disableTexGen() { texGenDim = 0; }
258 if (numLights != _rhs.numLights)
261 if (shadeMode != _rhs.shadeMode)
264 if (vertexColors != _rhs.vertexColors)
267 if (textured() != _rhs.textured())
275 if (colorMaterialMode != _rhs.colorMaterialMode)
279 if (fragmentTemplateFile != _rhs.fragmentTemplateFile)
282 if (geometryTemplateFile != _rhs.geometryTemplateFile)
285 if (vertexTemplateFile != _rhs.vertexTemplateFile)
288 if (tessControlTemplateFile != _rhs.tessControlTemplateFile)
291 if (tessEvaluationTemplateFile != _rhs.tessEvaluationTemplateFile)
294 if (macros != _rhs.macros)
297 if (texGenDim != _rhs.texGenDim)
302 if (texGenMode != _rhs.texGenMode)
305 if (texGenPerFragment != _rhs.texGenPerFragment)
309 if (shaderMods != _rhs.shaderMods)
313 return memcmp(lightTypes, _rhs.lightTypes, numLights *
sizeof(ShaderGenLightType)) == 0;
553 void setGLSLVersion(
int _version);
557 void addIncludeFile(QString _fileName);
586 void initDefaultUniforms();
596 void addInput(
const QString& _input);
606 void addInput(
const QString& _type,
const QString& _varname) {
addInput(_type + QString(
" ") + _varname); }
616 void addOutput(
const QString& _output);
626 void addOutput(
const QString& _type,
const QString& _varname) {
addOutput(_type + QString(
" ") + _varname); }
637 void addUniform(QString _uniform, QString _comment =
"");
646 void addDefine(
const QString& _define);
651 void addIODefine(
const QString& _macroName,
const QString& _resolvedName);
656 void addMacros(
const QStringList& _macros);
665 bool hasDefine(QString _define)
const;
674 void addLayout(QString _layout);
695 void addLight(
int lightIndex_, ShaderGenLightType _light);
702 void buildShaderCode(QStringList* _pMainCode,
const QStringList& _defaultLightingFunctions);
706 const QStringList& getShaderCode();
712 void saveToFile(
const char* _fileName);
727 void matchInputs(
const ShaderGenerator* _previousShaderStage,
bool _passToNextStage, QString _inputPrefix =
"outVertex", QString _outputPrefix =
"outGeometry");
739 void defineIOAbstraction(
const DefaultIODesc* _iodesc,
bool _vs,
bool _fs);
743 int getNumOutputs()
const;
749 QString getOutputName(
int _id)
const;
753 int getNumInputs()
const;
759 QString getInputName(
int _id)
const;
766 QString getIOMapName(
int _inId)
const;
778 QString macro_requestPosVS,
780 macro_requestTexcoord,
781 macro_requestVertexColor,
782 macro_requestNormalVS,
783 macro_requestNormalOS,
785 macro_requestRenormalize;
788 QString macro_inputPosVS,
794 macro_inputVertexColor,
799 macro_outputNormalVS,
800 macro_outputNormalOS,
801 macro_outputTexcoord,
802 macro_outputVertexColor;
814 QString vs_inputPrefix,
822 QString vs_inputPosition,
832 vs_outputVertexColor,
833 fs_outputFragmentColor;
844 void addStringToList(QString _str, QStringList* _list, QString _prefix =
"", QString _postfix =
"");
849 void addIOToCode(
const QStringList& _cmds);
860 QStringList outputs_;
861 QStringList uniforms_;
862 QStringList genDefines_;
863 QStringList layouts_;
1101 unsigned int getID() {
return modifierID_;}
1140 operator std::vector<unsigned int>()
const {
return std::vector<unsigned int>(1,modifierID_);}
1142 std::vector<unsigned int> operator | (
const std::vector<unsigned int>& _v)
const 1144 std::vector<unsigned int> r(1 + _v.size(), modifierID_);
1145 for (
size_t i = 0; i < _v.size(); ++i)
1151 unsigned int modifierID_;
1166 static void setShaderDir(QString _dir);
1171 static QString getShaderDir();
1219 void saveVertexShToFile(
const char* _fileName);
1220 void saveGeometryShToFile(
const char* _fileName);
1221 void saveFragmentShToFile(
const char* _fileName);
1225 const QStringList& getVertexShaderCode();
1229 const QStringList& getTessControlShaderCode();
1233 const QStringList& getTessEvaluationShaderCode();
1237 const QStringList& getGeometryShaderCode();
1241 const QStringList& getFragmentShaderCode();
1246 int getNumActiveModifiers()
const;
1263 bool hasGeometryShader()
const;
1267 bool hasTessControlShader()
const;
1271 bool hasTessEvaluationShader()
const;
1275 void generateShaders();
1282 static bool loadStringListFromFile(QString _fileName, QStringList* _out);
1287 static QString getAbsFilePath(QString _fileName);
1293 void loadShaderTemplateFromFile();
1297 void scanShaderTemplate(QStringList& _templateSrc, QString _templateFilename, QStringList* _outLayoutDirectives = 0);
1302 void init(
const ShaderGenDesc* _desc,
const unsigned int* _modifiers,
unsigned int _numActiveMods);
1304 void buildVertexShader();
1305 void buildTessControlShader();
1306 void buildTessEvalShader();
1307 void buildGeometryShader();
1308 void buildFragmentShader();
1310 void addVertexBeginCode(QStringList* _code);
1311 void addVertexEndCode(QStringList* _code);
1313 void addFragmentBeginCode(QStringList* _code);
1314 void addFragmentEndCode(QStringList* _code);
1320 void addLightingFunctions(QStringList* _code);
1324 void addLightingCode(QStringList* _code);
1328 void modifyLightingCode(QStringList* _code,
ShaderModifier* _modifier);
1332 void addTexGenCode(QStringList* _code,
bool _fragmentShader);
1335 static QString getPathName(QString _strFileName);
1339 int checkForIncludes(QString _str,
ShaderGenerator* _gen, QString _includePath);
1343 int checkForIncludes(QString _str, QStringList* _outImport, QString _includePath);
1349 static void loadLightingFunctions();
1357 QStringList vertexTemplate_;
1358 QStringList tessControlTemplate_;
1359 QStringList tessEvalTemplate_;
1360 QStringList geometryTemplate_;
1361 QStringList fragmentTemplate_;
1364 std::vector<ShaderModifier*> activeMods_;
1369 static std::vector<ShaderModifier*> registeredModifiers_;
1373 QString tessControlShaderFile_;
1374 QString tessEvalShaderFile_;
1375 QString geometryShaderFile_;
1376 QString fragmentShaderFile_;
1380 QStringList tessEvalLayout_;
1390 static QString shaderDir_;
1391 static QStringList lightingCode_;
QString vertexColorsInterpolator
interpolation qualifier for input vertex colors: "flat", "smooth", "noperspective" ...
bool inputTexCoord_
default attributes that should be imported in vertex shader
void clearTextures()
disables texture support and removes all texture types
QString vertexShaderFile_
path + filename to shader templates
QString toString() const
convert ShaderGenDesc to string format for debugging
virtual void modifyLightingCode(QStringList *_code, int _lightId, ShaderGenLightType _lightType)
Modify the default lighting code of the shader generator.
void addOutput(const QString &_type, const QString &_varname)
Add one GLSL output specifier.
virtual void modifyFragmentEndCode(QStringList *_code)
Append code the the fragment shader.
QStringList rawIO_
io block as glsl code
void addInput(const QString &_type, const QString &_varname)
Add one GLSL input specifier.
virtual void modifyVertexBeginCode(QStringList *_code)
Append code the the vertex shader.
virtual void modifyVertexEndCode(QStringList *_code)
Append code the the vertex shader.
void addTextureType(GLenum _type, bool _shadow, size_t _stage)
adds a texture type to the shader and enables texturing.
virtual void modifyTessEvalIO(ShaderGenerator *_shader)
Add your own inputs/outputs to the tessellation evaluation shader.
bool renormalizeLighting_
renormalize before lighting, default false, can be activated via "#define SG_REQUEST_RENORMALIZE" ...
void addRawIOBlock(QStringList _codeBlock)
Add a raw glsl IO code block.
bool inputArrays_
inputs of shader are arrays (tess-control, tess-eval, geometry)
QString outputPrefix_
prefix of outputs of this shader
QStringList imports_
glsl code imports (with #include )
QString inputPrefix_
prefix of inputs to this shader, same as prefix of ouputs of previous stage
bool normalizeTexColors
Defines if the textureVariable is normalized or not, if multiple textures are used.
static int numRegisteredModifiers_
registered shader modifier
Namespace providing different geometric functions concerning angles.
virtual void modifyFragmentBeginCode(QStringList *_code)
Append code the the fragment shader.
bool passPosVS_
default attributes that should be passed down from vertex shader
virtual void modifyTessControlIO(ShaderGenerator *_shader)
Add your own inputs/outputs to the tessellation control shader.
virtual void modifyVertexIO(ShaderGenerator *_shader)
Add your own inputs/outputs to the vertex shader.
virtual void modifyFragmentIO(ShaderGenerator *_shader)
Add your own inputs/outputs to the fragment shader.
std::map< size_t, TextureType > textureTypes_
holds the texture types (second) and the stage id (first). if empty, shader does not support textures...
bool outputArrays_
outputs of shader are arrays (tess-control)
virtual void modifyGeometryIO(ShaderGenerator *_shader)
Add your own inputs/outputs to the geometry shader.
ShaderGenerator::DefaultIODesc ioDesc_
default IO descriptor for the vertex shader
virtual bool replaceDefaultLightingCode()
Specify whether this modifier replaces or extends the default lighting code.
unsigned int getID()
Returns the modifier ID.
QStringList tessControlLayout_
layout() directives scanned from loaded templates