Colors are good and lovely to play with! Isn't it?
04/24/2007 (6:10 pm) by Fyodor "bank" Osokin

Few days ago (while browsing blogs here at GG) I end up in "GI10H - Extreme Kork Paintball!" .post by John Kabus.
I was thinking about ability to "dynamically paint" on DTS objects.
In mentioned resource, John is using decals - that's perfect solution for something like a paintball, but I need something else.
Here, on GG, is quite "old" resource (posted back in 2002) - "Skin Modifiers" - for those who don't have access, here is a short description:
Quote:
All we *really* wanted was a simple way to let players change their outfits: shirts, trousers, and shoes to start with, and maybe hair-color and similar things later.
After much pondering, I decided that something similar to the shape mounting system would be workable. But instead of mounting shapes to the base image, I'd be mounting "skin modifiers".
A skin modifier is a pair of images: a mask image and a print image. The mask image is used only for its alpha channel. It must be same dimensions as the skin of the model that it is modifying. The print image can be any size. The print can be a solid color, or a repeating pattern. Any alpha information in the print image is ignored. The mask image's alpha channel is combined with the print image to create an "overlay" that is applied to the model's skin.
But this requires you to have:
1. basic skin (as always)
2. different masks for every skin
3. limited to colors for which you have "print bitmaps"
Another way to change dynamically the outfit (or anything else) can be done by using setSkinSpecific/setSkinMesh (it's about setting different textures to different parts on player/object), but this requires you to have textures for everything:
1. many different skins
2. many different skins
etc.
So, after brief reading through the code of "Skin Modifiers" I've got an idea...
Why using existing textures for filling the texture?
After two days (in total about 12 hours of coding/modding and experimenting), here is the result:
I've managed to make a working solution for painting any ShapeBase derived object by specifying different "base" texture, "mask" and upto 4 colors that is used to "paint" on base texture by using RGBA channels on mask.
You need:
1. base texture(s) (you can have many, but at least 1 required, "base" is enough)
2. mask texture(s) (you can have many, but at least 1 required for painting, or no mask if replacing skin)
3. optional - specify colors to use for painting.
So, here we go:
I've made a simple box with the texture applied to it:

The masks:
The second one in editor:
Usage:
shapeBaseObject.addSkinModifier(layer, skinLocation, skinTexture [, maskTexture, color1 [, color2, color2, color3]]);
Where:
layer/slot - is an integer from 0 upto 29.
skinLocation - is a texture handle, e.g. for base.mytexture.jpg is will be "mytexture".
skinTexture - handle for skin: base.mytexture.jpg, foo.mytexture.jpg, etc.
maskTexture - the mask. It's possible to use special "mask" textures and "skinTexture" too.
color1-4 - are colors in a form of RGB or RGBA. The colors are used by "color-channel" from mask texture.
The color1 will use "red" channel from mask image, the second - green, third - blue and forth - alpha.
The opacity of the channel is applyed as "alpha" to the color for painting.
Here are some pictures:
%obj.addSkinModifier(0, "testbox", "base", "mask", "255 0 0 255");

%obj.addSkinModifier(0, "testbox", "base", "mask", "", "", "", "0 255 0 255");

%obj.addSkinModifier(0, "testbox", "base", "mask3", "0 255 0 255", "0 0 255 255", "", "");

%obj.addSkinModifier(0, "testbox", "base", "mask3", "", "", "", "255 255 0 255");

You can apply different masks into one "skin", but that can be "too heavy" for computing and can affect to frame-rate.
And, from in-game usage:
%obj.addSkinModifier(1, "hairB", "yellow", ""); // basic hairs

%obj.addSkinModifier(1, "hairB", "yellow", "yellow", "0 0 255 255"); // modified hairs, "red" channel

%obj.addSkinModifier(1, "hairB", "yellow", "yellow", "", "0 0 255 255"); // modified hairs, "green channel

%obj.addSkinModifier(1, "hairB", "yellow", "yellow", "127 0 0 255"); // modified hairs, "red" channel

It doesn't look "right" because I used skin texture as "mask" - this is why colors are bad. If mask image is done "right" - you will have nice looking results.
Calling
%obj.addSkinModifier(slot, location, skin, "");
just sets/replaces the skin (similar to .setSkinName(), but can be used for multiple skins on the same object).
The code itself is a mess and isn't optimized well. If the community is interested on this I can pack it up and publish as a resource.
Most my time I spent on trying to make "blending" to work as expected. Thanks God, I found Blending Tutorial on TDN, that article explained to me few things and gave ideas on how to handle that stuff.
And more, the texture generation is done in C++, so it could be slow comparing to OpenGL-stuff. If someone will be able to merge it to use for example "render to texture" - then if will be much more faster, personally, I don't that powerful in c++ to take that task.


About the author
Working on AfterWorld: http://www.afterworld.ru/ view profile »
#2
Sorry I didn't get back to you yet - we've been swamped lately. Looks great! And definitely works better for your application than the DTS decal/painter from our paintball gid.
04/24/2007 (10:26 pm)
Hi bank,Sorry I didn't get back to you yet - we've been swamped lately. Looks great! And definitely works better for your application than the DTS decal/painter from our paintball gid.
#3
04/24/2007 (10:35 pm)
definetly worth a resource I know a lot of people are looking for that kind of thing
#4
04/25/2007 (1:44 am)
Awesome! Please make it a resource :)
#5
@John: no problems.
Yeah, I'll pack it up within a few days (just need to find time to make it a bit less-messy).
Btw, right after I posted this .blog I found Colorizing Textures resource. It's similar to what I've done, but in my case you have more "power of control".
And I'm looking forward for community to develop more :) mostly - the optimization (performance).
04/25/2007 (2:22 am)
@All - thanks.@John: no problems.
Yeah, I'll pack it up within a few days (just need to find time to make it a bit less-messy).
Btw, right after I posted this .blog I found Colorizing Textures resource. It's similar to what I've done, but in my case you have more "power of control".
And I'm looking forward for community to develop more :) mostly - the optimization (performance).
#6
TDN/DTS/Dynamic_Skin_Modifiers
good luck!
P.S. You are free to do any improvements :) hehe
04/29/2007 (2:01 pm)
resource is up and ready!TDN/DTS/Dynamic_Skin_Modifiers
good luck!
P.S. You are free to do any improvements :) hehe

Torque Owner Chip Lambert