Closed unicomp21 closed 1 year ago
Reference material:
https://github.com/gltf-rs/mikktspace/tree/master/libmikktspace
Not sure if it make sense to rewrite in typescript, or use emscripten to compile the above for babylon.
Great description of the situation:
https://wiki.blender.org/index.php/Dev:Shading/Tangent_Space_Normal_Maps
Closing as we do not plan to work on it. Please reopen if this needs to be reevaluated
There is now a WebAssembly module for MikkTSpace: donmccurdy/mikktspace-wasm: MikkTSpace vertex tangent calculation for JavaScript/TypeScript/Node.js, using Web Assembly. (github.com). It would be good to integrate.
The MikkTSpace algorithm requires unindexed (unwelded) triangles as input. It is safe to create an index (welding vertices whose tangents and other attributes are identical) after generating tangents, but you cannot reuse prior indices after generating tangents. This additional cost is, perhaps, why some realtime engines choose to generate tangents with cheaper alternative algorithms, when pre-computed tangents are not provided with the asset.
Given this, maybe it's not a good idea to use this at runtime.
@bghgary do babylonjs shaders make use of the MikkTSpace tangents mentioned above?
If tangents are provided, yes. If not, we use a runtime compatible algorithm. https://github.com/BabylonJS/Babylon.js/blob/61c912b555c549794d976204975a051c038429d6/packages/dev/core/src/Shaders/ShadersInclude/bumpFragmentMainFunctions.fx#L84-L107
This is a placeholder for tracking whether or not mikkt space support in babylonjs makes sense.
See thread: http://www.html5gamedevs.com/topic/34364-gltf-support-and-mikkt-space/