How to create latitudinal (horizontal) contour lines in GLSL?

心已入冬 提交于 2019-12-04 12:04:20

fwidth is not exactly generating the lines, mainly fract is. fwidth is only used to keep the line width constant in screen space.

If you try to draw 1px lines only using fract, it will work. But if you want wide lines or antialiased lines, you'll need fwidth to make sensible interpolations.

To only have horizontal lines, you probably just need to remove one of the coordinates in the fract/fwidth calculation. Although maybe you should try with the simple version first from your link (a lot easier to understand :D):

varying vec3 k;

void main()
{
    vec3 f  = fract (k * 100.0);
    vec3 df = fwidth(k * 100.0);

    vec3 g = smoothstep(df * 1.0, df * 2.0, f);

    float c = g.x * g.y * g.z;

    gl_FragColor = vec4(c, c, c, 1.0);
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!