Commit 7d591916 authored by Jan Möbius's avatar Jan Möbius

Merge branch 'alpha-clipping' into 'master'

Implement Alpha clipping for GL-core rendering

See merge request !131
parents a97823aa 543d6e4b
......@@ -925,7 +925,12 @@ void IRenderer::bindObjectUniforms( ACG::RenderObject* _obj, GLSL::Program* _pro
_prog->setUniform("g_cAmbient", _obj->ambient);
_prog->setUniform("g_cSpecular", _obj->specular);
ACG::Vec4f materialParams(_obj->shininess, _obj->alpha, 0.0f, 0.0f);
float alphaRef = 0.f;
if (_obj->alphaTest && _obj->alphaFunc == GL_GREATER) {
alphaRef = _obj->alphaRef;
}
ACG::Vec4f materialParams(_obj->shininess, _obj->alpha, alphaRef, 0.0f);
_prog->setUniform("g_vMaterial", materialParams);
_prog->setUniform("g_cLightModelAmbient", globalLightModelAmbient_);
......
......@@ -189,6 +189,7 @@ void RenderObject::setMaterial( const SceneGraph::Material* _mat )
// material node sets the alpha test function to GL_GREATER
alphaFunc = GL_GREATER;
alphaTest = _mat->alphaTest();
alphaRef = _mat->alphaValue();
}
......
......@@ -1073,6 +1073,7 @@ void ShaderProgGenerator::initGenDefines(ShaderGenerator* _gen)
}
_gen->addDefine("SG_ALPHA g_vMaterial.y");
_gen->addDefine("SG_MINALPHA g_vMaterial.z");
_gen->addMacros(desc_.macros);
......@@ -1182,7 +1183,11 @@ void ShaderProgGenerator::addVertexBeginCode(QStringList* _code)
_code->push_back("vec3 sg_vNormalOS = vec3(0.0, 1.0, 0.0);");
if (desc_.vertexColors && (desc_.colorMaterialMode == GL_AMBIENT || desc_.colorMaterialMode == GL_AMBIENT_AND_DIFFUSE))
_code->push_back(QString("vec4 sg_cColor = vec4(g_cEmissive + g_cLightModelAmbient * ") + ShaderGenerator::keywords.macro_inputVertexColor + QString(".xyz, SG_ALPHA);"));
_code->push_back(QString("vec4 sg_cColor = vec4(g_cEmissive + g_cLightModelAmbient * ")
+ ShaderGenerator::keywords.macro_inputVertexColor
+ QString(".rgb, SG_ALPHA * ")
+ ShaderGenerator::keywords.macro_inputVertexColor
+ QString(".a);"));
else
_code->push_back("vec4 sg_cColor = vec4(g_cEmissive + g_cLightModelAmbient * g_cAmbient, SG_ALPHA);");
......@@ -1817,7 +1822,11 @@ void ShaderProgGenerator::addFragmentBeginCode(QStringList* _code)
if (desc_.vertexColors && (desc_.colorMaterialMode == GL_AMBIENT || desc_.colorMaterialMode == GL_AMBIENT_AND_DIFFUSE))
_code->push_back(QString("vec4 sg_cColor = vec4(g_cEmissive + g_cLightModelAmbient * ") + ShaderGenerator::keywords.macro_inputVertexColor + QString(".xyz, SG_ALPHA);"));
_code->push_back(QString("vec4 sg_cColor = vec4(g_cEmissive + g_cLightModelAmbient * ")
+ ShaderGenerator::keywords.macro_inputVertexColor
+ QString(".rgb, SG_ALPHA * ")
+ ShaderGenerator::keywords.macro_inputVertexColor
+ QString(".a);"));
else
_code->push_back("vec4 sg_cColor = vec4(g_cEmissive + g_cLightModelAmbient * g_cAmbient, SG_ALPHA);");
......@@ -1826,6 +1835,7 @@ void ShaderProgGenerator::addFragmentBeginCode(QStringList* _code)
(ioDesc_.passColor_ && (desc_.shadeMode == SG_SHADE_UNLIT || desc_.colorMaterialMode == GL_EMISSION)))
_code->push_back(QString("sg_cColor = ") + ShaderGenerator::keywords.macro_inputVertexColor + QString(";"));
_code->push_back(QString("if (sg_cColor.a < SG_MINALPHA) discard;"));
if (desc_.shadeMode == SG_SHADE_PHONG)
addLightingCode(_code);
......
Markdown is supported
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