BabylonJS / Babylon.js

Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.
http://www.babylonjs.com
Apache License 2.0
22.77k stars 3.39k forks source link

mikkt space and glTF #3345

Closed unicomp21 closed 1 year ago

unicomp21 commented 6 years ago

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/

unicomp21 commented 6 years 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.

https://github.com/kripken/emscripten

unicomp21 commented 6 years ago

Great description of the situation:

https://wiki.blender.org/index.php/Dev:Shading/Tangent_Space_Normal_Maps

deltakosh commented 3 years ago

Closing as we do not plan to work on it. Please reopen if this needs to be reevaluated

donmccurdy commented 3 years ago

FYI: https://github.com/KhronosGroup/glTF/issues/1252#issuecomment-771358688

bghgary commented 1 year ago

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.

bghgary commented 1 year ago

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.

unicomp21 commented 1 year ago

@bghgary do babylonjs shaders make use of the MikkTSpace tangents mentioned above?

bghgary commented 1 year ago

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