PGD Home

Object Highlighting Resource Posted on GarageGames

by on Jul.02, 2014, under News, Software and Games, Tutorials

I have posted this feature as a resource on GarageGames. It can be viewed HERE.

This is the text of the tutorial from the resource:

 

This resource is a very useful addition for highlighting objects using a PostFX shader.
When turned on, the screen will change to black and white, except for designated objects which will appear as bright red.

This could be used for night vision, thermal vision, highlighting objectives or special items in a game, highlighting ammunition or health pickups, etc.

The effect can be switched on and off at will.

More Images can be seen here:

http://phoenixgamedevelopment.com/blog/?p=727

The way this system works is by setting the diffuse color of the objects to be highlighted to pure red, by using this line:
%mat.diffuseColor[0] = “255 0 0 255”;
and then searching for that specific color in the shader by using this line:
if(ret.r > 0.98 && ret.g < 0.09){

When it is found, that pixel is set to red, while the rest are set to black and white. This is essentially a “green screen” type concept. As long as no other object in the game has exactly the same colour that the shader is replacing, this should work well.

A limitation of the system is that the selection of objects is done per material, not per object. Which means that multiple instances of the same object, which share the same material, will either be all highlighted or not highlighted at all. To circumvent this, it is possible to just create two version of the same object, with the same texture, but two different materials. Then, highlight one, but not the other.

Another possible limitation is that when using the “selected = 1” dynamic variable to select multiple objects, objects inside a simgroup will not be highlighted unless there is another object sharing the same material outside the simgroup.

To implement this resource, first download the code file from here: (2KB, .rar file).


http://www.phoenixgamedevelopment.com/downloads/ObjectHighlightingResource.rar

Place the shaders “objectshighlightP.hlsl” and “objecthighlightV.hlsl” into:
shaders/common/postFx

Place “ObjectHighlightingPostEffect.cs” into:
“scripts/client/postFX/”

Place “ObjectHighlighting.cs” into:
“scripts/server”

and execute is from “scripts/server/scriptExec.cs” by calling:
exec(“./objecthighlighting.cs”);

Using the effect is simple.

To highlight a single object, call:

enableselection(%obj);

and to switch back to regular vision call:

disableselection(%obj);

A more useful way to use this would be to add a dynamic variable called “selected” with a value of “1” to a group of objects in your scene. This can be done using the mission editor, or by calling: “%obj.selected = 1;” Bearing in mind, as mentioned before, that highlighting is done per-material, not per object.

Then, simply call:

enableselectionall(); and disableselectionall();

To enable and disable the effect.

PhoenixGameDevelopment91 Jul. 02 00.22 PhoenixGameDevelopment96 Jul. 02 00.23 PhoenixGameDevelopment102 Jul. 02 00.24 PhoenixGameDevelopment97 Jul. 02 00.23

Facebooktwitterredditpinterestlinkedinmail

Leave a Reply

*

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!