SHARE
TWEET

Untitled

a guest Apr 20th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --RAYMARCH_BEGIN--
  2.  
  3. #version 430
  4. layout(location = 0) out vec4 out_color;
  5. layout(location = 1) uniform vec4 parameters;
  6. layout(location = 2) uniform sampler2D tex;
  7. in vec2 ftexcoord;
  8. uniform float crap;//-1. 30.0 1.1
  9.  
  10. vec3 rotatex(in vec3 p, float ang) { return vec3(p.x, p.y*cos(ang) - p.z*sin(ang), p.y*sin(ang) + p.z*cos(ang)); }
  11.  
  12. vec3 rotatey(in vec3 p, float ang) { return vec3(p.x*cos(ang) - p.z*sin(ang), p.y, p.x*sin(ang) + p.z*cos(ang)); }
  13.  
  14. vec3 rotatez(in vec3 p, float ang) { return vec3(p.x*cos(ang) - p.y*sin(ang), p.x*sin(ang) + p.y*cos(ang), p.z); }
  15.  
  16. float scene(vec3 p)
  17. {
  18.     p = rotatex(p, 0.18*parameters.z);
  19.     p = rotatez(p, 0.20*parameters.z);
  20.     p = rotatey(p, 0.22*parameters.z);
  21.  
  22.     float d0 = length(max(abs(p) - 0.5, 0.0)) - 0.0 + clamp(sin((p.x +p.y + p.z)*crap)*0.03, 0.0, 1.0);
  23.     float d1 = length(p)-0.3;
  24.     return sin(max(d0, -d1));
  25. }
  26.  
  27. vec3 get_normal(vec3 p)
  28. {
  29.     vec3 eps = vec3(0.11, 0.0, 0.0);
  30.     float nx = scene(p + eps.xyy) - scene(p - eps.xyy);
  31.     float ny = scene(p + eps.yxy) - scene(p - eps.yxy);
  32.     float nz = scene(p + eps.yyx) - scene(p - eps.yyx);
  33.     return normalize(vec3(nx, ny, nz));
  34. }
  35.  
  36. void main(void)
  37. {
  38.     vec2 p = 2.0 * gl_FragCoord.xy / parameters.xy - 1.0;
  39.     p.x *= parameters.x / parameters.y;
  40.  
  41.     vec3 ro = vec3(0.0, 0.0, 1.7);
  42.     vec3 rd = normalize(vec3(p, -1.4));
  43.     vec3 color = (1.0 - vec3(length(p*0.5)))*0.2;
  44.  
  45.     vec3 pos = ro;
  46.     float dist = 0.0;
  47.     for (int i = 0; i < 64; i++)
  48.     {
  49.         float d = scene(pos);
  50.         pos += rd*d;
  51.         dist += d;
  52.     }
  53.  
  54.     if (dist < 100.0)
  55.     {
  56.         vec3 n = get_normal(pos);
  57.         vec3 r = reflect(normalize(pos - ro), n);
  58.         vec3 h = -normalize(n + pos - ro);
  59.         float diff = 1.0*clamp(dot(n, normalize(vec3(1, 1, 1))), 0.0, 1.0);
  60.         float diff2 = 0.2*clamp(dot(n, normalize(vec3(0.7, -1, 0.5))), 0.0, 1.0);
  61.         float diff3 = 0.1*clamp(dot(n, normalize(vec3(-0.7, -0.4, 0.7))), 0.0, 1.0);
  62.         //float spec = pow(clamp(dot(r, normalize(vec3(1,1,1))), 0.0, 1.0), 50.0);
  63.         float spec = pow(clamp(dot(h, normalize(vec3(1, 1, 1))), 0.0, 1.0), 50.0);
  64.         float amb = 0.2 + pos.y;
  65.         color = diff*vec3(1, 1, 1) + diff2*vec3(1, 0, 0) + diff3*vec3(1, 0, 1) + spec*vec3(1, 1, 1) + amb*vec3(0.2, 0.2, 0.2);
  66.         color /= dist;
  67.     }
  68.     out_color = vec4(color, 1.0);
  69. }
  70.  
  71. --RAYMARCH_END--
  72.  
  73. --POSTPROC_BEGIN--
  74.  
  75. #version 430
  76. layout(location = 0) out vec4 out_color;
  77. layout(location = 1) uniform vec4 parameters;
  78. layout(location = 2) uniform sampler2D tex;
  79. in vec2 ftexcoord;
  80.  
  81. uniform float sepia_level;//0.00 1.00 0.01
  82.  
  83. float xres = parameters.x;
  84. float yres = parameters.y;
  85. float time = parameters.z;
  86.  
  87. vec4 Sepia( in vec4 color )
  88. {
  89.     return vec4(
  90.           clamp(color.r * 0.393 + color.g * 0.769 + color.b * 0.189, 0.0, 1.0)
  91.         , clamp(color.r * 0.349 + color.g * 0.686 + color.b * 0.168, 0.0, 1.0)
  92.         , clamp(color.r * 0.272 + color.g * 0.534 + color.b * 0.131, 0.0, 1.0)
  93.         , color.a
  94.     );
  95. }
  96.  
  97. void main(void)
  98. {
  99.     vec4 color =  texture(tex, ftexcoord);
  100.  
  101.     vec4 sep_col = mix(color, Sepia(color), clamp(sepia_level,0.0,1.0) );
  102.     out_color = vec4(sep_col.rgb, 1.0);
  103. }
  104.  
  105. --POSTPROC_END--
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top