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
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!
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
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.