Files |  Tutorials |  Articles |  Links |  Home |  Team |  Forum |  Wiki |  Impressum

Aktuelle Zeit: Di Mai 14, 2024 03:42

Foren-Übersicht » English » English Programming Forum
Unbeantwortete Themen | Aktive Themen



Ein neues Thema erstellen Auf das Thema antworten  [ 10 Beiträge ] 
Autor Nachricht
 Betreff des Beitrags: Simple, but effective, reflections?
BeitragVerfasst: Fr Jul 20, 2007 21:23 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jan 24, 2007 00:44
Beiträge: 144
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.

_________________
Cheers, DpM
http://www.hmusiccentre.org.uk


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Jul 20, 2007 21:29 
Offline
Ernährungsberater
Benutzeravatar

Registriert: Sa Jan 01, 2005 17:11
Beiträge: 2067
Programmiersprache: C++
Why not blend that way? You first draw a texture including an alpha channel for the fading, then drawing the 'reflection' with blendmode on.

_________________
Steppity,steppity,step,step,step! :twisted:
❆ ❄ ❄ ❄ ❅ ❄ ❆ ❄ ❅ ❄ ❅ ❄ ❅ ❄ ❄
❄ ❄ ❄ ❅ ❄ ❄ ❄ ❅ ❄ ❄ ❆ ❄ ❄


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Jul 20, 2007 21:35 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jan 24, 2007 00:44
Beiträge: 144
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.

_________________
Cheers, DpM
http://www.hmusiccentre.org.uk


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Fr Jul 20, 2007 23:27 
Offline
Ernährungsberater
Benutzeravatar

Registriert: Sa Jan 01, 2005 17:11
Beiträge: 2067
Programmiersprache: C++
Using a texture like this:
Bild
Code:
  1.   glBlendFunc(GL_SRC_COLOR,GL_DST_COLOR);

will result in this:
Bild

_________________
Steppity,steppity,step,step,step! :twisted:
❆ ❄ ❄ ❄ ❅ ❄ ❆ ❄ ❅ ❄ ❅ ❄ ❅ ❄ ❄
❄ ❄ ❄ ❅ ❄ ❄ ❄ ❅ ❄ ❄ ❆ ❄ ❄


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Sa Jul 21, 2007 09:35 
Offline
DGL Member
Benutzeravatar

Registriert: Di Dez 27, 2005 12:44
Beiträge: 393
Wohnort: Berlin
Programmiersprache: Java, C++, Groovy
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);


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Sa Jul 21, 2007 09:59 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jan 24, 2007 00:44
Beiträge: 144
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!

_________________
Cheers, DpM
http://www.hmusiccentre.org.uk


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Done!
BeitragVerfasst: Sa Jul 21, 2007 11:50 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jan 24, 2007 00:44
Beiträge: 144
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.

_________________
Cheers, DpM
http://www.hmusiccentre.org.uk


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Re: Done!
BeitragVerfasst: Sa Jul 21, 2007 14:39 
Offline
Ernährungsberater
Benutzeravatar

Registriert: Sa Jan 01, 2005 17:11
Beiträge: 2067
Programmiersprache: C++
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.

_________________
Steppity,steppity,step,step,step! :twisted:
❆ ❄ ❄ ❄ ❅ ❄ ❆ ❄ ❅ ❄ ❅ ❄ ❅ ❄ ❄
❄ ❄ ❄ ❅ ❄ ❄ ❄ ❅ ❄ ❄ ❆ ❄ ❄


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Sa Jul 21, 2007 14:58 
Offline
DGL Member
Benutzeravatar

Registriert: Mi Jan 24, 2007 00:44
Beiträge: 144
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.

_________________
Cheers, DpM
http://www.hmusiccentre.org.uk


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: So Jul 22, 2007 23:43 
Offline
Guitar Hero
Benutzeravatar

Registriert: Do Sep 25, 2003 15:56
Beiträge: 7804
Wohnort: Sachsen - ERZ / C
Programmiersprache: Java (, Pascal)
yes, this looks better.

jm2c ;)

_________________
Blog: kevin-fleischer.de und fbaingermany.com


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 10 Beiträge ] 
Foren-Übersicht » English » English Programming Forum


Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 4 Gäste


Du darfst keine neuen Themen in diesem Forum erstellen.
Du darfst keine Antworten zu Themen in diesem Forum erstellen.
Du darfst deine Beiträge in diesem Forum nicht ändern.
Du darfst deine Beiträge in diesem Forum nicht löschen.
Du darfst keine Dateianhänge in diesem Forum erstellen.

Suche nach:
Gehe zu:  
cron
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.059s | 17 Queries | GZIP : On ]