scaling point sprites with distance

Posted by Will on Game Development See other posts from Game Development or by Will
Published on 2013-04-24T09:26:11Z Indexed on 2013/11/13 4:16 UTC
Read the original article Hit count: 262

Filed under:
|
|

How can you scale a point sprite by its distance from the camera?

GLSL fragment shader: gl_PointSize = size / gl_Position.w; seems along the right tracks; for any given scene all sprites seem nicely scaled by distance. Is this correct?

How do you compute the proper scaling for my vertex attribute size? I want each sprite to be scaled by the modelview matrix.

I had played with arbitrary values and it seems that size is the radius in pixels at the camera, and is not in modelview scale.

I've also tried:

gl_Position = pMatrix * mvMatrix * vec4(vertex,1.0);
vec4 v2 = pMatrix * mvMatrix * vec4(vertex.x,vertex.y+0.5*size,vertex.z,1.0);
gl_PointSize = length(gl_Position.xyz-v2.xyz) * gl_Position.w;

But this makes the sprites be bigger in the distance, rather than smaller:

enter image description here

© Game Development or respective owner

Related posts about sprites

Related posts about glsl