GL Tools Line/Point Structure & GLSL Weirdness

toneburst's picture

If I stick a Line or Point Structure patch inside a GLSL Shader patch, it seems to break the antialiasing of the Line, and the points become squares.

Anything I can do to workaround this?

Also, any chance of having texture coords on the line, so that, say, texture T coords go from 0 > 1 along the length of the line? Or is this already the case?

a|x

cwright's picture
Re: GL Tools Line/Point Structure & GLSL Weirdness

toneburst wrote:
Anything I can do to workaround this?

write a shader that duplicates the fixed-function antialiasing/blending?

toneburst wrote:
Also, any chance of having texture coords on the line, so that, say, texture T coords go from 0 > 1 along the length of the line? Or is this already the case?

Line structure doesn't currently make use of U/V coords (though it could pretty easily) -- it'd incur a 33% performance hit though (due to the additional structure lookups)...

toneburst's picture
Re: GL Tools Line/Point Structure & GLSL Weirdness

Quote:
write a shader that duplicates the fixed-function antialiasing/blending?

It's a shame that that breaks in the first place, though... Also, I'm not sure how I'd do what you suggest without working texture-coords for the shader to work with (or does the AA algorithm work on a 2D 'flattened' rendering of the geometry?).

Line structure doesn't currently make use of U/V coords (though it could pretty easily) -- it'd incur a 33% performance hit though (due to the additional structure lookups)... [/quote]

Ah, OK. Maybe you could add the option to turn U/Vs on/off (and maybe also per-point RGBA, too?). That way they'd be there if you needed them, but you could remove the overhead if you didn't. The same could be applied to the Quad/Triangle/Point structures too, perhaps...

Just a thought.

a|x

toneburst's picture
Re: GL Tools Line/Point Structure & GLSL Weirdness

Quote:
write a shader that duplicates the fixed-function antialiasing/blending?

Sorry to be a bit dense here, but I'm confused as to how I might approach this. The problem is I have both lines and points in the same shader, and I don't know how I would implement antialiasing appropriately on both types of geometry in the same shader. Any pointers would be much appreciated.

a|x http://machinesdontcare.wordpress.com

cwright's picture
Re: GL Tools Line/Point Structure & GLSL Weirdness

toneburst wrote:
Maybe you could add the option to turn U/Vs on/off (and maybe also per-point RGBA, too?). That way they'd be there if you needed them, but you could remove the overhead if you didn't. The same could be applied to the Quad/Triangle/Point structures too, perhaps...

I've been considering this too -- in a few places, we autodetect, but it's flaky (because it only checks the first vertex). It would add a bit of complexity, but keep expenses low when certain features weren't needed. I'll keep thinking about it. :)

cwright's picture
Re: GL Tools Line/Point Structure & GLSL Weirdness

I'm not sure if it's actually possible -- you'd need both line end points to feed to the fragment shader (which could then calculate the current fragment's position and distance from the true line, and blend using Wu's algorithm or something), but that isn't possible.

Doing a bit more research on this, it turns out to be a GPU bug -- ATI and Nvidia GPUs don't correctly line-smooth inside GLSL shaders (which leads me to believe that they do software line drawing behind the scenes outside of GLSL). My GMA950 actually does correctly alphablend lines in GLSL shaders.

For a point, you can find your current fragment's location and point's size, and then do some math with that.

However, GMA950's apparently /cannot/ draw points in GLSL if the blend mode is set to Alpha or Over -- the output pixels are always transparent for some reason.

So the official answer is: "GPUs suck, use software rendering" :)

toneburst's picture
Re: GL Tools Line/Point Structure & GLSL Weirdness

Cool. More options, but less overhead has to be a good thing, don't you think... :)

a|x

toneburst's picture
Re: GL Tools Line/Point Structure & GLSL Weirdness

Annoying.

Glad it wasn't just me being stupid though.

Quote:
For a point, you can find your current fragment's location and point's size, and then do some math with that.

I've done something similar on some of the earlier Random-Walk tests. You can actually do some quite cool fake depth-of-field effects by using a smoothstep function to draw a circle on each point-sprite, and modulate the 'softness' of the circle based on the point's distance from an arbitrary 'focus-centre'

I guess I could use separate RIIs for the lines and the points, and then comp them together afterwards. Would break depth-testing though, I imagine.

a|x

usefuldesign.au's picture
Re: GL Tools Line/Point Structure & GLSL Weirdness

For what its worth and not that I followed all that shader stuff but when Kineme GL Point Structure is not set to Alpha, the point circles start to look like round-cornered squares even in the regular Renderer. GPU: GeForce FX 5200