Space Sim
Loading...
Searching...
No Matches
atmosphere_from_space.vert
Go to the documentation of this file.
1
2#version 430 core
3
10
11layout(location = 0) in vec3 aPosition;
12layout(location = 1) in vec3 aNormal;
13
16out vec3 c0;
17out vec3 c1;
18out vec3 t0;
20
21layout(std140) uniform CameraData {
22 vec4 cam_pos;
23 vec4 cam_vel;
25 mat4 view;
26 mat4 inv_projection;
27 mat4 inv_view;
28};
29
30#define BODY_COUNT 15000
31struct Particle
32{
33 vec4 p_m;
34 vec4 mat;
35 vec4 vel;
36 vec4 acc;
37};
38layout(std430, binding=1) buffer ParticleData {
39
40 Particle p_spawn[BODY_COUNT];
41 vec4 p_colors[BODY_COUNT];
42 uint p_dead[BODY_COUNT];
43 uint claimed[BODY_COUNT];
44 int nodes_visited[BODY_COUNT];
45 uint star_particles[BODY_COUNT];
46 Particle p[];
47};
48#define MAX_LAYERS 24
49struct WarpLayer
50{
52 float freq0;
54 float freq1;
56 float freq2;
57 float amp;
58 float pad0;
59 float pad1;
60 float pad3;
61};
62
63struct PerlinLayer
64{
65 float freq;
66 float amp;
67 float pad0;
68 float pad1;
69};
70
71struct FBMLayer
72{
73 float freq;
74 float amp;
75 float pad0;
76 float pad1;
77};
78
79layout(std430, binding=13) buffer PlanetData {
80
81 int warp_count;
82 int perlin_count;
83 int fbm_count;
84 int pad0;
87
88 WarpLayer warp_layers[MAX_LAYERS];
89 PerlinLayer perlin_layers[MAX_LAYERS];
90 FBMLayer fbm_layers[MAX_LAYERS];
91
92};
93
95uniform float uInnerRadius;
96uniform float uInnerRadius2;
97uniform float uOuterRadius;
98uniform float uOuterRadius2;
100uniform float uFScale;
101uniform float uFScaleOverDepth;
102uniform float uFInvScaleDepth;
103uniform float uFScaleDepth;
104uniform float uG;
105uniform float uG2;
106uniform float ufKrESun;
107uniform float ufKmESun;
108uniform float ufKr4Pi;
109uniform float ufKm4Pi;
112
113
114float scale(float fCos)
115{
116 float x = 1.0 - fCos;
117 x = max(x, 0.1);
118 return 0.25 * exp(-0.00287 + x * (0.459 + x * (3.83 + x * (-6.80 + x * 5.25))));
119}
120
121uniform vec3 uCamPos;
122
123const int samples = 4;
124void main()
125{
126
127 vec3 planet_center = vec3(0.0);
128 float pscale = 1 / 10000;
129 vec3 scaled_cam = cam_pos.xyz - p[0].p_m.xyz;
130 vec3 pos = aPosition;
131 float size = pow(p[0].p_m.w, 1.0/3.0);
132 float inner = size * 0.99;
133
134 pos *= size;
135 float fscale = 1 / (size - inner);
136 float fscale_over_depth = fscale / 4.0f;
137
138 vec3 L = normalize(-sun_dir.xyz);
139 vec3 sphere_ray_to_cam = pos - scaled_cam.xyz;
140 float fFar = length(sphere_ray_to_cam);
141 sphere_ray_to_cam /= fFar;
142 float b = 2.0 * (dot(scaled_cam.xyz, sphere_ray_to_cam));
143 float c = dot(scaled_cam.xyz, scaled_cam.xyz) - size * size;
144 float det = max(0.0, b * b - 4.0 * c);
145
146
147 float fNear = 0.5 * -b - sqrt(det)* 0.5;
148
149 fNear = max(fNear, 0.1);
150
151 vec3 start = scaled_cam.xyz + sphere_ray_to_cam * fNear;
152 fFar = sqrt(det);
153
154 float start_height = length(start);
155 float start_depth = exp(fscale_over_depth * (inner - start_height));
156 float start_angle = 0;
157 if (start_height > 0) start_angle = dot(sphere_ray_to_cam, start) / start_height;
158 float start_offset = start_depth * scale(start_angle);
159
160 float sample_length = fFar / samples;
161 float scaled_length = sample_length * fscale;
162 vec3 sample_ray = sphere_ray_to_cam * sample_length;
163
164 vec3 color = vec3(0, 0, 0);
165
166 for (int i = 0; i < samples; i++)
167 {
168
169 float ti = (i + 0.5f) / float(samples);
170 ti *= fFar;
171 vec3 sample_point = start + sphere_ray_to_cam* ti;
172
173 float height = length(sample_point);
174 float depth = exp(fscale_over_depth * (inner - height));
175 float light_angle = 0;
176 if (height > 0) light_angle = clamp(dot(L, sample_point) / height, -1, 1);
177 float camera_angle = 0;
178 if (height > 0) camera_angle = clamp(dot(sphere_ray_to_cam, sample_point) / height, -1, 1);
179 float scatter = (start_offset + depth * (scale(light_angle) - scale(camera_angle)));
180 vec3 att = exp(-scatter * (uInvWavelength * ufKr4Pi + ufKm4Pi));
181 color += att * (depth * scaled_length);
182 }
183
184 vPos = aPosition;
185 vNormal = aNormal;
186 c0 = color * (uInvWavelength * ufKrESun);
187 c1 = color * ufKmESun;
188 t0 = (-sphere_ray_to_cam);
189
190
191 vViewDir = normalize(vec3(aPosition - cam_pos.xyz));
192 vec3 p2 = aPosition * size;
193 vec4 worldPos = uFakeProj * uFakeView * vec4(p2 + p[0].p_m.xyz, 1.0);
194 gl_Position = worldPos;
195
196}
in vec3 t0
in vec3 c0
uniform float uG2
in vec3 vPos
in vec3 vNormal
in vec3 vViewDir
uniform float uG
in vec3 c1
uniform float uInnerRadius2
uniform float uOuterRadius
uniform float ufKr4Pi
uniform float ufKm4Pi
uniform vec3 uCamPosWorld
uniform float ufKmESun
uniform float uFScale
uniform float ufKrESun
const int samples
uniform float uOuterRadius2
uniform vec3 uInvWavelength
uniform float uInnerRadius
uniform float uFScaleOverDepth
uniform mat4 uFakeView
uniform float uFScaleDepth
uniform float uFInvScaleDepth
float scale(float fCos)
uniform mat4 uFakeProj
uniform vec3 uCamPos
layout(local_size_x=16, local_size_y=16, local_size_z=1) in
uniform int depth
Definition com22.comp:76
vec3 sun_dir
Definition main.c:237
vec3 sun_color
Definition main.c:238
int main(int argc, char *argv[])
Definition main.c:1726
vec4 mat
Definition main.c:261
float clamp(float a, float b, float c)
Definition mathf.h:147
vec4 acc
Definition types.h:97
vec4 p_m
Definition types.h:94
vec3 vel
Definition main.h:10
Definition main.h:8
uniform mat4 projection
Definition shadow.vert:8
uniform mat4 view
Definition shadow.vert:9
const int size
Definition sky.frag:9
#define BODY_COUNT
Definition types.h:39
#define MAX_LAYERS
Definition types.h:407
Definition types.h:51
Definition main.h:5
Definition types.h:47
#define L
Definition water.comp:15
vec3 offset2
Definition types.h:378
float pad1
Definition types.h:403
float amp
Definition types.h:401
float freq0
Definition types.h:375
vec3 offset1
Definition types.h:376
float freq
Definition types.h:400
float amp
Definition types.h:391
float pad3
Definition types.h:383
float freq1
Definition types.h:377
float pad1
Definition types.h:382
float pad0
Definition types.h:392
float freq2
Definition types.h:379
vec3 offset0
Definition types.h:374
float pad1
Definition types.h:393
float pad0
Definition types.h:381
float amp
Definition types.h:380
float freq
Definition types.h:390
float pad0
Definition types.h:402