8000 IR-10191 mt stg studio flips green channel on normal maps by quaiquai-ir · Pull Request #2007 · ir-engine/ir-engine · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

IR-10191 mt stg studio flips green channel on normal maps #2007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

quaiquai-ir
Copy link
Collaborator

Summary

Subtasks Checklist

Breaking Changes

References

https://tsu.atlassian.net/browse/IR-10191

QA Steps

Add normal mapped gltf attached in ticket to a new scene.
Observe that the normal maps on the small quad display correctly

@quaiquai-ir
Copy link
Collaborator Author
quaiquai-ir commented Jun 3, 2025

@HexaField
We have a problem with this code: https://github.com/ir-engine/ir-engine/pull/2007/files#diff-63e41036118b337f383eb2a3d6e9fbeac555b58fc4915809114adb0e68f9906bR157-R179

We need to switch from using computeTangents() to MikkTSpace because computeTangents() breaks how our normal maps are imported—especially with GLTF files that use OpenGL-style tangent space. When we delete tangents for merging and use computeTangents(), the resulting tangents don't include the correct handedness (w component), which leads to flipped or incorrect lighting when using a normalScale of (1, 1) (which we choose for included tangents). ThreeJS even states that if we are going to calculate the Tangents we must flip the green channel. Currently with or without tangents we are computing the tangents. This mismatch causes normal maps that should work out of the box to render incorrectly appearing inverted. MikkTSpace solves this by generating tangents that match the standard expected by GLTF exporters and is recommended by Threejs to use. The current quick bandaid fix would be to always have the normal scale flipped for all gltfs.

Another way to get around this is to not delete tangents and comment out this code: https://github.com/ir-engine/ir-engine/blob/dev/packages/spatial/src/common/classes/BufferGeometryUtils.ts#L104

I tested that on many scenes and didnt find a problem but may be a super niche edge case where it would fail. Currently this problem is only with gltfs that have tangents

### Incorrect (Current implementation)
incorrect

### Correct
correct

@quaiquai-ir quaiquai-ir marked this pull request as ready for review June 4, 2025 22:21
@HexaField HexaField enabled auto-merge June 5, 2025 09:15
quaiquai-ir added 2 commits June 5, 2025 14:06
…10191-MT-STG-Studio-flips-green-channel-on-normal-maps
…ps' of https://github.com/ir-engine/ir-engine into IR-10191-MT-STG-Studio-flips-green-channel-on-normal-maps
@HexaField HexaField added this pull request to the merge queue Jun 5, 2025
Merged via the queue into dev with commit a766ff7 Jun 5, 2025
25 checks passed
@HexaField HexaField deleted the IR-10191-MT-STG-Studio-flips-green-channel-on-normal-maps branch June 5, 2025 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0