Skip to content

Commit 38b2e9a

Browse files
committed
cleaned up code significantly
1 parent 0fd60ed commit 38b2e9a

File tree

9 files changed

+127
-236
lines changed

9 files changed

+127
-236
lines changed

assets/shaders/atmo.frag

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
#version 330 core
2-
in vec3 ourColor;
3-
in vec3 TexCoords;
42

5-
//uniform vec2 resolution;
6-
const vec2 resolution = vec2(512.0);
3+
uniform vec2 resolution;
74
uniform float time;
85
uniform mat4 MVPM;
9-
uniform int check;
6+
107
out vec4 color;
118

129
// ----------------------------------------------------------------------------
@@ -277,17 +274,9 @@ void main()
277274
worldPos.xyz /= worldPos.w;
278275
point_cam = normalize(worldPos.xyz);
279276

280-
281-
if (check_pos(gl_FragCoord.xy/1.0, 4.0)!=check&&true==false){
282-
//reprojection from http://john-chapman-graphics.blogspot.ca/2013/01/what-is-motion-blur-motion-pictures-are.html
283-
//look into running all this on cpu
284-
discard;
285-
286-
} else {
287-
288277
vec3 col = vec3(0);
289278
if (point_cam.y>-0.05) {
290-
// sun
279+
// sun
291280
mat3 rot = rotate_around_x(-abs(sin(u_time / 20.)) * 90.);
292281
sun_dir *= rot;
293282

@@ -300,5 +289,4 @@ void main()
300289
}
301290
col = ACESFilm(col);
302291
color = vec4(col, 1);
303-
}
304292
}

assets/shaders/atmo.vert

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
#version 330 core
2-
in vec3 position;
3-
in vec3 color;
4-
in vec3 texCoords;
5-
6-
out vec3 ourColor;
7-
out vec3 TexCoords;
8-
out vec4 fragPos;
9-
10-
uniform mat4 MVPM;
2+
layout (location = 0) in vec2 position;
113

124
void main()
135
{
14-
15-
gl_Position = vec4(position.xy, 0.0, 1.0);
16-
ourColor = color;
17-
TexCoords = texCoords;
18-
fragPos = gl_Position;
6+
gl_Position = vec4(position, 0.0, 1.0);
197
}

assets/shaders/sky.frag

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
#version 330 core
2-
in vec3 ourColor;
3-
in vec3 TexCoords;
4-
in vec4 fragPos;
5-
62
//TODO update cloud shaping
73
//TODO fix up weather texture
84
//TODO add more flexibility to parameters
@@ -17,11 +13,9 @@ uniform sampler2D atmosphere;
1713

1814
uniform int check;
1915
uniform mat4 MVPM;
20-
uniform mat4 LFMVPM;
21-
uniform mat4 VM;
2216
uniform float aspect;
2317
uniform float time;
24-
uniform int camera_dirty;
18+
uniform vec2 resolution;
2519

2620
out vec4 color;
2721

@@ -245,7 +239,7 @@ void main()
245239
{
246240
vec2 shift = vec2(floor(float(check)/4.0), mod(float(check), 4.0));
247241
//shift = vec2(0.0);
248-
vec2 uv = (gl_FragCoord.xy*4.0+shift.yx)/vec2(512.0);
242+
vec2 uv = (gl_FragCoord.xy*4.0+shift.yx)/(resolution*4.0);
249243
uv = uv-vec2(0.5);
250244
uv *= 2.0;
251245
uv.x *= aspect;
@@ -257,7 +251,7 @@ void main()
257251
vec3 dir = normalize(worldPos.xyz/worldPos.w);
258252

259253
vec4 col = vec4(0.0);
260-
vec3 background = textureLod(atmosphere, TexCoords.xy, 0.0).xyz;
254+
vec3 background = textureLod(atmosphere, gl_FragCoord.xy/resolution, 0.0).xyz;
261255
//vec3 background = vec3(dot(normalize(dir), normalize(getSunDirection())));
262256
if (dir.y>0.0) {
263257
vec3 start = camPos+vec3(0.0, g_radius, 0.0)+dir*intersectSphere(camPos+vec3(0.0, g_radius, 0.0), dir, sky_b_radius);

assets/shaders/sky.vert

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
#version 330 core
2-
in vec3 position;
3-
in vec3 color;
4-
in vec3 texCoords;
5-
6-
out vec3 ourColor;
7-
out vec3 TexCoords;
8-
out vec4 fragPos;
9-
10-
uniform mat4 MVPM;
2+
layout (location = 0) in vec2 position;
113

124
void main()
135
{
14-
15-
gl_Position = vec4(position.xy, 0.0, 1.0);
16-
ourColor = color;
17-
TexCoords = texCoords;
18-
fragPos = gl_Position;
6+
gl_Position = vec4(position, 0.0, 1.0);
197
}

assets/shaders/tex.frag

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#version 330 core
2-
in vec3 ourColor;
3-
in vec3 TexCoords;
2+
in vec2 TexCoords;
43

54
uniform sampler2D fbo;
65

76
out vec4 color;
87

98
void main()
109
{
11-
color = texture(fbo, TexCoords.xy, 0.0);
10+
color = texture(fbo, TexCoords, 0.0);
1211
}

assets/shaders/tex.vert

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
#version 330 core
2-
in vec3 position;
3-
in vec3 color;
4-
in vec3 texCoords;
2+
layout (location = 0) in vec2 position;
53

6-
uniform float size;
7-
uniform float pos;
8-
9-
out vec3 ourColor;
10-
out vec3 TexCoords;
11-
12-
uniform mat4 MVPM;
4+
out vec2 TexCoords;
135

146
void main()
157
{
16-
17-
gl_Position = vec4(position.xy*size, 0.0, 1.0);
18-
ourColor = color;
19-
TexCoords = texCoords;
8+
gl_Position = vec4(position, 0.0, 1.0);
9+
TexCoords = position*0.5+0.5;
2010
}

assets/shaders/upscale.frag

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
#version 330 core
2-
in vec3 ourColor;
3-
in vec3 TexCoords;
4-
in vec4 fragPos;
52

63
uniform sampler2D buff;
74
uniform sampler2D pong;
85
uniform int check;
96
uniform mat4 MVPM;
107
uniform mat4 LFMVPM;
8+
uniform vec2 resolution;
119

1210
out vec4 color;
1311

@@ -21,14 +19,14 @@ void main()
2119
vec2 shift = vec2(floor(float(check)/4.0), mod(float(check), 4.0));
2220

2321
vec2 uv = floor(gl_FragCoord.xy/4.0);
24-
uv = uv/vec2(128.0);
22+
uv = uv/(resolution/4.0);
2523

2624
vec4 col = vec4(0.0);
2725
if (check_pos(gl_FragCoord.xy/1.0, 4.0)!=check&&true==true){
2826
//reprojection from http://john-chapman-graphics.blogspot.ca/2013/01/what-is-motion-blur-motion-pictures-are.html
2927
//look into running all this on cpu
3028
//discard;
31-
uv = gl_FragCoord.xy/512.0;
29+
uv = gl_FragCoord.xy/resolution;
3230
vec2 uvd = uv-vec2(0.5);
3331
uvd *= 2.0;
3432
vec4 uvdir = (vec4(uvd, 1.0, 1.0));
@@ -46,7 +44,7 @@ void main()
4644
lookup = uv.xy;
4745
col = texture(buff, lookup);
4846
} else {
49-
uv = gl_FragCoord.xy/512.0;
47+
uv = gl_FragCoord.xy/resolution;
5048
col = texture(pong, lookup);
5149
}
5250
} else {

assets/shaders/upscale.vert

+2-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,7 @@
11
#version 330 core
2-
in vec3 position;
3-
in vec3 color;
4-
in vec3 texCoords;
5-
6-
uniform float size;
7-
uniform float pos;
8-
9-
out vec3 ourColor;
10-
out vec3 TexCoords;
11-
out vec4 fragPos;
12-
13-
uniform mat4 MVPM;
2+
layout (location = 0) in vec2 position;
143

154
void main()
165
{
17-
18-
gl_Position = vec4(position.xy, 0.0, 1.0);
19-
ourColor = color;
20-
TexCoords = texCoords;
21-
fragPos = gl_Position;
6+
gl_Position = vec4(position, 0.0, 1.0);
227
}

0 commit comments

Comments
 (0)