PDA

View Full Version : How can I set my own depth comparison function?



zrzmonkey
05-15-2011, 07:21 AM
Hi,
The glDepthFunc can only set several depth comparison function.But now,I want to render by my own depth comparison function.For expamle,I want to compare depth with two depth buffers.If the fragment's depth less than one buffer and greater than the other,render it.
In fact,I only want to realize depth peeling and obtain n levels of depth buffer.
Interactive Order-Independent Transparency says "imagine that OpenGL supported multiple simultaneous depth units",but how can I use multiple simultaneous depth units in OPENGL.

zrzmonkey
05-17-2011, 01:22 AM
Maybe I haven't describe my question clearly before.
In fact,I want do depth peeling as Interactive Order-Independent Transparency says.But it says "imagine that OpenGL supported multiple simultaneous depth units".Does OpenGL offer the function like multiple simultaneous depth units?If not,how to do depth peeling in a simple way by OpenGL?
Thanks.

dukey
05-17-2011, 02:56 AM
Sort your polys into a BSP tree. I wouldn't even bother with the 'modern' approach, unless of course your scene has random polys all over the place.

Alfonse Reinheart
05-17-2011, 03:29 AM
Sort your polys into a BSP tree.

This kind of thinking smells of the hammer and a nail problem. When you first get a hammer, every problem starts looking like a nail.

BSPs have their uses. But those uses are mainly for static geometry. BSP sorting scenes that have millions of dynamic polygons in them is less practical than implementing depth peeling or other OIT methods. Doubly so when you want the GPU to do the T&L for those polygons.

As for the OP, in case he didn't see it in the other thread, I'll repeat my post here:


Maybe I haven't describe my question clearly before.
In fact,I want do depth peeling as Interactive Order-Independent Transparency says.But it says "imagine that OpenGL supported multiple simultaneous depth units".Does OpenGL offer the function like multiple simultaneous depth units?If not,how to do depth peeling in a simple way by OpenGL?

I don't understand what confuses you about the statement "imagine that OpenGL supported multiple simultaneous depth units." If the paper has to ask you to imagine it, then odds are good that it isn't true, right? If it were true, wouldn't it make more sense to just say, "OpenGL supports multiple simultaneous depth units," as well as explain how to use that feature? But the paper doesn't; it talks about using depth comparisons and alpha tests.


If not,how to do depth peeling in a simple way by OpenGL?

Why don't you read past page 4 of the paper (that has the quote you mentioned)? I downloaded the paper, and it seems quite thorough in explaining how to do depth peeling. Now granted, it sets things up in code based on the horrible "texture shaders" of the GeForce 3 days, but the technique would be easily adaptable to modern shaders today.

dorbie
05-19-2011, 10:39 AM
You cannot do this. You may want to consider some form of multi-pass or other attribute shading and readback or RTT but it will be slow unless you can refactor your algorithm for modern hardware pipelines.

The depth test is deeply ingrained and heavily optimized in the hardware rasterization pipeline optimization. Even altering z output from a shader or discarding fragments in the shader can defeat the implementation optimizations due to the out of order optimization of pipeline operations and advanced caching schemes.

You can get multiple simultaenous depth inputs using something like a depth texture and multi-pass or solve your problem with other tricks.