Game Development Community

PostFX Object selecting and colouring shader advice

by Jack Stone · in Torque 3D Professional · 06/27/2014 (8:57 pm) · 7 replies

I have an idea for a gameplay addition which would allow certain objects to be highlighted in different colours depending on the "vision mode" set by the player. For example, in "thermal vision" heat sources show up in bright red, in "EM" vision, objects with electrical power running through them glow brightly in blue. I could also add objectives, weapons, etc etc in different colours.

The idea is that this would be a full screen (postFX?) shader that the player could turn on and turn off. I think I can create the shader itself, and handle that aspect of it, but there's one thing I don't know how to do. I'm not sure if this is even possible, but, how would you select certain objects in a postfx shader?

My understanding of it is that the shader is dealing with an array of pixel values, so if I wanted to colour all objects with "heat emitting" set in their datablock, how would I check for this? Is there a way?

The only other alternative would be to apply a fullscreen shader to dim the screen (to produce a black-and-white effect) and then swap the materials of the "heat-emitting" objects to something that glows brightly, leaving every other object as it is. Would this be a better solution?

Thanks for any advice, I'm just brainstorming and researching at this point!

#1
06/27/2014 (11:41 pm)
Not sure if this is what you're after, but you can check out this
resource on color correction. Try out the infra-red one. You might be able to create your own color ramp to fit your needs. If it is set up right, it could augment a certain color to "glow" the way the red glows in the infra-red example , then you could swap the materials like you said, and these materials would have the augmented color in them. You will have to figure out how to switch the color ramp in real time. Oh, and if you figure that out, let me know too!
#2
06/29/2014 (4:37 pm)
Hello,

That's an excellent resource, thanks!

I think my working solution was the same as your suggestion, (great minds think alike?) with regards to swapping the materials and then highlighting that material in the shader.

I'll play around with this in the next few days, and then post what I have, hopefully it will work out!
#3
06/29/2014 (5:02 pm)
I think the best way to approach this would be the same way glow does. What glow does is render the glow objects a second time and use that as a glow mask to apply the shader.

You would make a new render bin and only put your highlighted objects in it when you switch your mode on. After the scene is rendered, the objects you want highlighted will render again to a special texture that's otherwise just black. You apply your shader to that mask and blend it to the backbuffer.

Here's a visualization. Glowing object:
i.imgur.com/KzRemaL.png

Glow buffer ( I made a debug visualizer ):
i.imgur.com/2K4rcir.png

It's expensive because you'll have to render your objects again, but depending on how your visualization works you may be able to get away with only rendering them to your texture.

The only other approach I could think of would be swapping out materials on all the objects in the scene with a material shader to draw it in that special way for your visualization and then swap them back when you shut it off. This seems like a lot more work than the other option.
#4
06/29/2014 (9:17 pm)
@Andrew:

That sounds like an infinitely better plan, unfortunately, my knowledge of shaders and T3D's rendering pipeline may not be up to that task!

I have achieved proof of concept of my idea, but I have hit a snag.

This image:

http://phoenixgamedevelopment.com/blog/wp-content/uploads/2014/06/PhoenixGameDevelopment71-Jun.-30-04.13-1024x793.jpg

Outlines what I am doing. The cone object has a texture applied with a plain colour. I am then selecting that colour in the shader using an if statement, and changing it's colour from there.

This is a hack, but it does seem to be working (although, of course, I will lose any texture information on the object, since I ap texturing it with a single-colour texture).

Another, more serious issue, is that due to scene lighting and shading,
the model is not all the same colour that it should be. In the image above for example, the side of the cone facing the sun is coloured green, but the side facing away from the sun is shaded, so it appears darker, and therefore doesn't get selected.

What I need is some way to select from the raw texture map, and not the light map, is this possible?
#5
06/29/2014 (11:37 pm)
Make the material Emissive and lighting won't be applied.
#6
06/29/2014 (11:44 pm)
Ahhh of course, why didn't I think of that! That works great, thanks a lot!
#7
07/01/2014 (7:38 pm)
I have posted a resource of my work on this, it can be seen here:
http://www.garagegames.com/community/resources/view/22772

and some more information and images on my site here:

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