MsCommonVert.glsl 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #pragma anki include "shaders/MsBsCommon.glsl"
  2. /// @name Attributes
  3. /// @{
  4. layout(location = 0) in highp vec3 position;
  5. layout(location = 3) in mediump vec2 texCoord;
  6. #if PASS_COLOR || TESSELLATION
  7. layout(location = 1) in mediump vec3 normal;
  8. #endif
  9. #if PASS_COLOR
  10. layout(location = 2) in mediump vec4 tangent;
  11. #endif
  12. /// @}
  13. /// @name Varyings
  14. /// @{
  15. out mediump vec2 vTexCoords;
  16. #if INSTANCE_ID_FRAGMENT_SHADER
  17. flat out uint vInstanceId;
  18. #endif
  19. #if PASS_COLOR || TESSELLATION
  20. out mediump vec3 vNormal;
  21. #endif
  22. #if PASS_COLOR
  23. out mediump vec4 vTangent;
  24. out mediump vec3 vVertPosViewSpace; ///< For env mapping. AKA view vector
  25. #endif
  26. #if TESSELLATION
  27. out highp vec3 vPosition;
  28. #endif
  29. /// @}
  30. //==============================================================================
  31. #define writePositionTexCoord_DEFINED
  32. void writePositionTexCoord(in mat4 mvp)
  33. {
  34. #if PASS_DEPTH && LOD > 0
  35. // No tex coords for you
  36. #else
  37. vTexCoords = texCoord;
  38. #endif
  39. #if TESSELLATION
  40. vPosition = position;
  41. #else
  42. gl_Position = mvp * vec4(position, 1.0);
  43. #endif
  44. }
  45. //==============================================================================
  46. #define writePositionNormalTangentTexCoord_DEFINED
  47. void writePositionNormalTangentTexCoord(in mat4 mvp, in mat3 normalMat)
  48. {
  49. #if TESSELLATION
  50. // Passthrough
  51. vNormal = normal;
  52. # if PASS_COLOR
  53. vTangent = tangent;
  54. # endif
  55. #else
  56. # if PASS_COLOR
  57. vNormal = normalMat * normal;
  58. vTangent.xyz = normalMat * tangent.xyz;
  59. vTangent.w = tangent.w;
  60. # endif
  61. #endif
  62. writePositionTexCoord(mvp);
  63. }
  64. //==============================================================================
  65. #if PASS_COLOR
  66. #define setVertPosViewSpace_DEFINED
  67. void setVertPosViewSpace(in mat4 modelViewMat)
  68. {
  69. vVertPosViewSpace = vec3(modelViewMat * vec4(position, 1.0));
  70. }
  71. #endif