If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.
![]() |
|
|
#1 |
|
Member
Join Date: Jul 2003
Location: Beijing
Posts: 640
|
Hi all:
I was told that user defined clip plane is disabled when using programmable pipeline in OpenGL, and my experiment also proved it. Now the question is how to emulate the clip effect. For now, I just evaluate the plane equation in pixel shader and output 0 if a pixel fails it. But it's far from a robust solution because it's quite possible that those clipped pixel is in front of the good pixel so that the latter is also clipped(because of z-buffering). Does anyone have a better method? |
|
|
|
|
|
#2 |
|
a.k.a. Ingenu
Join Date: Feb 2002
Location: Apsley, U.K.
Posts: 2,738
|
Using OpenGL Shader Language, clipping is done after Vertex Shader is applied, you need to fill a "special" register (don't remember the name, gl_ClipVertex most probably).
For the ASM Like interface (http://oss.sgi.com/projects/ogl-samp...ex_program.txt) issue 20 talks about it, you can use the position invariant" option to get them in if you want, or just move to the nifty GLSlang ! Never faced the problem, but it seems like you are indeed forced to take care/handle it in the fragment program on the ASM like interface (if not using the option).
__________________
So many things to do, and yet so little time to spend... |
|
|
|
|
|
#3 |
|
Member
Join Date: Jul 2003
Location: Beijing
Posts: 640
|
Thanks for the info, I'm using Cg ATM. Gotta take a look at the spec of GLSL.
|
|
|
|
|
|
#4 |
|
Junior Member
Join Date: Jul 2004
Location: USA
Posts: 65
|
I don't know about OGL but in DX pixel shaders i remember there being an PS instruction called texkill that was described as "being able to be used for arbitrary clip planes in the rasterizer". You might want to look into that.
|
|
|
|
|
|
#5 |
|
Crazy coder
|
It's much better to use real clip planes than emulating them with texkill. Texkill won't save any fillrate, unlike user clip planes that clips the actual geometry and therefore reduces the workload on the fragment shader a lot (assuming you're clipping away a lot).
|
|
|
|
|
|
#6 |
|
Regular
Join Date: Feb 2002
Location: California
Posts: 4,732
|
This brings up the question, was the "texkill" instruction in DX8 a real instruction, or was it just syntactic sugar for reusing alpha test hw, e.g. alpha = min(u,v,w)+bias, set up alpha test.
|
|
|
|
|
|
#7 |
|
Crazy coder
|
It's a real instruction. You can still use alpha testing to kill fragments that survived texkill.
|
|
|
|
|
|
#8 |
|
Junior Member
Join Date: Sep 2003
Posts: 65
|
Yes, like Hummus says, it is indeed an instruction. I have one correction for the above discussion though. Texkill does offer a fill-rate benefit over alpha test in that it allows a pixel shader to terminate immediately. In practice, this doesn't show up today, as all pixel engines are pipelined SIMD machines. You should however prefer texkill when it is reasonable, as it can be more efficient if/when the underlying computation model changes.
One other advantage clip planes have is that they antialias with multisampling. This is a non-insignificant quality issue. -Evan |
|
|
|
|
|
#9 |
|
Join Date: May 2002
Location: New York, NY
Posts: 12,678
|
Can you "draw" a quad in the z-buffer that would emulate the clip plane? This clearly won't work for all cases, but I suppose it depends upon what you want to do.
__________________
April 20, 1979 - America must never forget. |
|
|
|
|
|
#10 |
|
Junior Member
Join Date: Sep 2003
Posts: 65
|
The quad thing won't work most of the time. If the only issue is shaders, you can draw the object once without shaders and the clip plane on. Then use a depth function of EQUAL, but this requires that the transform match what you can do in fixed function.
-Evan |
|
|
|
|
|
#11 | |
|
Tea maker
Join Date: Feb 2002
Location: In the Island of Sodor, where the steam trains lie
Posts: 4,382
|
Quote:
__________________
"Your work is both good and original. Unfortunately the part that is good is not original and the part that is original is not good." -(attributed to) Samuel Johnson "I invented the term Object-Oriented, and I can tell you I did not have C++ in mind." Alan Kay |
|
|
|
|
|
|
#12 |
|
Junior Member
Join Date: Jul 2004
Location: USA
Posts: 65
|
@ the OP when you said that you were going to evaluate the plane equation in the pixel shader and output 0 if it failed it, what exactly did you mean by outputing 0? I'm still studying vertex shaders, i just started reading up on pixel shaders and haven't touched CG, HLSL, or GLSL. So when I thought about it I realized that i assumed that you meant outputing the pixel shader without moving anything into the 'output' register, is that what you meant or did what you say amount to a 'texkill' or some other way of killing the fragment?
@ Anyone - When you use texkill does it discard the z-write also? I'm assuming it does but its not explictly stated in the SDK. |
|
|
|
|
|
#13 | |
|
Tea maker
Join Date: Feb 2002
Location: In the Island of Sodor, where the steam trains lie
Posts: 4,382
|
Quote:
__________________
"Your work is both good and original. Unfortunately the part that is good is not original and the part that is original is not good." -(attributed to) Samuel Johnson "I invented the term Object-Oriented, and I can tell you I did not have C++ in mind." Alan Kay |
|
|
|
|
|
|
#14 | |
|
Member
Join Date: Jul 2003
Location: Beijing
Posts: 640
|
Quote:
|
|
|
|
|
|
|
#15 | |
|
Member
Join Date: Jul 2003
Location: Beijing
Posts: 640
|
Quote:
|
|
|
|
|
|
|
#16 | |||
|
Senior Member
Join Date: Mar 2002
Posts: 3,779
|
Quote:
Quote:
Quote:
|
|||
|
|
|
|
|
#17 |
|
Junior Member
Join Date: Sep 2003
Posts: 65
|
Mint,
I am aware of that info on TEXKILL. I wrote the OpenGL version of that document. As far as the Z optimizations go, the biggest thing to remember is that they are just that, optimizations. You should take advantage of them whenever it is appropriate. Sometimes it just isn't, and that is why the driver can turn them off. To clarify what I was saying about TEXKILL, if you are going to kill pixels anyway, you should kill them as far up the pipeline as possible. This means using TEXKILL where appropriate. (early depth test and HiZ are clearly higher still) I can't absolutely say it will increase performance in the future, but I can say that there are good reasons it should. -Evan |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Near Clip Plane and Radeon Z-Buffer Problems. | Jamm0r | 3D Architectures & Chips | 14 | 11-May-2003 01:06 |