Shuvit game master repo. http://shuvit.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

wind_pixel_lighting_normal.vert 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. varying vec2 texCoord;
  2. varying vec3 vNormal;
  3. varying vec3 eyePos;
  4. varying vec4 tangent;
  5. attribute vec4 Tangent;
  6. uniform float time;
  7. uniform float strength;
  8. uniform float speed;
  9. uniform float deforming;
  10. uniform float bending;
  11. uniform float ground;
  12. uniform vec2 direction;
  13. uniform mat4 ModelMatrix;
  14. uniform mat4 ViewMatrix;
  15. // ########################################Settings########################################
  16. vec2 windDirection = direction; // Direction of the wind
  17. float windStrength = strength; // Strength of the wind
  18. float groundLevel = ground; // Everything over ground level will have movement
  19. const int windSamples = 3; // Number of wind sine waves to add
  20. // ########################################Functions########################################
  21. vec2 getWind(vec4 worldPos, float height)
  22. // Function to generate the wind
  23. {
  24. vec2 wind;
  25. if (height > groundLevel)
  26. {
  27. float windTime = time*speed;
  28. float windDisplacement = cos(0.375*((17.5+worldPos.x)+(17.5+worldPos.y))+(windTime*1.25));
  29. for (int w = 0; w < windSamples; w++)
  30. {
  31. float rAnd = float(w)+1.0-(float(windSamples)/2.0);
  32. float rCnd = float(w)-1.0+(float(windSamples)/2.0);
  33. windDisplacement += sin(0.5*((17.5+rAnd+worldPos.x)+(rAnd+worldPos.y))+(windTime*(rAnd*0.1+1.75)));
  34. windDisplacement -= cos(0.5*((17.5+rCnd+worldPos.x)+(rAnd+worldPos.y))+(windTime*(rCnd*0.1+1.75)));
  35. }
  36. wind = windStrength*(height-0.25)*sin((worldPos.xy*normalize(windDirection))+vec2(windTime*0.5))*windDisplacement;
  37. wind *= ((height - groundLevel) * bending + 1.0 - bending);
  38. }
  39. else
  40. {
  41. wind = vec2(0.0,0.0);
  42. }
  43. return wind;
  44. }
  45. mat4 addWorldPos(mat4 modelMat, vec3 pos)
  46. {
  47. modelMat[3][0] += pos.x;
  48. modelMat[3][1] += pos.y;
  49. modelMat[3][2] += pos.z;
  50. return modelMat;
  51. }
  52. // ########################################Main-Function########################################
  53. void main()
  54. {
  55. vec4 verts = gl_Vertex;
  56. vec4 worldSpacePos = ModelMatrix * (verts*deforming+1.0-deforming);
  57. vec2 wind = getWind(worldSpacePos, verts.z);
  58. mat4 modelViewMatix = ViewMatrix * addWorldPos(ModelMatrix, vec3(wind, 0.0));
  59. texCoord = gl_MultiTexCoord0.xy;
  60. vNormal = gl_NormalMatrix * gl_Normal;
  61. eyePos = (modelViewMatix * verts).xyz;
  62. tangent.xyz = normalize(gl_NormalMatrix * Tangent.xyz);
  63. tangent.w = Tangent.w;
  64. gl_Position = gl_ProjectionMatrix * modelViewMatix * verts;
  65. }