Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSLES/Ocean2GLSLES.frag @ 12091

Last change on this file since 12091 was 12091, checked in by wiesep, 5 years ago

Updated programs and adjusted Material to work with GLSL>150

File size: 2.7 KB
Line 
1#version 100
2
3precision mediump int;
4precision mediump float;
5
6/*********************************************************************NVMH3****
7Copyright NVIDIA Corporation 2003
8TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
9*AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
10OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
11AND FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS
12BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES
13WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
14BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS)
15ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS
16BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
17
18
19Comments:
20        Simple ocean shader with animated bump map and geometric waves
21        Based partly on "Effective Water Simulation From Physical Models", GPU Gems
22
2311 Aug 05: converted from HLSL to GLSL by Jeff Doyle (nfz) to work in Ogre
246 Jan 10: converted from GLSL to GLSL ES by David Rogers (masterfalcon) to work in Ogre
25
26******************************************************************************/
27
28
29uniform sampler2D NormalMap;
30uniform samplerCube EnvironmentMap;
31uniform vec4 deepColor;
32uniform vec4 shallowColor;
33uniform vec4 reflectionColor;
34uniform float reflectionAmount;
35uniform float reflectionBlur;
36uniform float waterAmount;
37uniform float fresnelPower;
38uniform float fresnelBias;
39uniform float hdrMultiplier;
40
41varying mat3 rotMatrix; // first row of the 3x3 transform from tangent to cube space
42varying vec2 bumpCoord0;
43varying vec2 bumpCoord1;
44varying vec2 bumpCoord2;
45varying vec3 eyeVector;
46
47void 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}
Note: See TracBrowser for help on using the repository browser.