diff --git a/code/nel/include/nel/3d/program.h b/code/nel/include/nel/3d/program.h index c0e058a32..39db1b083 100644 --- a/code/nel/include/nel/3d/program.h +++ b/code/nel/include/nel/3d/program.h @@ -120,9 +120,9 @@ struct CProgramIndex ModelViewProjectionInverseTranspose, NormalMatrix, + ViewMatrix, Fog, - FogStart, FogEnd, FogColor, 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 d24f82245..f4e402688 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 @@ -287,6 +287,11 @@ namespace NL3D ss << "uniform mat3 normalMatrix;" << std::endl; } + void CGLSLShaderGenerator::addViewMatrix() + { + ss << "uniform mat4 viewMatrix;" << std::endl; + } + void CGLSLShaderGenerator::addAlphaTreshold() { ss << "uniform float alphaTreshold;" << std::endl; @@ -424,7 +429,7 @@ namespace NL3D ss << "vec4 getLight" << num << "Color()" << std::endl; ss << "{" << std::endl; - ss << "vec4 lightDir4 = modelView * vec4( light" << num << "DirOrPos, 1.0 );" << std::endl; + ss << "vec4 lightDir4 = viewMatrix * vec4( light" << num << "DirOrPos, 1.0 );" << std::endl; ss << "vec3 lightDir = lightDir4.xyz / lightDir4.w;" << std::endl; ss << "lightDir = normalize( lightDir );" << std::endl; ss << "vec3 normal3 = vnormal.xyz / vnormal.w;" << std::endl; @@ -461,7 +466,7 @@ namespace NL3D ss << "vec4 getLight" << num << "Color()" << std::endl; ss << "{" << std::endl; ss << "vec3 ecPos3 = ecPos4.xyz / ecPos4.w;" << std::endl; - ss << "vec4 lightPos4 = modelView * vec4( light" << num << "DirOrPos, 1.0 );" << std::endl; + ss << "vec4 lightPos4 = viewMatrix * vec4( light" << num << "DirOrPos, 1.0 );" << std::endl; ss << "vec3 lightPos = lightPos4.xyz / lightPos4.w;" << std::endl; ss << "vec3 lightDirection = lightPos - ecPos3;" << std::endl; ss << "float lightDistance = length( lightDirection );" << std::endl; @@ -538,10 +543,14 @@ namespace NL3D void CGLSLShaderGenerator::generateNormalVS() { - if( desc->fogEnabled() || desc->lightingEnabled() ) + if( desc->fogEnabled() || desc->hasPointLight() ) { ss << "uniform mat4 modelView;" << std::endl; } + if( desc->lightingEnabled() ) + { + addViewMatrix(); + } if( desc->fogEnabled() || desc->hasPointLight() ) { ss << "vec4 ecPos4;" << std::endl; @@ -608,6 +617,7 @@ namespace NL3D if( desc->lightingEnabled() ) { + addViewMatrix(); addNormalMatrix(); addLightUniformsVS(); addLightOutsVS(); 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 caab848d2..5fc2f43a4 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 @@ -59,6 +59,8 @@ namespace NL3D /// Adds the normal matrix declaration to the program void addNormalMatrix(); + void addViewMatrix(); + //////////////////////////// Alpha Threshold ////////////////// /// Adds the alpha threshold uniform to the program diff --git a/code/nel/src/3d/driver/opengl3/driver_opengl_program.cpp b/code/nel/src/3d/driver/opengl3/driver_opengl_program.cpp index b1972bc3e..e0570b735 100644 --- a/code/nel/src/3d/driver/opengl3/driver_opengl_program.cpp +++ b/code/nel/src/3d/driver/opengl3/driver_opengl_program.cpp @@ -778,6 +778,12 @@ namespace NL3D setUniform4x4f( program, mvpIndex, mvp ); } + int vmIndex = p->getUniformIndex( CProgramIndex::ViewMatrix ); + if( vmIndex != -1 ) + { + setUniform4x4f( program, vmIndex, _ViewMtx ); + } + int mvIndex = p->getUniformIndex( CProgramIndex::ModelView ); if( mvIndex != -1 ) { @@ -881,7 +887,11 @@ namespace NL3D if( lp != -1 ) { CVector v = _UserLight[ i ].getPosition(); - setUniform3f( program, lp, v.x, v.y, v.z ); + float pos[ 3 ]; + pos[ 0 ] = v.x - _PZBCameraPos.x; + pos[ 1 ] = v.y - _PZBCameraPos.y; + pos[ 2 ] = v.z - _PZBCameraPos.z; + setUniform3f( program, lp, pos[ 0 ], pos[ 1 ], pos[ 2 ] ); } } diff --git a/code/nel/src/3d/program.cpp b/code/nel/src/3d/program.cpp index 99fb762e2..c080e7489 100644 --- a/code/nel/src/3d/program.cpp +++ b/code/nel/src/3d/program.cpp @@ -90,9 +90,9 @@ const char *CProgramIndex::Names[NUM_UNIFORMS] = "modelViewProjectionInverseTranspose", "normalMatrix", + "viewMatrix", "fog", - "fogStart", "fogEnd", "fogColor",