Issue with the normal map (is there a way automate binormal/tangent generation?)

I have been trying to test bump lighting recently, and I have read around that you need a normal map to do this, and with a couple of tricks in blender 3d, I have do so, but when I apply it to my scene, it’s like if the light is turned off for the mesh.

Now, I have read around here, that you need something called a binormal and tangent to get it fully working, most of the solutions say bake it in blender 3d, but I also do my level designing in blender3d, so I am always updating the egg file incrementally.

I was wondering if there was a more automated solution to generate those in runtime with code? I seen some examples with procedural generation, I also heard of “recomputeTangentBinormal” and wonder if that is a automated process, but I don’t know how to use it or it’s syntax.

Anyway, thanks to anyone willing to help.

How are you exporting your model from Blender? If you’re using YABEE, then there should be a drop-down labeled “TBS generation”; selecting something other than “No” from this drop-down should prompt YABEE to generate tangent- and binormal- vectors for your geometry.

heh heh, I don’t know, it’s been since 2018 since I installed blender, but yeah I see it, I will check if this works, but I was also wondering if there is a more automated process or is it strictly baking from blender?

I mean, I’m not sure how much automated you can get than “select one option in the exporter and let it do its thing”… ^^;

I mean, you can write code to do this in your program, I daresay, but that seems like a more difficult approach to me!

1 Like

Okay it works and it is relatively easy (I will mark your post as the solution), though I still want to try from code because I keep making incremental changes to the egg file( I do my level editing though blender), thus it is a extra step, yes heh heh, it is laziness on my part.

If you set the option that you want in YABEE, then exit the exportation screen and save your Blender-file, you should find that the option remains set when you reload. Thus you have only to set it once! :slight_smile:

1 Like

okay, it does, thanks, you solved the complete thread then.


For anyone else wondering, I used “Blender” TBS generation not “Panda”, and that worked for me.

1 Like

so funny story, at the time of making this thread, I was already researching how apply binormal and tangent though code, and the article I was on when I made this thread turned out to have 95% of the solution how to code the light bumping effect in.

Even though this thread is solved for me, for the sake for others and curiosity’s sake I will post the code version.

from panda3d.egg import EggData, loadEggData
from panda3d.core import GlobPattern, Filename
                    egg = EggData()
                    egg.read(Filename("filepath/eggfile.egg"))
                    egg.recomputeTangentBinormal(GlobPattern(""))
                    egg.removeUnusedVertices(GlobPattern(""))
                    self.scene = NodePath(loadEggData(egg))
                    self.sceneTexture = loader.loadTexture("filepath/texture.png")
                    tsnormal = TextureStage("tsnormal")
                    normal = loader.loadTexture("filepath/normalmap.png")
                    tsnormal.setMode(TextureStage.MNormal)
                    self.scene.setTexture(self.sceneTexture)
                    self.scene.setTexture(tsnormal, normal)

Credit is given where it’s due (for the above code).


I have also included my method of generating normal maps, that I leaned it from this youtube video


But for those having trouble with the video, I have included my blender3d file here.
normalmap.blend (530.8 KB)
Where I have done all the work in the video, all you have to do is a open (or create) a new image from UV editor window on the right, then in the tab right of of the UV editor, change the “Image Texture” bar to “Displace-Texture”.

Then scroll down the image section and from that image icon change the image to your newly loaded image, and you will see a normal map of your image, click the camera icon in the 2nd bottommost bar of the screen which will open a new window.

Then in that window hit the Image tab then save as image, from here you will need to crop and resize the image on your own to match the source image the map was based on.

1 Like