Jump to content
  • Advertisement
Sign in to follow this  
#Include Graphics

geting tangent space stuff

This topic is 1418 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

Hello everyone,

 

I am struggling for a few days with this and I think am really in need of some help.

 

I am using deferred rendering, in that step i have this data:

* normals in view space

* positions

* other non 3D things, sure not valuable for this.

 

I need a way of getting tangent space (view and light vector) from the few stuff i have in that step and I really want to avoid having to pass tangents through the g-buffer. Even compacted.

 

I got some bad results trying to get tangents and bitangents from the normal:

 

from badBump1.png to BadBump2.png, yeah horrible, isnt it? my goal is at least reaching niceBump.png.

 

I have searched for long in this and other forums but not reaching to a clear way of doing it and I would really appreciate any direction you can drive me in through to achieve this, comments included.

 

My current unfortunately wrong code to get tangent and bitangent is:

float3 tangent;

   float3 c1;
   float3 c2;
   
   if( psInStruct.bump_map.x > 0.5f )
   {
      if( psInStruct.bump_map.y > 0.5f )
      {
         tangent = cross(normal, float3(0, -1, 1));
      }
      else
      {
         tangent = cross(normal, float3(0, 1, -1));
      }
   }
   else
   {
      if( psInStruct.bump_map.y > 0.5f )
      {
         tangent = cross(normal, float3(0, -1, -1));
      }
      else
      {
         tangent = cross(normal, float3(0, 1, 1));
      }
   }

   tangent = normalize(tangent);
   
   float3 bitangent = cross(normal, tangent);

As you can see i am a walking dreamer hehe...maybe is it better to be done at any other step?

 

So many thanks in advance to all the people sensibilized biggrin.png

 

Cheers

 

PS: Sorry for my english and for the missing "t" at geting tongue.png

Edited by #Include Graphics

Share this post


Link to post
Share on other sites
Advertisement

Transform the normal from the tangent space to the view space and all your problems are solved - no need to work with the tangent space when doing lighting calculations. Since you are already storing the normal in the G-buffer, it is just a question of using a common space for all the normals (ie. view space or some use world space). 

 

Cheers!

 

[edit] I guess I didn't understand why you need to use the tangent space

Edited by kauna

Share this post


Link to post
Share on other sites

Thank you so much for answering :D

 


I guess I didn't understand why you need to use the tangent space

 

I need the tangent space to transform the view direction and the light vector into texture object space because I am using bump. sad.png

 

 

 


Transform the normal from the tangent space to the view space and all your problems are solved - no need to work with the tangent space when doing lighting calculations. Since you are already storing the normal in the G-buffer, it is just a question of using a common space for all the normals (ie. view space or some use world space).

 

I noticed that this operation is highly cost and it is better to do the reversed one.

Edited by #Include Graphics

Share this post


Link to post
Share on other sites

Well, if typically you'd use a matrix to transform from object space to view space, with the normal map, you'll add one more matrix transformation. 

 

Something along these lines:

 

float3 GetNormal(SHADER_OUTPUT i)
{
float3 Normal = 2.0f * (texnormal.Sample(s_linear,i.vTex.xy) - 0.5f);
float3x3 mTBN = float3x3(i.Tangent, i.BiTangent ,i.Normal);
Normal = mul(Normal,mTBN);
 
return Normal;
} 
 
So, the cost is the same whether you do the lighting in the view space or tangent space since you'll need to transform something. The code assumes that the tangents and bitangents and the normal are transformed by the view and the world matrices (can be done in the vertex shader). 
 
If you don't have tangents / bitangents available then maybe you could look in to this : http://www.thetenthplanet.de/archives/1180

Share this post


Link to post
Share on other sites

Thank you so much Kauna!, I must have being very tired of mulling over the same...that my eyes were closed to that option...

 

Havent tested yet what you purposed but my initial feeling is that will work for me!

 

Thank you really so much :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!