TGEA Scaled Objects Diffuse Lighting Bug/Feature
by Gabriel Notman · in Torque Game Engine Advanced · 06/25/2007 (1:32 pm) · 17 replies
There seems to be a problem with the diffuse lighting on meshes if you scale them.
In the picture below there are 3 sphere meshes. Each of them are the same geometrically and have the same texture applied (without any material). On the left there is a sphere with a radius of 1 and next to it the same sphere scaled to "10 10 10". On the right there is the same sphere exported to DTS with a radius of 10 (prescaled). The one sphere that is scaled in the engine, has no diffuse/directional lighting but the sphere exported at that larger size does?
www.gabriel-notman.com/Lighting.png
I'm not sure what is causing this, is it a known issue? Ultimately it can be avoided by re-exported the resources at the required scale, but this reduces the flexibility of the editor and causes problems with instances.
Gabriel
In the picture below there are 3 sphere meshes. Each of them are the same geometrically and have the same texture applied (without any material). On the left there is a sphere with a radius of 1 and next to it the same sphere scaled to "10 10 10". On the right there is the same sphere exported to DTS with a radius of 10 (prescaled). The one sphere that is scaled in the engine, has no diffuse/directional lighting but the sphere exported at that larger size does?
www.gabriel-notman.com/Lighting.pngI'm not sure what is causing this, is it a known issue? Ultimately it can be avoided by re-exported the resources at the required scale, but this reduces the flexibility of the editor and causes problems with instances.
Gabriel
About the author
#2
In "material.cpp" line 295:
And in "renderElemMgr.cpp" line 29:
This should fix the problem - if not let me know.
07/01/2007 (7:41 pm)
Updated fixIn "material.cpp" line 295:
// fill in primary light //------------------------- Point3F lightPos = sgData.light.mPos; Point3F lightDir = sgData.light.mDirection; objTrans.mulP(lightPos); objTrans.mulV(lightDir); [b]lightDir.normalizeSafe();[/b] Point4F lightPosModel(lightPos.x, lightPos.y, lightPos.z, sgData.light.sgTempModelInfo[0]); GFX->setVertexShaderConstF(VC_LIGHT_POS1, (float*)&lightPosModel, 1); GFX->setVertexShaderConstF(VC_LIGHT_DIR1, (float*)&lightDir, 1); GFX->setVertexShaderConstF(VC_LIGHT_DIFFUSE1, (float*)&sgData.light.mColor, 1); GFX->setPixelShaderConstF(PC_AMBIENT_COLOR, (float*)&sgData.light.mAmbient, 1);
And in "renderElemMgr.cpp" line 29:
// fill in primary light //------------------------- Point3F lightPos = data.light.mPos; Point3F lightDir = data.light.mDirection; objTrans.mulP(lightPos); objTrans.mulV(lightDir); [b]lightDir.normalizeSafe();[/b] Point4F lightPosModel(lightPos.x, lightPos.y, lightPos.z, data.light.sgTempModelInfo[0]); GFX->setVertexShaderConstF(VC_LIGHT_POS1, (float*)&lightPosModel, 1); GFX->setVertexShaderConstF(VC_LIGHT_DIR1, (float*)&lightDir, 1); GFX->setVertexShaderConstF(VC_LIGHT_DIFFUSE1, (float*)&data.light.mColor, 1); GFX->setPixelShaderConstF(PC_AMBIENT_COLOR, (float*)&data.light.mAmbient, 1);
This should fix the problem - if not let me know.
#4

*Note Ambient Lighting is removed
07/02/2007 (3:17 am)
Also tested it... It's fine at scale 1 1 1, and as the scale gets bigger it almost seems like the light fades. In the screenshot you can still actually see the Diffuse lighting at all scales. 
*Note Ambient Lighting is removed
#5
07/02/2007 (11:19 am)
Hmm, it looks like you guys are not using bump mapping - it worked here with bump mapping. I'll take a look at getting it to work on diffuse only, but can you guys also verify that scaling and bump mapping works for you now?
#6
Let me know if this works correctly for you guys.
07/02/2007 (11:40 am)
I just updated the fix to work with diffuse-only materials. The same code fixes bump mapping too, so you can rollback the previous changes (take out the two normalizes in bump.cpp lines 180 and 187).Let me know if this works correctly for you guys.
#7
Yeah I have static planets (Can never reach, so the light is always the same on it) so there's no need for Bumpmapping.
Thanx for the help thus far John.
07/02/2007 (12:01 pm)
Testing it now... (compiling)Yeah I have static planets (Can never reach, so the light is always the same on it) so there's no need for Bumpmapping.
Thanx for the help thus far John.
#9
Gabe
07/02/2007 (12:25 pm)
I've tested it too and it works. However only up to the scale of 70. Scales of greater then 70 the same problem exists.Gabe
#10
07/02/2007 (12:33 pm)
Yeah also saw that... I think that has to do with zoning, might be wrong though.
#11
www.garagegames.com/mg/forums/result.thread.php?qt=64894
07/23/2007 (9:42 am)
@James - are you using specular lighting on any of your planets with a material? I'm wondering if you've seen a problem that I'm having and might have already solved it:www.garagegames.com/mg/forums/result.thread.php?qt=64894
#12
I dont see the "fix"... care to share? :)
EDIT: I'm an idiot sorry... You meant you're looking for the code, heh... Nope dont have it fixed, sorry
07/23/2007 (11:47 am)
Nope.... I'm not using Specular lighting for my planets... But I'm getting that with my ships (I think). I dont see the "fix"... care to share? :)
EDIT: I'm an idiot sorry... You meant you're looking for the code, heh... Nope dont have it fixed, sorry
#13
07/23/2007 (12:14 pm)
LOL... no worries! :o) Just wish someone could help!
#14
07/23/2007 (1:17 pm)
Hmmm... reading what John posts here and seeing Jeff Faust's problems with lighting on Player models, it looks like TGEA is very much built to "assume" that Bump Maps are being used on (nearly) all objects.
#15
In engine\shaderGen\bump.cpp around line 180:
I'm sure it'll be something similar... Just a missing normalize somewhere.
07/24/2007 (12:36 am)
Rob... here's the Bumpmapping fix, that might or might not fix your specular problem:In engine\shaderGen\bump.cpp around line 180:
//JLAKER - Fix (Undone)
+ LangElement * assign2 = new GenOp( " @.xyz = normalize(mul(@, @));\r\n", lightVec, texSpaceMat, lightVec );
- LangElement * assign2 = new GenOp( " @.xyz = mul(@, @);\r\n", lightVec, texSpaceMat, lightVec );
meta->addStatement( assign2 );
if(fd.features[GFXShaderFeatureData::DynamicLightDual])
{
Var *lightVecSec = (Var*)LangElement::find("outLightVecSec");
if(lightVecSec)
{
- meta->addStatement(new GenOp(" @.xyz = mul(@, @);\r\n", lightVecSec, texSpaceMat, lightVecSec));
+ meta->addStatement(new GenOp(" @.xyz = normalize(mul(@, @));\r\n", lightVecSec, texSpaceMat, lightVecSec));
}
}
//JLAKER - Fix *UndoneI'm sure it'll be something similar... Just a missing normalize somewhere.
#16
01/12/2008 (11:42 pm)
Helpful information, thanks
#17
01/13/2008 (12:23 am)
Is this not in 1.03 yet? Kind of surprised since it was back in JUly of last year that the final fix was added.

Torque Owner James Laker (BurNinG)