Added alpha test to generated shaders.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 11 years ago
parent d6558b5b0d
commit 06d7bd9c74

@ -45,6 +45,7 @@ namespace NL3D
Sampler1,
Sampler2,
Sampler3,
AlphaTreshold,
NUM_UNIFORMS
};

@ -190,7 +190,8 @@ namespace NL3D
"sampler0",
"sampler1",
"sampler2",
"sampler3"
"sampler3",
"alphaTreshold"
};
void CGLSLProgram::cacheUniformIndices()

@ -274,6 +274,17 @@ namespace NL3D
ss << "uniform vec4 constant3;" << std::endl;
}
void CGLSLShaderGenerator::addAlphaTreshold()
{
ss << "uniform float alphaTreshold;" << std::endl;
}
void CGLSLShaderGenerator::addAlphaTest()
{
if( material->getAlphaTest() )
ss << "if( fragColor.a <= ( alphaTreshold - 0.0001 ) ) discard;" << std::endl;
}
void CGLSLShaderGenerator::generateNormalVS()
{
ss << "void main( void )" << std::endl;
@ -464,6 +475,7 @@ namespace NL3D
}
addColor();
addConstants();
addAlphaTreshold();
ss << std::endl;
@ -504,10 +516,10 @@ namespace NL3D
if( vertexColor )
ss << "texel = color * texel;" << std::endl;
// Alpha test
//ss << "if( texel.a <= 0.5 ) discard;" << std::endl;
ss << "fragColor = texel;" << std::endl;
addAlphaTest();
ss << "}" << std::endl;
}
@ -872,6 +884,8 @@ namespace NL3D
addDiffuse();
addAlphaTreshold();
ss << std::endl;
ss << "void main( void )" << std::endl;
@ -910,6 +924,7 @@ namespace NL3D
}
ss << "fragColor = texel;" << std::endl;
addAlphaTest();
ss << "}" << std::endl;
ss << std::endl;
}
@ -920,6 +935,7 @@ namespace NL3D
ss << "uniform sampler2D sampler0;" << std::endl;
ss << "uniform samplerCube sampler1;" << std::endl;
addDiffuse();
addAlphaTreshold();
ss << "void main( void )" << std::endl;
ss << "{" << std::endl;
@ -931,6 +947,7 @@ namespace NL3D
ss << "texel.rgb = texel1.rgb * texel.a + texel.rgb;" << std::endl;
ss << "texel.a = texel1.a;" << std::endl;
ss << "fragColor = texel;" << std::endl;
addAlphaTest();
ss << "}" << std::endl;
}
@ -951,6 +968,8 @@ namespace NL3D
addConstants();
addAlphaTreshold();
ss << std::endl;
ss << "void main( void )" << std::endl;
@ -981,6 +1000,7 @@ namespace NL3D
}
ss << "fragColor = texel;" << std::endl;
addAlphaTest();
ss << "}" << std::endl;
}
@ -1010,6 +1030,8 @@ namespace NL3D
if( diffuse )
ss << "uniform sampler2D sampler3;" << std::endl;
addAlphaTreshold();
ss << std::endl;
ss << "void main( void )" << std::endl;
@ -1037,6 +1059,8 @@ namespace NL3D
else
ss << "fragColor = texel2" << std::endl;
addAlphaTest();
ss << "}" << std::endl;
ss << std::endl;
@ -1047,6 +1071,7 @@ namespace NL3D
ss << "uniform sampler2D sampler0;" << std::endl;
ss << "uniform sampler2D sampler1;" << std::endl;
addDiffuse();
addAlphaTreshold();
ss << std::endl;
ss << "void main( void )" << std::endl;
@ -1056,6 +1081,7 @@ namespace NL3D
ss << "vec4 tex = mix( tex0, tex1, diffuse.a );" << std::endl;
ss << "tex.a = 0;" << std::endl;
ss << "fragColor = tex;" << std::endl;
addAlphaTest();
ss << "}" << std::endl;
ss << std::endl;

@ -42,6 +42,8 @@ namespace NL3D
void addDiffuse();
void addColor();
void addConstants();
void addAlphaTreshold();
void addAlphaTest();
void generateNormalVS();
void generateSpecularVS();

@ -169,6 +169,9 @@ namespace NL3D
}
}
desc.setAlphaTest( mat.getAlphaTest() );
desc.setAlphaTestThreshold( mat.getAlphaTestThreshold() );
p = shaderCache.findShader( desc );
if( p != NULL )

@ -35,6 +35,8 @@ namespace NL3D
program = NULL;
vbFlags = 0;
nlightmaps = 0;
alphaTest = false;
alphaTestTreshold = 0.5f;
}
~CShaderDesc(){
@ -51,6 +53,18 @@ namespace NL3D
if( nlightmaps != o.nlightmaps )
return false;
if( alphaTest != o.alphaTest )
return false;
if( alphaTest )
{
if( alphaTestTreshold > o.alphaTestTreshold + 0.0001f )
return false;
if( alphaTestTreshold < o.alphaTestTreshold - 0.0001f )
return false;
}
for( int i = 0; i < MAX_TEXTURES; i++ )
if( texEnvMode[ i ] != o.texEnvMode[ i ] )
return false;
@ -63,6 +77,9 @@ namespace NL3D
void setShaderType( uint32 type ){ shaderType = type; }
void setProgram( IProgramObject *p ){ program = p; }
void setNLightMaps( uint32 n ){ nlightmaps = n; }
void setAlphaTest( bool b ){ alphaTest = b; }
void setAlphaTestThreshold( float t ){ alphaTestTreshold = t; }
IProgramObject* getProgram() const{ return program; }
private:
@ -70,6 +87,9 @@ namespace NL3D
uint32 vbFlags;
uint32 shaderType;
uint32 nlightmaps;
bool alphaTest;
float alphaTestTreshold;
IProgramObject *program;
};
}

Loading…
Cancel
Save