RE: [info-performer] drawing close and far objects with differing near far clip plains

Date view Thread view Subject view Author view

From: Colin Middleton (colin++at++sgi.com)
Date: 04/18/2005 02:23:20


Iberto,

There is another solution that I have used in the past, it is more "legal"
as it only uses Performer but comes with other drawbacks.

Rather than changing the near far distances for a single channel, you can
stack the channels on top of each other.

Chan0 -> setNearFar ( dist[1] , dist[2] );
Chan1 -> setNearFar ( dist[0] , dist[1] );

When in the channel draw function, clear chan0 normally, but for chan1 make
sure you leave the color buffer as it is ( by seetting the the appropriate
mask in pfClear ).

The advantage of this method is than Performer can then do the culling
correctly so the extra graphics load on the system is minimal, nodes are
only drawn twice if they intersect both channels which will happen if they
are at a distance of dist[1] in the example above. It will increase the CULL
load on the system as CULL will now have to traverse the database twice.

Unfortunately the disadvantage of this method is that there are likely to be
clipping artefacts as objects ( especially trnasparent ones ) transitive
from the far channels to the near one. This technique works best in a sparse
database ( such as space ) where the near and far clipping planes can be
dynamically moved ( in APP ) based on the positions of the database objects.

I hope this helps.

Colin.

> -----Original Message-----
> From: owner-info-performer++at++performer.engr.sgi.com
> [mailto:owner-info-performer++at++performer.engr.sgi.com] On
> Behalf Of Simon.Mills++at++esa.int
> Sent: 15 April 2005 15:43
> To: lberto++at++adelphia.net
> Cc: info-performer++at++sgi.com
> Subject: Re: [info-performer] drawing close and far objects
> with differing near far clip plains
>
>
> Hi Iberto,
>
> I had to solve the same problem. I wanted to draw the earth
> at real-world size in meters(!). I tried a similar idea but
> went to OpenGL level to temporarily extend out the near
> clipping plane while drawing this far away object. Seems to
> work for me but I did wonder how "legal" it was. Hope it helps.
>
> //
> // Work-around for flickering when drawing earth due to
> insufficient Z-buffer // resolution when drawing ISS and
> Earth to ACTUAL SCALE. It involves setting // draw callbacks
> to increase the near plane distance temporarily.
> //
> static void
> setEarthNearFarAdjust()
> {
> if (EarthDCS) {
> EarthDCS->setTravFuncs(PFTRAV_DRAW, preDrawEarthCB,
> postDrawEarthCB);
> }
> }
>
> //
> // -- Callbacks --
> //
>
> static int
> preDrawEarthCB(pfTraverser *trav, void *) {
> // Get current near, far distances
> float near, far;
> pfChannel *chan = trav->getChan();
> chan->getNearFar(&near, &far);
>
> // Get GL projection matrix
> float projMat[16];
> glGetFloatv(GL_PROJECTION_MATRIX, projMat);
>
> // Scale near place distance up by factor
> static const float nearScaleFactor = 1000.0f;
> float newNear = nearScaleFactor * near;
>
> // Scale elements of projection matrix that are near
> plane scale dependent.
> // This is only elements [2][2] and [2][3] or [10] and
> [14] if referred
> // to as a 1D GL matrix. See glFrustum man page.
> //
> float frustDepth = far - newNear;
> projMat[10] = - (far + newNear) / frustDepth;
> projMat[14] = - (2.0f * far * newNear) / frustDepth;
>
> // Push adjusted projection matrix
> glMatrixMode(GL_PROJECTION);
> glPushMatrix();
> glLoadMatrixf(projMat);
> glMatrixMode(GL_MODELVIEW);
>
> return PFTRAV_CONT;
> }
>
>
> static int
> postDrawEarthCB(pfTraverser *, void *)
> {
> // Pop adjusted projection matrix
> glMatrixMode(GL_PROJECTION);
> glPopMatrix();
> glMatrixMode(GL_MODELVIEW);
>
> return PFTRAV_CONT;
> }
>
>
> Regards, Simon
> ______________________________________________________________
> _________
>
> Simon Mills
> Modelling & Simulation Section (TEC-SWM) Tel: +31
> (0)71 565 3725
> European Space Agency (ESA/ESTEC) Fax: +31
> (0)71 565 5420
> Postbus 299, 2200AG Noordwijk e-mail:
> Simon.Mills++at++esa.int
> The Netherlands
> http://www.estec.esa.nl/wmwww/EMM
> ______________________________________________________________
> _________
>
>
> |---------+------------------------------------------->
> | | lberto++at++adelphia.net |
> | | Sent by: |
> | | owner-info-performer++at++performer.e|
> | | ngr.sgi.com |
> | | |
> | | |
> | | 14/04/2005 19:26 |
> | | |
> |---------+------------------------------------------->
>
> >-------------------------------------------------------------
> --------------------------------------------------------|
> |
> |
> | To: info-performer++at++sgi.com
> |
> | cc:
> |
> | Subject: [info-performer] drawing close and far
> objects with differing near far clip plains |
>
> >-------------------------------------------------------------
> --------------------------------------------------------|
>
>
>
>
> I am trying to change the near far clipplane in an objects
> draw callback to cut down on z fighting on objects far aw aye
> while maintaining close objects rendering ability.
> It seems that when I change the clip planes by setting the
> chan->setNearFar() command, the channel says that the clip
> plains are set appropriately but the close object dose not
> draw as expected.
>
> My question is, is this leagle to do?
> If so then why dose my close object draw as if the near clip
> plane in out to far.
> if Not then what is the correct way to draw near and far
> objects without z fighting?
>
> --------------------------------------------------------------
> ---------
> List Archives, Info, FAQ: http://www.sgi.com/software/performer/
> Open Development Project: http://oss.sgi.com/projects/performer/
> Submissions: info-performer++at++sgi.com
> Admin. requests: info-performer-request++at++sgi.com
> --------------------------------------------------------------
> ---------
>
>
>
>
>
>
> --------------------------------------------------------------
> ---------
> List Archives, Info, FAQ: http://www.sgi.com/software/performer/
> Open Development Project: http://oss.sgi.com/projects/performer/
> Submissions: info-performer++at++sgi.com
> Admin. requests: info-performer-request++at++sgi.com
> --------------------------------------------------------------
> ---------
>


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Mon Apr 18 2005 - 02:17:30 PDT