Advertisement
Guest User

Untitled

a guest
Jan 5th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. varying vec2 v_vTexcoord;
  2. varying vec4 v_vColour;
  3. varying vec2 v_vPosition;
  4. uniform vec3      iResolution;           // viewport resolution (in pixels)
  5. uniform float     iTime;                 // shader playback time (in seconds)
  6. uniform sampler2D iChannel0;
  7. //uniform sampler2D iChannel1;
  8. uniform float Alpha;
  9. uniform float brightness;
  10.  
  11. // rendering params
  12. const float sphsize=.0; // planet size
  13. const float dist=.27; // distance for glow and distortion
  14. const float perturb=.3; // distortion amount of the flow around the planet
  15. const float displacement=.015; // hot air effect
  16. const float windspeed=.4; // speed of wind flow
  17. const float steps=30.; // number of steps for the volumetric rendering - 110.
  18. const float stepsize=.05; //.025
  19. //const float brightness=.58; //.43 // .63
  20. const vec3 planetcolor=vec3(0.55,0.4,0.3);
  21. const float fade=.005; //fade by distance
  22. const float glow=3.5; // glow amount, mainly on hit side
  23.  
  24. // fractal params
  25. const int iterations=13;
  26. const float fractparam=.7;
  27. const vec3 offset=vec3(1.5,2.,-1.5);
  28.  
  29. float wind(vec3 p) {
  30.     float d=max(0.,dist-max(0.,length(p)-sphsize)/sphsize)/dist; // for distortion and glow area
  31.     float x=max(0.2,p.x*2.); // to increase glow on left side
  32.     p.y*=1.+max(0.,-p.x-sphsize*.25)*1.5; // left side distortion (cheesy)
  33.     p-=d*normalize(p)*perturb; // spheric distortion of flow
  34.     p+=vec3(iTime*windspeed,0.,0.); // flow movement
  35.     p=abs(fract((p+offset)*.1)-.5); // tile folding
  36.     for (int i=0; i<iterations; i++) {  
  37.         p=abs(p)/dot(p,p)-fractparam; // the magic formula for the hot flow
  38.     }
  39.     return length(p)*(1.+d*glow*x)+d*glow*x; // return the result with glow applied
  40. }
  41.  
  42. void main()
  43. {
  44.     // get ray dir 
  45.     vec2 uv = v_vPosition.xy / iResolution.xy-0.5;
  46.     //vec2 uv = v_vPosition.xy / iResolution.xy-.5;
  47.     vec3 dir=vec3(uv,1.);
  48.     dir.x*=iResolution.x/iResolution.y;
  49.     vec3 from=vec3(0.,0.,-2.+texture2D(iChannel0,uv*.5+iTime).x*stepsize); //from+dither
  50.  
  51.     float v=0., l=-0.0001, t=iTime*windspeed*.2;
  52.     for (float r=10.;r<steps;r++) {
  53.         vec3 p=from+r*dir*stepsize;
  54.         float tx=texture2D(iChannel0,uv*.2+vec2(t,0.)).x*displacement; // hot air effect
  55.         if (length(p)-sphsize-tx>0.)
  56.  
  57.             v+=min(50.,wind(p))*max(0.,1.-r*fade);
  58.         else if (l<0.)
  59.  
  60.             l=pow(max(.53,dot(normalize(p),normalize(vec3(-1.,.5,-0.3)))),4.)
  61.             *(.5+texture2D(iChannel0,uv*vec2(2.,1.)*(1.+p.z*.5)+vec2(tx+t*.5,0.)).x*2.);
  62.         }
  63.     v/=steps; v*=brightness; // average values and apply bright factor
  64.     vec3 col=vec3(v*1.25,v*v,v*v*v)+l*planetcolor; // set color
  65.    
  66.     col*=1.0-length(pow(abs(uv),vec2(5.0)))*14.0; // vignette (kind of)
  67.     gl_FragColor = mix(v_vColour,vec4(col,1.0),Alpha) * texture2D( gm_BaseTexture, v_vTexcoord );
  68.     //gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord );
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement