re: clipping planes bypassed in CG vertex shaders

Rhadamés Carmona <[email protected]>
Newsgroups gmane.games.devel.opengl
Organization Fat City Network Services, San Diego, California
Message-ID <[email protected]>
Thanks Pat

Lot of options. I am going to study them.
All d best!
Rix


      I haven't had time to respond to this thread yet. A few comments:

      The fundamental problem is that user clipping semantics defined in the
      spec are significantly tied to the fixed-function transformation
      pipeline. For user programs, the vertex transformation doesn't have any
      necessary correspondence to the fixed-function pipe, so specifying what
      happens there is more problematic.

      Many "real world" user programs actually do have this correspondence,
      but inferring whether an arbitrary program does or does not have this
      property in the driver is not a completely trivial task, especially in
      the face of optimizations (e.g., you know you only have 3-component
      input vertices, so might write your transformation accordingly).
      Clearly defining whether a shader has this property in a spec is even
      uglier, since there are so many different ways you can write the "same"
      transformation.

      So it's not a trivial problem. However, there are a number of different
      ways to get the desired clipping behavior.

      * As the original question seems to refer to Cg, I'll start by saying
      that Cg provides "CLP0" -- "CLP5" vertex result semantics for profiles
      where the clip distance outputs (described below) are available.

      * NV_vertex_program2 provides outputs o[CLP0] through o[CLP5] that
      allows a vertex program to write "clip distances". You evaluate the
      clipping dot product in the vertex program in whatever space you'd like.
      The hardware clips to the region where o[CLPx] >= 0. Clip distances map
      with clip planes.

      * NV_vertex_program2_option (and NV_vertex_program3 for the GeForce 6
      series) provide the same functionality with ARB-style programs. I think
      they're called "result.clip[0..5]".

      * NV_vertex_program2 is supported on NV30 (GeForce FX) and better.

      * If you need to make it work on NVIDIA parts prior to GeForce FX, the
      texture shader approach would probably be needed. That same set of
      parts doesn't support fragment programs, so your best bet might be to
      have one "basic" vertex program that writes either to a clip distance or
      texture coordinate component. You'll probably have to write different
      fragment shaders regardless.

      * Unextended ARB_vertex_program doesn't provide any explicit clip
      distance support. It does, however, support user clipping in
      conjunction with position invariant programs. In other words, if a
      fixed-function position transform is used, fixed-function user clipping
      works normally. (NV_vertex_program1_1, which was the first extension
      with position-invariant programs, doesn't do this -- this was added when
      ARB_vertex_program was standardized.)

      * GLSL has a "gl_ClipVertex" output where you basically pretend your
      output vector gives the eye coordinates for the vertex and use them with
      "standard" user clipping. This involves computing the dot product with
      the relevant clip planes, and then clipping to the region where the dot
      product is >= 0. If you use this functionality, keep in mind that the
      clip planes are transformed by the current modelview matrix at the time
      you specify them, so the values used for evaluating "clip vertex" dot
      products may not be the four values you pass in to glClipPlane.

      Hope this helps.

      Pat
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.