Advertisement
DEKTEN

WORKS_IN_AAC2020_11_16_2020

Nov 16th, 2020
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. #version 330 core
  2.  
  3. #define fragCoord gl_FragCoord
  4. #define fragColor FragColor
  5.  
  6. //|(( UNI ))_____________________________|//
  7. uniform vec3 iResolution;
  8. uniform float iTime ;
  9. uniform vec4 iMouse ;
  10.  
  11. //|(( INN ))_____________________________|//
  12. //: fag_tec:FrAG_shader_TExture_Coord
  13. in vec2 fag_tec;
  14.  
  15. //|(( OUT ))_____________________________|//
  16. out vec4 FragColor;
  17.  
  18.  
  19. // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
  20. // Created by S. Guillitte 2015
  21.  
  22. float zoom=1.;
  23.  
  24. vec2 cmul( vec2 a, vec2 b ) { return vec2( a.x*b.x - a.y*b.y, a.x*b.y + a.y*b.x ); }
  25. vec2 csqr( vec2 a ) { return vec2( a.x*a.x - a.y*a.y, 2.*a.x*a.y ); }
  26.  
  27.  
  28. mat2 rot(float a) {
  29. return mat2(cos(a),sin(a),-sin(a),cos(a));
  30. }
  31.  
  32. vec2 iSphere( in vec3 ro, in vec3 rd, in vec4 sph )//from iq
  33. {
  34. vec3 oc = ro - sph.xyz;
  35. float b = dot( oc, rd );
  36. float c = dot( oc, oc ) - sph.w*sph.w;
  37. float h = b*b - c;
  38. if( h<0.0 ) return vec2(-1.0);
  39. h = sqrt(h);
  40. return vec2(-b-h, -b+h );
  41. }
  42.  
  43. float map(in vec3 p) {
  44.  
  45. float res = 0.;
  46.  
  47. vec3 c = p;
  48. for (int i = 0; i < 10; ++i) {
  49. p =.7*abs(p)/dot(p,p) -.7;
  50. p.yz= csqr(p.yz);
  51. p=p.zxy;
  52. res += exp(-19. * abs(dot(p,c)));
  53.  
  54. }
  55. return res/2.;
  56. }
  57.  
  58.  
  59.  
  60. vec3 raymarch( in vec3 ro, vec3 rd, vec2 tminmax )
  61. {
  62. float t = tminmax.x;
  63. float dt = .02;
  64. //float dt = .2 - .195*cos(iTime*.05);//animated
  65. vec3 col= vec3(0.);
  66. float c = 0.;
  67. for( int i=0; i<64; i++ )
  68. {
  69. t+=dt*exp(-2.*c);
  70. if(t>tminmax.y)break;
  71. vec3 pos = ro+t*rd;
  72.  
  73. c = map(ro+t*rd);
  74.  
  75. col = .99*col+ .08*vec3(c*c, c, c*c*c);//green
  76. //col = .99*col+ .08*vec3(c*c*c, c*c, c);//blue
  77. }
  78. return col;
  79. }
  80.  
  81.  
  82. void main( )
  83. {
  84. float time = iTime;
  85. vec2 q = fragCoord.xy / iResolution.xy;
  86. vec2 p = -1.0 + 2.0 * q;
  87. p.x *= iResolution.x/iResolution.y;
  88. vec2 m = vec2(0.);
  89. if( iMouse.z>0.0 )m = iMouse.xy/iResolution.xy*3.14;
  90. m-=.5;
  91.  
  92. // camera
  93.  
  94. vec3 ro = zoom*vec3(4.);
  95. ro.yz*=rot(m.y);
  96. ro.xz*=rot(m.x+ 0.1*time);
  97. vec3 ta = vec3( 0.0 , 0.0, 0.0 );
  98. vec3 ww = normalize( ta - ro );
  99. vec3 uu = normalize( cross(ww,vec3(0.0,1.0,0.0) ) );
  100. vec3 vv = normalize( cross(uu,ww));
  101. vec3 rd = normalize( p.x*uu + p.y*vv + 4.0*ww );
  102.  
  103.  
  104. vec2 tmm = iSphere( ro, rd, vec4(0.,0.,0.,2.) );
  105.  
  106. // raymarch
  107. vec3 col = raymarch(ro,rd,tmm);
  108. if (tmm.x<0.){
  109.  
  110. col = vec3(1,1,1);
  111.  
  112. } else {
  113. vec3 nor=(ro+tmm.x*rd)/2.;
  114. nor = reflect(rd, nor);
  115. float fre = pow(.5+ clamp(dot(nor,rd),0.0,1.0), 3. )*1.3;
  116. col += vec3(1,1,1) * fre;
  117.  
  118. }
  119.  
  120. // shade
  121.  
  122. col = .5 *(log(1.+col));
  123. col = clamp(col,0.,1.);
  124. fragColor = vec4( col, 1.0 );
  125.  
  126. }
  127.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement