DGL
https://delphigl.com/forum/

Simple, but effective, reflections?
https://delphigl.com/forum/viewtopic.php?f=19&t=6764
Seite 1 von 1

Autor:  dpm_dpmartin [ Fr Jul 20, 2007 21:23 ]
Betreff des Beitrags:  Simple, but effective, reflections?

I was wondering if anyone could provide guidance on creating reflections - in a simple way (like just reversing the texture and using alpha blending) but having extra effects like fade-out of the reflection intensity as it gets further away from the thing being reflected. I have coded the following, simple stuff:

Code:
  1.   glLoadIdentity;
  2.   glTranslatef (X,Y,Z);
  3.  
  4.   glBindTexture (GL_TEXTURE_2D,Tex5);
  5.  
  6.   glColor4f (1,1,1,1);
  7.   glBegin (GL_QUADS);
  8.     glTexCoord2f (0,0);
  9.     glVertex3f (-1,-1,0);
  10.     glTexCoord2f (1,0);
  11.     glVertex3f (1,-1,0);
  12.     glTexCoord2f (1,1);
  13.     glVertex3f (1,1,0);
  14.     glTexCoord2f (0,1);
  15.     glVertex3f (-1,1,0);
  16.   glEnd;
  17.  
  18.   glTranslatef (0,-2.1,0);
  19.  
  20.   glEnable (GL_BLEND);
  21.   glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  22.   glColor4f (1,1,1,0.20);
  23.   glBegin (GL_QUADS);
  24.     glTexCoord2f (0,1);
  25.     glVertex3f (-1,-1,0);
  26.     glTexCoord2f (1,1);
  27.     glVertex3f (1,-1,0);
  28.     glTexCoord2f (1,0);
  29.     glVertex3f (1,1,0);
  30.     glTexCoord2f (0,0);
  31.     glVertex3f (-1,1,0);
  32.   glEnd;
  33.   glDisable (GL_BLEND);

Which produces something like this:

Bild

I think this looks quite effective; it's not terrible anyway. However, what I am wondering is whether I can make the bottom half of the reflected texture fade away even further into the background. Can I do this using any simple techniques or do I have to go into what I've seen referred to on other Internet articles - stencil buffers and suchlike? I'd prefer to keep it simple... or maybe use a trick... I was thinking like another texture blended over it that matches the white background - but the background could change. Any ideas appreciated - and code snippets showing me how are appreciated even more.

Autor:  i0n0s [ Fr Jul 20, 2007 21:29 ]
Betreff des Beitrags: 

Why not blend that way? You first draw a texture including an alpha channel for the fading, then drawing the 'reflection' with blendmode on.

Autor:  dpm_dpmartin [ Fr Jul 20, 2007 21:35 ]
Betreff des Beitrags: 

Are you able to elaborate a bit for me, please - I'm not 100% sure of where your suggestions are taking me? Do you mean, draw my 'solid' texture, then draw a reflected texture underneath it with an alpha-channel, then another with blending on? Will that enable my reflection to appear as though it fades out the further away it gets from the origin of the reflection? An example, pseudo-code even, would be very helpful - but I understand if it's too much hassle.

Autor:  i0n0s [ Fr Jul 20, 2007 23:27 ]
Betreff des Beitrags: 

Using a texture like this:
Bild
Code:
  1.   glBlendFunc(GL_SRC_COLOR,GL_DST_COLOR);

will result in this:
Bild

Autor:  dj3hut1 [ Sa Jul 21, 2007 09:35 ]
Betreff des Beitrags: 

Hello,

why not give every vertex its own alpha color and let interpolate it with glShadeModel(GL_SMOOTH)?
F.e. :

Code:
  1. glEnable (GL_BLEND);
  2. glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
  3. glBegin (GL_QUADS);
  4.     glTexCoord2f (0,1);
  5.     glColor4f (1,1,1,0.20);
  6.     glVertex3f (-1,-1,0);
  7.     glTexCoord2f (1,1);
  8.     glColor4f (1,1,1,0.20);
  9.     glVertex3f (1,-1,0);
  10.     glTexCoord2f (1,0);
  11.     glColor4f (1,1,1,0.0);
  12.     glVertex3f (1,1,0);
  13.     glTexCoord2f (0,0);
  14.     glColor4f (1,1,1,0.0);
  15.     glVertex3f (-1,1,0);
  16. glEnd;
  17. glDisable (GL_BLEND);

Autor:  dpm_dpmartin [ Sa Jul 21, 2007 09:59 ]
Betreff des Beitrags: 

That is very well done indeed! I liked both suggestions - and I had been playing around with the texture mask suggestion, however, I think the second suggestion works for my needs also, and it seems even simpler - so I am going to implement this I think. Thank you both very much!

Autor:  dpm_dpmartin [ Sa Jul 21, 2007 11:50 ]
Betreff des Beitrags:  Done!

I now have this, which I'm quite pleased with to be honest...

Bild

Thanks!

I have intentionally put a small gap between the bottom of the texture being reflected and the top of the texture reflection... does this look good, or would I be best starting the reflection immediately below the texture being reflected? I think this gives the appearance of a glossy floor without actually needing one.

Autor:  i0n0s [ Sa Jul 21, 2007 14:39 ]
Betreff des Beitrags:  Re: Done!

dpm_dpmartin hat geschrieben:
I have intentionally put a small gap between the bottom of the texture being reflected and the top of the texture reflection... does this look good, or would I be best starting the reflection immediately below the texture being reflected? I think this gives the appearance of a glossy floor without actually needing one.

This gap looks like there hovering. I would prever the immediately reflection.

Autor:  dpm_dpmartin [ Sa Jul 21, 2007 14:58 ]
Betreff des Beitrags: 

OK, so now I have this... and I think it looks good...

Bild

They also rotate smoothly when using the buttons on the MCE Remote Control... can't wait to integrate it to my project.

Autor:  Flash [ So Jul 22, 2007 23:43 ]
Betreff des Beitrags: 

yes, this looks better.

jm2c ;)

Seite 1 von 1 Alle Zeiten sind UTC + 1 Stunde
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/