color_id.glslv 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. #version GLSL_VERSION
  2. /*==============================================================================
  3. VARS
  4. ==============================================================================*/
  5. #var PRECISION highp
  6. #var NODES 0
  7. #var CAUSTICS 0
  8. #var CALC_TBN_SPACE 0
  9. #var MAIN_BEND_COL 0
  10. #var DETAIL_BEND 0
  11. #var CALC_TBN 0
  12. #var USE_TBN_SHADING 0
  13. #var USE_POSITION_CLIP 0
  14. #var ALPHA 0
  15. #var TEXTURE_COLOR 0
  16. #var AU_QUALIFIER GLSL_IN
  17. #var STATIC_BATCH 0
  18. #var WIND_BEND 0
  19. #var BEND_CENTER_ONLY 0
  20. #var BILLBOARD_PRES_GLOB_ORIENTATION 0
  21. #var BILLBOARD 0
  22. #var BILLBOARD_JITTERED 0
  23. #var DYNAMIC_GRASS 0
  24. #var SKINNED 0
  25. #var FRAMES_BLENDING 0
  26. #var VERTEX_ANIM 0
  27. #var SMAA_JITTER 0
  28. #var VERTEX_ANIM_MIX_NORMALS_FACTOR u_va_frame_factor
  29. #var MAX_BONES 0
  30. #var REFLECTION_TYPE REFL_NONE
  31. #var REFRACTIVE 0
  32. /*==============================================================================
  33. INCLUDES
  34. ==============================================================================*/
  35. #include <std.glsl>
  36. #include <math.glslv>
  37. #include <to_world.glslv>
  38. #include <scale_texcoord.glslv>
  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 || DYNAMIC_GRASS
  57. uniform vec3 u_camera_eye;
  58. #endif
  59. #if NODES && ALPHA
  60. # if SMAA_JITTER
  61. uniform vec2 u_subpixel_jitter;
  62. # endif
  63. # if USE_NODE_B4W_REFRACTION
  64. uniform PRECISION float u_view_max_depth;
  65. # endif
  66. #endif // NODES && ALPHA
  67. #if SKINNED
  68. uniform vec4 u_quatsb[MAX_BONES];
  69. uniform vec4 u_transb[MAX_BONES];
  70. uniform vec4 u_arm_rel_trans;
  71. uniform vec4 u_arm_rel_quat;
  72. # if FRAMES_BLENDING
  73. uniform vec4 u_quatsa[MAX_BONES];
  74. uniform vec4 u_transa[MAX_BONES];
  75. // near 0 if before, near 1 if after
  76. uniform float u_frame_factor;
  77. # endif
  78. #endif
  79. #if WIND_BEND
  80. # if BILLBOARD_JITTERED
  81. uniform float u_jitter_amp;
  82. uniform float u_jitter_freq;
  83. # endif
  84. uniform vec3 u_wind;
  85. uniform PRECISION float u_time;
  86. #endif
  87. #if VERTEX_ANIM
  88. uniform float u_va_frame_factor;
  89. #endif
  90. #if TEXTURE_COLOR
  91. uniform vec3 u_texture_scale;
  92. #endif
  93. /*==============================================================================
  94. SHADER INTERFACE
  95. ==============================================================================*/
  96. GLSL_IN vec3 a_position;
  97. GLSL_IN vec4 a_tbn_quat;
  98. #if NODES && ALPHA
  99. # if USE_TBN_SHADING
  100. GLSL_IN vec3 a_shade_tangs;
  101. # endif
  102. #endif // NODES && ALPHA
  103. #if SKINNED
  104. GLSL_IN vec4 a_influence;
  105. #endif
  106. #if WIND_BEND
  107. # if MAIN_BEND_COL
  108. GLSL_IN float a_bending_col_main;
  109. # if DETAIL_BEND
  110. GLSL_IN vec3 a_bending_col_detail;
  111. AU_QUALIFIER float au_detail_bending_amp;
  112. AU_QUALIFIER float au_branch_bending_amp;
  113. AU_QUALIFIER float au_detail_bending_freq;
  114. # endif
  115. # endif
  116. AU_QUALIFIER float au_wind_bending_amp;
  117. AU_QUALIFIER float au_wind_bending_freq;
  118. # if BEND_CENTER_ONLY
  119. GLSL_IN vec3 a_emitter_center;
  120. # endif
  121. #endif // WIND_BEND
  122. #if WIND_BEND || BILLBOARD
  123. AU_QUALIFIER vec3 au_center_pos;
  124. #endif
  125. #if VERTEX_ANIM
  126. GLSL_IN vec3 a_position_next;
  127. # if NODES && ALPHA
  128. # if USE_NODE_MATERIAL_BEGIN || USE_NODE_GEOMETRY_NO || USE_NODE_NORMAL_MAP \
  129. || CAUSTICS || CALC_TBN_SPACE
  130. GLSL_IN vec4 a_tbn_quat_next;
  131. # endif
  132. # endif
  133. #endif
  134. #if TEXTURE_COLOR
  135. GLSL_IN vec2 a_texcoord;
  136. #endif
  137. #if USE_TBN_SHADING
  138. GLSL_OUT vec3 v_shade_tang;
  139. #endif
  140. //------------------------------------------------------------------------------
  141. #if NODES && ALPHA
  142. GLSL_OUT vec3 v_pos_world;
  143. GLSL_OUT vec4 v_pos_view;
  144. GLSL_OUT vec3 v_normal;
  145. # if CALC_TBN_SPACE
  146. GLSL_OUT vec4 v_tangent;
  147. # endif
  148. # if REFLECTION_TYPE == REFL_PLANE || USE_POSITION_CLIP
  149. GLSL_OUT vec3 v_tex_pos_clip;
  150. # endif
  151. # if USE_NODE_B4W_REFRACTION && REFRACTIVE
  152. GLSL_OUT float v_view_depth;
  153. # endif
  154. #else // NODES && ALPHA
  155. # if TEXTURE_COLOR
  156. GLSL_OUT vec2 v_texcoord;
  157. # endif
  158. #endif // NODES && ALPHA
  159. /*==============================================================================
  160. INCLUDES
  161. ==============================================================================*/
  162. #include <skin.glslv>
  163. #include <wind_bending.glslv>
  164. #if NODES && ALPHA
  165. #include <nodes.glslv>
  166. #endif
  167. /*==============================================================================
  168. MAIN
  169. ==============================================================================*/
  170. void main(void) {
  171. mat3 view_tsr = u_view_tsr;
  172. vec3 position = a_position;
  173. #if NODES && ALPHA && (CALC_TBN_SPACE || USE_NODE_MATERIAL_BEGIN || USE_NODE_NORMAL_MAP \
  174. || USE_NODE_GEOMETRY_NO || CAUSTICS || WIND_BEND && MAIN_BEND_COL && DETAIL_BEND) \
  175. || USE_TBN_SHADING && CALC_TBN || USE_NODE_BSDF_BEGIN || USE_NODE_FRESNEL \
  176. || USE_NODE_TEX_COORD_NO || USE_NODE_LAYER_WEIGHT || USE_NODE_BUMP
  177. vec3 normal = qrot(a_tbn_quat, vec3(0.0, 1.0, 0.0));
  178. # if CALC_TBN_SPACE
  179. vec3 tangent = qrot(a_tbn_quat, vec3(1.0, 0.0, 0.0));
  180. vec3 binormal = sign(a_tbn_quat[3]) * cross(normal, tangent);
  181. # else
  182. vec3 tangent = vec3(0.0);
  183. vec3 binormal = vec3(0.0);
  184. # endif
  185. #else
  186. vec3 normal = vec3(0.0);
  187. vec3 tangent = vec3(0.0);
  188. vec3 binormal = vec3(0.0);
  189. #endif
  190. mat3 model_tsr = u_model_tsr;
  191. #if USE_TBN_SHADING
  192. # if CALC_TBN
  193. vec3 norm_world = normalize(tsr9_transform_dir(u_model_tsr, normal));
  194. vec3 shade_binormal = cross(vec3(0.0, 0.0, 1.0), norm_world);
  195. vec3 shade_tangent = cross(norm_world, shade_binormal);
  196. # else
  197. vec3 shade_tangent = a_shade_tangs;
  198. # endif
  199. #else
  200. vec3 shade_tangent = vec3(0.0);
  201. #endif
  202. #if VERTEX_ANIM
  203. position = mix(position, a_position_next, u_va_frame_factor);
  204. # if NODES && ALPHA
  205. # if USE_NODE_MATERIAL_BEGIN || USE_NODE_GEOMETRY_NO || USE_NODE_NORMAL_MAP \
  206. || CAUSTICS || CALC_TBN_SPACE
  207. vec3 normal_next = qrot(a_tbn_quat_next, vec3(0.0, 1.0, 0.0));
  208. normal = mix(normal, normal_next, VERTEX_ANIM_MIX_NORMALS_FACTOR);
  209. # endif
  210. # if CALC_TBN_SPACE
  211. vec3 tangent_next = qrot(a_tbn_quat_next, vec3(1.0, 0.0, 0.0));
  212. vec3 binormal_next = sign(a_tbn_quat_next[3]) * cross(normal_next, tangent_next);
  213. tangent = mix(tangent, tangent_next, u_va_frame_factor);
  214. binormal = mix(binormal, binormal_next, u_va_frame_factor);
  215. # endif
  216. # endif
  217. #endif
  218. #if SKINNED
  219. skin(position, tangent, binormal, normal);
  220. #endif
  221. #if WIND_BEND || BILLBOARD
  222. vec3 center = au_center_pos;
  223. #else
  224. vec3 center = vec3(0.0);
  225. #endif
  226. #if BILLBOARD
  227. vec3 wcen = tsr9_transform(model_tsr, center);
  228. # if BILLBOARD_PRES_GLOB_ORIENTATION && !STATIC_BATCH
  229. model_tsr = billboard_tsr_global(u_camera_eye, wcen,
  230. view_tsr, model_tsr);
  231. # else
  232. model_tsr = billboard_tsr(u_camera_eye, wcen, view_tsr);
  233. # endif
  234. # if WIND_BEND && BILLBOARD_JITTERED
  235. model_tsr = bend_jitter_rotate_tsr(u_wind, u_time,
  236. u_jitter_amp, u_jitter_freq, wcen, model_tsr);
  237. # endif
  238. vertex world = to_world(position - center, center, vec3(0.0), shade_tangent,
  239. vec3(0.0), vec3(0.0), model_tsr);
  240. world.center = wcen;
  241. #else
  242. vertex world = to_world(position, center, vec3(0.0), shade_tangent, vec3(0.0),
  243. vec3(0.0), model_tsr);
  244. #endif
  245. #if WIND_BEND
  246. # if NODES && ALPHA
  247. bend_vertex(world.position, world.center, normal, mat4(0.0));
  248. # else
  249. # if MAIN_BEND_COL && DETAIL_BEND
  250. vec3 bend_normal = qrot(a_tbn_quat, vec3(0.0, 1.0, 0.0));
  251. # else
  252. vec3 bend_normal = vec3(0.0);
  253. # endif
  254. bend_vertex(world.position, world.center, bend_normal, mat4(0.0));
  255. # endif // NODES && ALPHA
  256. #endif // WIND_BEND
  257. #if !(NODES && ALPHA)
  258. # if TEXTURE_COLOR
  259. v_texcoord = scale_texcoord(a_texcoord, u_texture_scale);
  260. # endif
  261. #endif // !(NODES && ALPHA)
  262. #if NODES && ALPHA
  263. v_pos_world = world.position;
  264. # if USE_NODE_MATERIAL_BEGIN || USE_NODE_GEOMETRY_NO || USE_NODE_NORMAL_MAP \
  265. || CAUSTICS || CALC_TBN_SPACE || WIND_BEND && MAIN_BEND_COL && DETAIL_BEND \
  266. || USE_NODE_TEX_COORD_NO || USE_NODE_BSDF_BEGIN || USE_NODE_FRESNEL \
  267. || USE_NODE_TEX_COORD_RE || USE_NODE_LAYER_WEIGHT || USE_NODE_BUMP
  268. v_normal = world.normal;
  269. # endif
  270. # if CALC_TBN_SPACE
  271. // calculate handedness as described in Math for 3D GP and CG, page 185
  272. float m = (dot(cross(world.normal, world.tangent),
  273. world.binormal) < 0.0) ? -1.0 : 1.0;
  274. v_tangent = vec4(world.tangent, m);
  275. # endif
  276. # if USE_TBN_SHADING
  277. v_shade_tang = world.shade_tang;
  278. # endif
  279. v_pos_view = vec4(tsr9_transform(view_tsr, world.position), 1.0);
  280. vec4 pos_clip = u_proj_matrix * v_pos_view;
  281. # if SMAA_JITTER
  282. pos_clip.xy += u_subpixel_jitter * pos_clip.w;
  283. # endif
  284. # if REFLECTION_TYPE == REFL_PLANE || USE_POSITION_CLIP
  285. v_tex_pos_clip = clip_to_tex(pos_clip);
  286. # endif
  287. # if USE_NODE_B4W_REFRACTION && REFRACTIVE
  288. v_view_depth = -v_pos_view.z / u_view_max_depth;
  289. # endif
  290. nodes_main();
  291. #endif // NODES && ALPHA
  292. gl_Position = u_proj_matrix * vec4(tsr9_transform(view_tsr, world.position), 1.0);
  293. }