MsCommonVert.glsl 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright (C) 2009-2016, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma anki include "shaders/MsFsCommon.glsl"
  6. //
  7. // Attributes
  8. //
  9. layout(location = POSITION_LOCATION) in highp vec3 in_position;
  10. layout(location = TEXTURE_COORDINATE_LOCATION) in mediump vec2 in_uv;
  11. #if PASS == COLOR || TESSELLATION
  12. layout(location = NORMAL_LOCATION) in mediump vec4 in_normal;
  13. #endif
  14. #if PASS == COLOR
  15. layout(location = TANGENT_LOCATION) in mediump vec4 in_tangent;
  16. #endif
  17. //
  18. // Varyings
  19. //
  20. out gl_PerVertex
  21. {
  22. vec4 gl_Position;
  23. };
  24. layout(location = 0) out mediump vec2 out_uv;
  25. #if PASS == COLOR || TESSELLATION
  26. layout(location = 1) out mediump vec3 out_normal;
  27. #endif
  28. #if PASS == COLOR
  29. layout(location = 2) out mediump vec4 out_tangent;
  30. // For env mapping. AKA view vector
  31. layout(location = 3) out mediump vec3 out_vertPosViewSpace;
  32. #endif
  33. #if INSTANCE_ID_FRAGMENT_SHADER
  34. layout(location = 4) flat out uint out_instanceId;
  35. #endif
  36. //==============================================================================
  37. #define writePositionAndUv_DEFINED
  38. void writePositionAndUv(in mat4 mvp)
  39. {
  40. #if PASS == DEPTH && LOD > 0
  41. // No tex coords for you
  42. #else
  43. out_uv = in_uv;
  44. #endif
  45. #if TESSELLATION
  46. gl_Position = vec4(in_position, 1.0);
  47. #else
  48. gl_Position = mvp * vec4(in_position, 1.0);
  49. #endif
  50. }
  51. //==============================================================================
  52. #if PASS == COLOR
  53. #define writeNormalAndTangent_DEFINED
  54. void writeNormalAndTangent(in mat3 normalMat)
  55. {
  56. #if TESSELLATION
  57. // Passthrough
  58. out_normal = in_normal.xyz;
  59. # if PASS == COLOR
  60. out_tangent = in_tangent;
  61. # endif
  62. #else
  63. # if PASS == COLOR
  64. out_normal = normalMat * in_normal.xyz;
  65. out_tangent.xyz = normalMat * in_tangent.xyz;
  66. out_tangent.w = in_tangent.w;
  67. # endif
  68. #endif
  69. }
  70. #endif
  71. //==============================================================================
  72. #if PASS == COLOR
  73. #define writeVertPosViewSpace_DEFINED
  74. void writeVertPosViewSpace(in mat4 modelViewMat)
  75. {
  76. out_vertPosViewSpace = vec3(modelViewMat * vec4(in_position, 1.0));
  77. }
  78. #endif