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.
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:
normal = normalize(vec3(2.0*(texture2D(SamplerForCaustics, vec2(TexCoord)) - 0.5)) * gl_NormalMatrix);
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:
gl_FragColor = texture2D(SamplerForReflectionMap, vec2(gl_TexCoord[0]) + normal / X);
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
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:
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.
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.