ForwardShadingParticles.ankiprog 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (C) 2009-2020, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma anki mutator ANIMATED_TEXTURE 0 1
  6. #pragma anki mutator LIGHT 0 1
  7. struct PerDraw
  8. {
  9. Mat4 m_ankiMvp;
  10. Mat3 m_ankiCameraRotationMatrix;
  11. #if ANIMATED_TEXTURE == 1
  12. F32 m_animationPeriod;
  13. #endif
  14. Vec4 m_colorScale;
  15. Vec4 m_colorBias;
  16. };
  17. layout(set = 1, binding = 0, row_major) uniform b_ankiMaterial
  18. {
  19. PerDraw u_ankiPerDraw;
  20. };
  21. layout(set = 1, binding = 1) uniform sampler u_ankiGlobalSampler;
  22. #if ANIMATED_TEXTURE == 0
  23. layout(set = 1, binding = 2) uniform texture2D u_diffuseMap;
  24. #endif
  25. #if ANIMATED_TEXTURE == 1
  26. layout(set = 1, binding = 2) uniform texture2DArray u_diffuseMapArr;
  27. #endif
  28. #pragma anki start vert
  29. #include <shaders/ForwardShadingCommonVert.glsl>
  30. layout(location = SCALE_LOCATION) in F32 in_scale;
  31. layout(location = ALPHA_LOCATION) in F32 in_alpha;
  32. layout(location = 0) flat out F32 out_alpha;
  33. layout(location = 1) out Vec2 out_uv;
  34. layout(location = 2) out Vec3 out_worldPos;
  35. void main()
  36. {
  37. out_uv = Vec2(gl_VertexID & 1, gl_VertexID >> 1);
  38. out_worldPos = u_ankiPerDraw.m_ankiCameraRotationMatrix * Vec3((out_uv - 0.5) * in_scale, 0.0) + in_position;
  39. gl_Position = u_ankiPerDraw.m_ankiMvp * Vec4(out_worldPos, 1.0);
  40. out_alpha = in_alpha;
  41. }
  42. #pragma anki end
  43. #pragma anki start frag
  44. #include <shaders/ForwardShadingCommonFrag.glsl>
  45. layout(location = 0) flat in F32 in_alpha;
  46. layout(location = 1) in Vec2 in_uv;
  47. layout(location = 2) in Vec3 in_worldPos;
  48. void main()
  49. {
  50. #if ANIMATED_TEXTURE == 1
  51. Vec4 texCol = readAnimatedTextureRgba(u_diffuseMapArr, u_ankiGlobalSampler, u_ankiPerDraw.m_animationPeriod, in_uv,
  52. anki_u_time);
  53. #else
  54. Vec4 texCol = texture(u_diffuseMap, u_ankiGlobalSampler, in_uv);
  55. #endif
  56. #if LIGHT
  57. texCol.rgb = computeLightColorLow(texCol.rgb, in_worldPos);
  58. #endif
  59. Vec4 colScale = u_ankiPerDraw.m_colorScale;
  60. colScale.a *= in_alpha;
  61. particleAlpha(texCol, colScale, u_ankiPerDraw.m_colorBias);
  62. }
  63. #pragma anki end