V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
sadyx
V2EX  ›  程序员

glsl 关于使用 dot 计算距离场的一个疑问

  •  
  •   sadyx · 322 天前 · 577 次点击
    这是一个创建于 322 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近在看 https://thebookofshaders.com/07

    看到这一部分代码有点疑惑,为什么这里计算距离场用 dot(dist,dist)*4.0 ?

    难道说是把 dot(dist,dist) 当做一个计算距离的系数吗?

    求大佬解惑

    https://i.imgur.com/pJqgqyE.png

    2 条回复    2023-06-09 15:18:44 +08:00
    psklf
        1
    psklf  
       322 天前   ❤️ 1
    dist 其实就是离中心点 (0.5, 0.5) 的距离, dot(dist, dist) 范围是 0~0.25; 乘 4 以后范围就是 0~1

    那么正好用来做 smoothstep
    sadyx
        2
    sadyx  
    OP
       322 天前
    @psklf 懂了,感谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2798 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 03:56 · PVG 11:56 · LAX 20:56 · JFK 23:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.