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

Aktuelle Zeit: Di Mai 14, 2024 15:32

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



Ein neues Thema erstellen Auf das Thema antworten  [ 5 Beiträge ] 
Autor Nachricht
BeitragVerfasst: Mi Aug 03, 2005 09:36 
Offline
DGL Member

Registriert: Fr Aug 13, 2004 17:43
Beiträge: 60
Wohnort: Belgien
Hello,

Can someone explain the techniques to create realistic water with runtime reflection? For example, if there is a windmill (with rotation wings of course) near the water, the wing sould be reflected correctly.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Mi Aug 03, 2005 23:28 
Offline
DGL Member

Registriert: Sa Mär 20, 2004 22:48
Beiträge: 104
I'm not the GL master, but I've done realistic water for a couple of time. I used Vertex and Fragment Shaders to do this. First you'll have to get a reflection map, I heard you can do this by using renderpasses. Now that you have your texture on the plane that should be the water, you only have to take care of the animation. I used a Vertex Shader that gives two texture units to the Fragment Shader, one for the reflection map and one for the caustics. In the Fragment Shader you can work with two texture units. First, use the caustics generator for generating some caustics for the water animation. To use these normal maps, use the following line in the Fragment Shader:

Code:
  1.  
  2. normal = normalize(vec3(2.0*(texture2D(SamplerForCaustics, vec2(TexCoord)) - 0.5)) * gl_NormalMatrix);
  3.  


Now that you have a normal map that has the normals of a water structure you must tell it to influence the gl_FragColor value witch represents the color of every single pixel:

Code:
  1.  
  2. gl_FragColor = texture2D(SamplerForReflectionMap, vec2(gl_TexCoord[0]) + normal / X);
  3.  


This line will render the texture on the plane, but it will move every pixel by looking at the normal map. This is done by adding the current normal of the normal map to the position value of the texture map. Try some different values for X to get best results.

I'm afraid I can't explain it much easier, I hope you understand it. If you don't, I can post the source code if this'll help.

_________________
Der Bump Mapping User ist nur zu faul, selbst eine Wand mit Tesselation zu erstellen ;-)


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Aug 04, 2005 07:30 
Offline
DGL Member

Registriert: Fr Aug 13, 2004 17:43
Beiträge: 60
Wohnort: Belgien
I understand it a bit but it would be very nice if you could post the source code.


Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags: Sourcecode
BeitragVerfasst: Do Aug 04, 2005 12:49 
Offline
DGL Member

Registriert: Sa Mär 20, 2004 22:48
Beiträge: 104
Ok, here's the code, I didn't include the libaries I used, you'll have to copy them in yourself. Here are some explainations because I forgot to make comments:

The procedure LoadTextures would load 32 normal maps into a texture array. I didn't include those normal maps because of the size. Just use the caustics generator to generate your own water normal maps. In the Render procedure a variable gets increased so every frame there's another normal map handed to the shader which results in a smooth water animation. This is done by the following lines:

Code:
  1.  
  2. glActiveTexture(GL_TEXTURE0);
  3. glBindTexture(GL_TEXTURE_2D, SampleTexture);
  4. ...
  5. glActiveTexture(GL_TEXTURE1);
  6. glBindTexture(GL_TEXTURE_2D, BumpTexture[Round(TextureToOverhand)]);
  7.  


The glActiveTexture lines tell the shader that the texture which is bound next should be placed in texture unit X.

Code:
  1.  
  2. glUniform1iARB(glGetUniformLocationARB(ProgramObject, 'texSampler2'), 1);
  3.  


This line has to be done before every frame because you are using two texture units. It tells the Fragment Shader to link texSampler2 to the second texture unit which is GL_TEXTURE_1.

Ok, I've already explained how the shaders work in my last answer, so I think everything should be clear by now.

btw.: Link to the caustics generator: http://www.lysator.liu.se/~kand/caustics/


Dateianhänge:
Dateikommentar: The Sourcecode
Water.rar [170.54 KiB]
310-mal heruntergeladen

_________________
Der Bump Mapping User ist nur zu faul, selbst eine Wand mit Tesselation zu erstellen ;-)
Nach oben
 Profil  
Mit Zitat antworten  
 Betreff des Beitrags:
BeitragVerfasst: Do Aug 04, 2005 17:56 
Offline
DGL Member

Registriert: Fr Aug 13, 2004 17:43
Beiträge: 60
Wohnort: Belgien
Thank you very much. I think I understand how to do it.


Nach oben
 Profil  
Mit Zitat antworten  
Beiträge der letzten Zeit anzeigen:  Sortiere nach  
Ein neues Thema erstellen Auf das Thema antworten  [ 5 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:  
  Powered by phpBB® Forum Software © phpBB Group
Deutsche Übersetzung durch phpBB.de
[ Time : 0.028s | 18 Queries | GZIP : On ]