Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tangents and BiTangents #1387

Open
ghost opened this issue Jun 16, 2020 · 4 comments
Open

Add Tangents and BiTangents #1387

ghost opened this issue Jun 16, 2020 · 4 comments

Comments

@ghost
Copy link

ghost commented Jun 16, 2020

Background

Can you add Tangets for geometry and calculation of the TBN matrix in shaders?

The best way to do it is by using UV differential algorithm like this:
http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-13-normal-mapping/

This would allow for correct normals transformation, which is useful for such effects like Normal Mapping, Displacement Mapping, etc.

Also, Tangets and BiTangets can be useful when you want to achieve some custom effects in shaders that require you to know vectors of the direction of U and V in model space, for example.

@ibgreen
Copy link
Collaborator

ibgreen commented Jun 16, 2020

@BogdanCrav Thanks for opening this request.

Let's start by trying to see if we can agree on an implementation approach then that could be an external PR or done by the core team.

@tsherif @igorDykhta Do you have input on this?

Would it be appropriate to add an extra tangent attribute to the primitives or is this better done with shader derivatives or other techniques?

@tsherif
Copy link
Contributor

tsherif commented Jun 16, 2020

Definitely doable, and the technique is general, so having one calculateTangents function would allow us to do it for all shapes. And you only need to calculate the tangents, as the bi-tangent can be calculated as a simple cross product in the shader.

My only suggestion would be to make it "opt-in". It's not an insignificant amount of time/memory to generate them and they're only useful for certain techniques. Wouldn't want users paying for them if they're not using them.

I worked on this tangent calculation algo in SceneJS: https://github.com/xeolabs/scenejs/blob/master/src/core/math.js#L2655-L2710
Not saying it's the best implementation, but might be useful as a reference.

@igorDykhta
Copy link
Collaborator

One approach is to add one vec4 vertex attribute with tangent vec3 and a value to restore bitangent. Here we have some stuff to setup with more per vertex data, probably less stuff to do in fragment shader.

Second solution is to calculate tangents based on tex coords derivatives in FS, no additional attributes, also not sure about performance issues, as used only first approach.

@xintongxia
Copy link
Contributor

@ibgreen @tarek If this issue has not been assigned yet, I can offer some time to add this to luma.gl.

@xintongxia xintongxia mentioned this issue Jun 20, 2020
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants