Commit fd2a7cd5 authored by Christopher Tenter's avatar Christopher Tenter
Browse files

force renormalization in fragment shader

parent c226967f
...@@ -80,8 +80,6 @@ macro_requestTexcoord("#define SG_REQUEST_TEXCOORD"), ...@@ -80,8 +80,6 @@ macro_requestTexcoord("#define SG_REQUEST_TEXCOORD"),
macro_requestVertexColor("#define SG_REQUEST_VERTEXCOLOR"), macro_requestVertexColor("#define SG_REQUEST_VERTEXCOLOR"),
macro_requestNormalVS("#define SG_REQUEST_NORMALVS"), macro_requestNormalVS("#define SG_REQUEST_NORMALVS"),
macro_requestNormalOS("#define SG_REQUEST_NORMALOS"), macro_requestNormalOS("#define SG_REQUEST_NORMALOS"),
// // renormalize normal-vec before lighting in fragment shader
macro_requestRenormalize("#define SG_REQUEST_RENORMARLIZE"),
// generic default attribute input keywords // generic default attribute input keywords
// these are extended by the correct input name by the generator for each stage // these are extended by the correct input name by the generator for each stage
...@@ -831,44 +829,44 @@ QStringList ShaderProgGenerator::lightingCode_; ...@@ -831,44 +829,44 @@ QStringList ShaderProgGenerator::lightingCode_;
ShaderProgGenerator::ShaderProgGenerator( const ShaderGenDesc* _desc ) ShaderProgGenerator::ShaderProgGenerator( const ShaderGenDesc* _desc )
: vertex_(0), tessControl_(0), tessEval_(0), geometry_(0), fragment_(0), renormalizeLighting_(false) : vertex_(0), tessControl_(0), tessEval_(0), geometry_(0), fragment_(0)
{ {
init(_desc, (ShaderModifier**)0, 0); init(_desc, (ShaderModifier**)0, 0);
} }
ShaderProgGenerator::ShaderProgGenerator( const ShaderGenDesc* _desc, const unsigned int* _modifierIDs, unsigned int _numActiveMods ) ShaderProgGenerator::ShaderProgGenerator( const ShaderGenDesc* _desc, const unsigned int* _modifierIDs, unsigned int _numActiveMods )
: vertex_(0), tessControl_(0), tessEval_(0), geometry_(0), fragment_(0), renormalizeLighting_(false) : vertex_(0), tessControl_(0), tessEval_(0), geometry_(0), fragment_(0)
{ {
init(_desc, _modifierIDs, _numActiveMods); init(_desc, _modifierIDs, _numActiveMods);
} }
ShaderProgGenerator::ShaderProgGenerator(const ShaderGenDesc* _desc, const std::vector<unsigned int>& _modifierIDs) ShaderProgGenerator::ShaderProgGenerator(const ShaderGenDesc* _desc, const std::vector<unsigned int>& _modifierIDs)
: vertex_(0), tessControl_(0), tessEval_(0), geometry_(0), fragment_(0), renormalizeLighting_(false) : vertex_(0), tessControl_(0), tessEval_(0), geometry_(0), fragment_(0)
{ {
init(_desc, _modifierIDs.empty() ? 0 : &_modifierIDs[0], (unsigned int)_modifierIDs.size()); init(_desc, _modifierIDs.empty() ? 0 : &_modifierIDs[0], (unsigned int)_modifierIDs.size());
} }
ShaderProgGenerator::ShaderProgGenerator(const ShaderGenDesc* _desc, const std::vector<unsigned int>* _modifierIDs) ShaderProgGenerator::ShaderProgGenerator(const ShaderGenDesc* _desc, const std::vector<unsigned int>* _modifierIDs)
: vertex_(0), tessControl_(0), tessEval_(0), geometry_(0), fragment_(0), renormalizeLighting_(false) : vertex_(0), tessControl_(0), tessEval_(0), geometry_(0), fragment_(0)
{ {
unsigned int numMods = !_modifierIDs || _modifierIDs->empty() ? 0 : (unsigned int)_modifierIDs->size(); unsigned int numMods = !_modifierIDs || _modifierIDs->empty() ? 0 : (unsigned int)_modifierIDs->size();
init(_desc, numMods ? &((*_modifierIDs)[0]) : 0, numMods); init(_desc, numMods ? &((*_modifierIDs)[0]) : 0, numMods);
} }
ShaderProgGenerator::ShaderProgGenerator(const ShaderGenDesc* _desc, ShaderModifier* const* _modifiers, unsigned int _numActiveMods) ShaderProgGenerator::ShaderProgGenerator(const ShaderGenDesc* _desc, ShaderModifier* const* _modifiers, unsigned int _numActiveMods)
: vertex_(0), tessControl_(0), tessEval_(0), geometry_(0), fragment_(0), renormalizeLighting_(false) : vertex_(0), tessControl_(0), tessEval_(0), geometry_(0), fragment_(0)
{ {
init(_desc, _modifiers, _numActiveMods); init(_desc, _modifiers, _numActiveMods);
} }
ShaderProgGenerator::ShaderProgGenerator(const ShaderGenDesc* _desc, const std::vector<ShaderModifier*>& _modifierIDs) ShaderProgGenerator::ShaderProgGenerator(const ShaderGenDesc* _desc, const std::vector<ShaderModifier*>& _modifierIDs)
: vertex_(0), tessControl_(0), tessEval_(0), geometry_(0), fragment_(0), renormalizeLighting_(false) : vertex_(0), tessControl_(0), tessEval_(0), geometry_(0), fragment_(0)
{ {
init(_desc, _modifierIDs.empty() ? 0 : &(_modifierIDs[0]), (unsigned int)_modifierIDs.size()); init(_desc, _modifierIDs.empty() ? 0 : &(_modifierIDs[0]), (unsigned int)_modifierIDs.size());
} }
ShaderProgGenerator::ShaderProgGenerator(const ShaderGenDesc* _desc, const std::vector<ShaderModifier*>* _modifierIDs) ShaderProgGenerator::ShaderProgGenerator(const ShaderGenDesc* _desc, const std::vector<ShaderModifier*>* _modifierIDs)
: vertex_(0), tessControl_(0), tessEval_(0), geometry_(0), fragment_(0), renormalizeLighting_(false) : vertex_(0), tessControl_(0), tessEval_(0), geometry_(0), fragment_(0)
{ {
unsigned int numMods = !_modifierIDs || _modifierIDs->empty() ? 0 : (unsigned int)_modifierIDs->size(); unsigned int numMods = !_modifierIDs || _modifierIDs->empty() ? 0 : (unsigned int)_modifierIDs->size();
init(_desc, numMods ? &((*_modifierIDs)[0]) : 0, numMods); init(_desc, numMods ? &((*_modifierIDs)[0]) : 0, numMods);
...@@ -1798,8 +1796,7 @@ void ShaderProgGenerator::addFragmentBeginCode(QStringList* _code) ...@@ -1798,8 +1796,7 @@ void ShaderProgGenerator::addFragmentBeginCode(QStringList* _code)
_code->push_back(QString("#ifdef ") + ShaderGenerator::keywords.macro_inputNormalVS); _code->push_back(QString("#ifdef ") + ShaderGenerator::keywords.macro_inputNormalVS);
_code->push_back(QString("vec3 sg_vNormalVS = ") + ShaderGenerator::keywords.macro_inputNormalVS + QString(";")); _code->push_back(QString("vec3 sg_vNormalVS = ") + ShaderGenerator::keywords.macro_inputNormalVS + QString(";"));
if (renormalizeLighting_) _code->push_back("sg_vNormalVS = normalize(sg_vNormalVS);");
_code->push_back("sg_vNormalVS = normalize(sg_vNormalVS);");
_code->push_back("#endif"); _code->push_back("#endif");
...@@ -2199,8 +2196,6 @@ void ShaderProgGenerator::generateShaders() ...@@ -2199,8 +2196,6 @@ void ShaderProgGenerator::generateShaders()
if (dummy.hasDefine(ShaderGenerator::keywords.macro_requestPosOS)) if (dummy.hasDefine(ShaderGenerator::keywords.macro_requestPosOS))
ioDesc_.passPosOS_ = true; ioDesc_.passPosOS_ = true;
if (dummy.hasDefine(ShaderGenerator::keywords.macro_requestRenormalize))
renormalizeLighting_ = true;
...@@ -2393,8 +2388,6 @@ void ShaderProgGenerator::scanShaderTemplate(QStringList& _templateSrc, QString ...@@ -2393,8 +2388,6 @@ void ShaderProgGenerator::scanShaderTemplate(QStringList& _templateSrc, QString
} }
else if (trimmedLine.startsWith(ShaderGenerator::keywords.macro_requestPosOS)) else if (trimmedLine.startsWith(ShaderGenerator::keywords.macro_requestPosOS))
ioDesc_.passPosOS_ = true; ioDesc_.passPosOS_ = true;
else if (trimmedLine.startsWith(ShaderGenerator::keywords.macro_requestRenormalize))
renormalizeLighting_ = true;
else if (trimmedLine.startsWith("SG_FRAGMENT_LIGHTING")) else if (trimmedLine.startsWith("SG_FRAGMENT_LIGHTING"))
{ {
// shader template performs lighting in fragment shader // shader template performs lighting in fragment shader
......
...@@ -786,9 +786,7 @@ public: ...@@ -786,9 +786,7 @@ public:
macro_requestTexcoord, // mesh texture coordinate macro_requestTexcoord, // mesh texture coordinate
macro_requestVertexColor, // vertex color macro_requestVertexColor, // vertex color
macro_requestNormalVS, // view space normal macro_requestNormalVS, // view space normal
macro_requestNormalOS, // object space normal macro_requestNormalOS; // object space normal
macro_requestRenormalize; // normal should be renormalized before using it for lighting
// input / output abstraction macros // input / output abstraction macros
QString macro_inputPosVS, QString macro_inputPosVS,
...@@ -1389,9 +1387,6 @@ private: ...@@ -1389,9 +1387,6 @@ private:
/// default IO descriptor for the vertex shader /// default IO descriptor for the vertex shader
ShaderGenerator::DefaultIODesc ioDesc_; ShaderGenerator::DefaultIODesc ioDesc_;
/// renormalize before lighting, default false, can be activated via "#define SG_REQUEST_RENORMALIZE"
bool renormalizeLighting_;
static QString shaderDir_; static QString shaderDir_;
static QStringList lightingCode_; static QStringList lightingCode_;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment