Game Development Community

Can self-illumination be dynamically set?

by Rubes · in Torque Game Engine · 02/27/2006 (7:26 pm) · 7 replies

In my game I've implemented object selection, so the player can select Items and other ShapeBase objects using the mouse. What I would like to accomplish is, when a particular object is selected, to make it appear as though it is self-illuminated. This seems to be the best solution for me since glowing only seems to be the domain of TSE, unless I'm mistaken.

So can an object's self-illumination be set dynamically? Are there any other similar solutions with TLK people might know of?

Thanks...

#1
02/28/2006 (8:37 am)
You can blend color into DTS objects by setting the C++ lighting parameter 'sgLightManager::sgGlobalBlendColor', while rendering, right before the object makes its call to 'installLights'.

This color is modulated (multiplied) into the object's lighting, so setting the parameter to (1.0, 1.0, 1.0) keeps the lighting the same, where as (0.5, 0.5, 0.5) halves it. To double the lighting use (2.0, 2.0, 2.0)

You can also blend custom colors into the lighting, as an example; blue (0.0, 0.0, 1.0), red (1.0, 0.0, 0.0).

You'll only need to setup the client side code to know what objects are selected, so your code knows the objects to apply the blend color to.

-John
#2
02/28/2006 (8:48 am)
Interesting...thanks. I'll have a look at that.
#3
02/28/2006 (1:06 pm)
Wow, that works really well. The client side code to identify the selected object is already in place from a different resource, so all it takes is adding a single line to the shapeBase.cc file. Thanks!
#4
03/15/2006 (9:29 am)
Sorry I wasn't very clear...

I've incorporated the Object Selection resource into my project so that I can select objects using the mouse. Some of that code modified shapeBase.cc, in the ShapeBase::renderObject method, so that the engine knows if the current object being rendered is also the currently "selected" object.

If it is the currently "selected" object, I want the TLK engine to render it brighter, so that it stands out. The way to render an object brighter, as John said, is to insert the following in ShapeBase::renderObject right before the call to "installLights":

[b]sgLightManager::sgGlobalBlendColor =  ColorF(#, #, #, #);[/b]

where # is a float from 0.0 to around 5.0 (I don't think going any higher does anything more).

So my code for ShapeBase::renderObject ended up looking like this at the beginning:

void ShapeBase::renderObject(SceneState* state, SceneRenderImage* image)
{
   PROFILE_START(ShapeBaseRenderObject);
   AssertFatal(dglIsInCanonicalState(), "Error, GL not in canonical state on entry");

   RectI viewport;
   dglGetViewport(&viewport);

   [b]// Rubes: object selection additions
   // if we have been selected, then render us with a brighter light.
   // Must be called just prior to the call to installLights().
   
   GameConnection* conn = GameConnection::getConnectionToServer();
   ShapeBase* selectedObj = NULL;
   
   if (conn)
	   selectedObj = conn->getSelectedObject();
   
   S32 selectedId = -1;
   
   if (selectedObj != NULL)
	   selectedId = selectedObj->getId();
   
   if (getId() == selectedId)
	   sgLightManager::sgGlobalBlendColor = ColorF(5.0, 5.0, 5.0, 5.0);
   else sgLightManager::sgGlobalBlendColor = ColorF(1.0, 1.0, 1.0, 1.0);
   
   // end Rubes addition[/b]
   
   installLights();

A lot of those additions are specific to the Object Selection resource, so for that code to function you'd have to use the whole resource. I'll put together a whole new resource incorporating these changes at some point.
#5
04/01/2006 (3:28 pm)
That is a very nice addition. It could be extended into a network-compatible per-shapebase blendColor setting in a very straightforward way too, being suitable for other effects (like making a player blink red when damaged, or become green when "poisoned").
#6
04/01/2006 (3:44 pm)
True, that would be an interesting effect. I've also made a similar modification as above to the GuiObjectView resource. I'm using it for an inventory resource, so that when you bring up the inventory and click on one of the items, TLK renders it brighter just like other objects in the game world.
#7
07/11/2006 (10:29 pm)
Hi,

Like Rubes, I've used the blend color property to render selected objects brighter. However, I notice that the effect doesn't stand out for transparent/translucent DTS objects. Is there a way to get around this? Thanks