Didjey228

water.vsh with forward rendering

Jul 23rd, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. #version 120
  2.  
  3. /*
  4. !! DO NOT REMOVE !!
  5. This code is from Chocapic13' shaders
  6. Read the terms of modification and sharing before changing something below please !
  7. !! DO NOT REMOVE !!
  8. */
  9.  
  10. //disabling is done by adding "//" to the beginning of a line.
  11.  
  12. //ADJUSTABLE VARIABLES//
  13.  
  14. #define WavingWater //Enable waving for water.
  15.  
  16. //#define WorldTimeAnimation
  17.  
  18. //ADJUSTABLE VARIABLES//
  19.  
  20. varying vec4 color;
  21. varying vec2 texcoord;
  22. varying vec2 lmcoord;
  23. varying vec3 binormal;
  24. varying vec3 normal;
  25. varying vec3 tangent;
  26. varying vec3 wpos;
  27. varying float mat;
  28.  
  29. attribute vec4 mc_Entity;
  30.  
  31. uniform vec3 cameraPosition;
  32. uniform mat4 gbufferModelView;
  33. uniform mat4 gbufferModelViewInverse;
  34. uniform int worldTime;
  35. uniform float frameTimeCounter;
  36. uniform int isEyeInWater;
  37.  
  38. const float PI = 3.1415927;
  39.  
  40. #ifdef WorldTimeAnimation
  41. float frametime = worldTime/20.0;
  42. #else
  43. float frametime = frameTimeCounter;
  44. #endif
  45.  
  46. float calcWaterMove0(vec3 pos){
  47. float speed = 2;
  48. float size = 2;
  49. float wave = 0;
  50. float wave1 = (sin(pos.x*size+frametime*speed) + cos(pos.z*size+frametime*speed))/2;
  51. float wave2 = (sin(pos.x*size/2+frametime*speed/3+30) + cos(pos.z*size/2+frametime*speed/3+30))/2;
  52. float wave3 = (sin(pos.x*size/1.5+frametime*speed*2+70) + cos(pos.z*size/1.5+frametime*speed*2+70))/2;
  53. float wave4 = (sin(pos.x*size/2.5+frametime*speed*1.4+120) + cos(pos.z*size/2.5+frametime*speed*1.4+120))/2;
  54. float mult1 = sin(frametime*speed);
  55. float mult2 = cos(frametime*speed);
  56. float mult3 = sin(frametime*speed+PI/4);
  57. float mult4 = cos(frametime*speed+PI/4);
  58. wave = (wave1*mult1+wave2*mult2+wave3*mult3+wave4*mult4)/4;
  59. return wave;
  60. }
  61.  
  62. //////////////////////////////VOID MAIN//////////////////////////////
  63. //////////////////////////////VOID MAIN//////////////////////////////
  64. //////////////////////////////VOID MAIN//////////////////////////////
  65. //////////////////////////////VOID MAIN//////////////////////////////
  66. //////////////////////////////VOID MAIN//////////////////////////////
  67.  
  68. void main() {
  69.  
  70. //vec4 viewpos = gl_ModelViewMatrix * gl_Vertex;
  71. vec4 position = gl_ModelViewMatrix * gl_Vertex;
  72. mat = 0.0f;
  73. float displacement = 0.0;
  74.  
  75. /* un-rotate */
  76. vec4 viewpos = gbufferModelViewInverse * position;
  77.  
  78. vec3 worldpos = viewpos.xyz + cameraPosition;
  79. wpos = worldpos;
  80.  
  81.  
  82.  
  83.  
  84. if (mc_Entity.x == 8.0 || mc_Entity.x == 9.0) {
  85. mat = 0.05;
  86. float fy = fract(worldpos.y + 0.001);
  87. #ifdef WavingWater
  88. float wave = calcWaterMove0(worldpos)*0.2;
  89. displacement = wave;
  90. viewpos.y += displacement;
  91. #endif
  92. }
  93. if (mc_Entity.x == 79.0 || mc_Entity.x == 95.0 || mc_Entity.x == 165.0 || mc_Entity.x == 212.0 || mc_Entity.x == 160.0) mat = 0.1;
  94. if (mc_Entity.x == 90.0) mat = 0.13;
  95.  
  96. /* re-rotate */
  97. viewpos = gbufferModelView * viewpos;
  98.  
  99. /* projectify */
  100. gl_Position = gl_ProjectionMatrix * viewpos;
  101.  
  102. color = gl_Color;
  103.  
  104. texcoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).st;
  105.  
  106. lmcoord = (gl_TextureMatrix[1] * gl_MultiTexCoord1).st;
  107.  
  108. gl_FogFragCoord = gl_Position.z;
  109.  
  110. tangent = vec3(0.0);
  111. binormal = vec3(0.0);
  112. normal = normalize(gl_NormalMatrix * normalize(gl_Normal));
  113.  
  114. if (gl_Normal.x > 0.5) {
  115. // 1.0, 0.0, 0.0
  116. tangent = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, -1.0));
  117. binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
  118. }
  119.  
  120. else if (gl_Normal.x < -0.5) {
  121. // -1.0, 0.0, 0.0
  122. tangent = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0));
  123. binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
  124. }
  125.  
  126. else if (gl_Normal.y > 0.5) {
  127. // 0.0, 1.0, 0.0
  128. tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0));
  129. binormal = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0));
  130. }
  131.  
  132. else if (gl_Normal.y < -0.5) {
  133. // 0.0, -1.0, 0.0
  134. tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0));
  135. binormal = normalize(gl_NormalMatrix * vec3( 0.0, 0.0, 1.0));
  136. }
  137.  
  138. else if (gl_Normal.z > 0.5) {
  139. // 0.0, 0.0, 1.0
  140. tangent = normalize(gl_NormalMatrix * vec3( 1.0, 0.0, 0.0));
  141. binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
  142. }
  143.  
  144. else if (gl_Normal.z < -0.5) {
  145. // 0.0, 0.0, -1.0
  146. tangent = normalize(gl_NormalMatrix * vec3(-1.0, 0.0, 0.0));
  147. binormal = normalize(gl_NormalMatrix * vec3( 0.0, -1.0, 0.0));
  148. }
  149.  
  150.  
  151. }
Add Comment
Please, Sign In to add comment