vertex_shader.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <type_traits>
  6. #include "common/vector_math.h"
  7. #include "pica.h"
  8. namespace Pica {
  9. namespace VertexShader {
  10. struct InputVertex {
  11. Math::Vec4<float24> attr[16];
  12. };
  13. struct OutputVertex {
  14. OutputVertex() = default;
  15. // VS output attributes
  16. Math::Vec4<float24> pos;
  17. Math::Vec4<float24> dummy; // quaternions (not implemented, yet)
  18. Math::Vec4<float24> color;
  19. Math::Vec2<float24> tc0;
  20. Math::Vec2<float24> tc1;
  21. float24 pad[6];
  22. Math::Vec2<float24> tc2;
  23. // Padding for optimal alignment
  24. float24 pad2[4];
  25. // Attributes used to store intermediate results
  26. // position after perspective divide
  27. Math::Vec3<float24> screenpos;
  28. float24 pad3;
  29. // Linear interpolation
  30. // factor: 0=this, 1=vtx
  31. void Lerp(float24 factor, const OutputVertex& vtx) {
  32. pos = pos * factor + vtx.pos * (float24::FromFloat32(1) - factor);
  33. // TODO: Should perform perspective correct interpolation here...
  34. tc0 = tc0 * factor + vtx.tc0 * (float24::FromFloat32(1) - factor);
  35. tc1 = tc1 * factor + vtx.tc1 * (float24::FromFloat32(1) - factor);
  36. tc2 = tc2 * factor + vtx.tc2 * (float24::FromFloat32(1) - factor);
  37. screenpos = screenpos * factor + vtx.screenpos * (float24::FromFloat32(1) - factor);
  38. color = color * factor + vtx.color * (float24::FromFloat32(1) - factor);
  39. }
  40. // Linear interpolation
  41. // factor: 0=v0, 1=v1
  42. static OutputVertex Lerp(float24 factor, const OutputVertex& v0, const OutputVertex& v1) {
  43. OutputVertex ret = v0;
  44. ret.Lerp(factor, v1);
  45. return ret;
  46. }
  47. };
  48. static_assert(std::is_pod<OutputVertex>::value, "Structure is not POD");
  49. static_assert(sizeof(OutputVertex) == 32 * sizeof(float), "OutputVertex has invalid size");
  50. OutputVertex RunShader(const InputVertex& input, int num_attributes, const Regs::ShaderConfig& config, const State::ShaderSetup& setup);
  51. } // namespace
  52. } // namespace