blend_shape.glsl 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* clang-format off */
  2. [vertex]
  3. /*
  4. from VisualServer:
  5. ARRAY_VERTEX=0,
  6. ARRAY_NORMAL=1,
  7. ARRAY_TANGENT=2,
  8. ARRAY_COLOR=3,
  9. ARRAY_TEX_UV=4,
  10. ARRAY_TEX_UV2=5,
  11. ARRAY_BONES=6,
  12. ARRAY_WEIGHTS=7,
  13. ARRAY_INDEX=8,
  14. */
  15. #ifdef USE_2D_VERTEX
  16. #define VFORMAT vec2
  17. #else
  18. #define VFORMAT vec3
  19. #endif
  20. /* INPUT ATTRIBS */
  21. layout(location = 0) in highp VFORMAT vertex_attrib;
  22. /* clang-format on */
  23. #ifdef ENABLE_OCTAHEDRAL_COMPRESSION
  24. layout(location = 2) in vec4 normal_tangent_attrib;
  25. #else
  26. layout(location = 1) in vec3 normal_attrib;
  27. #endif
  28. #ifdef ENABLE_TANGENT
  29. #ifdef ENABLE_OCTAHEDRAL_COMPRESSION
  30. // packed into normal_attrib zw component
  31. #else
  32. layout(location = 2) in vec4 tangent_attrib;
  33. #endif
  34. #endif
  35. #ifdef ENABLE_COLOR
  36. layout(location = 3) in vec4 color_attrib;
  37. #endif
  38. #ifdef ENABLE_UV
  39. layout(location = 4) in vec2 uv_attrib;
  40. #endif
  41. #ifdef ENABLE_UV2
  42. layout(location = 5) in vec2 uv2_attrib;
  43. #endif
  44. #ifdef ENABLE_SKELETON
  45. layout(location = 6) in ivec4 bone_attrib;
  46. layout(location = 7) in vec4 weight_attrib;
  47. #endif
  48. /* BLEND ATTRIBS */
  49. #ifdef ENABLE_BLEND
  50. layout(location = 8) in highp VFORMAT vertex_attrib_blend;
  51. layout(location = 9) in vec3 normal_attrib_blend;
  52. #ifdef ENABLE_TANGENT
  53. layout(location = 10) in vec4 tangent_attrib_blend;
  54. #endif
  55. #ifdef ENABLE_COLOR
  56. layout(location = 11) in vec4 color_attrib_blend;
  57. #endif
  58. #ifdef ENABLE_UV
  59. layout(location = 12) in vec2 uv_attrib_blend;
  60. #endif
  61. #ifdef ENABLE_UV2
  62. layout(location = 13) in vec2 uv2_attrib_blend;
  63. #endif
  64. #ifdef ENABLE_SKELETON
  65. layout(location = 14) in ivec4 bone_attrib_blend;
  66. layout(location = 15) in vec4 weight_attrib_blend;
  67. #endif
  68. #endif
  69. /* OUTPUTS */
  70. out VFORMAT vertex_out; //tfb:
  71. #ifdef ENABLE_NORMAL
  72. out vec3 normal_out; //tfb:ENABLE_NORMAL
  73. #endif
  74. #ifdef ENABLE_TANGENT
  75. out vec4 tangent_out; //tfb:ENABLE_TANGENT
  76. #endif
  77. #ifdef ENABLE_COLOR
  78. out vec4 color_out; //tfb:ENABLE_COLOR
  79. #endif
  80. #ifdef ENABLE_UV
  81. out vec2 uv_out; //tfb:ENABLE_UV
  82. #endif
  83. #ifdef ENABLE_UV2
  84. out vec2 uv2_out; //tfb:ENABLE_UV2
  85. #endif
  86. #ifdef ENABLE_SKELETON
  87. out ivec4 bone_out; //tfb:ENABLE_SKELETON
  88. out vec4 weight_out; //tfb:ENABLE_SKELETON
  89. #endif
  90. uniform float blend_amount;
  91. #ifdef ENABLE_OCTAHEDRAL_COMPRESSION
  92. vec3 oct_to_vec3(vec2 e) {
  93. vec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y));
  94. float t = max(-v.z, 0.0);
  95. v.xy += t * -sign(v.xy);
  96. return normalize(v);
  97. }
  98. #endif
  99. void main() {
  100. #ifdef ENABLE_BLEND
  101. vertex_out = vertex_attrib_blend + vertex_attrib * blend_amount;
  102. #ifdef ENABLE_NORMAL
  103. #ifdef ENABLE_OCTAHEDRAL_COMPRESSION
  104. normal_out = normal_attrib_blend + oct_to_vec3(normal_tangent_attrib.xy) * blend_amount;
  105. #else
  106. normal_out = normal_attrib_blend + normal_attrib * blend_amount;
  107. #endif
  108. #endif
  109. #ifdef ENABLE_TANGENT
  110. #ifdef ENABLE_OCTAHEDRAL_COMPRESSION
  111. tangent_out.xyz = tangent_attrib_blend.xyz + oct_to_vec3(vec2(normal_tangent_attrib.z, abs(normal_tangent_attrib.w) * 2.0 - 1.0)) * blend_amount;
  112. tangent_out.w = sign(tangent_attrib_blend.w);
  113. #else
  114. tangent_out.xyz = tangent_attrib_blend.xyz + tangent_attrib.xyz * blend_amount;
  115. tangent_out.w = tangent_attrib_blend.w; //just copy, no point in blending his
  116. #endif
  117. #endif
  118. #ifdef ENABLE_COLOR
  119. color_out = color_attrib_blend + color_attrib * blend_amount;
  120. #endif
  121. #ifdef ENABLE_UV
  122. uv_out = uv_attrib_blend + uv_attrib * blend_amount;
  123. #endif
  124. #ifdef ENABLE_UV2
  125. uv2_out = uv2_attrib_blend + uv2_attrib * blend_amount;
  126. #endif
  127. #ifdef ENABLE_SKELETON
  128. bone_out = bone_attrib_blend;
  129. weight_out = weight_attrib_blend + weight_attrib * blend_amount;
  130. #endif
  131. #else //ENABLE_BLEND
  132. vertex_out = vertex_attrib * blend_amount;
  133. #ifdef ENABLE_NORMAL
  134. #ifdef ENABLE_OCTAHEDRAL_COMPRESSION
  135. normal_out = oct_to_vec3(normal_tangent_attrib.xy) * blend_amount;
  136. #else
  137. normal_out = normal_attrib * blend_amount;
  138. #endif
  139. #endif
  140. #ifdef ENABLE_TANGENT
  141. #ifdef ENABLE_OCTAHEDRAL_COMPRESSION
  142. tangent_out.xyz = oct_to_vec3(vec2(normal_tangent_attrib.z, abs(normal_tangent_attrib.w) * 2.0 - 1.0)) * blend_amount;
  143. tangent_out.w = sign(normal_tangent_attrib.w);
  144. #else
  145. tangent_out.xyz = tangent_attrib.xyz * blend_amount;
  146. tangent_out.w = tangent_attrib.w; //just copy, no point in blending his
  147. #endif
  148. #endif
  149. #ifdef ENABLE_COLOR
  150. color_out = color_attrib * blend_amount;
  151. #endif
  152. #ifdef ENABLE_UV
  153. uv_out = uv_attrib * blend_amount;
  154. #endif
  155. #ifdef ENABLE_UV2
  156. uv2_out = uv2_attrib * blend_amount;
  157. #endif
  158. #ifdef ENABLE_SKELETON
  159. bone_out = bone_attrib;
  160. weight_out = weight_attrib * blend_amount;
  161. #endif
  162. #endif
  163. gl_Position = vec4(0.0);
  164. }
  165. /* clang-format off */
  166. [fragment]
  167. void main() {
  168. }
  169. /* clang-format on */