Space Sim
Loading...
Searching...
No Matches
postprocess.frag
Go to the documentation of this file.
1#version 430 core
2
4
5// uniform sampler2D uTexture;
6uniform sampler2D uScene;
7uniform sampler2D uDepth;
8uniform isampler2D uID;
9// uniform sampler2D uUI;
10// uniform float uTime;
11
12uniform sampler2D bloom;
13uniform sampler2D bloom2;
14uniform sampler2D history;
15uniform sampler2D shadow_map;
16uniform sampler2D uWater;
18uniform int uHovered;
19uniform int uSelected;
20uniform vec2 uTexel;
21
22#define BODY_COUNT 15000
23#define MAX_NODES 45000
24layout(std140) uniform CameraData {
25 vec4 cam_pos;
26 vec4 cam_vel;
28 mat4 view;
29 mat4 inv_projection;
30 mat4 inv_view;
31};
32struct Particle
33{
34 vec4 p_m;
35 vec4 mat;
36 vec4 vel;
37 vec4 acc;
38};
39layout(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
51layout(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
60const vec2 res = vec2(1920, 1080);
61float 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}
67void 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}
out vec4 fragColor
layout(local_size_x=16, local_size_y=16, local_size_z=1) in
int main(int argc, char *argv[])
Definition main.c:1726
uniform vec3 cam_right
Definition main.frag:24
float linearize(float z)
Definition main.frag:138
float clamp(float a, float b, float c)
Definition mathf.h:147
uniform int uSelected
Definition mesh.frag:25
uniform sampler2D shadow_map
Definition mesh.frag:65
const vec2 res
uniform sampler2D uScene
vec4 acc
Definition types.h:97
vec4 p_m
Definition types.h:94
in vec2 vUV
uniform sampler2D uWater
uniform int uHovered
uniform isampler2D uID
vec4 mat
Definition types.h:95
uniform sampler2D uDepth
uniform sampler2D bloom2
uniform sampler2D history
uniform sampler2D bloom
uniform vec2 uTexel
uniform int outside_atmosphere
vec3 vel
Definition main.h:10
Definition main.h:8
uniform mat4 projection
Definition shadow.vert:8
uniform mat4 view
Definition shadow.vert:9
#define BODY_COUNT
Definition types.h:39
Definition types.h:51
Definition types.h:45
Definition main.h:5
Definition types.h:47