Game Development Community

Dark shapebase objects.

by Phil Carlisle · in Torque Game Engine Advanced · 01/19/2007 (5:35 am) · 13 replies

We're seeing some weirdness in air ace when we add various shapebase derived classes into the engine. It basically makes the base textures a lot darker than we would want.

I remember showing an early plane to John K at !IGC and he showed us the exposure=2.0 variable to tweak, but we've added that and it seems not to have had any effect.

So is there any particular reason a mesh would appear dark? Considering if we import the same mesh as a static mesh it shows just fine?

#1
01/19/2007 (5:48 am)
Are you using ambient lighting, or are you relying in directional lighting alone? Are you using generated shaders or custom ones?
#2
01/19/2007 (6:18 am)
In these particular objects, we have generated shaders, with ambient + directional lighting. although I suspect the ambient isnt really working.
#3
01/19/2007 (2:37 pm)
Try setting the directional light color to 2.0 2.0 2.0 2.0 in the Sun object.
#4
01/20/2007 (10:48 am)
Hum might try playing around with specular settings on your material. Make sure both of your light source colors are the same.
#5
01/21/2007 (6:08 am)
I dont think youre getting me here guys.. its not that the object is dark, its that the object is dark WHEN IT IS A SHAPEBASE. It is fine as a static mesh.

So clearly, something on shapebase is different, which is where I think I need some help figuring if it is a bug or a feature, and if its a feature, how to turn it off :)
#6
01/21/2007 (10:41 am)
How dark is it? Does it look like the object is in shadow?

Tom
#7
01/21/2007 (11:57 am)
Phil i think you need a picture to clearly illustrate this one.

I have found some strange code in there... like i found this in LightManager::sgSetupLights()...
const F32 directionalFactor = 0.5f;
   const F32 ambientFactor = 0.5f;

   // Then further down.

   if(obj->overrideOptions)
   {
      if(outside)
      {
         light.mType = LightInfo::Vector;
         light.mDirection = sun->mDirection;
      }
      //else
      //{
         light.mColor = ambientColor * directionalFactor;
         light.mAmbient = ambientColor * ambientFactor;
      //}

If you look further thru that function you'll find a few more "magic numbers" which scale the light values in different cases. In particular these values are what are making some of my DTS shapes look dark in the scene... it may be the same issue your having Phil... set a breakpoint and check.

I'd love to understand what is going on here.
#8
01/21/2007 (12:48 pm)
(Tried posting in the lighting kit forums, but no one seems to read those :-) So quick copy/paste of parts - including pictures)

Brighter ship is a static shape. Darker is a shapebase derived ship class.

A few screenies to show the problem:

airaceonline.arcadersplanet.com/screenshots/shiplight1.jpg
airaceonline.arcadersplanet.com/screenshots/shiplight2.jpg
The dark ship is being added with these settings:

%aiship = new Ship() {
  dataBlock = American_Battleship;
  AIControlled = true;
  team = %team;
  receiveSunLight = "1";
  receiveLMLighting = "1";
  useCustomAmbientLighting = "0";
  customAmbientLighting = "0 0 0 1";
};

The thing here is, that its the same materials.cs used for both shapes. But there is a huge difference in how they get lit. Which is Phils point. Materials, lighting etc. should be the same for the same mesh inserted into the engine different ways.
#9
01/21/2007 (2:24 pm)
Did it do that with MSE3 build?

It could be something in the shapeBase files and maybe shapeImage.cpp?


ShapeBaseImageData::ShapeBaseImageData()
   lightType = ShapeBaseImageData::NoLight;
   lightColor.set(1.f,1.f,1.f,1.f);
   lightTime = 1000;
   lightRadius = 10.f;

Couple other interesting bits to look at in shapeBase.h

/// Miscellaneous inherited methods.
   /// @{

   DECLARE_CONOBJECT(ShapeBaseImageData);
   ShapeBaseImageData();
   ~ShapeBaseImageData();
   bool onAdd();
   bool preload(bool server, char errorBuffer[256]);
   S32 lookupState(const char* name);  ///< Get a state by name.
   static void initPersistFields();
   virtual void packData(BitStream* stream);
   virtual void unpackData(BitStream* stream);
   void registerImageLights(LightManager * lightManager, bool lightingScene, const Point3F &objectPosition, U32 startTime );

   /// @}


/// Get light information for a mounted image
   /// @param   imageSlot   Image slot id
   Light* getImageLight(U32 imageSlot);
#10
01/22/2007 (11:07 am)
What are the lighting options used on the TSStatic objects? I'm guessing receiveSunLight is enabled.

ShapeBase objects (except StaticShape and ScopeAlwaysShape) only receive lighting from the terrain or interior directly below the object. If you're not using an interior or terrain (or the terrain is Atlas for now) the lighting with not get picked up and the object's lighting defaults to (0.5 0.5 0.5) - see the last few lines of SceneObject::getLightingAmbientColor for details.

For environments similar to airace and the battleship game you should customize the object lighting. I recommend setting up all ShapeBase objects to receive sunlight directly:

ShapeBase::ShapeBase()
{
...

   overrideOptions = false;
   receiveLMLighting = false;
   receiveSunLight = true;
}
#11
01/22/2007 (11:50 am)
Hey John

Thanks a bunch for the "fix".

How about it defaulting to being this way? Just a thought. I have a hard time seeing a case where I do not want my objects to appear similar ingame with same material settings.

But I'm sure you have some good cases for "the other way" as it is now.
#12
01/22/2007 (12:24 pm)
It's setup to determine lighting information on moving objects from the environment, so when the object is in the shadow of an object or inside an interior the lighting is still correct.
#13
01/22/2007 (1:23 pm)
Make it a switch we can toggle in the world editor so it's not a compile issue.