Effect.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #pragma once
  2. #include <glm/vec2.hpp>
  3. #include <glm/vec4.hpp>
  4. #include <optional>
  5. #include <string>
  6. #include <vector>
  7. #include "Types.h"
  8. namespace WallpaperEngine::Data::Model {
  9. enum PassCommandType { Command_Copy = 0, Command_Swap = 1 };
  10. /** effect.json "conditions" entry (sub_1401E63B0): a combo against a number or {"value", "op"} */
  11. struct EffectCondition {
  12. enum Operator { Equal, GreaterEqual, Greater, LessEqual, Less };
  13. std::string combo;
  14. int value = 0;
  15. Operator op = Equal;
  16. };
  17. struct EffectConditions {
  18. std::vector<EffectCondition> tests;
  19. [[nodiscard]] bool holds (const ComboMap& combos) const;
  20. };
  21. struct FBO {
  22. std::string name;
  23. std::string format;
  24. /** an int from 1 to 255, anything else is 1 */
  25. float scale;
  26. bool unique;
  27. /** "clear": up to four numbers, what the buffer is cleared to when made and by a clear function */
  28. glm::vec4 clearColor = {};
  29. /** "clear" was empty or had all four numbers (wallpaper64.exe 2.8.42 sub_1401E7170, FBO flag 2) */
  30. bool clearOnCreate = false;
  31. /** width/height replace the object's size, fit shrinks the longer side to it (sub_1401EA500) */
  32. std::optional<uint32_t> width = std::nullopt;
  33. std::optional<uint32_t> height = std::nullopt;
  34. std::optional<uint32_t> fit = std::nullopt;
  35. /** "uvs": "repeat" */
  36. bool repeat = false;
  37. EffectConditions conditions = {};
  38. /** width/height/fit, divided by the scale, at least 2 */
  39. [[nodiscard]] glm::uvec2 bufferSize (glm::vec2 objectSize) const;
  40. };
  41. /**
  42. * An effect.json "functions" entry, run by IEffect.executeMaterialFunction. WE only keeps "clear" actions that
  43. * name at least one of the effect's buffers
  44. */
  45. struct EffectFunction {
  46. std::string name;
  47. /** indices into the effect's fbos of the names listed, WE only uses how many there are */
  48. std::vector<int> fbos;
  49. };
  50. struct EffectPass {
  51. /** a pass failing its conditions keeps its index for pass overrides */
  52. EffectConditions conditions;
  53. std::optional<MaterialUniquePtr> material;
  54. TextureMap binds;
  55. std::optional<PassCommandType> command;
  56. std::optional<std::string> source;
  57. std::optional<std::string> target;
  58. /** counted into the layer's buffer passes (sub_1401E7170) */
  59. bool compose = false;
  60. };
  61. struct Effect {
  62. /** For the UI */
  63. std::string name;
  64. /** For the UI */
  65. std::string description;
  66. /** For the UI */
  67. std::string group;
  68. std::string preview;
  69. std::vector<std::string> dependencies;
  70. std::vector<EffectPassUniquePtr> passes;
  71. std::vector<FBOUniquePtr> fbos;
  72. std::vector<EffectFunction> functions;
  73. };
  74. } // namespace WallpaperEngine::Data::Model