Use the view matrix instead of modelview to transform the light stuff.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 11 years ago
parent 8f2e75415c
commit a119d3e1a0

@ -120,9 +120,9 @@ struct CProgramIndex
ModelViewProjectionInverseTranspose, ModelViewProjectionInverseTranspose,
NormalMatrix, NormalMatrix,
ViewMatrix,
Fog, Fog,
FogStart, FogStart,
FogEnd, FogEnd,
FogColor, FogColor,

@ -287,6 +287,11 @@ namespace NL3D
ss << "uniform mat3 normalMatrix;" << std::endl; ss << "uniform mat3 normalMatrix;" << std::endl;
} }
void CGLSLShaderGenerator::addViewMatrix()
{
ss << "uniform mat4 viewMatrix;" << std::endl;
}
void CGLSLShaderGenerator::addAlphaTreshold() void CGLSLShaderGenerator::addAlphaTreshold()
{ {
ss << "uniform float alphaTreshold;" << std::endl; ss << "uniform float alphaTreshold;" << std::endl;
@ -424,7 +429,7 @@ namespace NL3D
ss << "vec4 getLight" << num << "Color()" << std::endl; ss << "vec4 getLight" << num << "Color()" << std::endl;
ss << "{" << 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 << "vec3 lightDir = lightDir4.xyz / lightDir4.w;" << std::endl;
ss << "lightDir = normalize( lightDir );" << std::endl; ss << "lightDir = normalize( lightDir );" << std::endl;
ss << "vec3 normal3 = vnormal.xyz / vnormal.w;" << 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 << "vec4 getLight" << num << "Color()" << std::endl;
ss << "{" << std::endl; ss << "{" << std::endl;
ss << "vec3 ecPos3 = ecPos4.xyz / ecPos4.w;" << 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 lightPos = lightPos4.xyz / lightPos4.w;" << std::endl;
ss << "vec3 lightDirection = lightPos - ecPos3;" << std::endl; ss << "vec3 lightDirection = lightPos - ecPos3;" << std::endl;
ss << "float lightDistance = length( lightDirection );" << std::endl; ss << "float lightDistance = length( lightDirection );" << std::endl;
@ -538,10 +543,14 @@ namespace NL3D
void CGLSLShaderGenerator::generateNormalVS() void CGLSLShaderGenerator::generateNormalVS()
{ {
if( desc->fogEnabled() || desc->lightingEnabled() ) if( desc->fogEnabled() || desc->hasPointLight() )
{ {
ss << "uniform mat4 modelView;" << std::endl; ss << "uniform mat4 modelView;" << std::endl;
} }
if( desc->lightingEnabled() )
{
addViewMatrix();
}
if( desc->fogEnabled() || desc->hasPointLight() ) if( desc->fogEnabled() || desc->hasPointLight() )
{ {
ss << "vec4 ecPos4;" << std::endl; ss << "vec4 ecPos4;" << std::endl;
@ -608,6 +617,7 @@ namespace NL3D
if( desc->lightingEnabled() ) if( desc->lightingEnabled() )
{ {
addViewMatrix();
addNormalMatrix(); addNormalMatrix();
addLightUniformsVS(); addLightUniformsVS();
addLightOutsVS(); addLightOutsVS();

@ -59,6 +59,8 @@ namespace NL3D
/// Adds the normal matrix declaration to the program /// Adds the normal matrix declaration to the program
void addNormalMatrix(); void addNormalMatrix();
void addViewMatrix();
//////////////////////////// Alpha Threshold ////////////////// //////////////////////////// Alpha Threshold //////////////////
/// Adds the alpha threshold uniform to the program /// Adds the alpha threshold uniform to the program

@ -778,6 +778,12 @@ namespace NL3D
setUniform4x4f( program, mvpIndex, mvp ); setUniform4x4f( program, mvpIndex, mvp );
} }
int vmIndex = p->getUniformIndex( CProgramIndex::ViewMatrix );
if( vmIndex != -1 )
{
setUniform4x4f( program, vmIndex, _ViewMtx );
}
int mvIndex = p->getUniformIndex( CProgramIndex::ModelView ); int mvIndex = p->getUniformIndex( CProgramIndex::ModelView );
if( mvIndex != -1 ) if( mvIndex != -1 )
{ {
@ -881,7 +887,11 @@ namespace NL3D
if( lp != -1 ) if( lp != -1 )
{ {
CVector v = _UserLight[ i ].getPosition(); 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 ] );
} }
} }

@ -90,9 +90,9 @@ const char *CProgramIndex::Names[NUM_UNIFORMS] =
"modelViewProjectionInverseTranspose", "modelViewProjectionInverseTranspose",
"normalMatrix", "normalMatrix",
"viewMatrix",
"fog", "fog",
"fogStart", "fogStart",
"fogEnd", "fogEnd",
"fogColor", "fogColor",

Loading…
Cancel
Save