From 4ba9d815d478444373afc090f964957d87d92dac Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 15 Sep 2013 22:11:23 +0200 Subject: [PATCH] Colors are now set from the light setup, rather than being hardcoded. --HG-- branch : gsoc2013-dfighter --- .../nel/src/3d/driver/OpenGL3/driver_opengl.h | 3 ++ .../3d/driver/OpenGL3/driver_opengl_light.cpp | 4 ++ .../driver/OpenGL3/driver_opengl_program.cpp | 43 ++++++++++++------- .../material_editor/nel3d_interface.cpp | 4 +- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl.h b/code/nel/src/3d/driver/OpenGL3/driver_opengl.h index 2beb74a96..b6d2c5183 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl.h +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl.h @@ -897,6 +897,9 @@ private: bool _LightMapDynamicLightDirty; // this is the backup of standard lighting (cause GL states may be modified by Lightmap Dynamic Lighting) CLight _UserLight0; +#ifdef GLSL + CLight _UserLight[MaxLight]; +#endif bool _UserLightEnable[MaxLight]; //\name description of the per pixel light diff --git a/code/nel/src/3d/driver/OpenGL3/driver_opengl_light.cpp b/code/nel/src/3d/driver/OpenGL3/driver_opengl_light.cpp index d5830d6a5..d0f946b5c 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_light.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_light.cpp @@ -69,6 +69,10 @@ void CDriverGL3::setLightInternal(uint8 num, const CLight& light) // Copy the mode _LightMode[num]=mode; +#ifdef GLSL + _UserLight[num] = light; +#endif + #ifndef GLSL // Set the ambiant color GLfloat colorGL[4]; 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 9357caab4..95070e1fb 100644 --- a/code/nel/src/3d/driver/OpenGL3/driver_opengl_program.cpp +++ b/code/nel/src/3d/driver/OpenGL3/driver_opengl_program.cpp @@ -294,12 +294,6 @@ namespace NL3D } - struct LightData - { - float direction[ 3 ]; - float color[ 4 ]; - }; - void CDriverGL3::setupUniforms( CMaterial& mat ) { @@ -387,33 +381,52 @@ namespace NL3D continue; ////////////////////////////////////////////////////////////////////// - LightData d; - d.direction[ 0 ] = _WorldLightDirection[ i ].x; - d.direction[ 1 ] = _WorldLightDirection[ i ].y; - d.direction[ 2 ] = _WorldLightDirection[ i ].z; - int ld = currentProgram->getUniformIndex( IProgramObject::EUniform( IProgramObject::Light0Dir + i ) ); if( ld != -1 ) { - setUniform3f( ld, d.direction[ 0 ], d.direction[ 1 ], d.direction[ 2 ] ); + CVector v = _UserLight[ i ].getDirection(); + setUniform3f( ld, v.x, v.y, v.z ); } int ldc = currentProgram->getUniformIndex( IProgramObject::EUniform( IProgramObject::Light0ColDiff + i ) ); if( ldc != -1 ) { - setUniform4f( ldc, 1.0f, 1.0f, 1.0f, 1.0f ); + GLfloat glCol[ 4 ]; + CRGBA col = _UserLight[ i ].getDiffuse(); + glCol[ 0 ] = col.R / 255.0f; + glCol[ 1 ] = col.G / 255.0f; + glCol[ 2 ] = col.B / 255.0f; + glCol[ 3 ] = col.A / 255.0f; + setUniform4f( ldc, glCol[ 0 ], glCol[ 1 ], glCol[ 2 ], glCol[ 3 ] ); } int lsc = currentProgram->getUniformIndex( IProgramObject::EUniform( IProgramObject::Light0ColSpec + i ) ); if( lsc != -1 ) { - setUniform4f( lsc, 1.0f, 1.0f, 1.0f, 1.0f ); + GLfloat glCol[ 4 ]; + CRGBA col = _UserLight[ i ].getSpecular(); + glCol[ 0 ] = col.R / 255.0f; + glCol[ 1 ] = col.G / 255.0f; + glCol[ 2 ] = col.B / 255.0f; + glCol[ 3 ] = col.A / 255.0f; + setUniform4f( lsc, glCol[ 0 ], glCol[ 1 ], glCol[ 2 ], glCol[ 3 ] ); } int lac = currentProgram->getUniformIndex( IProgramObject::EUniform( IProgramObject::Light0ColAmb + i ) ); if( lac != -1 ) { - setUniform4f( lac, 0.1f, 0.1f, 0.1f, 1.0f ); + GLfloat glCol[ 4 ]; + CRGBA col; + if( mat.getShader() == CMaterial::LightMap ) + col = _UserLight[ i ].getAmbiant(); + else + col.add( _UserLight[ i ].getAmbiant(), mat.getEmissive() ); + + glCol[ 0 ] = col.R / 255.0f; + glCol[ 1 ] = col.G / 255.0f; + glCol[ 2 ] = col.B / 255.0f; + glCol[ 3 ] = col.A / 255.0f; + setUniform4f( lac, glCol[ 0 ], glCol[ 1 ], glCol[ 2 ], glCol[ 3 ] ); } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp index 9ed79257a..97fe4156f 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp @@ -415,7 +415,9 @@ namespace MaterialEditor l->setMode( NL3D::ULight::DirectionalLight ); l->setDirection( NLMISC::CVector( -100.0f, 100.0f, 100.0f ) ); - l->setAmbiant( NLMISC::CRGBA::White ); + l->setAmbiant( NLMISC::CRGBA::CRGBA( 0.1f, 0.1f, 0.1f, 0.1f ) ); + l->setSpecular( NLMISC::CRGBA::White ); + l->setDiffuse( NLMISC::CRGBA::White ); driver->setLight( 0, *l ); driver->enableLight( 0, true );