Archived

This topic is now archived and is closed to further replies.

THCForce

Reflections on transparent surfaces

Recommended Posts

Hi there ! I''ve tried to create a more or less realistic looking water-surface using Tutorial #27 (Reflections using the Stencil Buffer). The reflection code works fine, but I didn''t manage to make the surface transparent, too (if it''s possible at all). I''d be very happy if anybody has an idea ! THANX in advance

Share this post


Link to post
Share on other sites
If you mean you want to make the quad that''s being drawn as water reflective, just add an alpha layer in (I have a texture drawn, so I would need an alpha layer. Maybe you just need to enable alpha blending and use glColor4f(...)). That should work, if that''s what you really want.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
No it is not possible, at least not with the stencil buffer method. But it can be done by rendering the reflected geometry to a texture and mapping this texture onto the water surface in the actual render pass, using alpha blending.

Share this post


Link to post
Share on other sites
Its a lot harder to do what you''re asking than it sounds.
there are several steps. The stencil buffer is not nessecary, but it can make things easier, but prevent use of a cool effect.

I''ve done it before though, either way, so it is possible.

first, render the scene from the mirrored position, facing in the mirrored direction, to a texture.
the easy way, as mentioned before, is use the stencil to draw the plane in the stencil buffer (but not colour buffer/z) then draw an ortho quad to the view with the texture, and additive trans.
Or. and this is the better, but harder, way.
you draw the water surface (with undulations if you want) with a the texture projected with a texture matrix inverse to that of the model view matrix using object tex coord generation.
Then, what you can do, is disable Q tex corrd generation and leave the q coords to a texture coord array, where they are shifting slightly, scaled by the perpendicular distance to the reflection plane. the end result is an undulating reflection that looks absolutly awesome.

Here is older code for setting up the texture matrix.
where fXrot and fYrot are the view rotations (I said it was old )

  
void ReflectionGen::GenTextureProjectionMatrix(float fXrot, float fYrot)
{
float cx=cosf(fXrot*pi_180);
float sx=sinf(fXrot*pi_180);
float cy=cosf(fYrot*pi_180);
float sy=sinf(fYrot*pi_180);

/*

the matrix is in this form:

cx sx 0 0
sx*sy -cx*sy cy 0
sx*cy -cs*cy -sy 0
0 0 0 1
*/

float Matrix[4][4];

Matrix[0][0]=cx; Matrix[1][0]=sx; Matrix[2][0]=0; Matrix[3][0]=0;
Matrix[0][1]=sx*sy; Matrix[1][1]=-cx*sy; Matrix[2][1]=cy; Matrix[3][1]=0;
Matrix[0][2]=sx*cy; Matrix[1][2]=-cx*cy; Matrix[2][2]=-sy; Matrix[3][2]=0;
Matrix[0][3]=0; Matrix[1][3]=0; Matrix[2][3]=0; Matrix[3][3]=1;

glMultMatrixf((float *) Matrix );
}

Share this post


Link to post
Share on other sites
Thanks for your Support , ya all !!!

But I think I''m not that advanced to perform your method,
RipTorn. But If you have the time to explain it more in
a simpler way , I would GREATLY appreciate that !

- May this forum never die -

Share this post


Link to post
Share on other sites