I had some issues with normalmapping, which I finally found a fix for: I had to calculate the binormal as the cross-product between tangent and normal, then it worked correctly. However, I don’t understand why. I’m using blend2bam, but can’t find any information on what it generates. Does it generate tangents, but not binormals?
Broken, normal-maps are used wrongly on some faces:
This is how the glTF format works (blend2bam uses glTF under the hood), it omits the bitangent and it is supposed to be constructed in the shader, with the w component indicating the direction. The way to reconstruct it is as follows:
Ooooh, thanks! Could this be added to the manual, maybe?
Or at least a function that lets you check (at runtime) whether a certain model has bitangents? It was quite difficult to figure this out, not least because when accessing p3d_Binormal in the shader there’s no error, it just contains nonsense, it seams…
Hmm, where in the manual do you think this should go?
Vertex columns that are not present contain (0, 0, 0, 1). I suppose that an error might make sense in this case, but I think it would be even better if Panda generated the column on the fly as needed by a shader.
The only place I found info on the Binormal was in the List of GLSL Shader inputs. So maybe there? It already says “if present”, but doesn’t go into detail.
Automatic generation would be nice, yes, although I’m not sure if everyone would want to use the variabl in the same way? Maybe someone would want the Binormals in a different space, maybe someone would want to animate them…? An error might be safer, maybe with a quick hint on how to generate them if required. Or there could be a flag on a per-model basis (“autogenerate_binormals”)?
Hmm, but the behaviour is specific to glTF models. That doesn’t feel like it belongs on that page. Maybe we need a page about loading glTF models. As it happens I am in the process of rewriting the model import section in the manual, maybe I’ll be able to fit it in somewhere there.
EDIT: maybe it makes sense after all. I think I’ll go and add it to the shader inputs page.
The only models I know of that use this scheme are those loaded by panda3d-gltf, so those models could be tagged in some way indicating that they use this scheme.