Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Updated programs and adjusted Material to work with GLSL>150

File size: 3.2 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
28uniform vec3 eyePosition;
29uniform float BumpScale;
30uniform vec2 textureScale;
31uniform vec2 bumpSpeed;
32uniform float time;
33uniform float waveFreq;
34uniform float waveAmp;
35uniform mat4 worldViewProj;
36
37varying mat3 rotMatrix; //  transform from tangent to obj space
38varying vec2 bumpCoord0;
39varying vec2 bumpCoord1;
40varying vec2 bumpCoord2;
41varying vec3 eyeVector;
42
43attribute vec4 vertex;
44attribute vec4 uv0;
45
46// wave functions
47struct Wave {
48  float freq;  // 2*PI / wavelength
49  float amp;   // amplitude
50  float phase; // speed * 2*PI / wavelength
51  vec2 dir;
52};
53
54
55void main(void)
56{
57        #define NWAVES 2
58
59        Wave wave[NWAVES];
60
61        wave[0] = Wave( waveFreq, waveAmp, 0.5, vec2(-1.0, 0.0) );
62        wave[1] = Wave( 3.0 * waveFreq, 0.33 * waveAmp, 1.7, vec2(-0.7, 0.7) );
63
64    vec4 P = vertex;
65
66        // sum waves
67        float ddx = 0.0, ddy = 0.0;
68        float deriv;
69        float angle;
70
71        // wave synthesis using two sine waves at different frequencies and phase shift
72        for(int i = 0; i<NWAVES; ++i)
73        {
74                angle = dot(wave[i].dir, P.xz) * wave[i].freq + time * wave[i].phase;
75                P.y += wave[i].amp * sin( angle );
76                // calculate derivate of wave function
77                deriv = wave[i].freq * wave[i].amp * cos(angle);
78                ddx -= deriv * wave[i].dir.x;
79                ddy -= deriv * wave[i].dir.y;
80        }
81
82        // compute the 3x3 transform from tangent space to object space
83        // compute tangent basis
84    vec3 T = normalize(vec3(1.0, ddy, 0.0)) * BumpScale; // Tangent
85    vec3 B = normalize(vec3(0.0, ddx, 1.0)) * BumpScale; // Binormal
86    vec3 N = normalize(vec3(ddx, 1.0, ddy));             // Normal
87
88        rotMatrix = mat3(T, B, N);
89//      rotMatrix = mat3(vec3(T[0], B[0], N[0]),
90//                                              vec3(T[1], B[1], N[1]),
91//                                              vec3(T[2], B[2], N[2]));
92
93        gl_Position = worldViewProj * P;
94
95        // calculate texture coordinates for normal map lookup
96        bumpCoord0.xy = uv0.xy * textureScale + time * bumpSpeed;
97        bumpCoord1.xy = uv0.xy * textureScale * 2.0 + time * bumpSpeed * 4.0;
98        bumpCoord2.xy = uv0.xy * textureScale * 4.0 + time * bumpSpeed * 8.0;
99
100        eyeVector = P.xyz - eyePosition; // eye position in vertex space
101}
Note: See TracBrowser for help on using the repository browser.