| 1 | #version 100 |
|---|
| 2 | |
|---|
| 3 | precision mediump int; |
|---|
| 4 | precision mediump float; |
|---|
| 5 | |
|---|
| 6 | /*********************************************************************NVMH3**** |
|---|
| 7 | Copyright NVIDIA Corporation 2003 |
|---|
| 8 | TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED |
|---|
| 9 | *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS |
|---|
| 10 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY |
|---|
| 11 | AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS |
|---|
| 12 | BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES |
|---|
| 13 | WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, |
|---|
| 14 | BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) |
|---|
| 15 | ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS |
|---|
| 16 | BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | Comments: |
|---|
| 20 | Simple ocean shader with animated bump map and geometric waves |
|---|
| 21 | Based partly on "Effective Water Simulation From Physical Models", GPU Gems |
|---|
| 22 | |
|---|
| 23 | 11 Aug 05: converted from HLSL to GLSL by Jeff Doyle (nfz) to work in Ogre |
|---|
| 24 | 6 Jan 10: converted from GLSL to GLSL ES by David Rogers (masterfalcon) to work in Ogre |
|---|
| 25 | |
|---|
| 26 | ******************************************************************************/ |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | uniform sampler2D NormalMap; |
|---|
| 30 | uniform samplerCube EnvironmentMap; |
|---|
| 31 | uniform vec4 deepColor; |
|---|
| 32 | uniform vec4 shallowColor; |
|---|
| 33 | uniform vec4 reflectionColor; |
|---|
| 34 | uniform float reflectionAmount; |
|---|
| 35 | uniform float reflectionBlur; |
|---|
| 36 | uniform float waterAmount; |
|---|
| 37 | uniform float fresnelPower; |
|---|
| 38 | uniform float fresnelBias; |
|---|
| 39 | uniform float hdrMultiplier; |
|---|
| 40 | |
|---|
| 41 | varying mat3 rotMatrix; // first row of the 3x3 transform from tangent to cube space |
|---|
| 42 | varying vec2 bumpCoord0; |
|---|
| 43 | varying vec2 bumpCoord1; |
|---|
| 44 | varying vec2 bumpCoord2; |
|---|
| 45 | varying vec3 eyeVector; |
|---|
| 46 | |
|---|
| 47 | void main(void) |
|---|
| 48 | { |
|---|
| 49 | // sum normal maps |
|---|
| 50 | // sample from 3 different points so no texture repetition is noticeable |
|---|
| 51 | vec4 t0 = texture2D(NormalMap, bumpCoord0) * 2.0 - 1.0; |
|---|
| 52 | vec4 t1 = texture2D(NormalMap, bumpCoord1) * 2.0 - 1.0; |
|---|
| 53 | vec4 t2 = texture2D(NormalMap, bumpCoord2) * 2.0 - 1.0; |
|---|
| 54 | vec3 N = t0.xyz + t1.xyz + t2.xyz; |
|---|
| 55 | |
|---|
| 56 | N = normalize(rotMatrix * N); |
|---|
| 57 | |
|---|
| 58 | // reflection |
|---|
| 59 | vec3 E = normalize(eyeVector); |
|---|
| 60 | vec3 R = reflect(E, N); |
|---|
| 61 | // Ogre conversion for cube map lookup |
|---|
| 62 | R.z = -R.z; |
|---|
| 63 | |
|---|
| 64 | vec4 reflection = textureCube(EnvironmentMap, R, reflectionBlur); |
|---|
| 65 | // cheap hdr effect |
|---|
| 66 | reflection.rgb *= (reflection.r + reflection.g + reflection.b) * hdrMultiplier; |
|---|
| 67 | |
|---|
| 68 | // fresnel |
|---|
| 69 | float facing = 1.0 - dot(-E, N); |
|---|
| 70 | float fresnel = clamp(fresnelBias + pow(facing, fresnelPower), 0.0, 1.0); |
|---|
| 71 | |
|---|
| 72 | vec4 waterColor = mix(shallowColor, deepColor, facing) * waterAmount; |
|---|
| 73 | |
|---|
| 74 | reflection = mix(waterColor, reflection * reflectionColor, fresnel) * reflectionAmount; |
|---|
| 75 | gl_FragColor = waterColor + reflection; |
|---|
| 76 | } |
|---|