JavaScript: Trouble assigning tangents to vertex buffer #4434
Unanswered
BStringhamVRSK
asked this question in
Q&A
Replies: 1 comment 3 replies
-
You should pass your tangents in the following format:
The current JavaScript extension seems to always select |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
@romainguy -
We are using SurfaceOrientation.Builder to generate the tangents for dynamically generated geometry. We have a version on PC/OpenGL that works fine, but our WebGL version has problems. Some of the lighting is showing problems that suggest that the tangents are not making it into the vertex buffer correctly.
For example, some of the "walls" are being lit as if their normals point vertically instead of horizontally. In this screen shot, all of the walls are essentially white to make the IBL lighting apparent. You can see the wall facing the camera is receiving yellow light (from above), when it should be getting green light (from behind the camera).
Since some of the surfaces seem to be lit correctly, I suspect the problem is assigning the tangent data into the vertex buffer, where we use HALF4s to store the tangents. Here is our vertex buffer format:
All code is in JavaScript/TypeScript.
vertexBuffer = Filament.VertexBuffer.Builder()
.bufferCount(2)
.vertexCount(numVerts)
.attribute(Filament.VertexAttribute.POSITION, 0, Filament.VertexBuffer$AttributeType.FLOAT3, 0, 20)
.attribute(Filament.VertexAttribute.UV0, 0, Filament.VertexBuffer$AttributeType.FLOAT2, 12, 20)
.attribute(Filament.VertexAttribute.TANGENTS, 1, Filament.VertexBuffer$AttributeType.HALF4, 0, 8)
.build(engine);
Here is our tangent generation code:
Here is the code to set the vertex buffer
I don't know of a way to see what values Filament is actually getting. SurfaceOrientation.Builder.GetQuats() returns signed shorts, which I assume are going to be interpreted properly as half-float values, but I don't know how to confirm that they are not getting cast into something incorrectly along the way.
Any thoughts would be very appreciated. I wouldn't be surprised if I am just missing a small element, but I can't figure out what's different between this and our PC/OpenGL implementation.
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions