Advertisement
Guest User

Yourself Waving Wheat + Plants + Leaves

a guest
Mar 23rd, 2011
10,623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. #define CURVATURE
  2. #define WAVING_WHEAT
  3. #define WAVING_PLANTS
  4. #define WAVING_LEAVES
  5.  
  6. #ifdef CURVATURE
  7. const float FLAT_RADIUS = 84.0;
  8. const float WORLD_RADIUS = 212.0;
  9. const float WORLD_RADIUS_SQUARED = WORLD_RADIUS*WORLD_RADIUS;
  10. #endif
  11.  
  12. const float PI = 3.1415926535897932384626433832795;
  13. const float PI2 = 6.283185307179586476925286766559;
  14.  
  15. uniform float sunVector;
  16. uniform float moonVector;
  17. uniform int worldTime;
  18. uniform int renderType;
  19.  
  20. varying float texID;
  21.  
  22. int getTextureID(vec2 coord);
  23.  
  24. void main() {
  25. vec4 position = gl_Vertex;
  26. #ifdef WAVING_WHEAT
  27. int tex = getTextureID(gl_MultiTexCoord0.st);
  28. if (87 < tex && tex < 96 && renderType != 0) {
  29. float t = float(mod(worldTime, 200))/200.0;
  30. vec2 pos = position.xz/16.0;
  31. if (round(16.0*gl_MultiTexCoord0.t) <= floor(16.0*gl_MultiTexCoord0.t)) {
  32. position.x += (sin(PI2*(2.0*pos.x + pos.y - 3.0*t)) + 0.6)/20.0;
  33. }
  34. }
  35. position = gl_ModelViewMatrix * position;
  36. #endif
  37. #ifdef CURVATURE
  38. if (gl_Color.a != 0.8) {
  39. // Not a cloud.
  40.  
  41. float dist = (length(position) - FLAT_RADIUS)/WORLD_RADIUS;
  42.  
  43. if (dist > 0) {
  44. dist *= dist;
  45. position.y -= WORLD_RADIUS - sqrt(max(1.0 - dist, 0.0)) * WORLD_RADIUS;
  46. }
  47.  
  48. }
  49. #endif
  50. #ifdef WAVING_PLANTS
  51. if ((tex == 12 || tex == 13 || tex == 15)&& renderType == 1) {
  52. float t = float(mod(worldTime, 500))/500.0;
  53. vec2 pos = position.xz/16.0;
  54. if (round(16.0*gl_MultiTexCoord0.t) <= floor(16.0*gl_MultiTexCoord0.t)) {
  55. position.x -= (sin(PI2*(2.0*pos.x + pos.y - 3.0*t)) + 0.6)/8.0;
  56. }
  57. }
  58. #endif
  59. #ifdef WAVING_LEAVES
  60. if ((tex == 52 || tex == 53 || tex == 132 || tex == 133)&& renderType == 1) {
  61. float t = float(mod(worldTime, 800))/800.0;
  62. vec2 pos = position.xz/16.0;
  63. if (round(8.0*gl_MultiTexCoord0.t) <= floor(16.32*gl_MultiTexCoord0.t)) {
  64. position.x -= (sin(PI2*(2.0*pos.x + pos.y - 3.0*t)) + 0.6)/24.0;
  65. position.y -= (sin(PI2*(3.0*pos.x + pos.y - 4.0*t)) + 1.2)/32.0;
  66. position.z -= (sin(PI2*(1.0*pos.x + pos.y - 1.5*t)) + 0.3)/8.0;
  67. }
  68. }
  69. #endif
  70.  
  71. #if defined(CURVATURE) || defined(WAVING_WHEAT) || defined(WAVING_LEAVES) || defined(WAVING_PLANTS)
  72. gl_Position = gl_ProjectionMatrix * position;
  73. #else
  74. gl_Position = ftransform();
  75. #endif
  76.  
  77. if (renderType != 0) {
  78. texID = float(getTextureID(gl_MultiTexCoord0.st));
  79. }
  80. else {
  81. texID = -1.0;
  82. }
  83.  
  84. gl_FrontColor = gl_BackColor = gl_Color;
  85. gl_TexCoord[0] = gl_MultiTexCoord0;
  86. gl_FogFragCoord = gl_Position.z;
  87. }
  88.  
  89. int getTextureID(vec2 coord) {
  90. int i = int(floor(16*coord.s));
  91. int j = int(floor(16*coord.t));
  92. return i + 16*j;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement