Help with bump maps.

Hi, all. I’ve been playing around with the sample for bump maps, and I sort of understand most of the code related to applying the shader but I cannot seem to get a simple column to work with a bump map.

I created a simple rectangular column in Wings3d, applied the diffuse and bump map, exported it to a vrml and then ran the vrml2egg. When I open the egg file, it only has the diffuse texture. So I was going to try to add the alpha channel manually by referencing the abstractroom.egg file that is included in the sample.

I’m not getting anywhere with it, though. As soon as I start adding things to it, all I have is a white rectangle. Is there anyone that can walk me through altering an .egg file to include a bump map?

Thanks

It might help if you shared the .vrml and .egg files so we could see what’s going wrong.

Note that a model needs to have binormals and tangents generated for normal mapping to work. If your export does not include those, you can use -tbnauto or -tbnall on the vrml2egg command-line to generate appropriate binormals and tangents.

Yea, Wings3d export doesn’t include the binormals, tangents, or Rbga. I will give your suggestion a try.

Thanks.

First you need to add a entry and give it a name (any name - in this example it will be ‘my_normal_map’). It’s usually added at the top of the file:

<Texture> my_normal_map  {
}

You need to point where the texture (image) file is located. It’s best to use relative paths (relative to the egg file that is). The quotes are probably not needed if you don’t have spaces in the filename - but better safe then sorry. In this example I presume the texture file is named “normal_map42.png” and it’s in a dir named “Textures” that’s one level up in the directory tree then the model file (so if the full windows-style path to the model was C:\my_game\Data\Model\my_model.egg, then the texture would be in C:\my_game\Data\Textures\normal_map42.png):

<Texture> my_normal_map  {
 "../Textures/normal_map42.png"
}

Next you need to tell panda that the texture is a normal map and should be used as such:

<Texture> my_normal_map  {
 "../Textures/normal_map42.png"
<Scalar> envtype { normal }
}

Some extra options can be added so the texture is displayed as you want it to:

<Texture> my_normal_map  {
 "../Textures/normal_map42.png"
<Scalar> envtype { normal }
<Scalar> format { rgb }
<Scalar> wrapu { clamp }
<Scalar> wrapv { clamp }
<Scalar> minfilter { linear_mipmap_linear }
<Scalar> magfilter { linear }
}

Now you need to tell panda to actually use the texture. This may take a bit more time unless you use some batch find&replace shortcuts.

For each polygon (that you want the texture to be used) you need to add a reference to the normal map texture. So if your polygons look like this:

<Polygon> {
    <VertexRef> { 23 17 14 <Ref> { Box01.verts } }
}

You need to change them to look like this:

<Polygon> {
    <TRef> { my_normal_map }
    <VertexRef> { 23 17 14 <Ref> { Box01.verts } }
}

The polygons may also have additional textures referenced or colors, don’t delete them (unless you want to):

<Polygon> {
    <RGBA> { 1 1 1 1 }
    <TRef> { Tex1 }    
    <TRef> { some_other_tex } 
    <VertexRef> { 15 4 1 <Ref> { Box01.verts } }
  }

In practice you need to find " {" and replace it with something like " {\n { my_normal_map }". The newline (\n) is optional and the file should work even if it’s all in one line.

If at this point your model has no tangent and binormals, run “egg-trans -tbnall input.egg >output.egg”. If that fails (it shouldn’t!) you can change your shader so that it won’t need tangent and binormals: Normal mapping without tangent/binormal

Thank you both.

rdb got me headed in the right direction and I could get it to work if I added the main texture into my python code. I wanted, however, for both the main texture and the bump map to be in my egg files.

wezu got me the rest of the way with his examples.

Thanks, again.