Multiple materials and UV's to a single DTS?
by metalliandy · in Torque Game Engine Advanced · 11/12/2007 (4:07 pm) · 17 replies
Hey All,
I have a question about applying multiple materials to a DTS
I have searched the forums but have been unable to reach the answer i have been looking for :(
Most of the information i found was here
www.garagegames.com/mg/forums/result.thread.php?qt=60180
Because the project i am working on is using large textures ranging from 1024 to 2048 (though this will be assessed and textures may be downsized and optimised further on in the Dev. stage) i am very aware that GPU memory is a finite resource and am looking for a good way to keep performance at a playable level for average PC hardware in around 1 year-18 months or so.
If i understand correctly TGEA does not require "common" textures to be in the same folder as the model using them, so in theory i could use 3 textures for 1 DTS model that is split into separate groups.
e.g. On a wooden barrel i could model the sides in one group, the top and bottom in another and the metal rings on a third and export a single DTS but with each group having a separate UV map, to which i could assign pre-made generic wood and metal textures @1024-2048, thus allowing me to have many models textured at a higher level of detail and using comparatively less resources than i would need for many models each with their own 1024-2048 map.
Now what is confusing me is, how is this to be achieved?
I currently use Blender 2.45, Ultimate Unwrap3d pro 3.0, Hexagon 2.2, Milkshape 1.82, and Silo 1.42 + 2.0.5.
How would i create multiple UV's for one model?
I have tried in Unwrap3d, but so far have been unsuccessful :(
Now as i understand it, .obj only supports 1 U map per model... what would be a good alternative to use in its place for my pipeline?
Collada maybe?
How would i map the textures to the DTS?
Something like this?
(Please excuse me if this seems a little silly, as i am mostly flying blind here and coding is not my forte S:)
Also does TGEA support true specular texture maps, rather than generic specular mapping seen above?
Any Ideas?
I apologise for the long post and all the questions, but im really scratching my head with these.
Thanks for looking :)
I have a question about applying multiple materials to a DTS
I have searched the forums but have been unable to reach the answer i have been looking for :(
Most of the information i found was here
www.garagegames.com/mg/forums/result.thread.php?qt=60180
Because the project i am working on is using large textures ranging from 1024 to 2048 (though this will be assessed and textures may be downsized and optimised further on in the Dev. stage) i am very aware that GPU memory is a finite resource and am looking for a good way to keep performance at a playable level for average PC hardware in around 1 year-18 months or so.
If i understand correctly TGEA does not require "common" textures to be in the same folder as the model using them, so in theory i could use 3 textures for 1 DTS model that is split into separate groups.
e.g. On a wooden barrel i could model the sides in one group, the top and bottom in another and the metal rings on a third and export a single DTS but with each group having a separate UV map, to which i could assign pre-made generic wood and metal textures @1024-2048, thus allowing me to have many models textured at a higher level of detail and using comparatively less resources than i would need for many models each with their own 1024-2048 map.
Now what is confusing me is, how is this to be achieved?
I currently use Blender 2.45, Ultimate Unwrap3d pro 3.0, Hexagon 2.2, Milkshape 1.82, and Silo 1.42 + 2.0.5.
How would i create multiple UV's for one model?
I have tried in Unwrap3d, but so far have been unsuccessful :(
Now as i understand it, .obj only supports 1 U map per model... what would be a good alternative to use in its place for my pipeline?
Collada maybe?
How would i map the textures to the DTS?
Something like this?
(Please excuse me if this seems a little silly, as i am mostly flying blind here and coding is not my forte S:)
new Material(material_barrel)
{
baseTex[0] = "woodsides";
bumpTex[0] = "woodsides_n";
baseTex[1] = "wood_top_bottom";
bumpTex[1] = "wood_top_bottom_n";
baseTex[2] = "metal";
bumpTex[2] = "metal_n";
mapTo = "barrel";
pixelSpecular[0] = true;
specular[0] = "0.1 0.1 0.1 0.1";
specularPower[1] = 3.0;
specular[1] = "0.1 0.1 0.1 0.1";
specularPower[1] = 3.0;
specular[2] = "0.1 0.1 0.1 0.1";
specularPower[2] = 3.0;
};Also does TGEA support true specular texture maps, rather than generic specular mapping seen above?
Any Ideas?
I apologise for the long post and all the questions, but im really scratching my head with these.
Thanks for looking :)
#2
Regarding the specular maps, what i mean is that the incarnation i have previously used (showed above) is too generic and IMHO cannot be used as it can result in undesired specularity.
e.g a light coloured piece of wood, with a rough texture to it would have very little specularity in real life but would show up with specularity in game.
The grayscale texture you mentioned is to what i was referring :)
I just wasn't sure whether TGEA supported them.
How would i go about implementing them?
Something like this?
As for the Multiple textures, i got the idea from looking at the way that Bethesda made Oblivion because they use the same technique.
My reasoning on why it would be better is purely detail based and texture memory based.
Would TGEA have to load and render the all materials as separate entity's or would it just cache the 3 textures and re use where needed?
if we had 2 x 2048 (total of 4096 squared) used on 50 models vs 50 maps @ 4096 (for the same level of detail) on 50 models wouldn't the latter be the worse performer?
Also the nvidia DDS filter wouldn't let me save a 6144 squared map, so i would run into problems if i wanted to use 2048x6144 ( the same LOD as 3x2048)...i would have to go smaller or up to 4096...which would take up more memory or give me less detail :(
no doubt this is due to having to use power of two maps.
Any ideas?
11/13/2007 (11:17 am)
Thanks for the reply :)Regarding the specular maps, what i mean is that the incarnation i have previously used (showed above) is too generic and IMHO cannot be used as it can result in undesired specularity.
e.g a light coloured piece of wood, with a rough texture to it would have very little specularity in real life but would show up with specularity in game.
The grayscale texture you mentioned is to what i was referring :)
I just wasn't sure whether TGEA supported them.
How would i go about implementing them?
Something like this?
new Material(material_barrel)
{
baseTex[0] = "woodsides";
bumpTex[0] = "woodsides_n";
specularTex[0] = "woodsides_s";
};As for the Multiple textures, i got the idea from looking at the way that Bethesda made Oblivion because they use the same technique.
My reasoning on why it would be better is purely detail based and texture memory based.
Would TGEA have to load and render the all materials as separate entity's or would it just cache the 3 textures and re use where needed?
if we had 2 x 2048 (total of 4096 squared) used on 50 models vs 50 maps @ 4096 (for the same level of detail) on 50 models wouldn't the latter be the worse performer?
Also the nvidia DDS filter wouldn't let me save a 6144 squared map, so i would run into problems if i wanted to use 2048x6144 ( the same LOD as 3x2048)...i would have to go smaller or up to 4096...which would take up more memory or give me less detail :(
no doubt this is due to having to use power of two maps.
Any ideas?
#3
The [x] in basetex and bumptex refer to seperate render passes, not to multitexturing.
For multitexturing, there are the texture[x]
For specularity and its own specularity map, you would use something similar to:
haven't tested this, but it should theoretically work
11/14/2007 (12:21 am)
You don't use multiple textures with your first materialThe [x] in basetex and bumptex refer to seperate render passes, not to multitexturing.
For multitexturing, there are the texture[x]
For specularity and its own specularity map, you would use something similar to:
new Material(material_barrel)
{
baseTex[0] = "woodsides";
bumpTex[0] = "woodsides_n";
baseTex[1] = "woodsides_s";
mapTo = "barrel";
specular[1] = "0.1 0.1 0.1 0.1";
specularPower[1] = 3.0;
pixelSpecular[1] = true;
};haven't tested this, but it should theoretically work
#4
great tip :)
I didn't realise the [0] and [1] were render passes :S, silly me...though it is cool to lean things like that....I have sorta stumbled my way through learning TGEA and info like that really helps.
I tried the method you suggested but even though I can get the spec. grayscale texture to be seen in game, but it does not change the secularity of the object...all i get is an overlayed version.
Any ideas?
11/14/2007 (11:44 am)
Thanks for reply.great tip :)
I didn't realise the [0] and [1] were render passes :S, silly me...though it is cool to lean things like that....I have sorta stumbled my way through learning TGEA and info like that really helps.
I tried the method you suggested but even though I can get the spec. grayscale texture to be seen in game, but it does not change the secularity of the object...all i get is an overlayed version.
Any ideas?
#5
Fixed the material above.
11/14/2007 (12:13 pm)
My error, forgot a line above. Without enabled specular it logically won't work.Fixed the material above.
#6
I tried the above and now get secularity, but it still isn't based upon the grayscale map.
Here is a screenie of with/without the spec. map, with the code used for the below.

Any ideas?
I really appreciate the help you are giving me...thanks again
11/14/2007 (4:13 pm)
Thanks for the quick reply :)I tried the above and now get secularity, but it still isn't based upon the grayscale map.
Here is a screenie of with/without the spec. map, with the code used for the below.

new Material(material_crate)
{
baseTex[0] = "crate";
bumpTex[0] = "crate_n";
baseTex[1] = "crate_s";
mapTo = "crate";
specular[1] = "1.0 1.0 1.0 1.0";
specularPower[1] = 5.0;
pixelSpecular[1] = true;
};Any ideas?
I really appreciate the help you are giving me...thanks again
#7
11/15/2007 (10:24 am)
Metalliandy, i didn't read all of the posts here because i haven't much time , but i guess you are trying to get more than one textures(each of them a separate file) on one DTS file.i have sold this problem myself using Multy/Sub-object materials(in 3ds max) and then applying shaders to these textures using addmaterialmapping(). Doing that you can make specular; bump; environment... etc. mapping for the desired faces of the mesh. There isn't enough information on the web how to do this , but you can use the 3ds max reference files to read how to use Multy/Sub-Objects and assing different texture file for the separate(or group) of faces. The only problem after doing that is the need for well understanding HLSL so you can build the desired effect on your mesh. Believe me using shaders is more worth than any other build-in techniques for making specular, opacity , etc... Using shaders also gives more fps. I hope i helped a little giving you a point on what to do.
#8
I will have a try at this within blender and will post back asap
11/16/2007 (6:01 am)
Thanks for the reply :)I will have a try at this within blender and will post back asap
#9
Sorry about the long time since i posted..i thought i would get back on here and tell you all how it was going.
Ive sorted out how to export muliple UV maps and the multiple materials now show in showtool but im not having much luck with seeing them in game.
The code im using is below...does anyone have any idea what im doing wrong?
The uv's have transferred into TGEA as i see the orange no material texture on the model at different resolutions (the UV's are poor but work as a proof of concept)

Once im finished with this and im finally successful (with no small part to you guys :) ) i will write a tutorial and post it along with a video showing how its done.
Im 90% there...just cant quite get it...lol
Thanks for looking :)
*Edit* *Edit* *Edit* *Edit* *Edit* *Edit* *Edit* *Edit* *Edit* *Edit* *Edit* *Edit* *Edit* *Edit* *Edit*
I got it working!

Just as i was reviewing my post i noticed that the names in the material code were incorrect, im not sure why but when i exported the DTS it expected the names of the textures to be the same as the groups...even though i had mapped the materials using the old names....
It should of been
instead of
I am so happy its sorted:)
Now for the specular map...lol
11/28/2007 (2:02 pm)
Hey all,Sorry about the long time since i posted..i thought i would get back on here and tell you all how it was going.
Ive sorted out how to export muliple UV maps and the multiple materials now show in showtool but im not having much luck with seeing them in game.
The code im using is below...does anyone have any idea what im doing wrong?new Material(material_barreltest)
{
baseTex[0] = "barreltest0";
baseTex[0] = "barreltest1";
baseTex[0] = "barreltest2";
baseTex[0] = "barreltest3";
mapTo = "barreltest";
pixelSpecular[0] = true;
specular[0] = "0.1 0.1 0.1 0.1";
specularPower[0] = 3.0;
};The uv's have transferred into TGEA as i see the orange no material texture on the model at different resolutions (the UV's are poor but work as a proof of concept)

Once im finished with this and im finally successful (with no small part to you guys :) ) i will write a tutorial and post it along with a video showing how its done.
Im 90% there...just cant quite get it...lol
Thanks for looking :)
*Edit* *Edit* *Edit* *Edit* *Edit* *Edit* *Edit* *Edit* *Edit* *Edit* *Edit* *Edit* *Edit* *Edit* *Edit*
I got it working!

Just as i was reviewing my post i noticed that the names in the material code were incorrect, im not sure why but when i exported the DTS it expected the names of the textures to be the same as the groups...even though i had mapped the materials using the old names....
It should of been
new Material(material_barreltest)
{
baseTex[0] = "handle";
baseTex[0] = "top";
baseTex[0] = "rings";
baseTex[0] = "sides";
mapTo = "barreltest";
pixelSpecular[0] = true;
specular[0] = "0.1 0.1 0.1 0.1";
specularPower[0] = 3.0;
};instead of
new Material(material_barreltest)
{
baseTex[0] = "barreltest0";
baseTex[0] = "barreltest1";
baseTex[0] = "barreltest2";
baseTex[0] = "barreltest3";
mapTo = "barreltest";
pixelSpecular[0] = true;
specular[0] = "0.1 0.1 0.1 0.1";
specularPower[0] = 3.0;
};I am so happy its sorted:)
Now for the specular map...lol
#10
I thought i would update you all on the texture front with my little experiment.
As previously posted, i now have multiple materials on my dts :D
There is a wood, metal and rope on the example shown below

I have made 3 normal maps for the textures but as of yet, have been unable to get them to work
with the following material code. :(
and
Does anyone know if there is a limitation on the amount of textures that can be placed upon a model within TGEA or spot anything in the code that could be wrong?
Thanks for looking :)
11/30/2007 (10:57 am)
Hey all,I thought i would update you all on the texture front with my little experiment.
As previously posted, i now have multiple materials on my dts :D
There is a wood, metal and rope on the example shown below

I have made 3 normal maps for the textures but as of yet, have been unable to get them to work
with the following material code. :(
new Material(material_barrel)
{
baseTex[0] = "rope.png";
baseTex[0] = "seemless_wood_planks.png";
baseTex[0] = "seamless metal.png";
baseTex[0] = "seemless_wood_planks.png";
bumpTex[0] = "rope_n.png";
bumpTex[0] = "seemless_wood_planks_n.png";
bumpTex[0] = "seamless metal_n.png";
bumpTex[0] = "seemless_wood_planks_n.png";
mapTo = "barrel";
pixelSpecular[0] = true;
specular[0] = "0.1 0.1 0.1 0.1";
specularPower[0] = 3.0;
};and
new Material(material_barrel)
{
baseTex[0] = "rope.png";
bumpTex[0] = "rope_n.png";
baseTex[0] = "seemless_wood_planks.png";
bumpTex[0] = "seemless_wood_planks_n.png";
baseTex[0] = "seamless metal.png";
bumpTex[0] = "seamless metal_n.png";
baseTex[0] = "seemless_wood_planks.png";
bumpTex[0] = "seemless_wood_planks_n.png";
pixelSpecular[0] = true;
specular[0] = "0.1 0.1 0.1 0.1";
specularPower[0] = 3.0;
};Does anyone know if there is a limitation on the amount of textures that can be placed upon a model within TGEA or spot anything in the code that could be wrong?
Thanks for looking :)
#11
They are common for all passes and similar to the "fixed pipeline" multitexturing where you set them to a specific stage (unless I've missunderstood their concept)
11/30/2007 (11:46 am)
To apply multiple textures, use Texture[0] - Texture[15]They are common for all passes and similar to the "fixed pipeline" multitexturing where you set them to a specific stage (unless I've missunderstood their concept)
#12
Thanks for the reply :)
Im not really sure what you mean.
Do you mean i should set-up the normal maps as a second render pass
or add an extension to the actual texture?
would you be so kind as to post an example please?
Thanks again.
11/30/2007 (12:06 pm)
Hey Marc,Thanks for the reply :)
Im not really sure what you mean.
Do you mean i should set-up the normal maps as a second render pass
baseTex[0] = "rope.png"; bumpTex[1] = "rope_n.png";
or add an extension to the actual texture?
baseTex[0] = "rope[1].png"; bumpTex[0] = "rope_n[1].png";
would you be so kind as to post an example please?
Thanks again.
#13
11/30/2007 (12:52 pm)
You are trying to do something very common, anyway one day you will find out that procedural shaders must not be used for creating materials because you have more powerful option - custom shaders. look aroud in TGEA and find out how shaders are created. For your first try you can use some of the already made shaders. Then you can create custom materials for each of the textures you used in your DTS and just use "Mapto" to carry the effects onto your textures. There are so many examples how this is made...for instance look in demo/data/shapes/test. All the DTSs there use custom materials (i.e. shaders). So actually you can make the different parts of your DTS use different shaders,i bet you'll like this more than using the "new Material" option.
#14
It looks very cool :)
So basically, using the cutom materials i can map a normal map/glow/etc. shader to my objects by using mapto function without the whole new material rigmarole?
I shall give it a go tomorrow and report back here asap
Thanks again
11/30/2007 (1:05 pm)
Thanks for the reply :)It looks very cool :)
So basically, using the cutom materials i can map a normal map/glow/etc. shader to my objects by using mapto function without the whole new material rigmarole?
I shall give it a go tomorrow and report back here asap
Thanks again
#15
11/30/2007 (1:55 pm)
Yes, in fact you need a "materials.cs" file in the directory you saved the DTS and its textures. in this materials.cs you write the definitions of your custom materials. "Mapto" works fine , you can also use addmaterialmapping() which will work too. For instance have a look the the other materials.cs files how to do the custom materials.
#16
(The engine will search for the texture files so be aware to never use duplicate names on art assets.)
If you make 1 material for each diffuse texture and use several diffuse textures on one DTS...the engine will load the files after it seeks them out!
...as simple as that.
Example from me:
[[this is from my brickstone texture folder and there is no need for the "mapto" command unless the basetexture's name is different from the texture needed.]]
//start
new Material(mbrickshort2)
{
baseTex[0] = "brickshort2";
bumpTex[0] = "./brickstonen/brickshort2n";
pixelSpecular[0] = true;
specular[0] = "1.0 1.0 1.0 1.0";
specularPower[0] = 32.0;
};
//end
Now I could do this to every texture file respectively and then use several diffuse maps on one DTS. The engine/scripts will find the texture and it's associated-material and load all.
...The ideas and concepts can become complex from this point, so I will stop here.
Also be aware that this idea is not the most optimized way of handling this issue BUT it works.
((I have not tested whether or not 'collapsing the mesh groups' to 'one mesh' has any difference on this 'using several materials' matter...but it is on my list of things to research.
Good luck.
12/05/2007 (6:38 am)
Actually, unless you modified the way the engine/scripts read and find things...you could make a texture directory to have the materials.cs files while leaving the shape file in a completely different location.(The engine will search for the texture files so be aware to never use duplicate names on art assets.)
If you make 1 material for each diffuse texture and use several diffuse textures on one DTS...the engine will load the files after it seeks them out!
...as simple as that.
Example from me:
[[this is from my brickstone texture folder and there is no need for the "mapto" command unless the basetexture's name is different from the texture needed.]]
//start
new Material(mbrickshort2)
{
baseTex[0] = "brickshort2";
bumpTex[0] = "./brickstonen/brickshort2n";
pixelSpecular[0] = true;
specular[0] = "1.0 1.0 1.0 1.0";
specularPower[0] = 32.0;
};
//end
Now I could do this to every texture file respectively and then use several diffuse maps on one DTS. The engine/scripts will find the texture and it's associated-material and load all.
...The ideas and concepts can become complex from this point, so I will stop here.
Also be aware that this idea is not the most optimized way of handling this issue BUT it works.
((I have not tested whether or not 'collapsing the mesh groups' to 'one mesh' has any difference on this 'using several materials' matter...but it is on my list of things to research.
Good luck.
#17
texel_render.rgb = tex2D( Map1, IN.Texcoord1 ) + tex2D( Map2, IN.Texcoord2 );
OUT.col = texel_render;
12/12/2007 (10:42 am)
You also can use multisub access in single shadertexel_render.rgb = tex2D( Map1, IN.Texcoord1 ) + tex2D( Map2, IN.Texcoord2 );
OUT.col = texel_render;
Torque 3D Owner Marc Dreamora Schaerer
Gayasoft
So what you can do is put the specular in a different rendering pass with a greyscale texture to handle it.
On your material: it looks nice but this should definitely be doable with a single texture created in an external application. Doing a 3 pass shader run for this is a serious waste of performance.