暂无描述

particle.frag 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #version 450
  2. #extension GL_ARB_separate_shader_objects : enable
  3. #extension GL_ARB_shading_language_420pack : enable
  4. layout (binding = 1) uniform sampler2D samplerSmoke;
  5. layout (binding = 2) uniform sampler2D samplerFire;
  6. layout (location = 0) in vec4 inColor;
  7. layout (location = 1) in float inAlpha;
  8. layout (location = 2) in flat int inType;
  9. layout (location = 3) in float inRotation;
  10. layout (location = 0) out vec4 outFragColor;
  11. void main ()
  12. {
  13. vec4 color;
  14. float alpha = (inAlpha <= 1.0) ? inAlpha : 2.0 - inAlpha;
  15. // Rotate texture coordinates
  16. // Rotate UV
  17. float rotCenter = 0.5;
  18. float rotCos = cos(inRotation);
  19. float rotSin = sin(inRotation);
  20. vec2 rotUV = vec2(
  21. rotCos * (gl_PointCoord.x - rotCenter) + rotSin * (gl_PointCoord.y - rotCenter) + rotCenter,
  22. rotCos * (gl_PointCoord.y - rotCenter) - rotSin * (gl_PointCoord.x - rotCenter) + rotCenter);
  23. if (inType == 0)
  24. {
  25. // Flame
  26. color = texture(samplerFire, rotUV);
  27. outFragColor.a = 0.0;
  28. }
  29. else
  30. {
  31. // Smoke
  32. color = texture(samplerSmoke, rotUV);
  33. outFragColor.a = color.a * alpha;
  34. }
  35. outFragColor.rgb = color.rgb * inColor.rgb * alpha;
  36. }