ForwardShadingParticles.ankiprog 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright (C) 2009-2021, 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. #pragma anki reflect b_ankiPerDraw
  18. layout(set = 1, binding = 0, row_major) uniform b_ankiPerDraw
  19. {
  20. PerDraw u_ankiPerDraw;
  21. };
  22. #pragma anki reflect u_ankiGlobalSampler
  23. layout(set = 1, binding = 1) uniform sampler u_ankiGlobalSampler;
  24. #if ANIMATED_TEXTURE == 0
  25. # pragma anki reflect u_diffuseMap
  26. layout(set = 1, binding = 2) uniform texture2D u_diffuseMap;
  27. #endif
  28. #if ANIMATED_TEXTURE == 1
  29. # pragma anki reflect u_diffuseMapArr
  30. layout(set = 1, binding = 2) uniform texture2DArray u_diffuseMapArr;
  31. #endif
  32. #pragma anki start vert
  33. #include <AnKi/Shaders/ForwardShadingCommonVert.glsl>
  34. layout(location = VERTEX_ATTRIBUTE_ID_SCALE) in F32 in_scale;
  35. layout(location = VERTEX_ATTRIBUTE_ID_ALPHA) in F32 in_alpha;
  36. layout(location = 0) flat out F32 out_alpha;
  37. layout(location = 1) out Vec2 out_uv;
  38. layout(location = 2) out Vec3 out_worldPos;
  39. void main()
  40. {
  41. out_uv = Vec2(gl_VertexID & 1, gl_VertexID >> 1);
  42. out_worldPos = u_ankiPerDraw.m_ankiCameraRotationMatrix * Vec3((out_uv - 0.5) * in_scale, 0.0) + in_position;
  43. gl_Position = u_ankiPerDraw.m_ankiMvp * Vec4(out_worldPos, 1.0);
  44. out_alpha = in_alpha;
  45. }
  46. #pragma anki end
  47. #pragma anki start frag
  48. #include <AnKi/Shaders/ForwardShadingCommonFrag.glsl>
  49. layout(location = 0) flat in F32 in_alpha;
  50. layout(location = 1) in Vec2 in_uv;
  51. layout(location = 2) in Vec3 in_worldPos;
  52. void main()
  53. {
  54. #if ANIMATED_TEXTURE == 1
  55. Vec4 texCol = readAnimatedTextureRgba(u_diffuseMapArr, u_ankiGlobalSampler, u_ankiPerDraw.m_animationPeriod, in_uv,
  56. u_clusteredShading.m_time);
  57. #else
  58. Vec4 texCol = texture(u_diffuseMap, u_ankiGlobalSampler, in_uv);
  59. #endif
  60. #if LIGHT
  61. texCol.rgb = computeLightColorLow(texCol.rgb, in_worldPos);
  62. #endif
  63. Vec4 colScale = u_ankiPerDraw.m_colorScale;
  64. colScale.a *= in_alpha;
  65. particleAlpha(texCol, colScale, u_ankiPerDraw.m_colorBias);
  66. }
  67. #pragma anki end