Guest User

Untitled

a guest
Mar 22nd, 2014
97
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define NDT_NORMAL 0
  2. #define NDT_AIRLIKE 1
  3. #define NDT_LIQUID 2
  4. #define NDT_FLOWINGLIQUID 3
  5. #define NDT_GLASSLIKE 4
  6. #define NDT_ALLFACES 5
  7. #define NDT_ALLFACES_OPTIONAL 6
  8. #define NDT_TORCHLIKE 7
  9. #define NDT_SIGNLIKE 8
  10. #define NDT_PLANTLIKE 9
  11. #define NDT_FENCELIKE 10
  12. #define NDT_RAILLIKE 11
  13. #define NDT_NODEBOX 12
  14. #define NDT_GLASSLIKE_FRAMED 13
  15.  
  16. #define TILE_MATERIAL_BASIC 0
  17. #define TILE_MATERIAL_ALPHA 1
  18. #define TILE_MATERIAL_LIQUID_TRANSPARENT 2
  19. #define TILE_MATERIAL_LIQUID_OPAQUE 3
  20. #define TILE_MATERIAL_LEAVES 4
  21. #define TILE_MATERIAL_PLANTS 5
  22.  
  23. uniform mat4 mWorldViewProj;
  24. uniform mat4 mInvWorld;
  25. uniform mat4 mTransWorld;
  26. uniform mat4 mWorld;
  27.  
  28. uniform float dayNightRatio;
  29. uniform vec3 eyePosition;
  30. uniform float animationTimer;
  31.  
  32. varying vec3 vPosition;
  33. varying vec3 worldPosition;
  34.  
  35. varying vec3 eyeVec;
  36. varying vec3 lightVec;
  37. varying vec3 tsEyeVec;
  38. varying vec3 tsLightVec;
  39.  
  40. const float e = 2.718281828459;
  41. const float BS = 10.0;
  42.  
  43. float smoothCurve( float x ) {
  44. return x * x *( 3.0 - 2.0 * x );
  45. }
  46. float triangleWave( float x ) {
  47. return abs( fract( x + 0.5 ) * 2.0 - 1.0 );
  48. }
  49. float smoothTriangleWave( float x ) {
  50. return smoothCurve( triangleWave( x ) ) * 2.0 - 1.0;
  51. }
  52.  
  53. void main(void)
  54. {
  55. gl_TexCoord[0] = gl_MultiTexCoord0;
  56.  
  57. vec4 pos, pos2;
  58. switch (MATERIAL_TYPE){
  59. case TILE_MATERIAL_PLANTS:
  60. pos = gl_Vertex;
  61. pos2 = mWorld * gl_Vertex;
  62. if (gl_TexCoord[0].y < 0.05) {
  63. pos.x += (smoothTriangleWave(animationTimer * 20.0 + pos2.x * 0.1 + pos2.z * 0.1) * 2.0 - 1.0) * 0.8;
  64. pos.y -= (smoothTriangleWave(animationTimer * 10.0 + pos2.x * -0.5 + pos2.z * -0.5) * 2.0 - 1.0) * 0.4;
  65. }
  66. gl_Position = mWorldViewProj * pos;
  67. break;
  68. case TILE_MATERIAL_LEAVES:
  69. pos = gl_Vertex;
  70. pos2 = mWorld*gl_Vertex;
  71. pos.x += (smoothTriangleWave(animationTimer*10.0 + pos2.x * 0.01 + pos2.z * 0.01) * 2.0 - 1.0) * 0.4;
  72. pos.y += (smoothTriangleWave(animationTimer*15.0 + pos2.x * -0.01 + pos2.z * -0.01) * 2.0 - 1.0) * 0.2;
  73. pos.z += (smoothTriangleWave(animationTimer*10.0 + pos2.x * -0.01 + pos2.z * -0.01) * 2.0 - 1.0) * 0.4;
  74. gl_Position = mWorldViewProj * pos;
  75. break;
  76. case TILE_MATERIAL_LIQUID_TRANSPARENT:
  77. case TILE_MATERIAL_LIQUID_OPAQUE:
  78. #ifdef ENABLE_WAVING_WATER
  79. pos = gl_Vertex;
  80. pos.y -= 2.0;
  81. pos.y -= sin (pos.z/WATER_WAVE_LENGTH + animationTimer * WATER_WAVE_SPEED * WATER_WAVE_LENGTH) * WATER_WAVE_HEIGHT
  82. + sin ((pos.z/WATER_WAVE_LENGTH + animationTimer * WATER_WAVE_SPEED * WATER_WAVE_LENGTH) / 7.0) * WATER_WAVE_HEIGHT;
  83. gl_Position = mWorldViewProj * pos;
  84. #else
  85. gl_Position = mWorldViewProj * gl_Vertex;
  86. #endif
  87. break;
  88. default:
  89. gl_Position = mWorldViewProj * gl_Vertex;
  90. }
  91.  
  92. vPosition = gl_Position.xyz;
  93. worldPosition = (mWorld * gl_Vertex).xyz;
  94. vec3 sunPosition = vec3 (0.0, eyePosition.y * BS + 900.0, 0.0);
  95.  
  96. vec3 normal, tangent, binormal;
  97. normal = normalize(gl_NormalMatrix * gl_Normal);
  98. if (gl_Normal.x > 0.5) {
  99. // 1.0, 0.0, 0.0
  100. tangent = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, -1.0));
  101. binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
  102. } else if (gl_Normal.x < -0.5) {
  103. // -1.0, 0.0, 0.0
  104. tangent = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0));
  105. binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
  106. } else if (gl_Normal.y > 0.5) {
  107. // 0.0, 1.0, 0.0
  108. tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0));
  109. binormal = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0));
  110. } else if (gl_Normal.y < -0.5) {
  111. // 0.0, -1.0, 0.0
  112. tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0));
  113. binormal = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0));
  114. } else if (gl_Normal.z > 0.5) {
  115. // 0.0, 0.0, 1.0
  116. tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0));
  117. binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
  118. } else if (gl_Normal.z < -0.5) {
  119. // 0.0, 0.0, -1.0
  120. tangent = normalize(gl_NormalMatrix * vec3(-1.0, 0.0, 0.0));
  121. binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
  122. }
  123. mat3 tbnMatrix = mat3( tangent.x, binormal.x, normal.x,
  124. tangent.y, binormal.y, normal.y,
  125. tangent.z, binormal.z, normal.z);
  126.  
  127. lightVec = sunPosition - worldPosition;
  128. tsLightVec = lightVec * tbnMatrix;
  129. eyeVec = (gl_ModelViewMatrix * gl_Vertex).xyz;
  130. tsEyeVec = eyeVec * tbnMatrix;
  131.  
  132. vec4 color;
  133. float day = gl_Color.r;
  134. float night = gl_Color.g;
  135. float light_source = gl_Color.b;
  136.  
  137. float rg = mix(night, day, dayNightRatio);
  138. rg += light_source * 2.5; // Make light sources brighter
  139. float b = rg;
  140.  
  141. // Moonlight is blue
  142. b += (day - night) / 13.0;
  143. rg -= (day - night) / 13.0;
  144.  
  145. // Emphase blue a bit in darker places
  146. // See C++ implementation in mapblock_mesh.cpp finalColorBlend()
  147. b += max(0.0, (1.0 - abs(b - 0.13)/0.17) * 0.025);
  148.  
  149. // Artificial light is yellow-ish
  150. // See C++ implementation in mapblock_mesh.cpp finalColorBlend()
  151. rg += max(0.0, (1.0 - abs(rg - 0.85)/0.15) * 0.065);
  152.  
  153. color.r = clamp(rg,0.0,1.0);
  154. color.g = clamp(rg,0.0,1.0);
  155. color.b = clamp(b,0.0,1.0);
  156.  
  157. // Make sides and bottom darker than the top
  158. color = color * color; // SRGB -> Linear
  159. if(gl_Normal.y <= 0.5)
  160. color *= 0.6;
  161. color = sqrt(color); // Linear -> SRGB
  162. color.a = gl_Color.a;
  163.  
  164. gl_FrontColor = gl_BackColor = color;
  165. }
RAW Paste Data