THREE.JS GLSL sprite always front to camera

本小妞迷上赌 提交于 2019-12-02 09:29:11

Are you looking for an implementation of billboarding? (make a 2D sprite always face camera) If so, all you need to do is this:

"vec3 billboard(vec2 v, mat4 view){",
    "   vec3 up = vec3(view[0][1], view[1][1], view[2][1]);",
    "   vec3 right = vec3(view[0][0], view[1][0], view[2][0]);",
    "   vec3 p = right * v.x + up * v.y;", 
    "   return p;",
"}"

v is the offset from the center, basically the 4 vertices in a plane that faces the z-axis. Eg. (1.0, 1.0), (1.0, -1.0), (-1.0, 1.0), and (-1.0, -1.0).

Use it like so:

"vec3 worldPos = billboard(a_offset, u_view);"
// then do whatever else.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!