Game Development Community

Instance parameters

by Guimo · in Torque Game Engine Advanced · 08/21/2007 (11:04 am) · 2 replies

Does anybody knows if TGEA can support material parameters for each object instance? I mean, allow an ShapeBase (any subclass) instance to send parameters to the shader based on its status?

Simple Examples:
a. I want to set the alpha level of a player based on its life. So any alpha level from 0 to 254 can be set. Each player in the game may have its own independent alpha level.

b. I want to set the player tint to reflect a game state. Any color can be selected in order to tint the object mesh.

These are just simple examples. I know that some functions in the engine may solve this problems but I have to pick simple examples in order to make my point so please bear with me.

So, as each player may have its own alpha or its own color, I should feed the shader (which of course should be able to support these parameters) with the particular parameters taken from the different player instances. Say I say one player has a RGBA color of "255 0 0 128" so it should look as red tinted with semitransparency while other is "255 136 50 255" and other "255 255 255 10".

Someone may suggest to create a material for each color combination in my game. But that would require at least 256 alpha state materials for each color!!!

This is just an example. I'm sure you may come with others like different glow colors or intensity, change material transparency and more.

I someone has found this same difficulty, may we discuss solutions to this problem?

Luck!
Guimo

#1
08/21/2007 (12:40 pm)
Maybe Jeff Faust could pipe in with his Alpha Fading solution? That involved switching shaders, though, if I remember correctly.
#2
08/22/2007 (11:18 am)
Do some searching.

Might want to first look and see where the shader constants are being set (setVertexShaderConst, setPixelShaderConst). Look at how lighting information gets passed to the material (afterall, multiple space orcs aren't shaded identically). Those two things should get you headed the right way.