Custom Geometry and bump mapping BTS space



I was playing around with the parallax/Bump mapping sample (1.9.4) and all was great, but then i tried loading a model i created myself (with GeomVertexWriters and so on), and the effect didn’t work anymore.

For this, i used a custom format to insert tangent and binormal in the geom, like this:

**array = GeomVertexArrayFormat()**
**array.addColumn('vertex', 3, Geom.NTFloat32, Geom.CPoint)**
**array.addColumn("texcoord", 2, Geom.NTFloat32, Geom.CTexcoord)**
**array.addColumn('tangent', 3, Geom.NTFloat32, Geom.CVector)**
**array.addColumn('binormal', 3, Geom.NTFloat32, Geom.CVector)**
**array.addColumn('normal', 3, Geom.NTFloat32, Geom.CNormal)**
**format = GeomVertexFormat()**
**format = GeomVertexFormat.registerFormat(format)**

When trying to read the egg file i got with bamtoegg.exe, binormal and tangent weren’t registered.
Using egg-trans allowed me to recompute BT vectors and adding them to the egg (parallax/bump mapping working fine in this case), but i’m looking for a way to do this without translating the file to an egg.

Is there a way to do such a thing? is Geom.CVector the correct format for tangent/binormal? is there specific names to use so that the vectors get used in the per-Pixel lighting shader?


Well, the format settings look correct. However, how exactly are you filling in this data? Perhaps the way you are calculating these vectors and writing them with the GeomVertexWriter is not correct. Sharing more code would be useful.


Thank you for your reply. I checked on the normal/tangent of the egg-trans and they indeed differ from mine: i used the normal of the triangles for each vertex that was part of it to compute binormal/tangent, whereas the cxx program seems to compute it for each point individually.

I checked on the GeomVertexWriter, and you were right: one of them wasn’t named correctly. Anyway, i used the usual way:

vdata = GeomVertexData(‘Data’, format, Geom.UHDynamic)

vertex = GeomVertexWriter( vdata, ‘vertex’ )
texcoord = GeomVertexWriter( vdata, ‘texcoord’)
normal = GeomVertexWriter( vdata, ‘normal’ )
binormal = GeomVertexWriter( vdata, ‘binormal’ )
tangent = GeomVertexWriter( vdata, ‘tangent’)


Seems to work now! (the models appeared unlighten with setShaderAuto beforehand, which is no longer the case)

PS: binormal and tangent were computed in a ‘dirty’ way mentioned above (haven’t had time to understand everything there is to understand on the topic, apparently one can use the texcoords in the calculus, but since i couldn’t locate the shader in the source code, i went the easy way):
normal is computed as the cross between two vectors building each triangle, and binormal as(normal[0], normal[2], -normal[1]), tangent as (normal[2], normal[1], -normal[0])
I guess i could use the eggtrans method to achieve “smooth” shading/bumping, but right now i’m just happy it works!

I could post more code, but i think it would be a waste of time, since most of it is a raw copy of the samples…
Thanks again for your quick reply!


Glad it seems to work now!

The binormal and tangent are technically intended to align along the U and V directions of the texture coordinates, but I don’t know how much this matters in practice.