Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSL/Ocean2GLSL.vert @ 12084

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

Reorganised shader programs

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