MsCommonVert.glsl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Copyright (C) 2009-2017, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #ifndef ANKI_SHADERS_MS_COMMON_VERT_GLSL
  6. #define ANKI_SHADERS_MS_COMMON_VERT_GLSL
  7. #include "shaders/MsFsCommon.glsl"
  8. //
  9. // Input
  10. //
  11. layout(location = POSITION_LOCATION) in highp vec3 in_position;
  12. layout(location = TEXTURE_COORDINATE_LOCATION) in highp vec2 in_uv;
  13. #if PASS == COLOR || TESSELLATION
  14. layout(location = NORMAL_LOCATION) in mediump vec4 in_normal;
  15. #endif
  16. #if PASS == COLOR
  17. layout(location = TANGENT_LOCATION) in mediump vec4 in_tangent;
  18. #endif
  19. //
  20. // Output
  21. //
  22. out gl_PerVertex
  23. {
  24. vec4 gl_Position;
  25. };
  26. #if NVIDIA_LINK_ERROR_WORKAROUND
  27. layout(location = 0) out highp vec4 out_uv;
  28. #else
  29. layout(location = 0) out highp vec2 out_uv;
  30. #endif
  31. #if PASS == COLOR || TESSELLATION
  32. layout(location = 1) out mediump vec3 out_normal;
  33. #endif
  34. #if PASS == COLOR
  35. layout(location = 2) out mediump vec4 out_tangent;
  36. #if CALC_BITANGENT_IN_VERT
  37. layout(location = 3) out mediump vec3 out_bitangent;
  38. #endif
  39. layout(location = 4) out mediump vec3 out_vertPosViewSpace;
  40. layout(location = 5) out mediump vec3 out_eyeTangentSpace; // Parallax
  41. layout(location = 6) out mediump vec3 out_normalTangentSpace; // Parallax
  42. #endif
  43. #define writePositionAndUv_DEFINED
  44. void writePositionAndUv(in mat4 mvp)
  45. {
  46. #if PASS == DEPTH && LOD > 0
  47. // No tex coords for you
  48. #else
  49. #if NVIDIA_LINK_ERROR_WORKAROUND
  50. out_uv = vec4(in_uv, 0.0, 0.0);
  51. #else
  52. out_uv = in_uv;
  53. #endif
  54. #endif
  55. #if TESSELLATION
  56. gl_Position = vec4(in_position, 1.0);
  57. #else
  58. ANKI_WRITE_POSITION(mvp * vec4(in_position, 1.0));
  59. #endif
  60. }
  61. #if PASS == COLOR
  62. #define writeNormalAndTangent_DEFINED
  63. void writeNormalAndTangent(in mat3 normalMat)
  64. {
  65. #if TESSELLATION
  66. // Passthrough
  67. out_normal = in_normal.xyz;
  68. #if PASS == COLOR
  69. out_tangent = in_tangent;
  70. #if CALC_BITANGENT_IN_VERT
  71. #error TODO
  72. #endif
  73. #endif
  74. #else
  75. #if PASS == COLOR
  76. out_normal = normalMat * in_normal.xyz;
  77. out_tangent.xyz = normalMat * in_tangent.xyz;
  78. out_tangent.w = in_tangent.w;
  79. #if CALC_BITANGENT_IN_VERT
  80. out_bitangent = cross(out_normal, out_tangent.xyz) * in_tangent.w;
  81. #endif
  82. #endif
  83. // #if TESSELLATION
  84. #endif
  85. }
  86. #endif
  87. #if PASS == COLOR
  88. #define writeVertPosViewSpace_DEFINED
  89. void writeVertPosViewSpace(in mat4 modelViewMat)
  90. {
  91. out_vertPosViewSpace = vec3(modelViewMat * vec4(in_position, 1.0));
  92. }
  93. #endif
  94. #if PASS == COLOR
  95. #define writeParallax_DEFINED
  96. void writeParallax(in mat3 normalMat, in mat4 modelViewMat)
  97. {
  98. vec3 n = normalMat * in_normal.xyz;
  99. vec3 t = normalMat * in_tangent.xyz;
  100. vec3 b = cross(n, t) * in_tangent.w;
  101. mat3 invTbn = transpose(mat3(t, b, n));
  102. writeVertPosViewSpace(modelViewMat);
  103. out_eyeTangentSpace = invTbn * out_vertPosViewSpace;
  104. out_normalTangentSpace = invTbn * n;
  105. }
  106. #endif
  107. #endif