Generate specular shader.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 12 years ago
parent 69cc5e48ed
commit 12df2fd71c

@ -208,6 +208,12 @@ namespace NL3D
case CMaterial::LightMap:
generateLightMapPS();
break;
case CMaterial::Specular:
generateSpecularPS();
break;
}
ps.assign( ss.str() );
@ -678,6 +684,50 @@ namespace NL3D
ss << std::endl;
}
void CGLSLShaderGenerator::generateSpecularPS()
{
uint sampler = 0;
for( int i = TexCoord0; i < NumOffsets; i++ )
{
if( hasFlag( vbFormat, vertexFlags[ i ] ) )
{
ss << "uniform sampler2D sampler" << sampler;
ss << ";";
ss << std::endl;
}
sampler++;
}
ss << std::endl;
ss << "void main( void )" << std::endl;
ss << "{" << std::endl;
ss << "float diffuse = vec4( ";
ss << float( material->getDiffuse().R / 255.0f ) << ", ";
ss << float( material->getDiffuse().G / 255.0f ) << ", ";
ss << float( material->getDiffuse().B / 255.0f ) << ", ";
ss << float( material->getDiffuse().A / 255.0f ) << " );";
ss << std::endl;
sampler = 0;
for( int i = TexCoord0; i < NumOffsets; i++ )
{
if( hasFlag( vbFormat, vertexFlags[ i ] ) )
{
ss << "vec4 texel" << sampler;
ss << " = texture2D( sampler" << sampler;
ss << ", " << attribNames[ i ] << " );" << std::endl;
}
sampler++;
}
ss << "vec4 texel = diffuse;" << std::endl;
ss << "texel.rgb = texel1.rgb * texel.alpha + texel.rgb;" << std::endl;
ss << "texel.a = color.a;" << std::endl;
ss << "fragColor = texel;" << std::endl;
ss << "}" << std::endl;
}
}

@ -46,6 +46,7 @@ namespace NL3D
void buildArg( unsigned int stage, unsigned int n, bool alpha, std::string &arg );
void generateLightMapPS();
void generateSpecularPS();
std::stringstream ss;
uint16 vbFormat;

Loading…
Cancel
Save