Material colors ( ambient, diffuse, specular ) should now be used when there's no texture available.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 11 years ago
parent a119d3e1a0
commit 9c69e1bf84

@ -183,6 +183,13 @@ namespace NL3D
}
ss << std::endl;
if( !desc->useTextures() )
{
addAmbient();
addDiffuse();
addSpecular();
}
switch( material->getShader() )
{
case CMaterial::Normal:
@ -264,11 +271,21 @@ namespace NL3D
ps.assign( ss.str() );
}
void CGLSLShaderGenerator::addAmbient()
{
ss << "uniform vec4 ambientColor;" << std::endl;
}
void CGLSLShaderGenerator::addDiffuse()
{
ss << "uniform vec4 diffuseColor;" << std::endl;
}
void CGLSLShaderGenerator::addSpecular()
{
ss << "uniform vec4 specularColor;" << std::endl;
}
void CGLSLShaderGenerator::addColor()
{
ss << "uniform vec4 materialColor;" << std::endl;
@ -435,9 +452,20 @@ namespace NL3D
ss << "vec3 normal3 = vnormal.xyz / vnormal.w;" << std::endl;
ss << "normal3 = normalMatrix * normal3;" << std::endl;
ss << "normal3 = normalize( normal3 );" << std::endl;
if( desc->useTextures() || ( material->getShader() == CMaterial::LightMap ) )
{
ss << "vec4 lc = getIntensity" << num << "( normal3, lightDir ) * light" << num << "ColDiff + ";
ss << "getSpecIntensity" << num << "( normal3, lightDir ) * light" << num << "ColSpec + ";
ss << "light" << num << "ColAmb;" << std::endl;
}
else
{
ss << "vec4 lc = getIntensity" << num << "( normal3, lightDir ) * light" << num << "ColDiff * diffuseColor + ";
ss << "getSpecIntensity" << num << "( normal3, lightDir ) * light" << num << "ColSpec * specularColor + ";
ss << "light" << num << "ColAmb * ambientColor;" << std::endl;
}
ss << "return lc;" << std::endl;
ss << "}" << std::endl;
ss << std::endl;
@ -480,9 +508,18 @@ namespace NL3D
ss << "normal3 = normalMatrix * normal3;" << std::endl;
ss << "normal3 = normalize( normal3 );" << std::endl;
if( desc->useTextures() || ( material->getShader() == CMaterial::LightMap ) )
{
ss << "vec4 lc = getIntensity" << num << "( normal3, lightDirection ) * light" << num << "ColDiff + ";
ss << "getSpecIntensity" << num << "( normal3, lightDirection ) * light" << num << "ColSpec + ";
ss << "light" << num << "ColAmb;" << std::endl;
}
else
{
ss << "vec4 lc = getIntensity" << num << "( normal3, lightDirection ) * light" << num << "ColDiff * diffuseColor+ ";
ss << "getSpecIntensity" << num << "( normal3, lightDirection ) * light" << num << "ColSpec * specularColor + ";
ss << "light" << num << "ColAmb * ambientColor;" << std::endl;
}
ss << "lc = lc / attenuation;" << std::endl;
ss << "return lc;" << std::endl;

@ -47,9 +47,15 @@ namespace NL3D
void setShaderDesc( CShaderDesc *d ){ desc = d; }
private:
/// Adds ambient color constant uniform declaration to the program
void addAmbient();
/// Adds diffuse constant uniform declaration to the program
void addDiffuse();
/// Adds specular color constant uniform declaration to the program
void addSpecular();
/// Adds Color constant uniform declaration to the program
void addColor();

@ -494,6 +494,8 @@ namespace NL3D
if( mat.getShader() == CMaterial::Normal )
{
bool useTextures = false;
int maxTextures = std::min( int( SHADER_MAX_TEXTURES ), int( IDRV_MAT_MAXTEXTURES ) );
for( int i = 0; i < maxTextures; i++ )
{
@ -505,10 +507,11 @@ namespace NL3D
if( desc.hasVBFlags( vertexFlags[ TexCoord0 + i ] ) )
{
desc.setUseTexStage( i, true );
useTextures = true;
}
}
if( !desc.getUseTexStage( 1 ) )
if( useTextures && !desc.getUseTexStage( 1 ) )
{
for( int i = 1; i < maxTextures; i++ )
{
@ -519,6 +522,11 @@ namespace NL3D
}
}
}
else
if( !useTextures )
{
desc.setNoTextures( true );
}
}
if( mat.getAlphaTest() )

@ -95,6 +95,7 @@ namespace NL3D
for( int i = 0; i < SHADER_MAX_TEXTURES; i++ )
useTextureStage[ i ] = false;
useFirstTextureCoordSet = false;
noTextures = true;
features = None;
shaderType = Normal;
@ -110,6 +111,9 @@ namespace NL3D
bool operator==( const CShaderDesc &o ) const
{
if( noTextures != o.noTextures )
return false;
if( shaderType != o.shaderType )
return false;
@ -169,6 +173,9 @@ namespace NL3D
void setUseTexStage( uint8 stage, bool b ){ useTextureStage[ stage ] = b; }
bool getUseTexStage( uint8 stage ) const{ return useTextureStage[ stage ]; }
void setNoTextures( bool b ){ noTextures = b; }
bool useTextures() const{ return !noTextures; }
void setVBFlags( uint32 flags ){ vbFlags = flags; }
bool hasVBFlags( uint32 flags ) const{
if( ( vbFlags & flags ) != 0 )
@ -254,6 +261,7 @@ namespace NL3D
uint32 texEnvMode[ SHADER_MAX_TEXTURES ];
bool useTextureStage[ SHADER_MAX_TEXTURES ];
bool useFirstTextureCoordSet;
bool noTextures;
uint32 vbFlags;
uint32 shaderType;
uint32 nlightmaps;

Loading…
Cancel
Save