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

Fix div-by-zero in TriangleBorder shader #242

Merged
merged 2 commits into from Jan 30, 2023

Conversation

EVAST9919
Copy link
Contributor

Part of fixing ppy/osu#22427

@@ -36,7 +36,7 @@ void main(void)
highp float dst3 = dstToLine(vec2(0.0, 1.0), vec2(0.5, 0.0), pixelPos);
highp float dst = min(min(dst1, dst2), dst3);

lowp float alpha = dst < texelSize ? dst / texelSize : smoothstep(texelSize, 0.0, dst - thickness);
lowp float alpha = texelSize == 0.0 ? (1.0 - step(thickness, dst)) : (dst < texelSize ? smoothstep(0.0, texelSize, dst) : smoothstep(texelSize, 0.0, dst - thickness));
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to say that when texelSize is zero, nothing is being displayed to the user? if so, would it not be simpler to just use a constant alpha of 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my head when texelSize is 0 it's like having a display of infinite dpi, so no smoothing should be applied.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd agree that zero texel size turning off smoothing makes sense. So triangles should show, just without smoothing.

From a code quality perspective though, this line is pretty awful with nested ternaries. I'd probably use actual ifs here, at least on the outer level. As far as the internet tells me ternaries are normal branches in glsl anyway (as in, not vectorised), so there should be no associated performance hit.

@peppy peppy merged commit 7808a80 into ppy:master Jan 30, 2023
@EVAST9919 EVAST9919 deleted the triangle-zero-div branch January 30, 2023 04:59
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.

None yet

3 participants