grass_map.glslv 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #version GLSL_VERSION
  2. /*==============================================================================
  3. VARS
  4. ==============================================================================*/
  5. #var DYNAMIC_GRASS_SIZE 0
  6. #var DYNAMIC_GRASS_COLOR 0
  7. #var WIND_BEND 0
  8. #var STATIC_BATCH 0
  9. #var BILLBOARD 0
  10. #var BILLBOARD_JITTERED 0
  11. /*==============================================================================
  12. INCLUDES
  13. ==============================================================================*/
  14. #include <std.glsl>
  15. #include <math.glslv>
  16. #include <to_world.glslv>
  17. /*==============================================================================
  18. SHADER INTERFACE
  19. ==============================================================================*/
  20. GLSL_IN vec3 a_position;
  21. #if DYNAMIC_GRASS_SIZE
  22. GLSL_IN float a_grass_size;
  23. #endif
  24. #if DYNAMIC_GRASS_COLOR
  25. GLSL_IN vec3 a_grass_color;
  26. #endif
  27. //------------------------------------------------------------------------------
  28. #if DYNAMIC_GRASS_SIZE
  29. # if DYNAMIC_GRASS_COLOR
  30. GLSL_OUT vec4 v_grass_params;
  31. # else
  32. GLSL_OUT float v_grass_params;
  33. # endif
  34. #else
  35. # if DYNAMIC_GRASS_COLOR
  36. GLSL_OUT vec3 v_grass_params;
  37. # endif
  38. #endif
  39. /*==============================================================================
  40. UNIFORMS
  41. ==============================================================================*/
  42. #if STATIC_BATCH
  43. // NOTE: mat3(0.0, 0.0, 0.0, --- trans
  44. // 1.0, --- scale
  45. // 0.0, 0.0, 0.0, 1.0, --- quat
  46. // 0.0);
  47. const mat3 u_model_tsr = mat3(0.0, 0.0, 0.0,
  48. 1.0,
  49. 0.0, 0.0, 0.0, 1.0,
  50. 0.0);
  51. #else
  52. uniform mat3 u_model_tsr;
  53. #endif
  54. uniform mat3 u_view_tsr;
  55. uniform mat4 u_proj_matrix;
  56. # if BILLBOARD
  57. uniform vec3 u_camera_eye;
  58. # endif
  59. #if WIND_BEND && BILLBOARD_JITTERED
  60. uniform vec3 u_wind;
  61. uniform float u_time;
  62. uniform float u_jitter_amp;
  63. uniform float u_jitter_freq;
  64. #endif
  65. /*==============================================================================
  66. MAIN
  67. ==============================================================================*/
  68. void main(void) {
  69. mat3 view_tsr = u_view_tsr;
  70. mat3 model_tsr = u_model_tsr;
  71. # if BILLBOARD
  72. vec3 wcen = tsr9_transform(model_tsr, vec3(0.0));
  73. mat3 model_tsr = billboard_tsr(u_camera_eye, wcen, view_tsr);
  74. # if WIND_BEND && BILLBOARD_JITTERED
  75. model_tsr = bend_jitter_rotate_tsr(u_wind, u_time,
  76. u_jitter_amp, u_jitter_freq, vec3(0.0), model_tsr);
  77. # endif
  78. vertex world = to_world(a_position, vec3(0.0), vec3(0.0), vec3(0.0),
  79. vec3(0.0), vec3(0.0), model_tsr);
  80. world.center = wcen;
  81. # else
  82. vertex world = to_world(a_position, vec3(0.0), vec3(0.0), vec3(0.0),
  83. vec3(0.0), vec3(0.0), model_tsr);
  84. # endif
  85. vec4 pos_clip = u_proj_matrix * vec4(tsr9_transform(view_tsr, world.position), 1.0);
  86. #if DYNAMIC_GRASS_SIZE
  87. # if DYNAMIC_GRASS_COLOR
  88. v_grass_params = vec4(a_grass_size, a_grass_color);
  89. # else
  90. v_grass_params = a_grass_size;
  91. # endif
  92. #else
  93. # if DYNAMIC_GRASS_COLOR
  94. v_grass_params = a_grass_color;
  95. # endif
  96. #endif
  97. gl_Position = pos_clip;
  98. }