Sky_mesh.shader 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. shader_type spatial;
  2. render_mode blend_mix,depth_draw_never,cull_back,unshaded;
  3. uniform float iTime;
  4. uniform int iFrame;
  5. uniform sampler2D iChannel0;
  6. float plane( in vec3 ro, in vec3 rd, vec3 c, vec3 u, vec3 v )
  7. {
  8. vec3 q = ro - c;
  9. vec3 n = cross(u,v);
  10. return -dot(n,q)/dot(rd,n);
  11. }
  12. float nz(in vec2 p){return textureLod(iChannel0, p*.01,0.).x;}
  13. float fbm(in vec2 p, in float d)
  14. {
  15. mat2 m2 = mat2( vec2(0.80, 0.60), vec2(-0.60, 0.80) );
  16. float time=iTime*2.;
  17. d = smoothstep(0.,100.,d);
  18. p *= .3/(d+0.2);
  19. float z=2.;
  20. float rz = 0.;
  21. p -= time*0.02;
  22. for (float i= 1.;i <=5.;i++ )
  23. {
  24. rz+= (sin(nz(p)*6.5)*0.5+0.5)*1.25/z; //clouds sin(iTime/10.)*
  25. z *= 2.1;
  26. p *= 2.15;
  27. p += time*0.027*(mod(i,2.)-1.5);
  28. p *= m2;
  29. }
  30. return pow(abs(rz),2.-d);
  31. }
  32. vec3 pldec(vec2 p)
  33. {
  34. float t = iTime*.13;
  35. p*=0.25;
  36. float a = t*.5;
  37. float s=sin(a), c=cos(a);
  38. p*=mat2(vec2(c,s),vec2(-s,c));
  39. p += .21*sin(p.yx*6.+t);
  40. p = abs(p);
  41. p*=mat2(vec2(c,s),vec2(-s,c));
  42. vec3 col =0.5 + 0.5*cos(t*1.4+vec3(p.xy,p.x)*5.+vec3(0,2,4)) + .3*sin(p.x*(1.1+.2*sin(t*.9))*20.+t*.4)+.3;
  43. col.g=0.25*max(0.65*col.r,0.5*col.b);
  44. col.r=0.5*max(col.r,0.85*col.b);
  45. col.r=max(col.r,.28-col.g);
  46. col.b=max(0.65*col.b,.6-col.g);
  47. return (pow(clamp(col*(1.-length(p*1.6)),vec3(0.),vec3(1.)),vec3(02.5)));
  48. }
  49. vec3 clouds(in vec3 ro, in vec3 rd, in bool wtr)
  50. {
  51. vec3 lgt = normalize(vec3(-1.0,0.1,.50));
  52. float tval=-.2+0.15*iTime;
  53. //tval=1.;
  54. lgt = normalize(vec3(sin(tval),-sin(tval),cos(tval)));
  55. vec3 hor = vec3(0);
  56. vec3 col1=vec3(0.70,1.0,1.0);
  57. vec3 col2=vec3(1.3,0.55,0.15);
  58. vec3 col3=vec3(0.5,0.75,1.);
  59. vec3 scol1=vec3(1.0,0.8,0.7);
  60. vec3 scol2=vec3(1.0,0.4,0.2);
  61. float hval=min(smoothstep(-0.0,0.15,abs(rd.y)),1.) ;
  62. float nval=lgt.y/(normalize(vec3(1.)).x);
  63. float mval2=smoothstep(-.9,-0.2,nval)*smoothstep(-0.8,-.1,nval);
  64. nval=max(lgt.y/(normalize(vec3(1.)).x),0.);
  65. float sun = clamp(dot(lgt,rd),0.0,1.0 );
  66. float mval=max(max(nval,sun),0.21);
  67. float v = 1.0/( 2. * ( 1. + rd.y ) );
  68. vec2 xy = vec2(rd.x * v, rd.z * v);
  69. vec3 exc=vec3(0.);
  70. vec3 col=vec3(0.);
  71. col2*=mval;
  72. col3*=mval;
  73. exc=(pldec(xy));
  74. scol1=mix(2.*exc,scol1,max(nval,sun));
  75. scol2=mix(scol2*0.5+1.5*exc,scol2,max(nval,sun));
  76. if (!wtr)
  77. {
  78. col += 0.8*scol1*pow(sun,512.0);
  79. col += 0.2*scol2*pow(sun,32.0);
  80. }
  81. else
  82. {
  83. //col3*=(1.-hval);
  84. col3=1.5*vec3(0.5509,0.42117,0.61725)*hval;
  85. col3=mix(col3/2.5,col3,nval);
  86. col += .625*scol1*pow(sun,512.0)*(1.-hval);
  87. col += 0.13*scol2*pow(sun,32.0)*(1.-hval);
  88. }
  89. hor = mix( col1, col2, 0.25+0.75*sun );//*(0.85+0.25*mval2);
  90. col += 0.4*mix( col3, hor, exp(-(4.+ 2.*(1.-sun))*max(0.0,rd.y-0.05)) );
  91. col += 0.1*scol2*pow(sun,4.0);
  92. float pt = (90.0-ro.y)/rd.y;
  93. vec3 bpos = ro + pt*rd;
  94. float dist = sqrt(distance(ro,bpos));
  95. float s2p = distance(bpos,lgt*100.);
  96. float cls = 0.005;
  97. float bz = 0.;
  98. float tot = bz;
  99. float ds = 2.;
  100. if (!wtr){
  101. bz=fbm(bpos.xz*cls,dist);
  102. tot=bz;
  103. tot = smoothstep(0.,1.15,tot);
  104. for (float i=0.;i<=3.;i++)
  105. {
  106. vec3 pp = bpos + ds*lgt;
  107. float vl = fbm(pp.xz*cls,dist);
  108. vl = smoothstep(0.,1.15,vl);
  109. tot += vl;
  110. ds *= .14*dist;
  111. }}
  112. bz*=hval;
  113. tot*=hval;
  114. col = mix(col,vec3(.5)*0.2*nval,pow(bz,1.5));
  115. tot = smoothstep(-7.5,-0.,1.-tot);
  116. vec3 sccol = mix(col3*vec3(0.1,0.1,0.2),scol1*vec3(.2,0.,0.1),smoothstep(0.,900.,s2p));
  117. col = mix(col,sccol,1.-tot)*1.6;
  118. vec3 sncol = mix(scol2*1.75,scol2*1.25,smoothstep(0.,1200.,s2p)); //ночь
  119. float sd = pow(sun,10.)+.7;
  120. col += sncol*bz*bz*bz*tot*tot*tot*sd;
  121. if (!wtr)col+=(1.-bz)*01.15*exc*(1.-mval);
  122. else col+=01.15*exc*(1.-mval)*(1.-hval);
  123. col=mix(col*col,col/1.5+col*col,nval);
  124. return col;
  125. }
  126. vec3 clouds_col(vec3 ro, vec3 rd){
  127. float pln = plane(ro, rd, vec3(0.,-4.,0), vec3(1.,0.,0.), vec3(0.0,.0,1.0));
  128. bool wtr = false;
  129. vec3 bm = vec3(0);
  130. if (pln < 500. && pln > 0.)
  131. {
  132. vec3 n = vec3(0,1,0);
  133. rd = reflect(rd,n);
  134. wtr = true;
  135. }
  136. vec3 clo = clouds(ro, rd, wtr);
  137. return clo;
  138. }
  139. void vertex() {
  140. }
  141. void fragment() {
  142. vec3 cam=((CAMERA_MATRIX*vec4(1.0)).xyz);
  143. vec3 rd=normalize(((CAMERA_MATRIX*vec4(normalize(-VERTEX),0.0)).xyz));
  144. ALBEDO = clouds_col(cam,reflect(rd,vec3(0.,-1.,0.)));
  145. ALPHA=1.;
  146. }