V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
sadyx
0.27D
V2EX  ›  程序员

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

  •  
  •   sadyx ·
    SADYX · Jun 9, 2023 · 1139 views
    This topic created in 1059 days ago, the information mentioned may be changed or developed.

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

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

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

    求大佬解惑

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

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

    那么正好用来做 smoothstep
    sadyx
        2
    sadyx  
    OP
       Jun 9, 2023
    @psklf 懂了,感谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   944 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 23:17 · PVG 07:17 · LAX 16:17 · JFK 19:17
    ♥ Do have faith in what you're doing.