Skip to content

Commit e1e0794

Browse files
committed
running on windows with upscale changes now
1 parent 2787beb commit e1e0794

File tree

5 files changed

+171
-165
lines changed

5 files changed

+171
-165
lines changed

assets/shaders/atmo.frag

+3-18
Original file line numberDiff line numberDiff line change
@@ -278,30 +278,15 @@ void main()
278278
point_cam = normalize(worldPos.xyz);
279279

280280

281-
if (check_pos(gl_FragCoord.xy/4.0, 4.0)!=check){
281+
if (check_pos(gl_FragCoord.xy/1.0, 4.0)!=check&&true==false){
282282
//reprojection from http://john-chapman-graphics.blogspot.ca/2013/01/what-is-motion-blur-motion-pictures-are.html
283283
//look into running all this on cpu
284284
discard;
285-
/*
286-
vec4 current = vec4((2.0 * point_ndc - 1.0) * aspect_ratio * fov, 1.0, 1.0);
287-
current = inverse(MVPM) * current;
288-
vec4 previous = LFMVPM * current;
289-
previous.xyz /= previous.w;
290-
previous.xy = previous.xy * 0.5 + 0.5;
291-
vec2 blurVec = previous.xy - TexCoords.xy;
292-
vec2 lookup = TexCoords.xy+blurVec;
293-
float mip = 0.0;
294-
if (lookup.x<0.0||lookup.x>1.0||lookup.y<0.0||lookup.y>1.0) {
295-
lookup = clamp(lookup, 0.0, 1.0);
296-
lookup = TexCoords.xy;
297-
mip = 1.0;
298-
}
299-
color = texture(lastFrame, lookup, mip);
300-
*/
285+
301286
} else {
302287

303288
vec3 col = vec3(0);
304-
if (point_cam.y>0.0) {
289+
if (point_cam.y>-0.05) {
305290
// sun
306291
mat3 rot = rotate_around_x(-abs(sin(u_time / 20.)) * 90.);
307292
sun_dir *= rot;

assets/shaders/sky.frag

+26-44
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ in vec4 fragPos;
1212
uniform sampler3D perlworl;
1313
uniform sampler3D worl;
1414
uniform sampler2D curl;
15-
uniform sampler2D lastFrame;
1615
uniform sampler2D weather;
1716
uniform sampler2D atmosphere;
1817

@@ -165,7 +164,7 @@ float HG(vec3 inv, vec3 outv, float g) {
165164
float density(vec3 p,vec3 weather, bool hq, float LOD) {
166165
p.x += time*10.0;
167166
float height_fraction = GetHeightFractionForPoint(p, vec2(float(sky_b_radius), float(sky_t_radius)));
168-
vec4 n = textureLod(perlworl, p*0.0002, LOD);
167+
vec4 n = textureLod(perlworl, p*0.0003, LOD);
169168
float fbm = n.g*0.625+n.b*0.25+n.a*0.125;
170169
weather.x = smoothstep(0.6, 1.2, weather.x);
171170
float g = densityHeightGradient(height_fraction, weather.z);
@@ -201,7 +200,7 @@ vec4 march(vec3 pos, vec3 end, vec3 dir, int depth) {
201200
float height_fraction = GetHeightFractionForPoint(p, vec2(float(sky_b_radius), float(sky_t_radius)));
202201
float weather_scale = 0.0001;
203202
vec3 weather_sample = texture(weather, p.xz*weather_scale).xyz;
204-
t = density(p, weather_sample, true, 0.0);
203+
t = density(p, weather_sample, true, 1.0);
205204
const float ldt = 0.5;
206205
float dt = exp(-ldt*t*ss);//, exp(-ldt*0.25*t*ss)*0.8);
207206
T *= dt;
@@ -244,56 +243,39 @@ vec4 march(vec3 pos, vec3 end, vec3 dir, int depth) {
244243

245244
void main()
246245
{
247-
248-
vec2 uv = TexCoords.xy;
246+
vec2 shift = vec2(floor(float(check)/4.0), mod(float(check), 4.0));
247+
//shift = vec2(0.0);
248+
vec2 uv = (gl_FragCoord.xy*4.0+shift.yx)/vec2(512.0);
249249
uv = uv-vec2(0.5);
250250
uv *= 2.0;
251251
uv.x *= aspect;
252-
vec4 uvdir = (vec4(fragPos.xy, 1.0, 1.0));
252+
vec4 uvdir = (vec4(uv.xy, 1.0, 1.0));
253253
mat4 invmat = inverse(MVPM);
254254
vec4 worldPos = (inverse((MVPM))*uvdir);
255-
worldPos.xyz /= worldPos.w;
255+
//worldPos.xyz /= worldPos.w;
256256
vec3 camPos = vec3(invmat[3]);
257-
vec3 dir = normalize(worldPos.xyz);
257+
vec3 dir = normalize(worldPos.xyz/worldPos.w);
258258

259259
vec4 col = vec4(0.0);
260-
if (check_pos(gl_FragCoord.xy/4.0, 4.0)!=check&&true==true){
261-
//reprojection from http://john-chapman-graphics.blogspot.ca/2013/01/what-is-motion-blur-motion-pictures-are.html
262-
//look into running all this on cpu
263-
vec4 current = uvdir;//vec4(0.5, 0.5, 1.0, 1.0);//uvdir;
264-
current = inverse(MVPM) * current;
265-
vec4 previous = LFMVPM * current;
266-
previous.xyz /= previous.w;
267-
previous.xy = previous.xy * 0.5 + 0.5;
268-
vec2 blurVec = previous.xy - TexCoords.xy;
269-
vec2 lookup = TexCoords.xy+blurVec;
270-
float mip = 0.0;
271-
if (lookup.x<0.0||lookup.x>1.0||lookup.y<0.0||lookup.y>1.0) {
272-
lookup = clamp(lookup, 0.0, 1.0);
273-
lookup = TexCoords.xy;
274-
mip = 1.0;
275-
}
276-
col = texture(lastFrame, lookup, mip);
260+
vec3 background = textureLod(atmosphere, TexCoords.xy, 0.0).xyz;
261+
//vec3 background = vec3(dot(normalize(dir), normalize(getSunDirection())));
262+
if (dir.y>0.0) {
263+
vec3 start = camPos+vec3(0.0, g_radius, 0.0)+dir*intersectSphere(camPos+vec3(0.0, g_radius, 0.0), dir, sky_b_radius);
264+
vec3 end = camPos+vec3(0.0, g_radius, 0.0)+dir*intersectSphere(camPos+vec3(0.0, g_radius, 0.0), dir, sky_t_radius);
265+
const float t_dist = sky_t_radius-sky_b_radius;
266+
float shelldist = (length(end-start));
267+
vec4 volume;
268+
int steps = int(mix(96.0, 54.0, dot(dir, vec3(0.0, 1.0, 0.0))));
269+
float dmod = smoothstep(0.0, 1.0, (shelldist/t_dist)/14.0);
270+
float s_dist = mix(t_dist, t_dist*4.0, dmod)/float(steps);
271+
vec3 raystep = dir*s_dist;//(shelldist/float(steps));
272+
volume = march(start, end, raystep, steps);
273+
col = vec4(background*(1.0-volume.a)+volume.xyz*volume.a, 1.0);
274+
if (volume.a>1.0) {col = vec4(1.0, 0.0, 0.0, 1.0);}
277275
} else {
278-
vec3 background = texture(atmosphere, uv*0.5+0.5, 0.0).xyz;
279-
//vec3 background = vec3(dot(normalize(dir), normalize(getSunDirection())));
280-
if (dir.y>0.0) {
281-
vec3 start = camPos+vec3(0.0, g_radius, 0.0)+dir*intersectSphere(camPos+vec3(0.0, g_radius, 0.0), dir, sky_b_radius);
282-
vec3 end = camPos+vec3(0.0, g_radius, 0.0)+dir*intersectSphere(camPos+vec3(0.0, g_radius, 0.0), dir, sky_t_radius);
283-
const float t_dist = sky_t_radius-sky_b_radius;
284-
float shelldist = (length(end-start));
285-
vec4 volume;
286-
int steps = int(mix(96.0, 54.0, dot(dir, vec3(0.0, 1.0, 0.0))));
287-
float dmod = smoothstep(0.0, 1.0, (shelldist/t_dist)/14.0);
288-
float s_dist = mix(t_dist, t_dist*4.0, dmod)/float(steps);
289-
vec3 raystep = dir*s_dist;//(shelldist/float(steps));
290-
volume = march(start, end, raystep, steps);
291-
col = vec4(background*(1.0-volume.a)+volume.xyz*volume.a, 1.0);
292-
if (volume.a>1.0) {col = vec4(1.0, 0.0, 0.0, 1.0);}
293-
} else {
294-
col = vec4(vec3(0.4), 1.0);
295-
//col.xyz = texture(curl, uv).yyy;
296-
}
276+
col = vec4(vec3(0.4), 1.0);
277+
//col.xyz = texture(curl, uv).yyy;
297278
}
279+
298280
color = col;
299281
}

assets/shaders/upscale.frag

+38-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#version 330 core
22
in vec3 ourColor;
33
in vec3 TexCoords;
4+
in vec4 fragPos;
45

56
uniform sampler2D buff;
7+
uniform sampler2D pong;
68
uniform int check;
9+
uniform mat4 MVPM;
10+
uniform mat4 LFMVPM;
711

812
out vec4 color;
913

@@ -14,16 +18,40 @@ int check_pos(vec2 x, float size) {
1418

1519
void main()
1620
{
17-
//if (check_pos(gl_FragCoord.xy/4.0, 4.0)!=check){
21+
vec2 shift = vec2(floor(float(check)/4.0), mod(float(check), 4.0));
22+
23+
vec2 uv = floor(gl_FragCoord.xy/4.0);
24+
uv = uv/vec2(128.0);
25+
26+
vec4 col = vec4(0.0);
27+
if (check_pos(gl_FragCoord.xy/1.0, 4.0)!=check&&true==true){
28+
//reprojection from http://john-chapman-graphics.blogspot.ca/2013/01/what-is-motion-blur-motion-pictures-are.html
29+
//look into running all this on cpu
1830
//discard;
19-
//}
20-
//compare pixel color to mipped pixel color
21-
vec4 pix = texture(buff, TexCoords.xy);
22-
//vec3 mip = texture(buff, TexCoords.xy, 1.0).xyz;
23-
//float diff = abs(length(pix.xyz)-length(mip))*pix.w;
31+
uv = gl_FragCoord.xy/512.0;
32+
vec2 uvd = uv-vec2(0.5);
33+
uvd *= 2.0;
34+
vec4 uvdir = (vec4(uvd, 1.0, 1.0));
35+
mat4 invmat = inverse(MVPM);
36+
vec4 worldPos = (inverse((MVPM))*uvdir);
37+
vec4 current = worldPos;
38+
vec4 previous = LFMVPM * current;
39+
previous.xyz /= previous.w;
40+
previous.xy = previous.xy * 0.5 + 0.5;
41+
vec2 blurVec = previous.xy - uv.xy;
42+
vec2 lookup = uv.xy+blurVec;
43+
float mip = 0.0;
44+
if (lookup.x<0.0||lookup.x>1.0||lookup.y<0.0||lookup.y>1.0) {
45+
lookup = clamp(lookup, 0.0, 1.0);
46+
lookup = uv.xy;
47+
col = texture(buff, lookup);
48+
} else {
49+
uv = gl_FragCoord.xy/512.0;
50+
col = texture(pong, lookup);
51+
}
52+
} else {
53+
col = texture(buff, uv.xy);
54+
}
55+
color.xyz = col.xyz;
2456
color.a = 1.0;
25-
color.xyz = pix.xyz;
26-
//if (diff>1.0) {
27-
//color.xyz = mip;
28-
//}
2957
}

assets/shaders/upscale.vert

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ uniform float pos;
88

99
out vec3 ourColor;
1010
out vec3 TexCoords;
11+
out vec4 fragPos;
1112

1213
uniform mat4 MVPM;
1314

@@ -17,4 +18,5 @@ void main()
1718
gl_Position = vec4(position.xy, 0.0, 1.0);
1819
ourColor = color;
1920
TexCoords = texCoords;
21+
fragPos = gl_Position;
2022
}

0 commit comments

Comments
 (0)