- normal = normalize(vec3(2.0*(texture2D(SamplerForCaustics, vec2(TexCoord)) - 0.5)) * gl_NormalMatrix);
DGL https://delphigl.com/forum/ |
|
Realistic water with shaders and runtime reflection https://delphigl.com/forum/viewtopic.php?f=19&t=4401 |
Seite 1 von 1 |
Autor: | BTierens [ Mi Aug 03, 2005 09:36 ] |
Betreff des Beitrags: | Realistic water with shaders and runtime reflection |
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. |
Autor: | Gran [ Mi Aug 03, 2005 23:28 ] |
Betreff des Beitrags: | |
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:
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:
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. |
Autor: | BTierens [ Do Aug 04, 2005 07:30 ] |
Betreff des Beitrags: | |
I understand it a bit but it would be very nice if you could post the source code. |
Autor: | Gran [ Do Aug 04, 2005 12:49 ] | ||
Betreff des Beitrags: | Sourcecode | ||
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:
The glActiveTexture lines tell the shader that the texture which is bound next should be placed in texture unit X. Code:
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/
|
Autor: | BTierens [ Do Aug 04, 2005 17:56 ] |
Betreff des Beitrags: | |
Thank you very much. I think I understand how to do it. |
Seite 1 von 1 | Alle Zeiten sind UTC + 1 Stunde |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |