Skip to content
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

Bias octahedral tangent y axis to avoid errors around 0 #73265

Merged
merged 1 commit into from
Feb 14, 2023

Conversation

clayjohn
Copy link
Member

@clayjohn clayjohn commented Feb 14, 2023

Fixes: #71571

This also fixes the simplified MRP in #71221 (comment) but I am unsure if it fixes the OP of #71221

In 3.x we applied a small bias to the tangent y axis while it was in the range [0, 1] to avoid discontinuities around 0

Vector2 VisualServer::tangent_to_oct(const Vector3 v, const float sign, const bool high_precision) {
float bias = high_precision ? 1.0f / 32767 : 1.0f / 127;
Vector2 res = norm_to_oct(v);
res.y = res.y * 0.5f + 0.5f;
res.y = MAX(res.y, bias) * SGN(sign);
return res;
}

In 4.0 the code is a little different because the output from octahedron_encode is already in [0,1] space.

Somehow we missed the bias when converting to 4.0, but it is still needed in some very rare cases.

Big thanks to @stoofin who narrowed the issue down to tangents with y-values very close to 0

@akien-mga akien-mga merged commit 570b04d into godotengine:master Feb 14, 2023
@akien-mga
Copy link
Member

Thanks!

@clayjohn clayjohn deleted the tangent-oct branch April 13, 2023 20:44
@clayjohn
Copy link
Member Author

I'm still having this issue with 4.0.2

Have you tried reimporting your asset?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

strange normal map behaviour on some meshes
2 participants