# Calculating the Tangent Space in FarCry!!!

This topic is 3972 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I was calculating the tangent space with a simple algorithm that described in "3D Game Engine Programming" book by Stefan Zerbst, and it was useful until i found a large difference between the results on my code and the results on far cry, The shape was planar but has a complex triangulation (view). I tested the specular in my code but it wasn't good enough (view) (view2). So i exported the object into the FarCry geometry format (CGF), and viewed the results which was amazing (view), after that i ran the FarCry within "PIX for Windows" (a program that enable me to spy on the vertex and index buffers...), pix gave me a surprising results about the tangent space information... I was expecting something like: -1.000 0.000 0.000------------- 0.000 0.000 -1.000------------- 0.000 1.000 0.000 for all vertices, because the object is planar and the uv map is also planar, but the result was: -1.000 0.000 0.000------------- 0.000 0.053 -0.999------------- 0.000 0.999 0.053 -1.000 -0.000 -0.000------------- 0.000 -0.320 -0.947------------- 0.000 0.947 -0.320 -1.000 0.000 -0.000------------- 0.000 -0.428 -0.904------------- 0.000 0.904 -0.428 -1.000 0.000 -0.000------------- 0.000 -0.428 -0.904------------- 0.000 0.904 -0.428 -1.000 -0.000 -0.000------------- 0.000 -0.320 -0.947------------- 0.000 0.947 -0.320 -1.000 0.000 -0.000------------- 0.000 -0.428 -0.904------------- 0.000 0.904 -0.428 -1.000 -0.000 0.000------------- -0.000 -0.670 0.742------------- -0.000 -0.742 -0.670 -1.000 -0.000 0.000------------- 0.000 -0.603 0.798------------- -0.000 -0.798 -0.603 Of course the difference in the first line is not notable but on the the other lines the result was so far from other programs give (i tested it on a big mass of programs). I tried to use the tangent space algorithm which is distributed within the CryMod SDK, and the result was almost the same of my first results... So do you know anything about the algorithm that used in the real FarCry???!!!!

##### Share on other sites
Maybe this is a deep technical issue, but any response from you is very useful to me...
So don't be stingy... I'm waiting for you ;-)

##### Share on other sites
why are u hung up on farcry?

instead look at your own code and figure out what ur doing wrong... try rendering the tangents as color for each vertex and see what your doing... and for troubleshooting u can just set the tangents in the vertex shader manually since the object is planar...

there is no "special algorithm" to calculate tangents as far as im aware... and there are no "special" tangents either...

##### Share on other sites
I tried to beleive that, but the model as you see is planar, so the normals are all pointing upwards.
And the UVs are projected by the uvwmap modifier inside 3dsmax as (plane) and I left the plane as is... so the tangents are DEFINITELY parallel, and also the binormals... and as I said I expected 0,0,1 and 0,1,0 vectors for tangents and binormals on all vertices... and as you see far cry had given me very strange results, and I said that the problem was the same of my own in FX Composer, which proves my thoughts... and finally I hardcoded my expected results into the tangents and binormals in my shader, but the result was the same....

So tangent calculation and my shader was completely right (I inspired the shader from far cry's one just to compare)...

What can I do ???????

##### Share on other sites
well if you are convinced that your tangent calculations are right then whats the problem?

you pretty much saying that your doing it right but its wrong... ?

##### Share on other sites
You maybe want to check out the article "Triangle Mesh Tangent Space Calculation" by Martin Mittring (Lead Graphics Programmer at Crytek) in ShaderX 4. IIRC he exactly describes how they did it in the CryEngine.

##### Share on other sites
Thank you IndyJones, I didn't know that he wrote something like this, it will be useful, but only if I know how to get this article (or that book).

##### Share on other sites
The only thing I found that is freely available is a presentation here. Don't know if it goes as deep into detail as the article in ShaderX does ...

##### Share on other sites
I can tell by your second screenshot that you are "incorrectly" interpolating some parameter across your triangle, when it should be recalculated per pixel in the pixel shader. Your artifacts are really "mach bands" caused by gourard shading.

enjoy

1. 1
Rutin
26
2. 2
3. 3
4. 4
5. 5

• 9
• 11
• 10
• 13
• 20
• ### Forum Statistics

• Total Topics
632948
• Total Posts
3009390
• ### Who's Online (See full list)

There are no registered users currently online

×