Support vertex tangents

via @ondys


A simple cube mode with normal map that simulates flat shading:
normal_map_flat-20190201T224012Z-001.zip

The cube has smooth geometry normals (no normal seams on cube edges) + a normal map that simulates flat shading.

threejs flat babylonjs flat
three_js babylon_js

Babylon.js rendering seems to work correctly but three.js produces a weird looking result (cesium viewer also seem to work correctly)

For comparison, if normal map is set to a constant value (128, 128, 255), the resulting geometry is smooth for both three.js and babylon.js:

threejs smooth babylonjs smooth
three_js_smooth babylon_js_smooth

Cube with constant normal map is here:
normal_map_smooth-20190201T224029Z-001.zip

Author: Fantashit

1 thought on “Support vertex tangents

  1. The vertex attribute is a vec4, but vTBN only (directly) depends on the .xyz components.

    I would say the matrix depends on .xyzw, but I see you are, in fact, using the 4th component to set the correct bi-tangent vector, which was my concern.

    Since your vTBN matrix will be interpolated in the fragment shader, and will no longer be orthonormal, it may be preferable to pass varyings vec3 vNormal, vec3 vTangent, and vec3 vBitangent, instead, and construct the orthonormal TBN matrix in the fragment shader.

    However it is typically done is fine…

    And thanks for this! 🙂

Comments are closed.