Space Sim
Loading...
Searching...
No Matches
mesh.vert
Go to the documentation of this file.
1
2#version 460
3
9layout(location = 0) in vec3 aPosition;
10layout(location = 1) in vec3 aNormal;
11layout(location = 2) in vec3 aColor;
15out float vDist;
19uniform float uPlanetRadius;
20layout(std140) uniform CameraData {
21 vec4 cam_pos;
22 vec4 cam_vel;
24 mat4 view;
25 mat4 inv_projection;
26 mat4 inv_view;
27};
28
29
30#define BODY_COUNT 30000
31#define MAX_NODES 100000
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
51
52layout(std430, binding=8) buffer MarchingCubesData
53{
54 int EDGE_TO_VERTICES[12][2];
55 int EDGE_TABLE[256];
56 int TRIANGLE_TABLE[256][16];
57};
58layout(std430, binding=9) buffer DensityData
59{
60 float density[];
61};
62struct Vertex
63{
64 vec3 pos;
65 float pad0;
66 vec3 normal;
67 float pad1;
68 vec3 color;
69 float pad2;
70};
71#define LODMAX 4
72#define MAX_CHUNKS 1000
73layout(std430, binding=10) buffer DensityVertexData
74{
75 int chunk_vertex_offset[MAX_CHUNKS];
76 Vertex vertices[];
77};
78layout(std430, binding=6) buffer NodeCounter {
79 uint queue_out;
80 int p_dead_cnt;
81 int p_spawn_cnt;
82 uint star_pcnt;
83};
84
85uniform int uType;
86// uniform vec3 cam_pos;
87
88#define NUM_OCTAVES 5
89float mod289(float x){return x - floor(x * (1.0 / 289.0)) * 289.0;}
90vec4 mod289(vec4 x){return x - floor(x * (1.0 / 289.0)) * 289.0;}
91vec4 perm(vec4 x){return mod289(((x * 34.0) + 1.0) * x);}
92
93float noise(vec3 p){
94 vec3 a = floor(p);
95 vec3 d = p - a;
96 d = d * d * (3.0 - 2.0 * d);
97
98 vec4 b = a.xxyy + vec4(0.0, 1.0, 0.0, 1.0);
99 vec4 k1 = perm(b.xyxy);
100 vec4 k2 = perm(k1.xyxy + b.zzww);
101
102 vec4 c = k2 + a.zzzz;
103 vec4 k3 = perm(c);
104 vec4 k4 = perm(c + 1.0);
105
106 vec4 o1 = fract(k3 * (1.0 / 41.0));
107 vec4 o2 = fract(k4 * (1.0 / 41.0));
108
109 vec4 o3 = o2 * d.z + o1 * (1.0 - d.z);
110 vec2 o4 = o3.yw * d.x + o3.xz * (1.0 - d.x);
111
112 return o4.y * d.y + o4.x * (1.0 - d.y);
113}
114
115
116float fbm(vec3 x) {
117 float v = 0.0;
118 float a = 0.5;
119 // float f = 1.0;
120 vec3 shift = vec3(100);
121 for (int i = 0; i < NUM_OCTAVES; ++i) {
122 v += a * noise(x);
123 x = x * 2.0 + shift;
124 // f *= 2.5;
125 a *= 0.45;
126 }
127 return v;
128}
130{
131 float x = float(p & 0xFF) / 255.0;
132 float y = float((p >> 8) & 0xFF) / 255.0;
133
134 vec2 f = vec2(x, y) * 2.0 - 1.0;
135
136 vec3 n = vec3(f.x, f.y, 1.0 - abs(f.x) - abs(f.y));
137
138 float t = clamp(-n.z, 0.0, 1.0);
139 n.xy += vec2(n.x >= 0.0 ? -t : t, n.y >= 0.0 ? -t : t);
140
141 return normalize(n);
142}
143uniform int uSelected;
144uniform sampler3D perlin_tex;
145
146
147
148
150{
151
152 float d = (p.z);
153
154 vec3 warp =
155 vec3(texture(perlin_tex, p * 0.001).r * 2.0f - 1.0f,
156 texture(perlin_tex, p* 0.001 + vec3(1.0, 1.0, 1.0)).r * 2.0f - 1.0f,
157 texture(perlin_tex, p* 0.001 + vec3(5.0, 5.0, 5.0)).r * 2.0f - 1.0f);
158 p += warp * 2.0f;
159 d += (float(texture(perlin_tex, p * 0.001).r) * 2.0f - 1.0f) * 1.55;
160 d += (float(texture(perlin_tex, p * 0.0025).r) * 2.0f - 1.0f) * 1.0;
161 d += (float(texture(perlin_tex, p * 0.007).r) * 2.0f - 1.0f) * 0.5;
162
163 d += fbm(p * 0.5) * 8;
164 return d;
165}
166void main()
167{
168
169
170 uint id = gl_VertexID;
171 Vertex v = vertices[id];
172 vec3 pos = v.pos;
173 pos.z += uPlanetRadius;
174
175 float height = pos.z;
176 float slope = 1.0 - abs(dot(-v.normal, vec3(0,0,1)));
177
178
179 vec3 base = mix(vec3(0.2,0.35,0.2), vec3(0.4,0.25,0.2), slope);
180 base = mix(base, vec3(0.4, 0.4, 0.5), max(pos.z, 0.0) / 3);
181
182 vColor = vec4(base, 1.0);
183 FragPos= vec4(pos, 1.0);
184
185 vDist = length(pos - cam_pos.xyz);
186
187 vNormal = normalize(-v.normal);
188
189
190
192 gl_Position = projection * view * vec4(pos , 1.0);
193}
in vec3 vNormal
layout(local_size_x=16, local_size_y=16, local_size_z=1) in
in vec3 vColor
Definition clouds.frag:4
uniform float uPlanetRadius
Definition clouds.frag:15
#define NUM_OCTAVES
Definition density.comp:111
float mod289(float x)
Definition density.comp:112
vec4 perm(vec4 x)
Definition density.comp:114
float fbm(vec3 x)
Definition density.comp:139
float * perlin_tex
Definition init.c:610
int main(int argc, char *argv[])
Definition main.c:1726
vec4 mat
Definition main.c:261
in float vDist
Definition main.frag:14
float density_fn(vec3 p)
const int TRIANGLE_TABLE[256][16]
const int EDGE_TO_VERTICES[12][2]
const int EDGE_TABLE[256]
float clamp(float a, float b, float c)
Definition mathf.h:147
uniform int uType
Definition mesh.frag:67
in vec4 vFragPosLightSpace
Definition mesh.frag:12
uniform int uSelected
Definition mesh.frag:25
in vec4 FragPos
Definition mesh.frag:10
uniform mat4 light_proj
Definition mesh.vert:18
uniform mat4 light_view
Definition mesh.vert:17
vec3 unpack_normal(uint p)
Definition mesh.vert:129
vec4 acc
Definition types.h:97
vec4 p_m
Definition types.h:94
vec3 vel
Definition main.h:10
Definition main.h:8
vec3 color
Definition types.h:353
float pad1
Definition types.h:352
float pad0
Definition types.h:350
uniform mat4 projection
Definition shadow.vert:8
uniform mat4 view
Definition shadow.vert:9
vec3 pos
Definition types.h:349
float pad2
Definition types.h:354
vec3 normal
Definition types.h:351
float x
Definition types.h:45
float x
Definition main.h:5
float noise(vec3 p)
Definition density.comp:116
#define BODY_COUNT
Definition types.h:39
float y
Definition types.h:45
float y
Definition types.h:47
float y
Definition main.h:5
#define MAX_CHUNKS
Definition types.h:182
float z
Definition main.h:5
Definition types.h:51
Definition types.h:45
Definition main.h:5
Definition types.h:47
uniform float t
Definition water.comp:23