PuppetClipping.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma once
  2. #include <cstdint>
  3. #include <optional>
  4. #include <string>
  5. #include <vector>
  6. namespace WallpaperEngine::Render::Objects {
  7. /**
  8. * Clipping masks of a puppet mesh (MDLV 23+), read and turned into draws the way wallpaper64.exe 2.8.42 does: the
  9. * loader (sub_140261880) reads the part ranges and the records, the image setup (sub_14020AE00, sub_14020B720) splits
  10. * the index buffer into draws and builds the command list the final draw (sub_140208670 / sub_140208C80) walks.
  11. */
  12. struct PuppetClipping {
  13. enum RecordFlags : uint32_t {
  14. /** the targets are drawn additively instead of translucent */
  15. Additive = 0x1,
  16. /** the mask is inverted: cleared to white, the shader flips it (g_RenderVar0.x) */
  17. Inverted = 0x2,
  18. /** the sources only make the mask, they aren't drawn themselves */
  19. HideSources = 0x4,
  20. /** the mask is drawn where its targets are instead of after its last source, not ported */
  21. AtTargets = 0x8,
  22. };
  23. struct Part {
  24. uint32_t firstIndex = 0;
  25. uint32_t indexCount = 0;
  26. };
  27. struct Record {
  28. /** texture name relative to materials/, sampled through the mesh UVs */
  29. std::string mask;
  30. uint32_t flags = 0;
  31. /** parts drawn through the mask */
  32. std::vector<uint32_t> targets;
  33. /** parts that make the mask */
  34. std::vector<uint32_t> sources;
  35. /** the record whose targets contain every source of this one, its mask is multiplied in */
  36. int parent = -1;
  37. };
  38. struct Draw {
  39. uint32_t offset = 0;
  40. uint32_t count = 0;
  41. };
  42. enum Command : int {
  43. /** draw the next draw normally */
  44. PlainDraw = 0,
  45. /** record: its mask from the next draw, the targets with the one after */
  46. Mask = 1,
  47. /** chain length, (record, mask draw) per ancestor, record: like Mask with the ancestors' masks multiplied in */
  48. NestedMask = 2,
  49. };
  50. /**
  51. * Reads what follows a puppet's index buffer. offset is the end of the index data, nullopt when the file has no
  52. * clipping records
  53. */
  54. static std::optional<PuppetClipping>
  55. read (const std::vector<char>& data, size_t offset, int version, size_t indexCount);
  56. /** Splits the mesh's indices into WE's draws and fills commands, false when the records can't be drawn here */
  57. bool build (const std::vector<uint16_t>& meshIndices);
  58. std::vector<Part> parts;
  59. std::vector<Record> records;
  60. std::vector<uint16_t> indices;
  61. std::vector<Draw> draws;
  62. std::vector<int> commands;
  63. };
  64. } // namespace WallpaperEngine::Render::Objects