Sign in to follow this  
ic0de

Weird point sprite perspective

Recommended Posts

So I have this problem where my point sprites are not becoming smaller as the get farther from the camera but rather larger. I tried GL_POINT_DISTANCE_ATTENUATION but it didn't seem to have any affect. I also wrote a shader to scale the point sprites based on there distance:

[CODE]
gl_PointSize = scr_h / distance(-(gl_ModelViewMatrix * gl_Vertex), gl_Vertex);
[/CODE]

This works but doesn't stop the sprites from getting bigger, what happens is that the sprite gets smaller with distance but only starting at a certain point before that the are growing forming a sort of "bulge" in the middle of a row of sprites. Any idea where this scaling upward is coming from, is there something that I can disable? I certainly didn't enable anything except this:

[CODE]
glEnable(GL_POINT_SPRITE);
glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
[/CODE]

Share this post


Link to post
Share on other sites
[quote name='ic0de' timestamp='1348186098' post='4982200']
gl_PointSize = scr_h / distance(-(gl_ModelViewMatrix * gl_Vertex), gl_Vertex);
[/quote]
What are you doing here ? You take the distance between a point in [i]object space [/i]and [i]camera space[/i], what is your object space for point sprites ? When you have a transformed point in camera space, the camera position is (0,0,0), therefore you just need either this for linear depth

[CODE]
// assumption: -z points into the screen
gl_PointSize = scr_h / -(gl_ModelViewMatrix * gl_Vertex).z;
[/CODE]

or this for radial depth
[CODE]
vec3 pointInCS = (gl_ModelViewMatrix * gl_Vertex);
gl_PointSize = scr_h / sqrt(dot(pointInCS,pointInCS));
[/CODE]

Share this post


Link to post
Share on other sites
[quote name='Ashaman73' timestamp='1348204862' post='4982242']
[quote name='ic0de' timestamp='1348186098' post='4982200']
gl_PointSize = scr_h / distance(-(gl_ModelViewMatrix * gl_Vertex), gl_Vertex);
[/quote]
What are you doing here ? You take the distance between a point in [i]object space [/i]and [i]camera space[/i], what is your object space for point sprites ? When you have a transformed point in camera space, the camera position is (0,0,0).
[/quote]

True, I modified my code based on your suggestion for radial depth but the problem seems to be coming from somewhere outside the shader. Is there a way I can make sure that gl_PointSize is only affected by the shader and nothing else? Edited by ic0de

Share this post


Link to post
Share on other sites
Issue seems to be with the NVIDIA driver, I ported the same game from windows to Linux and the problem just went away, no code changes all cross platform libs. I was wondering if anyone knew any workarounds so that the windows one can work?

Share this post


Link to post
Share on other sites
[quote name='ic0de' timestamp='1348519331' post='4983353']
I was wondering if anyone knew any workarounds so that the windows one can work?
[/quote]
Don't use point sprites [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img] To be honest, point sprites in OGL have a long history of issues, either on ATI or on NVidia videocards. I would use geometry shaders instead and quads as fallback for older videocards.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this