Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSL150/Ocean2GLSL.frag @ 12083

Last change on this file since 12083 was 12083, checked in by wiesep, 6 years ago

Reorganised shader programs

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