@@ -12,7 +12,6 @@ in vec4 fragPos;
12
12
uniform sampler3D perlworl;
13
13
uniform sampler3D worl;
14
14
uniform sampler2D curl;
15
- uniform sampler2D lastFrame;
16
15
uniform sampler2D weather;
17
16
uniform sampler2D atmosphere;
18
17
@@ -165,7 +164,7 @@ float HG(vec3 inv, vec3 outv, float g) {
165
164
float density(vec3 p,vec3 weather, bool hq, float LOD) {
166
165
p.x += time* 10.0 ;
167
166
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);
169
168
float fbm = n.g* 0.625 + n.b* 0.25 + n.a* 0.125 ;
170
169
weather.x = smoothstep (0.6 , 1.2 , weather.x);
171
170
float g = densityHeightGradient(height_fraction, weather.z);
@@ -201,7 +200,7 @@ vec4 march(vec3 pos, vec3 end, vec3 dir, int depth) {
201
200
float height_fraction = GetHeightFractionForPoint(p, vec2 (float (sky_b_radius), float (sky_t_radius)));
202
201
float weather_scale = 0.0001 ;
203
202
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 );
205
204
const float ldt = 0.5 ;
206
205
float dt = exp (- ldt* t* ss);// , exp(-ldt*0.25*t*ss)*0.8);
207
206
T *= dt;
@@ -244,56 +243,39 @@ vec4 march(vec3 pos, vec3 end, vec3 dir, int depth) {
244
243
245
244
void main()
246
245
{
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 );
249
249
uv = uv- vec2 (0.5 );
250
250
uv *= 2.0 ;
251
251
uv.x *= aspect;
252
- vec4 uvdir = (vec4 (fragPos .xy, 1.0 , 1.0 ));
252
+ vec4 uvdir = (vec4 (uv .xy, 1.0 , 1.0 ));
253
253
mat4 invmat = inverse(MVPM);
254
254
vec4 worldPos = (inverse((MVPM))* uvdir);
255
- worldPos.xyz /= worldPos.w;
255
+ // worldPos.xyz /= worldPos.w;
256
256
vec3 camPos = vec3 (invmat[3 ]);
257
- vec3 dir = normalize (worldPos.xyz);
257
+ vec3 dir = normalize (worldPos.xyz/ worldPos.w );
258
258
259
259
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 );}
277
275
} 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;
297
278
}
279
+
298
280
color = col;
299
281
}
0 commit comments