当前threejs版本为:99
threejs的SpriteMaterial新增属性sizeAttenuation,文档上的解释是Whether the size of the sprite is attenuated by the camera depth. (Perspective camera only.) Default is true.,呈现的效果就是,无论鼠标放大还是缩小,sprite在视野中的大小不变,shader中的核心代码如下(sprite_vert.glsl):
uniform float rotation;
uniform vec2 center;
#include <common>
#include <uv_pars_vertex>
#include <fog_pars_vertex>
#include <logdepthbuf_pars_vertex>
#include <clipping_planes_pars_vertex>
void main() {
#include <uv_vertex>
vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 ); //获取camera的深度
vec2 scale;
scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );
scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );
#ifndef USE_SIZEATTENUATION
bool isPerspective = ( projectionMatrix[ 2 ][ 3