debug_view.glslv 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #version GLSL_VERSION
  2. /*==============================================================================
  3. VARS
  4. ==============================================================================*/
  5. #var PRECISION highp
  6. #var USE_INSTANCED_PARTCLS 0
  7. #var DEBUG_VIEW_SPECIAL_SKYDOME 0
  8. #var DEBUG_SPHERE 0
  9. #var WIND_BEND 0
  10. #var DYNAMIC_GRASS 0
  11. #var BILLBOARD 0
  12. #var VERTEX_ANIM 0
  13. #var SKINNED 0
  14. #var STATIC_BATCH 0
  15. #var AU_QUALIFIER GLSL_IN
  16. #var BEND_CENTER_ONLY 0
  17. #var FRAMES_BLENDING 0
  18. #var MAIN_BEND_COL 0
  19. #var MAX_BONES 0
  20. #var DETAIL_BEND 0
  21. #var BILLBOARD_JITTERED 0
  22. #var BILLBOARD_PRES_GLOB_ORIENTATION 0
  23. /*==============================================================================
  24. INCLUDES
  25. ==============================================================================*/
  26. #include <std.glsl>
  27. #include <math.glslv>
  28. #include <to_world.glslv>
  29. /*==============================================================================
  30. SHADER INTERFACE
  31. ==============================================================================*/
  32. GLSL_IN vec3 a_position;
  33. GLSL_IN vec4 a_tbn_quat;
  34. GLSL_IN float a_polyindex;
  35. #if USE_INSTANCED_PARTCLS
  36. GLSL_IN vec4 a_part_ts;
  37. GLSL_IN vec4 a_part_r;
  38. #endif
  39. #if !DEBUG_SPHERE
  40. # if WIND_BEND
  41. # if MAIN_BEND_COL
  42. GLSL_IN float a_bending_col_main;
  43. # if DETAIL_BEND
  44. GLSL_IN vec3 a_bending_col_detail;
  45. AU_QUALIFIER float au_detail_bending_amp;
  46. AU_QUALIFIER float au_branch_bending_amp;
  47. AU_QUALIFIER float au_detail_bending_freq;
  48. # endif
  49. # endif
  50. AU_QUALIFIER float au_wind_bending_amp;
  51. AU_QUALIFIER float au_wind_bending_freq;
  52. # if BEND_CENTER_ONLY
  53. GLSL_IN vec3 a_emitter_center;
  54. # endif
  55. # endif
  56. #if (WIND_BEND || DYNAMIC_GRASS || BILLBOARD) && !USE_INSTANCED_PARTCLS
  57. AU_QUALIFIER vec3 au_center_pos;
  58. # endif
  59. # if VERTEX_ANIM
  60. GLSL_IN vec3 a_position_next;
  61. # endif
  62. # if SKINNED
  63. GLSL_IN vec4 a_influence;
  64. # endif
  65. #endif // DEBUG_SPHERE
  66. //------------------------------------------------------------------------------
  67. GLSL_OUT vec3 v_barycentric;
  68. /*==============================================================================
  69. UNIFORMS
  70. ==============================================================================*/
  71. #if STATIC_BATCH
  72. // NOTE: mat3(0.0, 0.0, 0.0, --- trans
  73. // 1.0, --- scale
  74. // 0.0, 0.0, 0.0, 1.0, --- quat
  75. // 0.0);
  76. const mat3 u_model_tsr = mat3(0.0, 0.0, 0.0,
  77. 1.0,
  78. 0.0, 0.0, 0.0, 1.0,
  79. 0.0);
  80. #else
  81. uniform mat3 u_model_tsr;
  82. #endif
  83. uniform mat3 u_view_tsr;
  84. uniform mat4 u_proj_matrix;
  85. #if !DEBUG_SPHERE
  86. # if WIND_BEND
  87. uniform vec3 u_wind;
  88. uniform PRECISION float u_time;
  89. # if BILLBOARD && BILLBOARD_JITTERED
  90. uniform float u_jitter_amp;
  91. uniform float u_jitter_freq;
  92. # endif
  93. # endif
  94. # if DYNAMIC_GRASS || BILLBOARD
  95. uniform vec3 u_camera_eye;
  96. # endif
  97. # if VERTEX_ANIM
  98. uniform float u_va_frame_factor;
  99. # endif
  100. # if SKINNED
  101. uniform vec4 u_quatsb[MAX_BONES];
  102. uniform vec4 u_transb[MAX_BONES];
  103. uniform vec4 u_arm_rel_trans;
  104. uniform vec4 u_arm_rel_quat;
  105. # if FRAMES_BLENDING
  106. uniform vec4 u_quatsa[MAX_BONES];
  107. uniform vec4 u_transa[MAX_BONES];
  108. // near 0 if before, near 1 if after
  109. uniform float u_frame_factor;
  110. # endif
  111. # endif
  112. # if DYNAMIC_GRASS
  113. uniform PRECISION sampler2D u_grass_map_depth;
  114. uniform sampler2D u_grass_map_color;
  115. uniform vec4 u_camera_quat;
  116. uniform vec3 u_grass_map_dim;
  117. uniform float u_grass_size;
  118. uniform float u_scale_threshold;
  119. # endif
  120. #endif // DEBUG_SPHERE
  121. /*==============================================================================
  122. INCLUDES
  123. ==============================================================================*/
  124. #if !DEBUG_SPHERE
  125. #include <skin.glslv>
  126. #include <wind_bending.glslv>
  127. #include <dynamic_grass.glslv>
  128. #endif
  129. /*==============================================================================
  130. MAIN
  131. ==============================================================================*/
  132. void main() {
  133. if (a_polyindex == 0.0)
  134. v_barycentric = vec3(1.0, 0.0, 0.0);
  135. else if (a_polyindex == 1.0)
  136. v_barycentric = vec3(0.0, 0.0, 1.0);
  137. else // ~0.5 because of normalizing an unsigned byte value
  138. v_barycentric = vec3(0.0, 1.0, 0.0);
  139. #if DEBUG_VIEW_SPECIAL_SKYDOME
  140. gl_Position = vec4(a_position.xy, 0.9999999, 1.0);
  141. #else
  142. # if USE_INSTANCED_PARTCLS
  143. mat3 model_tsr = mat3(a_part_ts[0], a_part_ts[1], a_part_ts[2],
  144. a_part_ts[3], a_part_r[0], a_part_r[1],
  145. a_part_r[2], a_part_r[3], 1.0);
  146. # if !STATIC_BATCH
  147. model_tsr = tsr_multiply(u_model_tsr, model_tsr);
  148. # endif
  149. # else
  150. mat3 model_tsr = u_model_tsr;
  151. # endif
  152. mat3 view_tsr = u_view_tsr;
  153. vec3 position = a_position;
  154. vec3 normal = qrot(a_tbn_quat, vec3(0.0, 1.0, 0.0));
  155. # if DEBUG_SPHERE
  156. vertex world = to_world(position, vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0),
  157. vec3(0.0), model_tsr);
  158. # else
  159. # if VERTEX_ANIM
  160. position = mix(position, a_position_next, u_va_frame_factor);
  161. # endif
  162. # if SKINNED
  163. vec3 tangent = vec3(0.0);
  164. vec3 binormal = vec3(0.0);
  165. skin(position, tangent, binormal, normal);
  166. # endif
  167. # if (WIND_BEND || DYNAMIC_GRASS || BILLBOARD) && !USE_INSTANCED_PARTCLS
  168. vec3 center = au_center_pos;
  169. # elif DYNAMIC_GRASS && USE_INSTANCED_PARTCLS
  170. vec3 center = a_part_ts.xyz;
  171. position = tsr9_transform(model_tsr, position);
  172. # else
  173. vec3 center = vec3(0.0);
  174. # endif
  175. # if DYNAMIC_GRASS
  176. vertex world = grass_vertex(position, vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0),
  177. center, u_grass_map_depth, u_grass_map_color,
  178. u_grass_map_dim, u_grass_size, u_camera_eye, u_camera_quat,
  179. view_tsr);
  180. # else
  181. # if BILLBOARD
  182. vec3 wcen = tsr9_transform(model_tsr, center);
  183. # if BILLBOARD_PRES_GLOB_ORIENTATION && !STATIC_BATCH || USE_INSTANCED_PARTCLS
  184. model_tsr = billboard_tsr_global(u_camera_eye, wcen,
  185. view_tsr, model_tsr);
  186. # else
  187. model_tsr = billboard_tsr(u_camera_eye, wcen, view_tsr);
  188. # endif
  189. # if WIND_BEND && BILLBOARD_JITTERED
  190. vec3 vec_seed = wcen;
  191. model_tsr = bend_jitter_rotate_tsr(u_wind, u_time,
  192. u_jitter_amp, u_jitter_freq, vec_seed, model_tsr);
  193. # endif
  194. vertex world = to_world(position - center, center, vec3(0.0), vec3(0.0),
  195. vec3(0.0), vec3(0.0), model_tsr);
  196. world.center = wcen;
  197. # else
  198. vertex world = to_world(position, center, vec3(0.0), vec3(0.0), vec3(0.0),
  199. vec3(0.0), model_tsr);
  200. # endif
  201. # endif
  202. # if WIND_BEND
  203. bend_vertex(world.position, world.center, normal, mat4(0.0));
  204. # endif
  205. # endif // DEBUG_SPHERE
  206. gl_Position = u_proj_matrix * vec4(tsr9_transform(view_tsr, world.position), 1.0);
  207. #endif // DEBUG_VIEW_SPECIAL_SKYDOME
  208. }