PDA

View Full Version : Two esoteric GL questions:



gonk
10-23-2006, 07:18 AM
1) Say you have a fragment shader that does some expensive calculation, and you'd like to do some kind of antialiasing of just the edges of your polygons (the interiors are naturally antialiased, and you don't care about intersections); is there a way to multisample without calling your fragment shader more than once per fragment? I.e., multisample coverage (and perhaps depth), but not color?

2) Is there a way to tell the z-buffer that a z-test should pass so long as the incoming z-value is less-than-or-equal-or-ALMOST-equal to the current z-value in the depth buffer? E.g., is there a way to do something like polygonoffset, where the offset z-value is only used for testing, and the non-offset-z-value is what is written to the z-buffer?

Thanks in advance for any help.

jide
10-23-2006, 08:10 AM
I think you can do the second using shaders, but you'll loose (AFAIK) early depth test. The problem would reside on storing your offset z values, maybe with using a high detailed texture.

For one, I would have said you can do it with multi pass. In the second pass, do the multisample drawing only the edges. You might also need some bleding.

But I'm really unsure for all that points.

Hope that could help.

AlexN
10-23-2006, 08:52 AM
Multisample only executes the fragment shader once per final output pixel, the result is replicated to all written multisample samples. So, what you are describing should already be what is happening.

I don't know of any way to supply the hardware depth test with one value for testing and another for writing...as jide suggested you could store a value in a texture, but the details of that will depend a lot on what you're trying to do. Perhaps something involving alpha test to fake your own depth test, but beware that this can break multisampling unless you're using something like alpha to coverage or the special alpha test mode available on the newer nvidia cards.

gonk
10-23-2006, 09:06 AM
Originally posted by AlexN:
Multisample only executes the fragment shader once per final output pixel, the result is replicated to all written multisample samples. So, what you are describing should already be what is happening.
Okay... I get a huge performance hit when I try to multisample, so I figured it was calling my fragment shader at every sample, and I couldn't find any info to confirm or contradict this.

I guess what I really want is a way to just edge-antialias using something like "GL_POLYGON_SMOOTH", but without having to turn off the depth buffer, which is what I was getting at in my second question. Edge antialiasing seems to be dirt cheap, and gives good enough looking results. It would really useful if there was a way to tell the depth buffer to pass values that were "close enough".

Korval
10-23-2006, 10:04 AM
Okay... I get a huge performance hit when I try to multisample, so I figured it was calling my fragment shader at every sample, and I couldn't find any info to confirm or contradict this.Multisampling isn't free. And if you're doing something like depth writes, I imagine it's even less free.

It still takes up x more bandwidth and x more memory. Your performance hit could be from texture thrashing.


Edge antialiasing seems to be dirt cheap, and gives good enough looking results.That's what multisampling is. But what it isn't is free.

gonk
10-23-2006, 11:09 AM
Originally posted by Korval:

Edge antialiasing seems to be dirt cheap, and gives good enough looking results.That's what multisampling is. But what it isn't is free. I think I may have misspoke. When I said "edge antialiasing", I meant GL_POLYGON_SMOOTH. Are you saying that GL_POLYGON_SMOOTH is implemented with multisampling? I don't see how that could be, since GL_POLYGON_SMOOTH works even if your backbuffer isn't set up for multisampling.

Edit: the more I think about it, the more I think that GL_POLYGON_SMOOTH really should be "free". All the redbook says it does is tweak the alpha channels along the edges of the polygons to equal whatever the coverage value at that pixel should be, and that coverage value can be computed analytically very simply, without having to resort to sampling.

zeoverlord
10-23-2006, 12:24 PM
Originally posted by gonk:

Edit: the more I think about it, the more I think that GL_POLYGON_SMOOTH really should be "free". All the redbook says it does is tweak the alpha channels along the edges of the polygons to equal whatever the coverage value at that pixel should be, and that coverage value can be computed analytically very simply, without having to resort to sampling. It's not free, but it is cheap.
Though GL_POLYGON_SMOOTH has other problems as lines are antialiased poorly, and you need to use some kind of blending for it to be useful, i only find it useful for rendering outline text and other similar stuff.

gonk
10-23-2006, 06:07 PM
yeah, I know it's not a panacea, but I have been trying it out, and it beats the pants off of doing nothing, without the performance hit of multisampling. The big drawback (for me, anyway) is having to turn off the depth buffer to get it to work.

AlexN
10-23-2006, 06:27 PM
Well, you keep saying turning off the depth buffer makes it work. Perhaps you just need to sort so that you are drawing your polygon_smooth geometry back to front. Either sort everything back to front, or just the polygon_smooth geometry and draw it after drawing your other geometry.