From f194704a28fbaac37e64baaf541e4b95ef1f8e20 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 18 Sep 2013 07:23:53 +0200 Subject: [PATCH] Refactored directional lighting a little. No need to calculate things more than once. --HG-- branch : gsoc2013-dfighter --- .../OpenGL3/driver_glsl_shader_generator.cpp | 37 ++++++++----------- 1 file changed, 15 insertions(+), 22 deletions(-) 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 dd3744fdd..1d855005f 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 @@ -411,20 +411,16 @@ namespace NL3D void CGLSLShaderGenerator::addDirectionalFunctionVS( int num ) { - ss << "float getIntensity" << num << "( void )" << std::endl; + ss << "float getIntensity" << num << "( vec3 normal3 )" << std::endl; ss << "{" << std::endl; - ss << "vec3 normal3 = vnormal.xyz / vnormal.w;" << std::endl; - ss << "normal3 = normalMatrix * normal3;" << std::endl; ss << "float angle = dot( normalize( light" << num << "Dir ), normal3 );" << std::endl; ss << "angle = max( 0.0, angle );" << std::endl; ss << "return angle;" << std::endl; ss << "}" << std::endl; ss << std::endl; - ss << "float getSpecIntensity" << num << "( void )" << std::endl; + ss << "float getSpecIntensity" << num << "( vec3 normal3 )" << std::endl; ss << "{" << std::endl; - ss << "vec3 normal3 = vnormal.xyz / vnormal.w;" << std::endl; - ss << "normal3 = normalMatrix * normal3;" << std::endl; ss << "vec3 halfVector = normalize( light" << num << "Dir + normal3 );" << std::endl; ss << "float angle = dot( normal3, halfVector );" << std::endl; ss << "angle = max( 0.0, angle );" << std::endl; @@ -432,6 +428,17 @@ namespace NL3D ss << "return si;" << std::endl; ss << "}" << std::endl; ss << std::endl; + + ss << "vec4 getLight" << num << "Color()" << std::endl; + ss << "{" << std::endl; + ss << "vec3 normal3 = vnormal.xyz / vnormal.w;" << std::endl; + ss << "normal3 = normalMatrix * normal3;" << std::endl; + ss << "vec4 lc = getIntensity" << num << "( normal3 ) * light" << num << "ColDiff + "; + ss << "getSpecIntensity" << num << "( normal3 ) * light" << num << "ColSpec + "; + ss << "light" << num << "ColAmb;" << std::endl; + ss << "return lc;" << std::endl; + ss << "}" << std::endl; + ss << std::endl; } void CGLSLShaderGenerator::addPointLightFunctionVS( int num ) @@ -515,24 +522,10 @@ namespace NL3D for( int i = 0; i < SHADER_MAX_LIGHTS; i++ ) { - switch( desc->getLight( i ) ) - { - case CShaderDesc::Nolight: + if( desc->getLight( i ) == CShaderDesc::Nolight ) continue; - break; - - case CShaderDesc::Directional: - ss << "lightColor = lightColor + ("; - ss << "getIntensity" << i << "() * light" << i << "ColDiff + "; - ss << "getSpecIntensity" << i << "() * light" << i << "ColSpec + "; - ss << "light" << i << "ColAmb );"; - ss << std::endl; - break; - case CShaderDesc::Point: - ss << "lightColor = lightColor + getLight" << i << "Color();" << std::endl; - break; - } + ss << "lightColor = lightColor + getLight" << i << "Color();" << std::endl; } }