[Solved] Bug in TangentBinormalGenerator (or light vector tangent space transformation)

I think there’s a bug in the TangentBinormalGenerator. It can be seen in the Material Editor using Lighting.j3md and setting NormalMap to this debug normal texture (2x2, all (0, 0, 1) vector). It looks like this:





See the little white half ring on top of the sphere? It’s because the light vector transformed by the TBN matrix and interpolated by “varying” is not correct.

Have you tried it with the tangent debug something amterial stuff (that one taht shows the hundreds of arrows) ?

how does it looks like on an actual sphere in the engine.

the TangentBinormalGenerator has been reworked numerous times and tested against complex uv layouts, and looked ok last time I checked.

Also note that if you generated your normal map with blender, you have to invert the green channel in order to make it look correct in JME.

If you generated it with another source you might want to play with this setting (inverting red, green, blue channels) until you get a correct result

I gave the hint with the Material Editor because it’s easiest for others to reproduce it. Below screen shots are from the engine with … wait for it … Green Lantern’s Light! :smiley:



32 segments sphere:





256 segments sphere:





I’m quite sure my normal map is correct. It’s “GIMPed”. 3 channels (128, 128, 255) which is roughly (0, 0, 1). See here:





Popular textures like “BrickWall_normal.jpg” have the same color on flat areas. I also tested (127, 127, 255) or a 256x256 texture with that color.

I think that would explain the lighting behavior I was seeing when I used textured spheres. Sadly I can’t produce anything now since I’ve switched to procedural textures. :confused:

@EmpirePhoenix: I think you mean TestTangentGen.java. Everything looks ok there. Probably my topic is wrong. All I can say is that the light vector is wrong in those light areas on top of the sphere after transforming it with the TBN matrix AND interpolating it by “varying” AND normalizing it in the fragment shader. If it’s not normalized, the sphere looks ok, but the intensity / attenuation is wrong (especially with point lights).

It’s not a question of being correct or not, really, normal maps are baked different ways depending on the software that generates it.

I’m not sure the brick wall normal map is “correct” in the JME sense neither. It was generated a long time ago, and the lighting system changed since then.

Here a screenie with “TangentBinormalGenerator.genTbnLines()”:





The vectors look ok but the light ring is there. The normalized light vector in tangent space in the fragment shader is wrong in those areas. Might be a rounding error or interpolation problem. I don’t know. It’s easy to reproduce. Just wanted to let you know. I found it in my shader and it gave me sleepless nights, but then I saw it happens in the reference shader “Lighting.j3md”, too. So I’ll postpone to find a solution for this.

Did you notice this problem on a “real” model?

It could be due to the sphere UVs…

@Momoko_Fan what do you think? problem in the TBG or in the shader?

I think you’re right. The problem seems to be the sphere of fear. The seam has double vertices and thus double and different TBN vectors.







I’ll try to make a sphere in blender, just one sec…



…hours later… I think I’m too stupid to get the blender imported sphere (.obj file) lit. I’m assigning the same material in code. It shows lit in jME Scene Explorer.

I know that the build-in jME3 sphere has rather crappy UVs especially in the poles. Blender somewhat has a similar issue, especially since the UVs become very stretched at the poles, you may need to UV map them separately for it to work.

1 Like

I finally managed to create a decent uv mapped sphere in blender (see here and here). After finding a version of the ogre xml exporter and blender that fit together and produce output that jme sdk can convert to j3o, the result looks like this:







The visible seam is probably because I created the sphere using warp. So the problem was indeed com.jme3.scene.shape.Sphere. Sorry for the confusion and thanks for replying.

2 Likes

good!

You could try an icososphere in blender?

Well, at least now we are certain the Sphere is screwed up. :smiley:

1 Like