Game Development Community

Normal Maps?

by GI_JOEJK · in Technical Issues · 08/24/2008 (3:05 pm) · 19 replies

I did a search on implementing Normal maps and Secular textures for TEA meshes, but didn't find what I was looking for. So here is my question;

How do I get my Normal maps and Specular to show up in game? Do I need to assign them to the model in the 3D modeling software? Or do I need to set it up in some script or code? Also, can someone tell me what naming conventions to use? I came across a few threads on the subject but it was kind of confusing.

Many thanks!

#1
08/24/2008 (3:50 pm)
There is no naming convention for the filename of a normal map, it just has to be linked through the materials code. Each folder with data/textures in it which should be normal mapped (for interiors, shapes, players, etc...) should contain a materials.cs file with all of the details.

This might help you. Also take a look at how it was done in the demos. Take a look at the boombot folder ("scriptsAndAssets/data/shapes/players/BoomBot") to see a good example of mapping each texture and setting up the materials in the materials.cs. To see how it's done for Interiors (it's simple and similar) look in the interiors folder, for a subFolder called "test".
#2
08/24/2008 (9:52 pm)
OK I took a look at the examples you mentioned. But I am still confused... First, modeling and texturing are not an issue for me. I also create my own normal maps. But what am trying to do here is to learn how to set up the materials.cs file for a .dts mesh. So far I haven't been able to assign a normal map to a model. Instead the model turns orange with test saying that there is no material.

I found this little script; http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=12241

What I need is a short-to-the-point, step-by-step materials.cs tutorial. Specifically for static meshes such as buildings, rocks and foliage.

Thanks
#3
08/25/2008 (2:02 am)
Hey i have the same problem, except i can get the diffuse texture on fine in the game, just not the normal map even after changing the code. I'm going to post the exact steps i take in a little while, hopefully someone can help us.
#4
08/25/2008 (3:04 am)
Okay I'm obviously doing something wrong here, can someone experienced please quickly look over these screenshots to see what I'm screwing up. I tried searching the forums and TDN but couldn't find an answer as to why normal maps were not working on my models. Below is what im doing to create a simple cabinet.

Step 1: I put the base texture and normal map in a temp folder on the desktop like below.

i397.photobucket.com/albums/pp58/cyn9431/1.jpg

Step 2: I apply the diffuse material and normal map to the diffuse and bump map slot respectively in the 3dsmax material editor and then apply it to a cube with a simple uvw map unwrap to one side.

i397.photobucket.com/albums/pp58/cyn9431/2.jpg

Step 3: I make the bounding box for the static mesh.

i397.photobucket.com/albums/pp58/cyn9431/3.jpg

Step 4: I embed the cabinet and export whole shape to the same temporary folder that holds my textures on the desktop.

i397.photobucket.com/albums/pp58/cyn9431/4.jpg

Step 5: I copy all these files into the interior folder in the TGEA Barricade folder.

i397.photobucket.com/albums/pp58/cyn9431/5.jpg

Step 6: I open the material.cs file which is in the same interior folder and write a new method like in the image below and save the file.

i397.photobucket.com/albums/pp58/cyn9431/6.jpg

Step 7:I open TGEA and import the model i just created but no NORMAL MAP is working on it!!!! :(

i397.photobucket.com/albums/pp58/cyn9431/7.jpg

Step 8: I compare it to my realtime viewport render with a direct x shader that shows normal maps in the 3dsmax viewport and cry.

i397.photobucket.com/albums/pp58/cyn9431/8.jpg

Lol what am i doing wrong??? Anyone?

Regards
Rob
#5
08/25/2008 (3:09 am)
Sorry i just realized the image size is ridiculously annoying with the side scrolling thing all the way at the bottom but im way too tired to reduce the size of them.
#6
08/25/2008 (3:20 am)
This may be nothing, but try taking out the "mapto" in the meterial.cs for that texture and see what happens.
Neil
#7
08/25/2008 (3:50 am)
Thanks mate, worked like a charm.


new Material(cabinettest)
{

baseTex[0] = "cabinets01a";
bumpTex[0] = "cabinets01a_normal";
pixelSpecular[0] = true;
specular[0] = "1 1 1 0.1";
specularPower[0] = 32;

};

While changing this code, i also realized that i could leave the mapto statement in there but it has to mapto the base texture and not the model like i had it before. But mapTo = "cabinets01a"; is not necessary like you said.

I'm having a weird problem with the light reflection off the model now though, how come there are white lines where it should just be shiny, see the pic. My specular settings are set at
specular[0] = "1 1 1 0.1";
specularPower[0] = 32;

Does it have something to do with this?


i397.photobucket.com/albums/pp58/cyn9431/9.jpg
#8
08/25/2008 (4:12 am)
Sometimes the normal map resolution can have an effect, but specular is how shiny the material is and power is how strong the highlight is, like spec level and gloss in max. try lowering the specular[0]'s to 0.8 or something, play with them (0.0-1.0) and the power to lower numbers and see what happens as the values you have are at metal shiny level. just play to get a point of reference.

hope that helps

Neil.
#9
08/25/2008 (8:47 am)
The pixel specular in TGEA is a real pain in the ass to deal with because you don't just have a global power value, but also a global color value and then the per pixel specular map data!

specular[0] = "1 1 1 0.1";

This value essentially controls the specular colour that will be displayed in-game on your model. Generally this colour will be some sort of shade of grey for most material types, but there are some cases, say a red rubber ball, where you will want it to be another colour.

specularPower[0] = 32;

Specular Power controls how strong the specular will be.

Lastly and most importantly there is the per pixel specular (held in the alpha channel of your Diffuse texture)

baseTex[0] = "cabinets01a";

This is the key to the kingdom if you want good looking specular results. The shader reads the greyscale information from the alpha channel (which is your specular bitmap) and uses it to control just how much of the previous settings you defined will be affected on a particular pixel.

Manipulating this bitmap will allow you to get much better results that more accurately represent the type of material that the subject is (ie. rubber, metal, glass, plastic, etc.). Generally this is going to take a lot of tweaking on your part to get the right type of settings going, use a lot of real world samples to compare your results to. Of course it should be noted for best results you would actually have a shader defined for each of those types of models.
#10
08/25/2008 (12:13 pm)
I have a few questions:

1. After I set up the materials.cs document, do I "save" it or do I need to "compile" it?


new Material(cube)
{

baseTex[0] = "Brick005_D";
bumpTex[0] = "Brick005_N";
pixelSpecular[0] = true;
specular[0] = "1 1 1 0.1";
specularPower[0] = 32;

};


2. This is how my project is setup currently, and where my cube test model and textures are located. Is this correct?

C:\Torque\TGEA_1_7_1\Projects\My_Demo\game\scriptsAndAssets\data\shapes\cube

3. Does it matter what 3D program I use? Is there a specific way to set up the texture/shader in Maya to get the normal map to work? Currently I am using the "bump mapping" section in the Common Materials Attribute.

4. Currently I'm placing the specular texture into the alpha channel in the normal map, is this correct? Or should I put into the diffuse texture? Note, that if I do put the spec into the diffuse, then my cube becomes semi transparent.



Thank you
#11
08/25/2008 (1:00 pm)
1. Just save it.

2. It really shouldn't matter as long as materials.cs, each texutre (normal, diffuse, etc...) and the model are in the same folder.

3. No idea about 3d modelers, I'm awful with them.

4. I've read that many manuals say to place the specular as an alpha into the normal map, but have also read from other Torque users that this information is wrong and should be applied to the diffuse. I don't know why it is showing up as transparent however.

The problem you had earlier, with mapTo not working is because you are setting mapTo to your model name, and not the name of the texture. It would work if you used:
mapTo = "cabinets01a";
But if baseTex is the same texture as mapTo, you can skip that line. You may also want to turn down your specularity unless that is some extremely polished wood. Try specular[0] = "0.1 0.1 0.1 0.1"; for a very light specular reflection.
#12
08/25/2008 (1:54 pm)
Another question.

Do I need to set up the lighting for the scene in a specific way, in order to see the normal map and the specular? Or can I just use the main demo level?

Thank you
#13
08/25/2008 (2:09 pm)
@GI_JOEJK

3. The only thing TGEA reads when it loads the DTS is the name of the bitmap defined in your diffuse slot, all of the other data that you can choose to setup in your 3D application material is ignored by the engine. The engine uses the diffuse bitmap name to find the correct matial datablock (which has the shader, specular, normal and other data defined in it) to display the information on your DTS shape.

4. Specular for Torque is always expected to be stored in the diffuse texture not the normal. If its going transparent then make certain that you aren't telling the material to go transparent, because it shouldn't be doing this unless you have specified it to.

@Morrock

Actually that would give you a near black specular lighting since that value affects the color and not the strength of the specular. But as I said this is also multiplied by the data in the per pixel specular as well, so until he gets that working properly any other changes wont really do much of anything.
#14
08/25/2008 (2:49 pm)
@L Foster

Actually if I create a Png texture with an alpha (using Superpng plugin), I do not need to specify the alpha. It just works without a materials.cs.

Thus, if I put a specular image in the diffuse alpha, and save it as a Png, my model will have transparencies instead of specular... Should I use a Targa instead?
#15
08/25/2008 (8:15 pm)
Here are some of the combinations I have tried with no success. I know this is a simple thing to do and that the solution is looking right at me, but.......

i438.photobucket.com/albums/qq102/mad_max007/HELP.jpg?t=1219713670
#16
08/26/2008 (7:59 am)
@GI_JOEJK

Just out of curiousity, are you using the old super_png plugin that actually saved alpha channel data, or the new one (the one on the devs site) which basicly uses the alpha to knock out pixel data? Its tough to tell the difference unless you do an "Open As" in Photoshop, choose superPNG as your file type and load the file.

Logan
#17
08/26/2008 (10:17 am)
I am using the old super_png plugin.
#18
08/27/2008 (8:35 am)
That is bizzare to say the least. Congratuations you have managed to do something I honestly have never seen done before :)

I guess I would say in the mean time try out DDS or JNG. Also if you are willing, I would love to see all of your scene/source files to help you zero out what's going on so that it won't happen to you again in the figure. Let me know if you are intersted and I will contact you.
#19
08/27/2008 (11:06 am)
If this is TGEA 1.7.1, I've found that you need to add
translucent = false;
to a material if your texture has an alpha channel.