Space Sim
Toggle main menu visibility
Loading...
Searching...
No Matches
src
render
water.vert
Go to the documentation of this file.
1
#version 440
2
layout
(location = 0) in
vec3
aPosition;
3
9
layout
(std140) uniform CameraData {
10
vec4
cam_pos;
11
vec4
cam_vel;
12
mat4
projection
;
13
mat4
view
;
14
mat4
inv_projection;
15
mat4
inv_view;
16
};
17
18
out
vec3
vNormal
;
19
out
vec3
vPos
;
20
out
vec3
rvPos
;
21
out
vec3
rvNormal
;
22
out
float
vDist
;
23
out
vec2
vUV
;
24
out
vec3
vViewDir
;
25
out
vec4
vFragPosLightSpace
;
26
27
28
const
float
water_scale
= 256;
29
const
float
water_level
= -3.0f;
30
31
uniform
float
uTime
;
32
uniform sampler2D
uFFT
;
33
uniform sampler2D
uSlope
;
34
uniform sampler2D
shadow_map
;
35
uniform
float
uPlanetRadius
;
36
uniform
mat4
light_proj
;
37
uniform
mat4
light_view
;
38
39
int
L
= 1000;
40
int
N
= 128;
41
int
NUM_TILES_PER_WATER_SCALE
= 1;
42
43
44
void
main
()
45
{
46
vec3
pos = aPosition;
47
float
patchSize =
water_scale
;
48
49
pos.xy = aPosition.xy *
water_scale
+ cam_pos.xy;
50
vec2
uv = ((aPosition.xy *
water_scale
+ cam_pos.xy) / (
N
/
NUM_TILES_PER_WATER_SCALE
));
51
52
vec2
texel =
vec2
(1.0 /
N
);
53
54
float
h1 = texture(
uFFT
, uv).r;
55
vec2
dxy1 = texture(
uSlope
, uv).rb;
56
57
float
strength = 1.0 / 0.15;
58
59
float
dx = dxy1.
x
* strength;
60
float
dy = dxy1.
y
* strength;
61
float
h = h1;
62
63
pos.
z
=
water_level
+ h;
64
pos.
z
+=
uPlanetRadius
;
65
vec2
grad =
vec2
(dx, dy);
66
pos.xy += grad;
67
68
vec3
normal = normalize(
vec3
(dx, dy, 1.0));
69
70
vNormal
= normal;
71
72
vUV
= uv;
73
vPos
= pos;
74
75
vDist
= h;
76
77
vViewDir
= normalize(cam_pos.xyz - pos.xyz);
78
79
vFragPosLightSpace
=
light_proj
*
light_view
*
vec4
(pos, 1.0);
80
gl_Position =
projection
*
view
*
vec4
(pos, 1.0);
81
82
}
vPos
in vec3 vPos
Definition
atmosphere.frag:10
vNormal
in vec3 vNormal
Definition
atmosphere.frag:11
vViewDir
in vec3 vViewDir
Definition
atmosphere.frag:15
N
#define N
Definition
bit_reversal.comp:13
layout
layout(local_size_x=16, local_size_y=16, local_size_z=1) in
uPlanetRadius
uniform float uPlanetRadius
Definition
clouds.frag:15
main
int main(int argc, char *argv[])
Definition
main.c:1726
uTime
float uTime
Definition
main.c:775
vDist
in float vDist
Definition
main.frag:14
vFragPosLightSpace
in vec4 vFragPosLightSpace
Definition
mesh.frag:12
shadow_map
uniform sampler2D shadow_map
Definition
mesh.frag:65
light_proj
uniform mat4 light_proj
Definition
mesh.vert:18
light_view
uniform mat4 light_view
Definition
mesh.vert:17
vUV
in vec2 vUV
Definition
postprocess.frag:3
projection
uniform mat4 projection
Definition
shadow.vert:8
view
uniform mat4 view
Definition
shadow.vert:9
vec2::x
float x
Definition
types.h:45
vec2::y
float y
Definition
types.h:45
vec3::z
float z
Definition
main.h:5
mat4
Definition
types.h:51
vec2
Definition
types.h:45
vec3
Definition
main.h:5
vec4
Definition
types.h:47
L
#define L
Definition
water.comp:15
NUM_TILES_PER_WATER_SCALE
int NUM_TILES_PER_WATER_SCALE
Definition
water.frag:118
uFFT
uniform sampler2D uFFT
Definition
water.frag:88
rvPos
in vec3 rvPos
Definition
water.frag:22
rvNormal
in vec3 rvNormal
Definition
water.frag:23
uSlope
uniform sampler2D uSlope
Definition
water.frag:89
water_scale
const int water_scale
Definition
water.frag:111
water_level
const float water_level
Definition
water.vert:29
Generated by
1.18.0