Transparency, sorting and pfText

New Message Reply Date view Thread view Subject view Author view

Harri Kaimio (harri.kaimio++at++yle.fi)
Wed, 21 Aug 1996 12:59:34 +0300


Hi all Performers!

I am having problems with depth sorting when using textured fonts and
transparent objects in the same scene. It seems to me that pfText
objects are always drawn before transparent geometry and so appear
behind it (when using blendfunction transparency). Is this a bug or is
there some trick I have missed?

With multisample transparency it works, but the image quality is not
good enough, and I must be able to run on Impact too.

I include a short test program that illustrates my problem.

-----------------------------------------------------------------
Harri Kaimio | harri.kaimio++at++yle.fi
Computer Graphics Specialist | http://cartes.hut.fi/~hkaimio
Finnish Broadcasting Company | Tel. +358-40-50 67 679
TV Production Operations | Fax. +358-0-1480 4769

#include <Performer/pf/pfChannel.h>
#include <Performer/pf/pfDCS.h>
#include <Performer/pf/pfScene.h>
#include <Performer/pf/pfGeode.h>
#include <Performer/pr/pfTexture.h>
#include <Performer/pr/pfGeoSet.h>
#include <Performer/pr/pfGeoState.h>
#include <Performer/pf/pfLightSource.h>
#include <Performer/pf/pfText.h>
#include <Performer/pf/pfChannel.h>
#include <Performer/pf/pfNode.h>
#include <Performer/pf/pfDCS.h>
#include <Performer/pf/pfText.h>
#include <Performer/pr/pfString.h>
#include <Performer/pfdu.h>
#include <Performer/pfutil.h>

pfScene *
makeScene()
{
  pfScene * scene = new pfScene;

  // Text will be in xz-plane, so this should appear behind it
  pfVec3 *coords = (pfVec3*) new(4*sizeof(pfVec3)) pfMemory;
  coords[0].set(-1.0f, 10.0f, -1.0f);
  coords[1].set( 1.0f, 10.0f, -1.0f );
  coords[2].set( 1.0f, 10.0f, 1.0f );
  coords[3].set(-1.0f, 10.0f, 1.0f );
   
  ushort *vertexlist = (ushort*) new(4*sizeof(ushort)) pfMemory;
  vertexlist[0] = 0;
  vertexlist[1] = 1;
  vertexlist[2] = 2;
  vertexlist[3] = 3;
  pfVec4 *color = new pfVec4( 1.0, 1.0, 1.0, 0.5 );

  pfGeoSet *sqGset = new pfGeoSet;
  sqGset->setAttr(PFGS_COORD3, PFGS_PER_VERTEX, coords, NULL);
  sqGset->setAttr(PFGS_COLOR4, PFGS_PER_PRIM, color, NULL);
  sqGset->setPrimType(PFGS_QUADS);
  sqGset->setNumPrims(1);

  pfGeoState * gstate = new pfGeoState;
  gstate->setMode( PFSTATE_ENLIGHTING, 0);
  gstate->setMode( PFSTATE_TRANSPARENCY, PFTR_HIGH_QUALITY | PFTR_NO_OCCLUDE );
  gstate->setMode(PFSTATE_ALPHAFUNC, PFAF_NOTEQUAL);
  gstate->setVal(PFSTATE_ALPHAREF, 0.0f);

  sqGset->setGState( gstate );

  pfGeode * sqGeode = new pfGeode;
  sqGeode->addGSet( sqGset );

  scene->addChild( sqGeode );

  // Make text

  pfFont * font = pfdLoadFont( "type1", "Helvetica", PFDFONT_TEXTURED );
  pfText * title = new pfText;
  pfString * str = new pfString;
  str->setFont( font );
  str->setMode( PFSTR_JUSTIFY, PFSTR_MIDDLE );
  str->setColor( 0.2, 0.2, 1.0, 1.0 );
  str->setString( "Just some text" );
  title->addString( str );

  scene->addChild( title );

  pfLightSource * light = new pfLightSource;
  light->setColor( PFLT_DIFFUSE, 1.0, 1.0, 1.0 );
  light->setPos( 1.0, -1.0, 1.0, 0.0 );
  scene->addChild( light );

  return scene;
}

int
main()
{
  // Initialize Performer
  pfInit();
  pfMultiprocess( PFMP_DEFAULT );
  pfConfig();
   
  pfPipe *p = pfGetPipe(0);
  pfPipeWindow *pw = new pfPipeWindow(p);
  pw->setWinType(PFPWIN_TYPE_X);
  pw->setName("IRIS Performer");
  pw->setOriginSize(0,0,720,576);
  pw->open();
   
  pfFilePath(".:/usr/share/Performer/data");
  pfChannel *chan = new pfChannel(p);

  chan->setScene(makeScene());
  chan->setAspect( PFFRUST_CALC_VERT, 4.0/3.0 );
  chan->setFOV(45.0f, 0.0f);
  chan->setNearFar(1.0f, 50.0f );

  chan->setTravMode( PFTRAV_CULL, PFCULL_VIEW | PFCULL_SORT );
  chan->setBinSort( PFSORT_TRANSP_BIN, PFSORT_BACK_TO_FRONT, NULL );

  pfCoord view;
  view.hpr.set( 0.0, 0.0, 0.0 );
  view.xyz.set( 0.0,
               -25.0f,
               0.0f );
  chan->setView(view.xyz, view.hpr);
   
   
  for( ;; ) {
    pfSync();
    pfFrame();
  }
  return 0;
}

=======================================================================
List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/
            Submissions: info-performer++at++sgi.com
        Admin. requests: info-performer-request++at++sgi.com


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:53:23 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.