Skip to main content
GameDev.net gamedev.net
🔒 Locked

point sprites size dependant on distance

Started by judge dreadz Apr 8, 2006 at 3:15 PM 2 replies 3.3k views
Original Post
judge dreadz
judge dreadz
is there a setting that will make my point sprites bigger when they are close to the camera? or do i have to do the calculation manually in the shaders? using openGL and Cg. thanks
Morpheus011
Morpheus011
I think what you are looking for is GL_POINT_DISTANCE_ATTENUATION_ARB. This modifies the point sprites scale based on a distance from the camera. Check out the opengl.org site (probably a quick search for this parameter will do the trick) for more details.
judge dreadz
judge dreadz
thanks morpheus. actually thinking about it, i am sure i need to calculate it manually since i am determining the point size within the vertex shader, not the openGL code. this shouldnt be a problem (actually its quite handy because i could do with putting some more maths work in the shader to hide the vertex texture fetch latency!), but i need a decent forumla to do it.

i couldnt find anything about it on the opengl.org site, but i found the following post on another forum:

Quote:

Yes GL_POINT_DISTANCE_ATTENUATION isn't define in GL_ARB_point_sprite because it' a define from GL_ARB_point_parameter Wink

It's used with the function glPointParameterfvARB as the following :
glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, vec3(a, b, c));

This function is used to calculate the point size according to the depth distance between the camera and the point. It's possible configure the calcule with the three parameters a, b, c.

The size of each point rendered is calculated using the formula :


derived_size = clamp(size * sqrt(1 / (a + b * d + c * d ^ 2)))


By default a, b, c are null.



the above is great (assuming its correct), the problem is i have no idea what d is!
Morpheus011
Morpheus011
d is the distance from the point to the camera. a, b, and c are the coefficients of attenuation. This formula is often simplified to 1/(d*d) for optimization purposes. Although, I don't know where the squareroot comes from in this equation. I've never seen the square root taken for this formula, it's always the formula, clamped between 0 and 1.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.