Colors are now set from the light setup, rather than being hardcoded.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 11 years ago
parent 6f396aa8f7
commit 4ba9d815d4

@ -897,6 +897,9 @@ private:
bool _LightMapDynamicLightDirty; bool _LightMapDynamicLightDirty;
// this is the backup of standard lighting (cause GL states may be modified by Lightmap Dynamic Lighting) // this is the backup of standard lighting (cause GL states may be modified by Lightmap Dynamic Lighting)
CLight _UserLight0; CLight _UserLight0;
#ifdef GLSL
CLight _UserLight[MaxLight];
#endif
bool _UserLightEnable[MaxLight]; bool _UserLightEnable[MaxLight];
//\name description of the per pixel light //\name description of the per pixel light

@ -69,6 +69,10 @@ void CDriverGL3::setLightInternal(uint8 num, const CLight& light)
// Copy the mode // Copy the mode
_LightMode[num]=mode; _LightMode[num]=mode;
#ifdef GLSL
_UserLight[num] = light;
#endif
#ifndef GLSL #ifndef GLSL
// Set the ambiant color // Set the ambiant color
GLfloat colorGL[4]; GLfloat colorGL[4];

@ -294,12 +294,6 @@ namespace NL3D
} }
struct LightData
{
float direction[ 3 ];
float color[ 4 ];
};
void CDriverGL3::setupUniforms( CMaterial& mat ) void CDriverGL3::setupUniforms( CMaterial& mat )
{ {
@ -387,33 +381,52 @@ namespace NL3D
continue; 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 ) ); int ld = currentProgram->getUniformIndex( IProgramObject::EUniform( IProgramObject::Light0Dir + i ) );
if( ld != -1 ) 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 ) ); int ldc = currentProgram->getUniformIndex( IProgramObject::EUniform( IProgramObject::Light0ColDiff + i ) );
if( ldc != -1 ) 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 ) ); int lsc = currentProgram->getUniformIndex( IProgramObject::EUniform( IProgramObject::Light0ColSpec + i ) );
if( lsc != -1 ) 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 ) ); int lac = currentProgram->getUniformIndex( IProgramObject::EUniform( IProgramObject::Light0ColAmb + i ) );
if( lac != -1 ) 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 ] );
} }
} }

@ -415,7 +415,9 @@ namespace MaterialEditor
l->setMode( NL3D::ULight::DirectionalLight ); l->setMode( NL3D::ULight::DirectionalLight );
l->setDirection( NLMISC::CVector( -100.0f, 100.0f, 100.0f ) ); 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->setLight( 0, *l );
driver->enableLight( 0, true ); driver->enableLight( 0, true );

Loading…
Cancel
Save