pc.SEMANTIC_TANGENT appears to have no value

Hello, I am working on a parallax shader where multiple layers can be displayed with appearent distance between the layers.

To determine how much i have to shift the UVs around to produce parallax I need to know the camera view angle in tangent space.

I read up on tangent space an found an implentation for playcanvas in post: [SOLVED] Add skinning code to a custom shader

I use the normal and tangent semantic to construct a TBN world-to-tangent matrix.

It works as it is supposed to. But i found that the tangent value, that is gotten through the pc.SEMANTIC_TANGENT is an empty vector (0,0,0).

I tested this by passing the tangent to the fragment shader and displaying the vector as color. Only blackness showed up.

Another problem I ran into is that when I hardcoded a value as the tangent, the effect only works on a plane that has not been rotated. I thought rotation would not be an issue since the tangent is multiplied by the model_matrix when it is used to make the TBN matrix.

link to project: PlayCanvas | HTML5 Game Engine

Let me know if I need to provide more info.

Thanks in advance.

Hi @Eele_Roet and welcome,

Calling @mvaligursky on this.

Playcanvas does not use SEMANTIC_TANGENT vertex attribute on majority of its meshes (not unless a user creates a mesh with it). TBN matrix is calculated without tangent attribute, based on Followup: Normal Mapping Without Precomputed Tangents | The Tenth Planet. See the code here: engine/TBNderivative.frag.js at main · playcanvas/engine · GitHub

So that’s the TBN you should likely be using.

You can also inspect the built in parallax mapping functionality to see how this is done. It’s enabled by specifying a heightMap on a standard material: engine/standard-material.js at 4bace9844e94e7bbdf7a1d6e339fa62fa8770e91 · playcanvas/engine · GitHub

Here’s the implementation of it, which uses TBN matrix to convert world view vector to tangent space:


Hey thanks for the reply, I got the parallax working. It’s all running on the vertex shader now so im really happy with the performance.

I had still did not get the tangent semantic working, though. I exported a couple fbx planes from blender with the tangent option on. But once i had it imported the data never showed up.

Did some googling and I saw others had this problem too. Not sure if it is a problem with the blender exporter or the playcanvas inporter tho.

Nice you got it to work.
Playcanvas fbx importer does not export tangent space to glb files. You could work around that by using glb directly most likely, nothing from those gets stripped.

1 Like