TBN basis for normal mapping

aik6980

06-02-2008 19:55:01

hi,

I'm trying implement the bump mapping onto the terrain.
Is there anyway that i can calculate Tangent and binormal, then add them into OGRE vertex's stream?
I'm looking at the source code, and still have no idea how to add more component onto the OGRE's vertex structure

Any help will be very appreciated =)

Thanks,
Aik. :D

CABAListic

06-02-2008 20:14:39

ETM only generates normals (if requested) for the terrain. Tangents and binormals are not supported right now, and I'm not even sure if they would make sense on a per-vertex basis. Seeing as how LOD interferes with with their values, you'd probably need to create a texture for tangents and binormals so that you can actually get a result which looks good independent of the current level of detail.
Even so, you'd currently have to do the calculations yourself.

Nauk

06-02-2008 20:26:30

That would explain why no matter what I try I get nothing to show up :)

aik6980

06-02-2008 21:15:14

thanks,

I just want to ask, where i can change the vertex format in order to add more information.

Currently, I'm looking at "ETTile.h" which I think I might be able to start from here.
Do you think the LoD gonna mess it up?

If I have any further information, I will call

Thanks,
Aik.

CABAListic

06-02-2008 22:11:51

ETTile.cpp contains the code to create the actual vertex buffers, you'd have to extend it. But yes, LOD will mess up the results because when LOD changes, then there are fewer vertices displayed and therefore the interpolation of the tangents, binormals and normals will change. This will change the result you get, so for a decent, LOD independent result you will have to use a normal map etc.

aik6980

06-02-2008 22:39:13

thanks for your response,

I'm a bit worried about LoD as well. Not only the Normal mapping problem, but also my project is going to have 4 cameras split-screen.

about this function

mTerrainMgr->setLODErrorMargin(2, OgreManager.GetCamera()->getViewport()->getActualHeight());


seem like LoD can mess up the detail on other cameras view =(.
How about average the height from all of my cameras?

is it ok to turn LoD off? How big is the effect to the framerate?
My project is going to be 4-players action shooter, and framerate is pretty much our first priority. =)
I still try to modify ETile in order to add the TBN info.

thanks for your help.
Aik.

CABAListic

06-02-2008 22:45:04

Depends on how big your terrain is. You will definitely notice a drop in framerate when deactivating LOD.
Different cameras should not be that much of a problem. LOD is determined for the current camera which renders a frame. You will only get problems if a camera has a considerably smaller viewport than the others, in which case you might need to reduce the pixel error margin.

Actually, for a shooter type game, LOD is not the ideal solution. You would profit more from horizon occlusion culling so that terrain patches and other objects behind mountains are not rendered. But this is difficult to implement and requires a dedicated scene manager; it's not doable in ETM directly.

aik6980

06-02-2008 23:59:51

thank you very much,
pretty much working right now, basically.



didn't try with the LoD yet.


cheers,
Aik.

Nauk

13-02-2008 09:20:34

Looking good! 8) So how did you do it? You (or anyone else) would make a simple troll very happy if you could share some insight for starters on the basics:

- Can this solely be done with a shader or do you have to calculate those Tangents in C++?

- Once you got the Tangents for all vertices can you "simply" apply ogres sample normalmapping shaders?

aik6980

14-02-2008 01:33:41

Thanks for interested in my work.

Yes, the TBN basis have been calculated in C++, which is fairly simple once you already knew the vertex's normals.

Here's some snippet from my function

void TerrainInfo::getTBBasisAt(Ogre::Vector3* tangentVec, Ogre::Vector3* binormalVec,
float x, float z) const
{
int flip = 1;
Vector3 here (x, getHeightAt(x, z), z);
Vector3 left (x-1, getHeightAt(x-1, z), z);
Vector3 down (x, getHeightAt(x, z+1), z+1);
if (left.x < 0.0)
{
flip *= -1;
left = Vector3(x+1, getHeightAt(x+1, z), z);
}
if (down.z >= mOffset.z + mScale.z*(mHeight-1))
{
flip *= -1;
down = Vector3(x, getHeightAt(x, z-1), z-1);
}
left -= here;
down -= here;

*tangentVec = flip * left;
*binormalVec = flip * down;
tangentVec->normalise();
binormalVec->normalise();
}


then you need to modify OGRE's VBO in order to make it fit with the new components (TANGENT and BINORMAL)

After this, just turn on dynamic lighting then use any shader you like =)

This is the latest screenshot of my project, which I used paralax mapping and detailed textures blending,

aik6980

14-02-2008 01:39:56

I still got some problem about the texture sampling.

I already turned off the LOD function in the TerrainMgr, but seems like OGRE still try to do LOD on my texture.
This problem makes each chunk of the terrain not connected smoothly.



you can see the problem on the top left and right of the terrain?
Any suggestion? :?:

It disappears when you fly close enough to those chunks.
Anyway that we can turn off OGRE texture's LOD? in material script or ..?

thanks
Aik

CABAListic

14-02-2008 05:03:58

Material LOD is not supported by ETM, therefore cannot apply here. The only texture LOD that Ogre would do is mipmapping - are your mipmaps screwed up? Other than that, I have no immediate insight...

Nauk

14-02-2008 19:08:31

Thanks for sharing Aik :) Thats a good pointer into the right direction, looking forward to try it!

SongOfTheWeave

14-02-2008 22:38:03

you can see the problem on the top left and right of the terrain?
Any suggestion? :?:

It disappears when you fly close enough to those chunks.
Anyway that we can turn off OGRE texture's LOD? in material script or ..?

thanks
Aik


Do you provide techniques for different LODs in your material script? If so, I suppose the answer would be to either remove them or modify when they are used.

At a shallow angle it would be fine to use that LOD at that distance, but when you're looking down on it it isn't...

aik6980

16-02-2008 13:26:49

I believe i didn't mention any texture LOD into my material.
I also test by cutting off the fallback technique which still no use.


currently, I cover that glitch by linear fog at distant :oops: