Weird point sprite perspective

Started by
3 comments, last by Ashaman73 11 years, 6 months ago
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:


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


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:


glEnable(GL_POINT_SPRITE);
glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
Advertisement

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

What are you doing here ? You take the distance between a point in object space and camera space, 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


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


or this for radial depth

vec3 pointInCS = (gl_ModelViewMatrix * gl_Vertex);
gl_PointSize = scr_h / sqrt(dot(pointInCS,pointInCS));

[quote name='ic0de' timestamp='1348186098' post='4982200']
gl_PointSize = scr_h / distance(-(gl_ModelViewMatrix * gl_Vertex), gl_Vertex);

What are you doing here ? You take the distance between a point in object space and camera space, 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?
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?

I was wondering if anyone knew any workarounds so that the windows one can work?

Don't use point sprites tongue.png 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.

This topic is closed to new replies.

Advertisement