Per-object color changing, and dynamic materials
by Jack Stone · in Torque Game Engine Advanced · 12/13/2008 (6:46 pm) · 1 replies
I am working on an online game, with character customisation. I would like to be able to change the colour of a character at runtime. I can do this very easily on the client by using colormultiply, however, that does not work on the server, because two players could be using the same texture, and the colormultiply change would be applied to all textures using that material.
I then need to do one of two things:
Make the color change per object, rather than per material. This is what I tried to do here:
http://www.garagegames.com/mg/forums/result.thread.php?qt=67237
The problem I have with that is that I cant seem to change the color for each object individually. I can have one color for the objects on the server, and a different one for that same texture on the client, but no two objects sharing a texture can have a different color applied.
I would need to change the rendering code to implement this, and I would appreciate any advice in that area.
The second thing I could do, (and this would probably be less efficient) would be to figure out how to create a dynamic material. In this way, a unique material could be create for each object at runtime, and the color change could be applied to that material. Another player could have an identical material, but a different material name.
I do not know how to create dynamic materials however. I assume it is possible, because of this:
http://www.garagegames.com/blogs/6912/15787
The advantage of having dynamic materials would of course be that I could do more than just change the color. I could allow the player to play with shader effects, such as glow, and also change the texture, and if the material had a unique name, all of this would apply only to their character.
I have tried simply creating a new material from script, and the console printed:
Warning, overwriting material properties for: HairTexture which I took to be good, however, there was no change to the game at all, none of the new materials settings overwrote the old ones. I tried respawning the player, and reloadtextures(), there was still no change.
Should I try actually writing the new material out to a materials.cs file, and then calling reloadmaterials?
Also, how would torque handle multiple materials mapping to a single texture? For example, two materials mapping to a texture called hairtexture, but each material using different colormultiply values?
Any advice would be appreciated, thank you.
Jack
I then need to do one of two things:
Make the color change per object, rather than per material. This is what I tried to do here:
http://www.garagegames.com/mg/forums/result.thread.php?qt=67237
The problem I have with that is that I cant seem to change the color for each object individually. I can have one color for the objects on the server, and a different one for that same texture on the client, but no two objects sharing a texture can have a different color applied.
I would need to change the rendering code to implement this, and I would appreciate any advice in that area.
The second thing I could do, (and this would probably be less efficient) would be to figure out how to create a dynamic material. In this way, a unique material could be create for each object at runtime, and the color change could be applied to that material. Another player could have an identical material, but a different material name.
I do not know how to create dynamic materials however. I assume it is possible, because of this:
http://www.garagegames.com/blogs/6912/15787
The advantage of having dynamic materials would of course be that I could do more than just change the color. I could allow the player to play with shader effects, such as glow, and also change the texture, and if the material had a unique name, all of this would apply only to their character.
I have tried simply creating a new material from script, and the console printed:
Warning, overwriting material properties for: HairTexture which I took to be good, however, there was no change to the game at all, none of the new materials settings overwrote the old ones. I tried respawning the player, and reloadtextures(), there was still no change.
Should I try actually writing the new material out to a materials.cs file, and then calling reloadmaterials?
Also, how would torque handle multiple materials mapping to a single texture? For example, two materials mapping to a texture called hairtexture, but each material using different colormultiply values?
Any advice would be appreciated, thank you.
Jack
Torque 3D Owner J.C. Smith
Example
new Material(head5100mat) { baseTex[0] = "~/data/shapes/character/textures/head/head5.dds"; bumpTex[0] = "~/data/shapes/character/textures/head/head5_nm.dds"; pixelSpecular[0] = true; specular[0] = "0.15 0.15 0.15 0.15"; specularPower[0] = 0.6; MapTo = "head5101"; preload = false; }; new Material(head5101mat) { baseTex[0] = "~/data/shapes/character/textures/head/head5.dds"; bumpTex[0] = "~/data/shapes/character/textures/head/head5_nm.dds"; pixelSpecular[0] = true; specular[0] = "0.15 0.15 0.15 0.15"; specularPower[0] = 0.6; MapTo = "head5101"; preload = false; tintColor[0] = "0.8 0.75 0.7 1.0"; useTintColor[0] = true; };In that example, they are both using the same textures and normal map, but one is tinted to be darker skinned. NOTE: TintColor is a different resource I wrote before ColorMultiply was integrated, you could use ColorMultiply instead but I just cut and pasted from one of my files. You'd swap between them by using a player.setskin using the MapTo name as the filename.
It's not the most elegant solution due to having to make material names for the various tints your using, though you could automate that with a script. It does work though.