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

[g-webgl] SDF 绘制的 Rect 边缘模糊 #1367

Closed
xiaoiver opened this issue Jun 12, 2023 · 3 comments
Closed

[g-webgl] SDF 绘制的 Rect 边缘模糊 #1367

xiaoiver opened this issue Jun 12, 2023 · 3 comments
Assignees

Comments

@xiaoiver
Copy link
Contributor

Image

@xiaoiver
Copy link
Contributor Author

使用 SDF 实现圆角矩形,可以应用 instanced array 绘制效率最高:
https://www.shadertoy.com/view/Nlc3zf

唯一限制是 radius 得保持一致,否则需要降级到目前 Path 的实现,即每个 Rect 对应一条 draw call,性能较差。

@xiaoiver
Copy link
Contributor Author

xiaoiver commented Jun 15, 2023

考虑宽高比和描边宽度:

vec2 r = (v_Radius - (omitStroke ? 0.0 : u_StrokeWidth)) / v_Radius.y;
float wh = v_Radius.x / v_Radius.y; // 宽高比

outer_df = sdRoundedBox(v_Data.xy, vec2(wh, 1.0), 0.0);
inner_df = sdRoundedBox(v_Data.xy, r, 0.0);

目前的效果会清晰很多:

Image

@xiaoiver
Copy link
Contributor Author

还有一个需要解决的问题是,Rect 的宽高是支持负数的,此时需要按照 Y / X 轴翻转。

xiaoiver added a commit that referenced this issue Jun 19, 2023
* fix: adjust anchor of SDF #1377

* fix: remove comment from sdf.vert

* fix: use SDF to draw rect only when all the radius are the same #1367

* chore: remove material test case from CI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant