Advertisement
Guest User

Untitled

a guest
Dec 9th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. /**
  2. * Example Fragment Shader
  3. * Sets the color and alpha of the pixel by setting gl_FragColor
  4. */
  5.  
  6. // Set the precision for data types used in this shader
  7. precision highp float;
  8. precision highp int;
  9.  
  10. // Default THREE.js uniforms available to both fragment and vertex shader
  11. uniform mat4 modelMatrix;
  12. uniform mat4 modelViewMatrix;
  13. uniform mat4 projectionMatrix;
  14. uniform mat4 viewMatrix;
  15. uniform mat3 normalMatrix;
  16.  
  17. // Default uniforms provided by ShaderFrog.
  18. uniform vec3 cameraPosition;
  19. uniform float time;
  20. uniform sampler2D noise;
  21.  
  22. // A uniform unique to this shader. You can modify it to the using the form
  23. // below the shader preview. Any uniform you add is automatically given a form
  24. uniform vec3 color;
  25.  
  26. // Example varyings passed from the vertex shader
  27. varying vec3 vPosition;
  28. varying vec3 vNormal;
  29. varying vec2 vUv;
  30. varying vec2 vUv2;
  31.  
  32. void main() {
  33.  
  34. // Fragment shaders set the gl_FragColor, which is a vector4 of
  35. // ( red, green, lue, alpha ).
  36. float steps = 24.0;
  37. float step = 1.0 / steps;
  38. float scale = 0.3;
  39. float minv = 0.4;
  40. float maxv = 0.8;
  41. vec3 top = vec3(1.0, 0.0, 0.0);
  42. vec3 side = vec3(0.5, 0.5, 0.5);
  43.  
  44.  
  45. float h;
  46. vec3 col;
  47. vec2 base = vUv * scale;
  48. for (int i = -3; i < 3; i++) {
  49. vec2 ccoord = ((vUv + vec2(0, float(i) * step)) * steps) / steps * scale;
  50. vec2 coord = floor((vUv + vec2(0, float(i) * step)) * steps) / steps * scale;
  51.  
  52. gl_FragColor = vec4(texture2D(noise, coord));
  53. //return;
  54. int th = 6 - (i + 3);
  55. h = texture2D(noise, ccoord).r;
  56. h = (h - minv) / (maxv - minv);
  57. int hi = int(floor(h * 6.0));
  58.  
  59. gl_FragColor = vec4(vec3(h), 1.0);
  60. //return;
  61. float shadow = 1.0 * float(6 - (i + 3)) / 6.0;
  62. shadow *= (base.y - ccoord.y)*steps*6.0;
  63.  
  64. gl_FragColor = vec4(vec3(shadow), 1.0);
  65. //return;
  66. if (hi == th) {
  67. col = top * shadow;
  68. break;
  69. } else if (hi > th) {
  70. //float shadow = (h - th) * (ccoord.y - coord.y) / scale * steps;
  71. col = side * shadow;
  72. break;
  73. }
  74. }
  75.  
  76. gl_FragColor = vec4(col, 1.0);
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement