geomipterrain and binormals/tangets

Hey there,

I’m trying to write a shader for a geomip-generated terrain. Good success so far, but now I want to add normal-mapping to it and need the binormals and tangents for each vertex. Geomip-terrain doesn’t seem to generate those - I’m getting all (0,0,0)-vectors for

float3 vtx_tangent0 : TANGENT,
float3 vtx_binormal0 : BINORMAL,

with my normalmap provided - or am I missing something here?

And if geomip-terrain doesn’t generate these vectors, should I calculate them manually? The only “built-in” way to get binormals and tangents seems to be with the egg-tools.

So, I’m pretty lost. I’d appreciate if somebody could point me in the right direction for getting normal-mapping to work on generated terrain. Thanks for any kind of suggestion!

I haven’t work with geomipmap terrain so I can’t really help you.

On my own terrain classes, I had to had the binormal by ‘hand’. It’s very costly, but since your only doing it at the start of the application.

The mathematical formula can be find anywhere, and it easier than it’s seems to create.

You can probably easily calculate it within a shader. Calculating the binormal and tangent of a terrain vertex is a lot easier than of a usual model, so I think you won’t need to do any calculation on CPU.

If you want to keep it CPU-side and avoid a geometry shader, I have code that calculates tangents/binormals for GeoMipTerrains – But it relies upon some other code that changes the behavior of the normal generation for GMTs, which is why I haven’t tried to get it committed yet.

If you’re interested I can post a patch. But it’s not difficult to calculate these on the fly in a shader, since GMT UVs are uniform. However, if you use the normal passed along with the vertex, it won’t work exactly as you expect…

Actually, I think you can do it without geometry shader too. The only thing you need to calculate is the Z component of the binormal and tangent vectors, and you can easily do that by using the normal vector.

Yeah, I feel a bit stupid about not really thinking about what I need the tangent/binormals for. BTW, for anyone as slow on the uptake as I am, I figured tangents and binormals boil down to

float3 tangent = float3(normal.x, normal.z, -normal.y);
float3 binormal = float3(normal.z, normal.y, -normal.x);

being perpendicular and unit vectors and all (I have to check that mathematically though, but common sense suggests it should be O.K.).

Yes, you don’t even technically need to use tangent space mapping – You can get away with object space, since your terrain isn’t going to be be sheared, scaled, or otherwise deformed. Or at least I assume so. :slight_smile: