Sign in to follow this  

Pre calculating bi-tangents

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

Currently, in my projects, I pass the position, normal, tangent and texture UV of each vertex to the shaders, and then calculate the bi tangent in the pixel shader at runtime.
Is it faster to pre-calculate the bi-tangent of each vertex when loading the mesh instead of doing it in pixel shader every frame?
Or should I try both methods and see which is faster? Because the way I'm currently doing it, I dont have to pass so much information to the GPU which might be faster right?

Share this post


Link to post
Share on other sites
It depends: Is the mesh dynamic, so that it is passed once per frame, or else is it static and only loaded once at all? Is the vertex layout cache friendly, e.g. does a single vertex fit into a multiple of 32 bytes? Is the computation a "simple" cross-product or is there some unpacking required before? Is the vertex cache used nicely, so that the GPU doesn't need to wait too much on the VRAM? ...

I think it is best to try both ways. Even then you have checked on a single configuration only, but perhaps the qualitative result holds for other configurations. too. Just my 2 Cents.

Share this post


Link to post
Share on other sites
First you don't need to calculate it in the fragment shader. Calculate it in the vertex shader instead.
As for your question, that depends. If your program uses a lot of memory bandwidth then calculating on the gpu will be faster.
And if it is gpu bound then offloading it from the gpu will help, but really you need to profile your application to be sure.

Share this post


Link to post
Share on other sites
[quote name='haegarr' timestamp='1310225546' post='4833101']
It depends: Is the mesh dynamic, so that it is passed once per frame, or else is it static and only loaded once at all?
[/quote]
The mesh is static.

[quote name='haegarr' timestamp='1310225546' post='4833101']
Is the vertex layout cache friendly, e.g. does a single vertex fit into a multiple of 32 bytes?
[/quote]
A single vertex uses 44 bytes. So If I added the bi-tangent it would use 56 bytes.

[quote name='haegarr' timestamp='1310225546' post='4833101']
Is the computation a "simple" cross-product or is there some unpacking required before?
[/quote]
Just a simple cross-product.

[quote name='haegarr' timestamp='1310225546' post='4833101']
Is the vertex cache used nicely, so that the GPU doesn't need to wait too much on the VRAM?
[/quote]
What does that mean?

Is this related to the memory bus? The vertex should fit in the memory bus width?

Share this post


Link to post
Share on other sites
You could never say for sure without profiling your application with actual assets on target hardware. So if you really want to know for sure, you should try that.

In general, GPU's tend to have much more in the way of shader ALU as opposed to bandwidth. So I would guess that calculating the bitangent in the vertex shader would win out in most cases. However I would also guess that the difference would be pretty minimal.

Share this post


Link to post
Share on other sites

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