Tattos ( and other multitextured stuff ) will now show up again, even if there's only one texture coordinate set.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 11 years ago
parent 7f7a3e159b
commit 9c0e1c2449

@ -93,7 +93,7 @@ namespace NL3D
"texCoord7" "texCoord7"
}; };
const char *texelNames[ 4 ] = const char *texelNames[ SHADER_MAX_TEXTURES ] =
{ {
"texel0", "texel0",
"texel1", "texel1",
@ -802,16 +802,13 @@ namespace NL3D
void CGLSLShaderGenerator::generateNormalPS() void CGLSLShaderGenerator::generateNormalPS()
{ {
uint sampler = 0; uint sampler = 0;
for( int i = TexCoord0; i < NumOffsets; i++ ) for( int i = 0; i < SHADER_MAX_TEXTURES; i++ )
{ {
if( hasFlag( vbFormat, vertexFlags[ i ] ) ) if( desc->getUseTexStage( i ) )
{ ss << "uniform sampler2D sampler" << sampler << ";" << std::endl;
ss << "uniform sampler2D sampler" << sampler;
ss << ";";
ss << std::endl;
}
sampler++; sampler++;
} }
addColor(); addColor();
addConstants(); addConstants();
addAlphaTreshold(); addAlphaTreshold();
@ -840,13 +837,19 @@ namespace NL3D
bool textures = false; bool textures = false;
sampler = 0; sampler = 0;
for( int i = TexCoord0; i < NumOffsets; i++ ) for( int i = 0; i < SHADER_MAX_TEXTURES; i++ )
{ {
if( hasFlag( vbFormat, vertexFlags[ i ] ) ) if( desc->getUseTexStage( i ) )
{ {
ss << "vec4 texel" << sampler; ss << "vec4 texel" << sampler << " = texture2D( sampler" << sampler << ",";
ss << " = texture2D( sampler" << sampler << ",";
ss << attribNames[ i ] << " );" << std::endl; if( !desc->getUseFirstTexCoords() )
ss << attribNames[ TexCoord0 + i ] << " );";
else
ss << attribNames[ TexCoord0 ] << " );";
ss << std::endl;
textures = true; textures = true;
} }
sampler++; sampler++;
@ -888,14 +891,13 @@ namespace NL3D
void CGLSLShaderGenerator::generateTexEnv() void CGLSLShaderGenerator::generateTexEnv()
{ {
uint32 stage = 0; uint32 stage = 0;
for( int i = TexCoord0; i < TexCoord4; i++ ) for( int i = 0; i < SHADER_MAX_TEXTURES; i++ )
{ {
if( hasFlag( vbFormat, vertexFlags[ i ] ) ) if( desc->getUseTexStage( i ) )
{ {
generateTexEnvRGB( stage ); generateTexEnvRGB( stage );
generateTexEnvAlpha( stage ); generateTexEnvAlpha( stage );
} }
stage++; stage++;
} }
} }

@ -31,6 +31,47 @@ namespace
"constant3" "constant3"
}; };
uint16 vertexFlags[ NL3D::CVertexBuffer::NumValue ] =
{
NL3D::CVertexBuffer::PositionFlag,
NL3D::CVertexBuffer::WeightFlag,
NL3D::CVertexBuffer::NormalFlag,
NL3D::CVertexBuffer::PrimaryColorFlag,
NL3D::CVertexBuffer::SecondaryColorFlag,
NL3D::CVertexBuffer::FogFlag,
NL3D::CVertexBuffer::PaletteSkinFlag,
0,
NL3D::CVertexBuffer::TexCoord0Flag,
NL3D::CVertexBuffer::TexCoord1Flag,
NL3D::CVertexBuffer::TexCoord2Flag,
NL3D::CVertexBuffer::TexCoord3Flag,
NL3D::CVertexBuffer::TexCoord4Flag,
NL3D::CVertexBuffer::TexCoord5Flag,
NL3D::CVertexBuffer::TexCoord6Flag,
NL3D::CVertexBuffer::TexCoord7Flag
};
enum AttribOffset
{
Position,
Weight,
Normal,
PrimaryColor,
SecondaryColor,
Fog,
PaletteSkin,
Empty,
TexCoord0,
TexCoord1,
TexCoord2,
TexCoord3,
TexCoord4,
TexCoord5,
TexCoord6,
TexCoord7,
NumOffsets
};
} }
namespace NL3D namespace NL3D
@ -443,15 +484,35 @@ namespace NL3D
if( mat.getShader() == CMaterial::LightMap ) if( mat.getShader() == CMaterial::LightMap )
desc.setNLightMaps( mat._LightMaps.size() ); desc.setNLightMaps( mat._LightMaps.size() );
int i = 0; //int i = 0;
if( mat.getShader() == CMaterial::Normal ) if( mat.getShader() == CMaterial::Normal )
{ {
int maxTextures = std::min( int( SHADER_MAX_TEXTURES ), int( IDRV_MAT_MAXTEXTURES ) ); int maxTextures = std::min( int( SHADER_MAX_TEXTURES ), int( IDRV_MAT_MAXTEXTURES ) );
for( i = 0; i < maxTextures; i++ ) for( int i = 0; i < maxTextures; i++ )
{ {
desc.setTexEnvMode( i, mat.getTexEnvMode( i ) ); desc.setTexEnvMode( i, mat.getTexEnvMode( i ) );
} }
for( int i = 0; i < maxTextures; i++ )
{
if( desc.hasVBFlags( vertexFlags[ TexCoord0 + i ] ) )
{
desc.setUseTexStage( i, true );
}
}
if( !desc.getUseTexStage( 1 ) )
{
for( int i = 1; i < maxTextures; i++ )
{
if( mat.getTexture( i ) != NULL )
{
desc.setUseTexStage( i, true );
desc.setUseFirstTexCoords( true );
}
}
}
} }
if( mat.getAlphaTest() ) if( mat.getAlphaTest() )

@ -92,6 +92,10 @@ namespace NL3D
for( int i = 0; i < SHADER_MAX_LIGHTS; i++ ) for( int i = 0; i < SHADER_MAX_LIGHTS; i++ )
lightMode[ i ] = Nolight; lightMode[ i ] = Nolight;
for( int i = 0; i < SHADER_MAX_TEXTURES; i++ )
useTextureStage[ i ] = false;
useFirstTextureCoordSet = false;
features = None; features = None;
shaderType = Normal; shaderType = Normal;
vbFlags = 0; vbFlags = 0;
@ -135,9 +139,16 @@ namespace NL3D
if( shaderType == Normal ) if( shaderType == Normal )
{ {
if( useFirstTextureCoordSet != o.useFirstTextureCoordSet )
return false;
for( int i = 0; i < SHADER_MAX_TEXTURES; i++ ) for( int i = 0; i < SHADER_MAX_TEXTURES; i++ )
if( texEnvMode[ i ] != o.texEnvMode[ i ] ) if( texEnvMode[ i ] != o.texEnvMode[ i ] )
return false; return false;
for( int i = 0; i < SHADER_MAX_TEXTURES; i++ )
if( useTextureStage[ i ] != o.useTextureStage[ i ] )
return false;
} }
if( lightingEnabled() ) if( lightingEnabled() )
@ -151,7 +162,21 @@ namespace NL3D
} }
void setTexEnvMode( uint32 index, uint32 mode ){ texEnvMode[ index ] = mode; } void setTexEnvMode( uint32 index, uint32 mode ){ texEnvMode[ index ] = mode; }
void setUseFirstTexCoords( bool b ){ useFirstTextureCoordSet = b; }
bool getUseFirstTexCoords() const{ return useFirstTextureCoordSet; }
void setUseTexStage( uint8 stage, bool b ){ useTextureStage[ stage ] = b; }
bool getUseTexStage( uint8 stage ) const{ return useTextureStage[ stage ]; }
void setVBFlags( uint32 flags ){ vbFlags = flags; } void setVBFlags( uint32 flags ){ vbFlags = flags; }
bool hasVBFlags( uint32 flags ) const{
if( ( vbFlags & flags ) != 0 )
return true;
else
return false;
}
void setShaderType( uint32 type ){ shaderType = type; } void setShaderType( uint32 type ){ shaderType = type; }
void setNLightMaps( uint32 n ){ nlightmaps = n; } void setNLightMaps( uint32 n ){ nlightmaps = n; }
@ -227,6 +252,8 @@ namespace NL3D
uint32 features; uint32 features;
uint32 texEnvMode[ SHADER_MAX_TEXTURES ]; uint32 texEnvMode[ SHADER_MAX_TEXTURES ];
bool useTextureStage[ SHADER_MAX_TEXTURES ];
bool useFirstTextureCoordSet;
uint32 vbFlags; uint32 vbFlags;
uint32 shaderType; uint32 shaderType;
uint32 nlightmaps; uint32 nlightmaps;

Loading…
Cancel
Save