MsCommonVert.glsl 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright (C) 2009-2015, 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/MsBsCommon.glsl"
  6. //
  7. // Attributes
  8. //
  9. layout(location = POSITION_LOCATION) in highp vec3 inPosition;
  10. layout(location = TEXTURE_COORDINATE_LOCATION) in mediump vec2 inTexCoord;
  11. #if PASS == COLOR || TESSELLATION
  12. layout(location = NORMAL_LOCATION) in mediump vec4 inNormal;
  13. #endif
  14. #if PASS == COLOR
  15. layout(location = TANGENT_LOCATION) in mediump vec4 inTangent;
  16. #endif
  17. //
  18. // Varyings
  19. //
  20. out gl_PerVertex
  21. {
  22. vec4 gl_Position;
  23. };
  24. layout(location = 0) out mediump vec2 outTexCoords;
  25. #if PASS == COLOR || TESSELLATION
  26. layout(location = 1) out mediump vec3 outNormal;
  27. #endif
  28. #if PASS == COLOR
  29. layout(location = 2) out mediump vec4 outTangent;
  30. // For env mapping. AKA view vector
  31. layout(location = 3) out mediump vec3 outVertPosViewSpace;
  32. #endif
  33. #if INSTANCE_ID_FRAGMENT_SHADER
  34. layout(location = 4) flat out uint outInstanceId;
  35. #endif
  36. //==============================================================================
  37. #define writePositionTexCoord_DEFINED
  38. void writePositionTexCoord(in mat4 mvp)
  39. {
  40. #if PASS == DEPTH && LOD > 0
  41. // No tex coords for you
  42. #else
  43. outTexCoords = inTexCoord;
  44. #endif
  45. #if TESSELLATION
  46. gl_Position = vec4(inPosition, 1.0);
  47. #else
  48. gl_Position = mvp * vec4(inPosition, 1.0);
  49. #endif
  50. }
  51. //==============================================================================
  52. #define writePositionNormalTangentTexCoord_DEFINED
  53. void writePositionNormalTangentTexCoord(in mat4 mvp, in mat3 normalMat)
  54. {
  55. #if TESSELLATION
  56. // Passthrough
  57. outNormal = inNormal.xyz;
  58. # if PASS == COLOR
  59. outTangent = inTangent;
  60. # endif
  61. #else
  62. # if PASS == COLOR
  63. outNormal = normalMat * inNormal.xyz;
  64. outTangent.xyz = normalMat * inTangent.xyz;
  65. outTangent.w = inTangent.w;
  66. # endif
  67. #endif
  68. writePositionTexCoord(mvp);
  69. }
  70. //==============================================================================
  71. #if PASS == COLOR
  72. #define writeVertPosViewSpace_DEFINED
  73. void writeVertPosViewSpace(in mat4 modelViewMat)
  74. {
  75. outVertPosViewSpace = vec3(modelViewMat * vec4(inPosition, 1.0));
  76. }
  77. #endif