p2.shader 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. shader_type spatial;
  2. render_mode blend_mix,depth_draw_opaque, cull_back,diffuse_burley,specular_schlick_ggx,unshaded,shadows_disabled;
  3. uniform vec3 dir_angle;
  4. uniform sampler2D iChannel0;
  5. uniform float iTime;
  6. //clouds from https://www.shadertoy.com/view/ll3XRf
  7. //sky texture from https://opengameart.org/content/cloudy-skyboxes
  8. float Hash(vec2 p)
  9. {
  10. p = fract(p / vec2(.166,.173));
  11. p += dot(p.xy, p.yx+19.19);
  12. return fract(p.x * p.y);
  13. }
  14. float Noise( in vec2 x )
  15. {
  16. vec2 p = floor(x);
  17. vec2 f = fract(x);
  18. f = f*f*(3.0-2.0*f);
  19. float res = mix(mix( Hash(p), Hash(p+ vec2(1.0, 0.0)),f.x),
  20. mix( Hash(p+ vec2(.0, 1.0)), Hash(p+ vec2(1.0, 1.0)),f.x),f.y);
  21. return res;
  22. }
  23. float FractalNoise(in vec2 xy)
  24. {
  25. float w = .7;
  26. float f = 0.0;
  27. for (int i = 0; i < 3; i++)
  28. {
  29. f += Noise(xy) * w;
  30. w = w*0.6;
  31. xy = 2.0 * xy;
  32. }
  33. return f;
  34. }
  35. vec2 uv_sphere(vec3 v)
  36. {
  37. float pi = 3.1415926536;
  38. return vec2(0.5 + atan(v.z, v.x) / (2.0 * pi), acos(v.y) / pi);
  39. }
  40. vec3 sky(in vec3 rd)
  41. {
  42. vec3 sunLight = normalize( -dir_angle);
  43. vec3 sunColour = vec3(1.0, .58, .39);
  44. vec3 cloud_col = vec3(1.,0.95,1.);
  45. float sunAmount = max( dot( rd, sunLight), 0.0 );
  46. float v = pow(1.0-max(rd.y,0.0),6.);
  47. vec3 skyc=texture(iChannel0,uv_sphere(rd)).rgb;
  48. skyc = sqrt(skyc)*0.3;
  49. vec3 sky = mix(skyc, vec3(.32, .32, .32), v);
  50. /* sun rays */
  51. sky = sky + sunColour * sunAmount * sunAmount * .25;
  52. sky = sky + sunColour * min(pow(sunAmount, 800.0)*1.5, .4);
  53. /* clouds */
  54. vec2 iuv = rd.xz * (1.0/rd.y);
  55. iuv+=rd.y>0.?iTime:-iTime;
  56. v = FractalNoise(iuv) * .3;
  57. sky = mix(sky, sunColour, v*v);
  58. return clamp(sky+vec3(.2,.2,.2), 0.0, 1.0);
  59. }
  60. void fragment() {
  61. vec3 rd=normalize(((CAMERA_MATRIX*vec4(normalize(-VERTEX),0.0)).xyz));
  62. rd=-rd;
  63. vec3 sky_col=sky(rd);
  64. ALBEDO=sky_col;
  65. //ALBEDO=ALBEDO*ALBEDO; //to use in Godot GLES3 add this color correction
  66. }