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

Date view Thread view Subject view Author view

From: MLM Veraart (veraart++at++fel.tno.nl)
Date: 04/18/2005 07:23:43


You can use multiple pfScene-s.
One for each channel.
Now culling has a very easy job for the far objects.

Mario

Colin Middleton wrote:
>
> 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
> >
> > | | lberto++at++adelphia.net |
> >
> > 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?

-- 
------------------------------------------------------------------------------
The disclaimer that applies to e-mail from TNO
can be found on: http://www.tno.nl/disclaimer/email.html
------------------------------------------------------------------------------


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Mon Apr 18 2005 - 07:24:12 PDT