GL_POINTS Distance Attenuation
Members - Reputation: 808
Posted 21 June 2010 - 06:29 AM
It says that attenuation is does by clamping the attenuation factor by the implementation's clamp and the user's clamp. Also, distance is the distance the point is from the camera. I have that setup, but I'm not completely sure how to find what a, b, and c represent. I was told they are attenuation factors, which makes sense, then I was also told that a = 1.0f, b = 0.0f, and c = 0.0f which would make the bottom part of the attenuation factor zero by default. This is not correct.
Does anyone have any advise on how to emulate this? Screen-aligned points are not helping me when my particle emitters are being transformed in 3D perspective.
Members - Reputation: 291
Posted 22 June 2010 - 10:18 AM
dist_atten(d) = -------------------
a + b * d + c * d^2
OK d == distance
u can supply a,b+c quadratic equation
try some numbers
1 / ( 1 + 0 * d + 0 * d^2 ) == 1, i.e. point size will never change no matter how far away it is
1 / ( 1 + 1 * 1 + 0 * 1^2 ) = 0.5 @ 1 unit distance point is half size
1 / ( 1 + 1 * 10 + 0 * 10^2 ) = 0.09 @ 10 units distance point is smaller than a tenth
i.e. by changing a,b,c, u can control how quickly the point will shrink
Crossbones+ - Reputation: 9463
Posted 22 June 2010 - 10:41 AM
Bear in mind that there is a maximum point-size you can use, so up really close your points will be clamped to this size. If that's not what you want you'll probably need to use billboards instead.
Members - Reputation: 123
Posted 16 September 2012 - 02:20 PM
// vertex shader:
gl_Position = modelViewProjectionMatrix * position ;
vec3 ndc = gl_Position.xyz / gl_Position.w ; // perspective divide.
float zDist = 1.0-ndc.z ; // 1 is close (right up in your face,)
// 0 is far (at the far plane)
gl_PointSize = 50.0*zDist ; // between 0 and 50 now.
psColor = vec4( color, 1 ) ;
psColor.xyz = vec3( zDist, zDist, zDist ) ;
I'm not sure this is exactly what point distance attenuation did in 1.0, but it works pretty well