Sign in to follow this  

Calculating the Tangent Space in FarCry!!!

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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... ?

i guess we could help you better if u showed us your code...

Share this post


Link to post
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 this post


Link to post
Share on other sites
The problem is not the geometry, but your vertex/pixel shader.
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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this