Clone of mesa.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CH18-mandel.frag.txt 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // Fragment shader for drawing the Mandelbrot set
  3. //
  4. // Authors: Dave Baldwin, Steve Koren, Randi Rost
  5. // based on a shader by Michael Rivero
  6. //
  7. // Copyright (c) 2002-2005: 3Dlabs, Inc.
  8. //
  9. // See 3Dlabs-License.txt for license information
  10. //
  11. varying vec3 Position;
  12. varying float LightIntensity;
  13. uniform float MaxIterations;
  14. uniform float Zoom;
  15. uniform float Xcenter;
  16. uniform float Ycenter;
  17. uniform vec3 InnerColor;
  18. uniform vec3 OuterColor1;
  19. uniform vec3 OuterColor2;
  20. void main()
  21. {
  22. float real = Position.x * Zoom + Xcenter;
  23. float imag = Position.y * Zoom + Ycenter;
  24. float Creal = real; // Change this line...
  25. float Cimag = imag; // ...and this one to get a Julia set
  26. float r2 = 0.0;
  27. float iter;
  28. // for (iter = 0.0; iter < MaxIterations && r2 < 4.0; ++iter)
  29. for (iter = 0.0; iter < 12 && r2 < 4.0; ++iter)
  30. {
  31. float tempreal = real;
  32. real = (tempreal * tempreal) - (imag * imag) + Creal;
  33. imag = 2.0 * tempreal * imag + Cimag;
  34. r2 = (real * real) + (imag * imag);
  35. }
  36. // Base the color on the number of iterations
  37. vec3 color;
  38. if (r2 < 4.0)
  39. color = InnerColor;
  40. else
  41. color = mix(OuterColor1, OuterColor2, fract(iter * 0.05));
  42. color *= LightIntensity;
  43. gl_FragColor = vec4(color, 1.0);
  44. }