diff --git a/code/nel/src/3d/driver/OpenGL3/driver_glsl_shader_generator.cpp b/code/nel/src/3d/driver/OpenGL3/driver_glsl_shader_generator.cpp index facc9b1c6..ecf7bbff5 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_glsl_shader_generator.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_glsl_shader_generator.cpp @@ -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; + } + } diff --git a/code/nel/src/3d/driver/OpenGL3/driver_glsl_shader_generator.h b/code/nel/src/3d/driver/OpenGL3/driver_glsl_shader_generator.h index a7be48e78..df32470db 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_glsl_shader_generator.h +++ b/code/nel/src/3d/driver/OpenGL3/driver_glsl_shader_generator.h @@ -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;