• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

PhoenixMee Apr 11th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #version 330
2.
3. // Uniforms
4. uniform mat4 matrixProjection;
5. uniform mat4 matrixModelView;
6. uniform float t;
7.
8. layout (location = 0) in vec3 aVertex;
9. layout (location = 2) in vec3 aNormal;
10. layout (location = 3) in vec2 aTexCoord;
11.
12. out vec4 color;
13. out vec4 position;
14. out vec3 normal;
15. out vec2 texCoord0;
16. out float reflFactor;
17. mat4 reflectedViewMatrix;
18.
19. // wave function
20. float wave(float A, float x, float y, float t)
21. {
22.     t *= 2;
23.     return A * (
24.                 sin(2.0 * (x * 0.2 + y * 0.7) + t * 1.0) +
25.                 sin(2.0 * (x * 0.2 + y * 0.7) + t * 0.8) +
26.                 pow(sin(2.0* (x * 0.6 + y * 0.5) + t * 1.2), 2) +
27.                 pow(sin(2.0* (x * 0.8 + y * 0.2) + t * 1.1), 2)
28.                );
29. }
30.
31. void main(void)
32. {
33.     // calculate waves
34.     float a = 0.05;
35.     float y = wave(a, aVertex.x, aVertex.z, t);
36.
37.     float d = 0.05;
38.     float dx = (wave(a, aVertex.x + d, aVertex.z, t) - wave(a, aVertex.x - d, aVertex.z, t)) / 2 / d;
39.     float dz = (wave(a, aVertex.x, aVertex.z + d, t) - wave(a, aVertex.x, aVertex.z - d, t)) / 2 / d;
40.
41.     vec3 newVertex = vec3(aVertex.x, y, aVertex.z);
42.     vec3 newNormal = normalize(vec3(-dx, 1, -dz));
43.
44.     // calculate positions
45.     position = matrixModelView * vec4(newVertex, 1.0);
46.     gl_Position = matrixProjection * position;
47.
48.     // calculate normal
49.     normal = normalize(mat3(matrixModelView) * newNormal);
50.
51.     // calculate texture coordinate
52.     texCoord0 = aTexCoord;
53.
54.     // calculate reflection coefficient
55.     float cosTheta = dot(normal, normalize(-position.xyz));
56.     float R0 = 0.02;
57.     reflFactor = R0 + (1 - R0) * pow (1.0 - cosTheta, 5);
58.
59.     // no light calculation for water
60.     color = vec4(1, 1, 1, 1);
61. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?