Re: 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 23:20:07 GMT


Hello all,

After giving up on the Performer/caustics problem, I went back to
beating my head against it and finally got it working. The problem was
that the textures in the scene on the second render pass were
overriding my caustic texture binding.

So the only change required was from:

    //-----------
    pfDraw(); // render caustic pass
    //-----------

to:

    //-----------
    // Prevent textures in scene traversal from being activated, because we
    // only want the caustic texture to render
    pfOverride(PFSTATE_ENTEXTURE | PFSTATE_TEXTURE | PFSTATE_TEXENV,
               PF_ON);

    pfDraw(); // render caustic pass

    // turn overrides off
    pfOverride(PFSTATE_ENTEXTURE | PFSTATE_TEXTURE | PFSTATE_TEXENV,
               PF_OFF);
    //-----------

If someone knows how to do this using Performer-only calls instead of
OGL, I'd be interested in seeing it.

Thanks to Andy Schein from SGI for helping me through this!

Cheers,
chris

Chris Kline
MIT Media Lab
Synthetic Characters Group

"ck" == Christopher Kline <ckline++at++media.mit.edu> writes:

ck> Hello,

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

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

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

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

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

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

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

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

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

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

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

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

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

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

ck> glBindTexture(GL_TEXTURE_2D, CAUSTIC_BASE + currentCaustic+1);

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

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

ck> }

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

ck> thanks,
ck> chris

ck> Chris Kline
ck> MIT Media Lab
ck> 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.