Instability with maths in PointSprite shader..

I am using a LOD system to replace a big array of QUADS with Point Sprites.
The QUADS or point sprites are in a tightly packed blended volume to create a cloud or nebula effect.

In order to get the Point Sprites to “edge-blend” together nicely I am using GL_COORD_REPLACE_ARB and then using those coordinates in my fragment shader to make the PointSprites render as circles, thus…

	vec2 mod_coord = gl_TexCoord[0].st * 2.0 - 1.0;
	gl_FragColor = gl_Color * (1.0 - length(mod_coord));

But this gives me instability and flickering in the rendering on a frame by frame basis. 50% of the time I get portions of the block disappearing.

If I remove the above logic and replace it with…

gl_FragColor = gl_Color;

I get square point sprites, but they are stable.

I pass the texture coords into the fragment shader from the vertex shader, thus…

	gl_TexCoord[0] = gl_MultiTexCoord0;	

…relying on the fixed funtion pipeline to generate them.

Although I am not technically using the point sprites as point sprites, but rather fast quads, can anyone explain why I would see the instability?


Not sure what you mean by “instability”. Aliasing?

Haven’t used point sprites myself, but if there’s a way to use your sprite fragment’s distance to center to look up a Gaussian (function or texture) or such you may get a nicer falloff. Linear falloffs don’t work as well for AA points and lines.

No, what I am seeing is almost like an out of sync refresh.

There are 96x96x96 QUADS, or POINTS.
I use the same logic in the fragment shaders for the QUADS, with the only difference being I generate the TexCoords myself in a varying variable in the vertex shader. And so far it gives really nice soft circles which give the whole block a nice soft fluffy feel.

WIth or without movement of the viewpoint I will get sections, almost like paths of ‘God Rays’ through the block (if drawn as POINTS) winking in and out.

Remove the maths from the shader and they all draw rock solid, but square!

I have tried playing with blending modes, and depth sorting etc. just in case, but the effect of those should be the same in either case. To my mind the shader logic would make no difference to that.

So I take it you suspect a driver bug?

I think the SOP is to submit your hardware configuration and driver version along with a minimal application that faithfully reproduces the problem to the relevant vendor.

In the meantime consider side stepping the point sprite business with your own quads, just to make sure it’s not a simple mistake somewhere else. Eliminating the bits you suspect can sometimes help to pin down the actual problem.

Hope it helps.

Aha, but there’s the rub…

Like I said I am doing the exact same thing with quads with no problem.
The two systems are interchangeable. I use an option key, or distance check to switch between them. So I have already done what you suggest.

The reason for using Points is that they are over double the speed (and a quarter of the memory footprint) of quads for this structure when it is distant. I suspect I can work around it with a more costly fragment shader that does the same thing.

I was hoping someone knew of a reason my fragment logic may be flawed.
I hate immediately pointing the finger at a driver bug.

Sorry, my friend, don’t do point sprites.

Hopefully someone with more experience with these creatures will grace us with a few pearls…

No worries. Your input is always appreciated…

One thing I did notice this afternoon is that if I shove all the vertices onto the GPU side then the flickering goes away… So it seems like some kind of memory access conflict… In any case I will always run the point sprites out of GPU space so I can kind of ignore the problem for now…

btw Noticed you are a BASE jumper… Where abouts do you do it mostly? Ever got out to Asia? I am more on the hopping out of plane side of things, but plan to get to Norway at some point in the future…

the base jumping bit is a joke… far too chicken to jump off anything taller than a step ladder. Can’t even get on a plane. Absurdly acrophobic, it grieves me to say.

Plane jumper, eh? Something wrong with you guys… serotonin deficiency or something :wink: