Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #define PI 3.14159265359
  2. #define PI2 6.28318530718
  3.  
  4. // Comment or uncomment
  5. // (Leave commented if in shadergif)
  6. // (uncomment if in shadertoy)
  7. //#define shadertoy 1
  8.  
  9. #ifdef shadertoy
  10. // time is iGlobalTime in shadertoy
  11. #define time iGlobalTime
  12. #endif
  13. #ifndef shadertoy
  14. // Define some uniforms
  15. // (which shadertoy already defines for us, but not shadergif)
  16. precision highp float;
  17. uniform float time;
  18. uniform float iGlobalTime;
  19. varying vec2 UV;
  20. uniform vec3 iResolution;
  21. #endif
  22.  
  23. float map(vec3 pos){
  24. pos = fract(pos) * 2.0 - 1.0;
  25.  
  26. return length(max(abs(pos) - 0.2, 0.0));
  27. }
  28.  
  29. float trace(vec3 o, vec3 r){
  30. vec3 p;
  31. float t = 0.0;
  32. float d;
  33.  
  34. for(int i = 0; i < 50; i++){
  35. p = o + r * t;
  36. d = map(p);
  37. t += d * 0.45;
  38.  
  39. if(d < 0.04){
  40. break;
  41. }
  42. }
  43.  
  44. return t;
  45. }
  46.  
  47. void mainImage( out vec4 fragColor, in vec2 fragCoord )
  48. {
  49. vec2 uv = fragCoord.xy / iResolution.xy;
  50. float ratio = iResolution.x / iResolution.y;
  51. uv.x *= ratio;
  52.  
  53. vec4 col = vec4(0.0);
  54.  
  55. vec2 pos = uv - vec2(0.5 * ratio, 0.5);
  56.  
  57. pos *= 1.0;
  58.  
  59. vec3 r,o;
  60.  
  61. r = normalize(vec3(pos, 1.0));
  62.  
  63. o = vec3(0.0, 0.0, -3.0);
  64.  
  65. o.z += time;
  66.  
  67.  
  68.  
  69. float t = trace(o, r);
  70.  
  71. col += 1.0 / (1.0 + t * t * 0.03);
  72.  
  73. col = 0.1 * floor(col * 10.0);
  74.  
  75. col.a = 1.0;
  76.  
  77. fragColor = col;
  78. }
  79.  
  80. #ifndef shadertoy
  81. void main(){
  82. vec2 uv = UV.xy * iResolution.xy;
  83. vec4 col;
  84.  
  85. mainImage(col, uv);
  86.  
  87. gl_FragColor = col;
  88. }
  89. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement