OpenGL Water Tutorial 8: Soft Edges (FINAL)
Final episode of the tutorial series about programming 3D water using OpenGL!
Smoothing up those hard water edges this week!
DuDv Map and Normal Map:
https://www.dropbox.com/sh/z21kj5s448vzfql/AADy_KocZ6gDgK1lYjv7_SBAa?dl=0
Conversion Code:
https://www.dropbox.com/s/4b0xv8crvn68ip5/Conversion%20Code.txt?dl=0
Conversion Explanations:
http://web.archive.org/web/20130416194336/http://olivers.posterous.com/linear-depth-in-glsl-for-real
http://stackoverflow.com/questions/6652253/getting-the-true-z-value-from-the-depth-buffer
gl_FragCoord:
https://www.opengl.org/sdk/docs/man/html/gl_FragCoord.xhtml
One thing I didn't mention: if you want to make deeper water look murky then you can add something like this into the fragment shader:
refractColour = mix(refractColour, murkyWaterColour, clamp(waterDepth/60.0, 0.0, 1.0));
Common Problems:
-If the edges of the water quad look a bit glitchy and jagged (especially when you zoom out with the camera) then you may have a problem with the precision of the depth buffer. This can be fixed by increasing the NEAR_PLANE value of your projection matrix in the MasterRenderer, or by changing "new PixelFormat()" to "new PixelFormat().withDepthBits(24)" when creating the display.
Series Overview:
1. Introduction
2. Rendering to textures
3. Clipping planes
4. Projective texturing
5. Du Dv Maps
6. Fresnel Effect
7. Lighting
8. Depth Effects
Tumblr: http://thinmatrix.tumblr.com/
Facebook Page: https://www.facebook.com/thinmatrix
Instagram: http://instagram.com/thin_matrix
Twitter: https://twitter.com/ThinMatrix
Pinterest: https://uk.pinterest.com/thinmatrix/
Check out my game on IndieDB: http://www.indiedb.com/games/socuwan
Contact me: thinmatrix@gmail.com
End of video music- Kai Engel, "Waking Stars":
http://freemusicarchive.org/music/Kai_Engel/Evening_Colors/01_-_Waking_Stars