Debian Codegraph @

tests/manual/advancedcustommaterial/shaders/gl3/water.vert

raw
1 #version 150 core
2
3 in vec3 vertexPosition;
4 in vec3 vertexNormal;
5 in vec2 vertexTexCoord;
6 in vec4 vertexTangent;
7
8 out vec3 worldPosition;
9 out vec3 worldNormal;
10 out vec4 worldTangent;
11 out vec2 texCoord;
12 out vec2 movtexCoord;
13 out vec2 multexCoord;
14 out vec2 waveTexCoord;
15 out vec2 skyTexCoord;
16 out vec3 vpos;
17
18 uniform mat4 modelMatrix;
19 uniform mat3 modelNormalMatrix;
20 uniform mat4 mvp;
21
22 uniform float offsetx;
23 uniform float offsety;
24 uniform float vertYpos;
25 uniform float texCoordScale;
26 uniform float waveheight;
27 uniform float waveRandom;
28
29
30 void main()
31 {
32 // Scale texture coordinates for for fragment shader
33 texCoord = vertexTexCoord * texCoordScale;
34 movtexCoord = vertexTexCoord * texCoordScale;
35 multexCoord = vertexTexCoord * (texCoordScale*0.5);
36 waveTexCoord = vertexTexCoord * (texCoordScale * 6);
37 skyTexCoord = vertexTexCoord * (texCoordScale * 0.2);
38
39 // Add Animated x and y Offset to SKY, MOV and MUL texCoords
40 movtexCoord = vec2(texCoord.x+offsetx,texCoord.y+offsety);
41 multexCoord = vec2(texCoord.x-offsetx,texCoord.y+offsety);
42 skyTexCoord = vec2(texCoord.x-(offsetx/2),texCoord.y-(offsety/2));
43
44 // Transform position, normal, and tangent to world coords
45 worldPosition = vec3(modelMatrix * vec4(vertexPosition, 1.0));
46 worldNormal = normalize(modelNormalMatrix * vertexNormal);
47 worldTangent.xyz = normalize(vec3(modelMatrix * vec4(vertexTangent.xyz, 0.0)));
48 worldTangent.w = vertexTangent.w;
49
50 // Calculate animated vertex positions
51
52 float sinPos = (vertexPosition.z)+(vertexPosition.x);
53 float sinPos2 = (vertexPosition.y/2)+(vertexPosition.z);
54 vec3 vertMod = vec3(vertexPosition.x,vertexPosition.y,vertexPosition.z);
55
56 vertMod = vec3(vertMod.x+=sin(vertYpos*2.2-sinPos2)*waveheight,
57 vertMod.y=sin(vertYpos*2.2+sinPos)*waveheight,
58 vertMod.z-=sin(vertYpos*2.2-cos(sinPos2))*waveheight);
59
60 vec3 vertModCom = vec3(vertMod.x+=cos(vertYpos*2.2-cos(sinPos2))*waveheight,
61 vertMod.y=sin(vertYpos*2.2+cos(sinPos))*waveheight,
62 vertMod.z-=cos(vertYpos*2.2-cos(sinPos))*waveheight);
63
64
65 // Add wave animation only to vertices above world pos.y zero
66 if(vertexPosition.y < 0.0){vertModCom = vertexPosition;}
67 else{vertModCom = vertModCom;}
68
69 vpos = vertModCom;
70
71 // Calculate vertex position in clip coordinates
72 gl_Position = mvp * vec4(vertModCom, 1.0);
73 }