Skip to content

Commit 98d93fc

Browse files
committed
still pulling out atmosphere shader pass
1 parent f773945 commit 98d93fc

File tree

4 files changed

+12
-73
lines changed

4 files changed

+12
-73
lines changed

assets/shaders/basic.vert

-17
This file was deleted.

assets/shaders/sky.frag

+6-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//TODO add more flexibility to parameters
55
//rain
66
//
7+
//TODO add 2d cloud layer on top
78
//TODO either integrate atmosphere or cut out completely
89
//integrated is nice because i can sample sun color anytime
910
//seperate is nice cause I do each pixel only once and can benefit from that cheap mipmapping
@@ -13,7 +14,6 @@ uniform sampler3D perlworl;
1314
uniform sampler3D worl;
1415
uniform sampler2D curl;
1516
uniform sampler2D weather;
16-
uniform sampler2D atmosphere;
1717

1818
uniform int check;
1919
uniform mat4 MVPM;
@@ -30,10 +30,6 @@ const float sky_t_radius = 602300.0;//top of cloud layer
3030
const float c_radius = 6008400.0; //2d noise layer
3131

3232

33-
34-
35-
36-
3733
/*
3834
Atmospheric scattering based off of:
3935
*/
@@ -261,11 +257,10 @@ vec3 U2Tone(vec3 x) {
261257
}
262258

263259
vec3 getSunDirection() {
264-
vec3 sun_dir = vec3(0.0, 1.0, 0.0);
260+
const vec3 sun_dir = vec3(0.0, 1.0, 0.0);
265261

266262
mat3 rot = rotate_around_x(-abs(sin(time / 20.)) * 90.);
267-
sun_dir *= rot;
268-
return sun_dir;
263+
return sun_dir*rot;
269264
}
270265

271266
vec3 getSunColor() {
@@ -274,7 +269,8 @@ vec3 getSunColor() {
274269
}
275270

276271
vec3 getSkyColor() {
277-
return texture(atmosphere, vec2(0.5, 0.9), 7).xyz;
272+
vec3 dir = getSunDirection();
273+
return mix(vec3(0.2, 0.3, 0.4), vec3(0.9, 0.9, 1.0), smoothstep(0.05, 0.2, dir.y));
278274
}
279275

280276
int check_pos(vec2 x, float size) {
@@ -430,7 +426,7 @@ vec4 march(vec3 pos, vec3 end, vec3 dir, int depth) {
430426
float beers = max(exp(-ld*ncd*lss), exp(-ld*0.25*ncd*lss)*0.7);
431427
float powshug = 1.0-exp(-ld*ncd*lss*2.0);
432428

433-
vec3 ambient = 9.0*ambientLight*mix(0.25, 1.0, height_fraction);
429+
vec3 ambient = 9.0*ambientLight*mix(0.05, 1.0, height_fraction);
434430
vec3 sunC = sunLight*40.0;
435431
L += (ambient+sunC*beers*powshug*2.0*phase)*(t)*T*ss;
436432
alpha += (1.0-dt)*(1.0-alpha);

gen_noise.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
#include "include/TileableVolumeNoise/TileableVolumeNoise.h"
1010
#include "include/stb_image_write.h"
1111

12+
//TODO make a repeating 2d cirrus noise texture
13+
//TODO Clean this up for github
14+
//TODO Make a repeating curl noise implementation
15+
1216
/*
1317
* g++ include/TileableVolumeNoise/tileableVolumeNoise.cpp gen_noise.cpp -o gen_noise -std=c++11
1418
*/

main.cpp

+2-46
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ int main()
8686
Shader ourShader("sky.vert", "sky.frag");
8787
Shader postShader("tex.vert", "tex.frag");
8888
Shader upscaleShader("upscale.vert", "upscale.frag");
89-
Shader atmoShader("atmo.vert", "atmo.frag");
9089

9190
// Set up vertex data (and buffer(s)) and attribute pointers
9291
GLfloat vertices[] = {
@@ -156,22 +155,7 @@ int main()
156155
glBindFramebuffer(GL_FRAMEBUFFER, subbuffer);
157156
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, subbuffertex, 0);
158157

159-
160-
//small buffer for rendering sky background//should be removed and incorporated into sky
161-
GLuint skyfbo, skytex;
162-
163-
glGenFramebuffers(1, &skyfbo);
164-
glGenTextures(1, &skytex);
165-
glBindTexture(GL_TEXTURE_2D, skytex);
166-
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, WIDTH/downscale, HEIGHT/downscale, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
167-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
168-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
169-
glBindTexture(GL_TEXTURE_2D, 0);
170-
171-
glBindFramebuffer(GL_FRAMEBUFFER, skyfbo);
172-
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, skytex, 0);
173-
174-
glBindFramebuffer(GL_FRAMEBUFFER, 0);
158+
glBindFramebuffer(GL_FRAMEBUFFER, 0);
175159

176160
//setup noise textures
177161
GLuint curltex, worltex, perlworltex, weathertex;
@@ -240,7 +224,6 @@ int main()
240224
GLuint worluniform = glGetUniformLocation(ourShader.Program, "worl");
241225
GLuint curluniform = glGetUniformLocation(ourShader.Program, "curl");
242226
GLuint weatheruniform = glGetUniformLocation(ourShader.Program, "weather");
243-
GLuint atmosphereuniform = glGetUniformLocation(ourShader.Program, "atmosphere");
244227

245228
upscaleShader.Use();
246229
GLuint upuniformMatrix = glGetUniformLocation(upscaleShader.Program, "MVPM");
@@ -250,12 +233,6 @@ int main()
250233
GLuint updownscale = glGetUniformLocation(upscaleShader.Program, "downscale");
251234
GLuint buffuniform = glGetUniformLocation(upscaleShader.Program, "buff");
252235
GLuint ponguniform = glGetUniformLocation(upscaleShader.Program, "pong");
253-
254-
atmoShader.Use();
255-
GLuint atmotimeu = glGetUniformLocation(atmoShader.Program, "time");
256-
GLuint atmochecku = glGetUniformLocation(atmoShader.Program, "check");
257-
GLuint atmoresolution = glGetUniformLocation(atmoShader.Program, "resolution");
258-
GLuint atmouniformMatrix = glGetUniformLocation(atmoShader.Program, "MVPM");
259236

260237
// Game loop
261238
int check = 0;
@@ -286,25 +263,7 @@ int main()
286263
std::cout<<err<<std::endl;
287264
}
288265

289-
/*
290-
glBindFramebuffer(GL_FRAMEBUFFER, skyfbo);
291-
glViewport(0, 0, WIDTH/downscale, HEIGHT/downscale);
292-
293-
atmoShader.Use();
294-
295-
glUniformMatrix4fv(atmouniformMatrix, 1, GL_FALSE, glm::value_ptr(MVPM));
296-
glUniform1f(atmotimeu, timePassed);
297-
glUniform2f(atmoresolution, float(WIDTH/downscale), float(HEIGHT/downscale));
298-
299-
glBindVertexArray(VAO);
300-
glDrawArrays(GL_TRIANGLES, 0, 3);
301-
glBindVertexArray(0);
302-
303-
glActiveTexture(GL_TEXTURE0);
304-
glBindTexture(GL_TEXTURE_2D, skytex);
305-
glGenerateMipmap(GL_TEXTURE_2D);
306-
*/
307-
266+
308267
//Write to quarter scale buffer
309268
glBindFramebuffer(GL_FRAMEBUFFER, subbuffer);
310269
glViewport(0, 0, WIDTH/downscale, HEIGHT/downscale);
@@ -322,7 +281,6 @@ int main()
322281
glUniform1i(worluniform, 1);
323282
glUniform1i(curluniform, 2);
324283
glUniform1i(weatheruniform, 3);
325-
glUniform1i(atmosphereuniform, 4);
326284

327285
glActiveTexture(GL_TEXTURE0);
328286
glBindTexture(GL_TEXTURE_3D, perlworltex);
@@ -332,8 +290,6 @@ int main()
332290
glBindTexture(GL_TEXTURE_2D, curltex);
333291
glActiveTexture(GL_TEXTURE3);
334292
glBindTexture(GL_TEXTURE_2D, weathertex);
335-
glActiveTexture(GL_TEXTURE4);
336-
glBindTexture(GL_TEXTURE_2D, skytex);
337293

338294
glBindVertexArray(VAO);
339295
glDrawArrays(GL_TRIANGLES, 0, 3);

0 commit comments

Comments
 (0)