Space Sim
Toggle main menu visibility
Loading...
Searching...
No Matches
src
render
postprocess.frag
Go to the documentation of this file.
1
#version 430 core
2
3
in
vec2
vUV
;
4
5
// uniform sampler2D uTexture;
6
uniform sampler2D
uScene
;
7
uniform sampler2D
uDepth
;
8
uniform isampler2D
uID
;
9
// uniform sampler2D uUI;
10
// uniform float uTime;
11
12
uniform sampler2D
bloom
;
13
uniform sampler2D
bloom2
;
14
uniform sampler2D
history
;
15
uniform sampler2D
shadow_map
;
16
uniform sampler2D
uWater
;
17
uniform
vec3
cam_right
;
18
uniform
int
uHovered
;
19
uniform
int
uSelected
;
20
uniform
vec2
uTexel
;
21
22
#define BODY_COUNT 15000
23
#define MAX_NODES 45000
24
layout
(std140) uniform CameraData {
25
vec4
cam_pos;
26
vec4
cam_vel;
27
mat4
projection
;
28
mat4
view
;
29
mat4
inv_projection;
30
mat4
inv_view;
31
};
32
struct
Particle
33
{
34
vec4
p_m
;
35
vec4
mat
;
36
vec4
vel
;
37
vec4
acc
;
38
};
39
layout
(std430, binding=1) buffer
ParticleData
{
40
41
Particle
p_spawn[
BODY_COUNT
];
42
vec4
p_colors[
BODY_COUNT
];
43
uint p_dead[
BODY_COUNT
];
44
uint claimed[
BODY_COUNT
];
45
int
nodes_visited[
BODY_COUNT
];
46
uint star_particles[
BODY_COUNT
];
47
Particle
p[];
48
};
49
50
51
layout
(std430, binding=6) buffer
NodeCounter
{
52
uint queue_out;
53
int
p_dead_cnt;
54
int
p_spawn_cnt;
55
uint star_pcnt;
56
};
57
58
uniform
int
outside_atmosphere
;
59
out
vec4
fragColor
;
60
const
vec2
res
=
vec2
(1920, 1080);
61
float
linearize
(
float
z)
62
{
63
float
near = 1.0;
64
float
far = 5.0;
65
return
(2.0 * near) / (far + near - z * (far - near));
66
}
67
void
main
()
68
{
69
vec2
uv =
vUV
;
70
float
closest = 1000.0;
71
vec4
color =
vec4
(0.0, 0.0, 0.0, 1.0);
72
73
int
middle_id =
uHovered
;
74
int
selected =
uSelected
;
75
int
id
= texture(
uID
, uv).r;
76
77
78
79
80
// for (int i = 0; i < star_pcnt; i++)
81
// {
82
// vec4 starPos = p[star_particles[i]].p_m;
83
84
// vec4 clip = projection * view * vec4(starPos.xyz,1.0);
85
// vec2 starScreen = clip.xy / clip.w;
86
// starScreen = starScreen * 0.5 + 0.5;
87
// float starDepth = clip.z / clip.w;
88
// starDepth = starDepth * 0.5 + 0.5;
89
// vec2 delta = uv - starScreen;
90
// if (starDepth < closest)
91
// {
92
// closest = starDepth;
93
// }
94
// else
95
// {
96
// continue;
97
// }
98
// float sceneDepth = texture(uDepth, uv).r;
99
100
// // if (sceneDepth < starDepth) continue;
101
// float weight = starPos.w;
102
// float massRadius = pow(weight, 0.5);
103
104
// float scale = 1.0f;
105
// float size = pow(weight, 1.0/3.0) * scale;
106
// // float size = massRadius;
107
// // size = clamp(size, 0.1, 50.0);
108
109
// vec4 c = projection * view * vec4(starPos.xyz,1.0);
110
// vec4 e = projection * view * vec4(starPos.xyz + cam_right * size,1.0);
111
112
// vec2 center = c.xy / c.w;
113
// vec2 edge = e.xy / e.w;
114
// center *= 0.5 + 0.5;
115
// edge *= 0.5 + 0.5;
116
117
// float screenRadius = length(edge - center) * 0.5;
118
119
120
// delta.x *= res.x / res.y;
121
// float mass = 0.2;
122
// float r = length(delta);
123
// if (r < screenRadius) continue;
124
// float rnorm = r / screenRadius;
125
126
// float alpha = mass* 5/(rnorm* rnorm + 1.0);
127
128
// float mask = smoothstep(1.0, 2.0, rnorm);
129
// // float streak = pow(abs(dot(normalize(delta), vec2(1,1))), 32.0);
130
// // color += p_colors[star_particles[i]] * streak * 0.01 * alpha;
131
132
// uv += alpha * 0.05 * normalize(delta) * mask;
133
134
// }
135
136
137
vec4
sc = texture(
uScene
, uv);
138
vec4
wc = texture(
uWater
, uv);
139
float
mask = float(wc.a < sc.a);
140
if
(
outside_atmosphere
== 0)
141
{
142
color.rgb += mix(sc.rgb, wc.rgb, mask);
143
}
144
else
145
{
146
color.rgb += sc.rgb;
147
}
148
float
abb_amt = 0.005;
149
color.rgb = pow(color.rgb,
vec3
(0.9));
150
color.rgb =
clamp
((color.rgb - 0.15) * 1.4 + 0.1, 0.0, 1.0);
151
color.rgb *=
vec3
(1.05, 0.95, 1.1);
152
153
float
gamma = 2.2;
154
color.rgb = pow(color.rgb,
vec3
(1.0/gamma));
155
156
fragColor
=
vec4
(color.rgb, 1.0);
157
}
fragColor
out vec4 fragColor
Definition
atmosphere.frag:9
layout
layout(local_size_x=16, local_size_y=16, local_size_z=1) in
main
int main(int argc, char *argv[])
Definition
main.c:1726
cam_right
uniform vec3 cam_right
Definition
main.frag:24
linearize
float linearize(float z)
Definition
main.frag:138
clamp
float clamp(float a, float b, float c)
Definition
mathf.h:147
uSelected
uniform int uSelected
Definition
mesh.frag:25
shadow_map
uniform sampler2D shadow_map
Definition
mesh.frag:65
res
const vec2 res
Definition
postprocess.frag:60
uScene
uniform sampler2D uScene
Definition
postprocess.frag:6
Particle::acc
vec4 acc
Definition
types.h:97
Particle::p_m
vec4 p_m
Definition
types.h:94
vUV
in vec2 vUV
Definition
postprocess.frag:3
uWater
uniform sampler2D uWater
Definition
postprocess.frag:16
uHovered
uniform int uHovered
Definition
postprocess.frag:18
uID
uniform isampler2D uID
Definition
postprocess.frag:8
Particle::mat
vec4 mat
Definition
types.h:95
uDepth
uniform sampler2D uDepth
Definition
postprocess.frag:7
bloom2
uniform sampler2D bloom2
Definition
postprocess.frag:13
history
uniform sampler2D history
Definition
postprocess.frag:14
bloom
uniform sampler2D bloom
Definition
postprocess.frag:12
uTexel
uniform vec2 uTexel
Definition
postprocess.frag:20
outside_atmosphere
uniform int outside_atmosphere
Definition
postprocess.frag:58
Particle::vel
vec3 vel
Definition
main.h:10
Particle
Definition
main.h:8
projection
uniform mat4 projection
Definition
shadow.vert:8
view
uniform mat4 view
Definition
shadow.vert:9
BODY_COUNT
#define BODY_COUNT
Definition
types.h:39
NodeCounter
Definition
types.h:204
ParticleData
Definition
types.h:129
mat4
Definition
types.h:51
vec2
Definition
types.h:45
vec3
Definition
main.h:5
vec4
Definition
types.h:47
Generated by
1.18.0