bugs-lighting-model-vsh.glsl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #define PHONG
  2. varying vec3 vViewPosition;
  3. #include <common>
  4. #include <uv_pars_vertex>
  5. #include <displacementmap_pars_vertex>
  6. #include <envmap_pars_vertex>
  7. #include <color_pars_vertex>
  8. #include <fog_pars_vertex>
  9. #include <normal_pars_vertex>
  10. #include <morphtarget_pars_vertex>
  11. #include <skinning_pars_vertex>
  12. #include <shadowmap_pars_vertex>
  13. #include <logdepthbuf_pars_vertex>
  14. #include <clipping_planes_pars_vertex>
  15. varying vec3 vWorldNormal;
  16. uniform vec2 bugsSize;
  17. uniform vec4 bugsParams;
  18. uniform float time;
  19. uniform sampler2D heightmap;
  20. uniform vec3 heightmapParams;
  21. attribute vec3 offset;
  22. void main() {
  23. #include <uv_vertex>
  24. #include <color_vertex>
  25. #include <morphcolor_vertex>
  26. // #include <beginnormal_vertex>
  27. vec3 objectNormal = vec3(0.0, 1.0, 0.0);
  28. #ifdef USE_TANGENT
  29. vec3 objectTangent = vec3( tangent.xyz );
  30. #endif
  31. // #include <begin_vertex>
  32. vec3 transformed = vec3( position );
  33. #ifdef USE_ALPHAHASH
  34. vPosition = vec3( position );
  35. #endif
  36. vec4 bugHashVal = hash42(offset.xz);
  37. float BUG_SCALE = mix(0.35, 0.55, bugHashVal.z);
  38. transformed *= BUG_SCALE;
  39. const float FLAP_SPEED = 20.0;
  40. float flapTimeSample = time * FLAP_SPEED + bugHashVal.x * 100.0;
  41. transformed.y += mix(0.0, sin(flapTimeSample), abs(position.x)) * BUG_SCALE;
  42. transformed.x *= abs(cos(flapTimeSample));
  43. float TIME_PERIOD = 20.0;
  44. float repeatingTime = TIME_PERIOD * 0.5 - abs(mod(time, TIME_PERIOD) - TIME_PERIOD * 0.5);
  45. float height = noise11(time * 3.0 + bugHashVal.x * 100.0);
  46. // transformed.y += height * 0.5;
  47. // Loop
  48. float loopTime = time * 0.5 + bugHashVal.x * 123.23;
  49. float loopSize = 2.0;
  50. vec3 bugsOffset = vec3(sin(loopTime) * loopSize, height * 0.125, cos(loopTime) * loopSize) + offset;
  51. // Forward
  52. transformed = rotateY(-loopTime + PI / 2.0) * transformed;
  53. transformed += bugsOffset;
  54. // Center
  55. vec3 bugCenter = offset;
  56. vec3 bugsWorldPos = (modelMatrix * vec4(bugCenter, 1.0)).xyz;
  57. vec2 heightmapUV = vec2(
  58. remap(bugsWorldPos.x, -heightmapParams.z * 0.5, heightmapParams.z * 0.5, 0.0, 1.0),
  59. remap(bugsWorldPos.z, -heightmapParams.z * 0.5, heightmapParams.z * 0.5, 1.0, 0.0));
  60. float terrainHeight = texture2D(heightmap, heightmapUV).x * heightmapParams.x - heightmapParams.y;
  61. transformed.y += terrainHeight;
  62. if (terrainHeight < -11.0) {
  63. transformed.y -= 1000.0;
  64. }
  65. objectNormal = normal;
  66. #include <morphnormal_vertex>
  67. #include <skinbase_vertex>
  68. #include <skinnormal_vertex>
  69. #include <defaultnormal_vertex>
  70. #include <normal_vertex>
  71. #include <morphtarget_vertex>
  72. #include <skinning_vertex>
  73. #include <displacementmap_vertex>
  74. // #include <project_vertex>
  75. vec4 mvPosition = vec4( transformed, 1.0 );
  76. #ifdef USE_INSTANCING
  77. mvPosition = instanceMatrix * mvPosition;
  78. #endif
  79. mvPosition = modelViewMatrix * mvPosition;
  80. gl_Position = projectionMatrix * mvPosition;
  81. #include <logdepthbuf_vertex>
  82. #include <clipping_planes_vertex>
  83. vViewPosition = - mvPosition.xyz;
  84. #include <worldpos_vertex>
  85. #include <envmap_vertex>
  86. #include <shadowmap_vertex>
  87. #include <fog_vertex>
  88. vWorldNormal = (modelMatrix * vec4(normal.xyz, 0.0)).xyz;
  89. }