Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. #define NNOISE 4
  2.  
  3. #define PI 3.141592653
  4.  
  5. #define PALE_BLUE vec4(0.25, 0.25, 0.35, 1.0)
  6. //#define PALE_BLUE vec4(0.90, 0.90, 1.0, 1.0)
  7. #define MEDIUM_BLUE vec4(0.10, 0.10, 0.30, 1.0)
  8. #define DARK_BLUE vec4(0.05, 0.05, 0.26, 1.0)
  9. #define DARKER_BLUE vec4(0.03, 0.03, 0.20, 1.0)
  10.  
  11. varying vec3 normal;
  12. varying vec4 pos;
  13. varying vec4 rawpos;
  14.  
  15. uniform float scale;
  16.  
  17. float noise(vec4);
  18. float snoise(vec4);
  19. float noise(vec3);
  20. float snoise(vec3);
  21. vec4 marble_color(float);
  22. vec4 spline(float x, int y, vec4 z[]);
  23.  
  24. void main() {
  25. //vec4 color = gl_FrontMaterial.diffuse;
  26. vec4 matspec = gl_FrontMaterial.specular;
  27. float shininess = gl_FrontMaterial.shininess;
  28. vec4 lightspec = gl_LightSource[0].specular;
  29. vec4 lpos = gl_LightSource[0].position;
  30. vec4 s = -normalize(pos-lpos); //not sure why this needs to
  31. // be negated, but it does.
  32. vec3 light = s.xyz;
  33. vec3 n = normalize(normal);
  34. vec3 r = -reflect(light, n);
  35. r = normalize(r);
  36. vec3 v = -pos.xyz; // We are in eye coordinates,
  37. // so the viewing vector is
  38. // [0.0 0.0 0.0] - pos
  39. v = normalize(v);
  40.  
  41. float scalelocal;
  42. if (scale == 0.0) {
  43. scalelocal = 1.0; //default value
  44. } else {
  45. scalelocal = scale;
  46. }
  47.  
  48. vec4 tp = gl_TexCoord[0] * scalelocal;
  49. vec3 rp = rawpos.xyz * scalelocal;
  50.  
  51. // create the grayscale marbling here
  52. float marble=0.0;
  53. float f = 1.0;
  54. for(int i=0; i < NNOISE; i++) {
  55. marble += noise(rp*f)/f;
  56. f *= 2.17;
  57. }
  58.  
  59. vec4 color;
  60. color = marble_color(marble);
  61.  
  62. // for some reason the colors are awfully dark
  63. // I think it looks better this way
  64. color *= 2.85;
  65. /*
  66. float x = pow(sin(marble * PI) * 0.5 + 0.5, 10.0);
  67. float y=0.1;
  68. vec4 matdiffcol= gl_FrontMaterial.diffuse;
  69. vec4 othercolor = vec4( vec3(1.0)-((vec3(1.0)-matdiffcol.rgb)*y), 1.0);
  70. //vec4 color = mix(vec4(1.0, 1.0, 1.0, 1.0), matdiffcol, x);
  71. color = mix(othercolor, matdiffcol, x);
  72. */
  73.  
  74. //color = mix(vec4(1.0, 1.0, 1.0, 1.0), vec4(0.4, 0.6, 1.0, 1.0), vec4(marble, marble, marble, 1.0));
  75. // color = vec4(marble, marble, marble, 1.0);
  76.  
  77. vec4 diffuse = color * max(0.0, dot(n, s.xyz)) * gl_LightSource[0].diffuse;
  78. vec4 specular;
  79. if (shininess != 0.0) {
  80. specular = lightspec * matspec * pow(max(0.0, dot(r, v)), shininess);
  81. } else {
  82. specular = vec4(0.0, 0.0, 0.0, 0.0);
  83. }
  84.  
  85. gl_FragColor = diffuse + specular;
  86. // gl_FragColor = noise4(pos) != 0.0 ? vec4(1.0, 0.0, 0.0, 1.0) : vec4(0.0, 0.0, 1.0, 1.0);
  87.  
  88. }
  89.  
  90. vec4 marble_color(float m) {
  91. vec4 c[25];
  92.  
  93. c[0] = PALE_BLUE;
  94. c[1] = PALE_BLUE;
  95. c[2] = MEDIUM_BLUE;
  96. c[3] = MEDIUM_BLUE;
  97. c[4] = MEDIUM_BLUE;
  98. c[5] = PALE_BLUE;
  99. c[6] = PALE_BLUE;
  100. c[7] = DARK_BLUE;
  101. c[8] = DARK_BLUE;
  102. c[9] = DARKER_BLUE;
  103. c[10] = DARKER_BLUE;
  104. c[11] = PALE_BLUE;
  105. c[12] = DARKER_BLUE;
  106.  
  107. vec4 res = spline(clamp(2.0*m + 0.75, 0.0, 1.0), 13, c);
  108.  
  109. return res;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement