Help needed with caustic rendering in Performer's draw callback

New Message Reply Date view Thread view Subject view Author view

Christopher Kline (ckline++at++media.mit.edu)
Sat, 10 Jan 1998 07:49:19 GMT


Hello,

I'm having a bit of trouble adapting the underwater caustic rendering
scheme described by Mark Kilgard at

       http://reality.sgi.com/mjk_asd/tips/caustics/

to work in Iris Performer. I have successfully created a draw callback
and can get the caustics to render perfectly as long as I do not have
any other textures in my scene. Once I add textures to the scene, the
caustics don't work.

Being new to Performer and at my wit's end, I was hoping someone might
have already done this or would be willing to take a quick look at my
callback and see if there's anything obvious that I am doing
incorrectly.

Here's a comparison of what happens when I do and do not have textures
on the geometry of my scene:

       http://www.media.mit.edu/~ckline/caustics.html

You can see that as soon as I add textures to the scene, the caustics
fail to show up and the scene darkens in color.

Does this stick out to anyone as something obvious that I am doing
wrong? If it helps, here's the code from my draw callback:

void channelDrawCallback(pfChannel *chan, void *data)
{
       
  // The 0.03 in the Y column is just to shift the texture coordinates
  // a little based on Y (depth in the water) so that vertical faces
  // do not get totally vertical caustics.
  static GLfloat sPlane[4] = { 0.05, 0.03, 0.0, 0.0 };
  static GLfloat tPlane[4] = { 0.0, 0.03, 0.05, 0.0 };
  static int causticTexturesHaveBeenLoaded = 0;
   
  // data passed in telling the callback whether or not to do the OGL
  // voodoo necessary to render the caustics
  PassData *pd = (PassData*)data;
   
  //-----------
  chan->clear();
  pfDraw(); // render normal pass
  //-----------

  if (pd->causticsOn)
  {
    if (!causticTexturesHaveBeenLoaded)
    {
      // Load in the caustic texture maps from files
      initCaustics();
      causticTexturesHaveBeenLoaded = 1;
    }

    glEnable(GL_TEXTURE_2D);
         
    // Disable depth buffer update and exactly match depth buffer values for
    // slightly faster rendering.
    glDepthMask(GL_FALSE);
    glDepthFunc(GL_EQUAL);
                                    
    // Multiply the source color (from the caustic luminance texture) with the
    // previous color from the normal pass. The caustics are modulated into the
    // scene.
    glBlendFunc(GL_ZERO, GL_SRC_COLOR);
    glEnable(GL_BLEND);

    // The causticScale determines how large the caustic "ripples" will
    // be. See the "Increate/Decrease ripple size" menu options.
     
    sPlane[0] = 0.05 * causticScale;
    sPlane[1] = 0.03 * causticScale;
     
    tPlane[1] = 0.03 * causticScale;
    tPlane[2] = 0.05 * causticScale;
     
    // Set current color to "white" and disable lighting
    // to emulate OpenGL 1.1's GL_REPLACE texture environment.
    glColor3f(1.0, 1.0, 1.0);
    glDisable(GL_LIGHTING);

    // Generate the S & T coordinates for the caustic textures
    // from the object coordinates.

    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
    glTexGenfv(GL_S, GL_OBJECT_PLANE, sPlane);
    glTexGenfv(GL_T, GL_OBJECT_PLANE, tPlane);
    glEnable(GL_TEXTURE_GEN_S);
    glEnable(GL_TEXTURE_GEN_T);

    glBindTexture(GL_TEXTURE_2D, CAUSTIC_BASE + currentCaustic+1);

    // cycle through the pattern of caustics
    currentCaustic = (currentCaustic + causticIncrement) % NUM_PATTERNS;
   
    //-----------
    pfDraw(); // render caustic pass
    //-----------

    glEnable(GL_LIGHTING);
    glDisable(GL_BLEND);
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_TEXTURE_GEN_S);
    glDisable(GL_TEXTURE_GEN_T);
   
    glDepthMask(GL_TRUE);
    glDepthFunc(GL_LESS);
   
  }

}

This one really has me stumped. Any help would be greatly appreciated!

thanks,
chris

Chris Kline
MIT Media Lab
Synthetic Characters Group
=======================================================================
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:56:33 PDT

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