如何将抗脉化应用于着色器中的等距网格线?
我有一个等距网格着色器,当缩放
这些间隙不应存在,线条应该看起来平滑。我如何对此进行抗抗衡?
代码
const float tileSize = 0.04;
const float borderSize = 0.98;
vec2 aGrid(vec2 uv) {
return vec2(mod(uv.x, 1.0), mod(uv.y * 2.0, 1.0));
}
vec2 bGrid(vec2 uv) {
return vec2(mod(uv.x - 0.5, 1.0), mod((uv.y * 2.0) - 0.5, 1.0));
}
float los(vec2 pos, float border) {
vec2 abspos = abs(pos - vec2(0.5));
return sign(abspos.x * border + abspos.y * border - border * border);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = fragCoord / iResolution.xy;
float border = 0.5 * borderSize;
vec2 size = (uv / tileSize) / 2.0;
float alos = los(aGrid(size), border);
float blos = los(bGrid(size), border);
float color = min(alos, blos);
fragColor = vec4(color);
}
这是我必须在此处使此等距网格在ShaderToy https:///www.shadertoy中运行的 。 com/view/slbbz3
我找到了另一个用于抗矩形网格的着色器。
I have an isometric grid shader that looks like this when zoomed out
Those gaps should not be there and lines should look smooth. How I can apply antialising to this?
This is the code I have to make this isometric grid
const float tileSize = 0.04;
const float borderSize = 0.98;
vec2 aGrid(vec2 uv) {
return vec2(mod(uv.x, 1.0), mod(uv.y * 2.0, 1.0));
}
vec2 bGrid(vec2 uv) {
return vec2(mod(uv.x - 0.5, 1.0), mod((uv.y * 2.0) - 0.5, 1.0));
}
float los(vec2 pos, float border) {
vec2 abspos = abs(pos - vec2(0.5));
return sign(abspos.x * border + abspos.y * border - border * border);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = fragCoord / iResolution.xy;
float border = 0.5 * borderSize;
vec2 size = (uv / tileSize) / 2.0;
float alos = los(aGrid(size), border);
float blos = los(bGrid(size), border);
float color = min(alos, blos);
fragColor = vec4(color);
}
Here is running in shadertoy https://www.shadertoy.com/view/slBBz3
I found this other shader for an antialiased rectangle grid https://www.shadertoy.com/view/7lBBz3 I tried to apply the same technique but I can't find how
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议简化您的代码。使用 lineare equation 根据片段的x坐标计算一条
线距离片段的y坐标的距离,并获得瓷砖大小的其余部分:
计算到线中心的绝对距离:
使用
smoothStep
用于抗sialiasing:最小示例:
I suggest to simplify your code. Use the Linear equation to calculate a line depending on the x-coordinate of the fragment:
Calculate the distance to the y-coordinate of the fragment and get the rest of the division with the tile size:
Compute the absolute distance to the center of the line:
Use
smoothstep
for antialiasing:Minimal example: