Space Sim
Loading...
Searching...
No Matches
atmosphere.vert
Go to the documentation of this file.
1#version 430 core
2
9
10layout(location = 0) in vec3 aPosition;
11layout(location = 1) in vec3 aNormal;
12
15out vec3 c0;
16out vec3 c1;
17out vec3 t0;
19
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#define MAX_LAYERS 24
30struct WarpLayer
31{
33 float freq0;
35 float freq1;
37 float freq2;
38 float amp;
39 float pad0;
40 float pad1;
41 float pad3;
42};
43
44struct PerlinLayer
45{
46 float freq;
47 float amp;
48 float pad0;
49 float pad1;
50};
51
52struct FBMLayer
53{
54 float freq;
55 float amp;
56 float pad0;
57 float pad1;
58};
59
60layout(std430, binding=13) buffer PlanetData {
61
62 int warp_count;
63 int perlin_count;
64 int fbm_count;
65 int pad0;
68
69 WarpLayer warp_layers[MAX_LAYERS];
70 PerlinLayer perlin_layers[MAX_LAYERS];
71 FBMLayer fbm_layers[MAX_LAYERS];
72
73};
74
76uniform float uInnerRadius;
77uniform float uInnerRadius2;
78uniform float uOuterRadius;
79uniform float uOuterRadius2;
81uniform float uFScale;
82uniform float uFScaleOverDepth;
83uniform float uFInvScaleDepth;
84uniform float uFScaleDepth;
85uniform float uG;
86uniform float uG2;
87uniform float ufKrESun;
88uniform float ufKmESun;
89uniform float ufKr4Pi;
90uniform float ufKm4Pi;
93
94
95float scale(float fCos)
96{
97 float x = 1.0 - fCos;
98 return 0.25 * exp(-0.00287 + x * (0.459 + x * (3.83 + x * (-6.80 + x * 5.25))));
99}
100
101uniform vec3 uCamPos;
102
103const int samples = 4;
104void main()
105{
106
107 vec3 planet_center = vec3(0.0);
108 float pscale = 1 / 10000;
109 vec3 scaled_cam = uCamPosWorld;
110 vec3 apos = aPosition;
111 vec3 pos = (aPosition);
112 pos *= uOuterRadius;
113
114 vec3 L = normalize(-sun_dir.xyz);
115 vec3 sphere_ray_to_cam = pos - scaled_cam.xyz;
116 float fFar = length(sphere_ray_to_cam);
117 sphere_ray_to_cam /= fFar;
118 float b = 2.0 * (dot(scaled_cam.xyz, sphere_ray_to_cam));
119 float c = dot(scaled_cam.xyz, scaled_cam.xyz) - uOuterRadius * uOuterRadius;
120 float det = max(0.0, b * b - 4.0 * c);
121
122 float fNear = 0.5 * (-b - sqrt(det));
123 fFar = 0.5 * (-b + sqrt(det));
124
125 fNear = max(fNear, 0.0);
126
127 vec3 start = scaled_cam.xyz + sphere_ray_to_cam * fNear;
128 fFar -= fNear;
129
130 float start_height = length(start);
131 float start_depth = exp(uFScaleOverDepth * (uInnerRadius - start_height));
132 float start_angle = dot(sphere_ray_to_cam, start) / start_height;
133 float start_offset = start_depth * scale(start_angle);
134
135 float sample_length = fFar / samples;
136 float scaled_length = sample_length * uFScale;
137 vec3 sample_ray = sphere_ray_to_cam * sample_length;
138 vec3 sample_point = start + sample_ray * 0.5;
139
140 vec3 color = vec3(0, 0, 0);
141
142 for (int i = 0; i < samples; i++)
143 {
144
145 float height = length(sample_point);
146 float depth = exp(uFScaleOverDepth * (uInnerRadius - height));
147 float light_angle = dot(L, sample_point) / height;
148 float camera_angle = dot(sphere_ray_to_cam, sample_point) / height;
149 float scatter = (start_offset + depth * (scale(light_angle) - scale(camera_angle)));
150 vec3 att = exp(-scatter * (uInvWavelength * ufKr4Pi + ufKm4Pi));
151 color += att * (depth * scaled_length);
152 sample_point += sample_ray;
153 }
154
155 vPos = aPosition;
156 vNormal = aNormal;
157 c0 = color * (uInvWavelength * ufKrESun);
158 c1 = color * ufKmESun;
159 t0 = (-sphere_ray_to_cam);
160
161 vViewDir = normalize(vec3(aPosition - cam_pos.xyz));
162 vec3 p2 = pos;
163 p2.z -= uInnerRadius;
164 p2.z -= scaled_cam.z - uInnerRadius;
165 vec4 worldPos = uFakeProj * uFakeView * vec4(p2+ cam_pos.xyz, 1.0);
166 gl_Position = worldPos;
167
168}
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
uniform mat4 projection
Definition shadow.vert:8
uniform mat4 view
Definition shadow.vert:9
float z
Definition main.h:5
#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