LightingShaderGen.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2008 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <string_view>
  5. #include "Common/CommonTypes.h"
  6. class ShaderCode;
  7. #define LIGHT_COL "{}[{}].color.{}"
  8. #define LIGHT_COL_PARAMS(index, swizzle) (I_LIGHTS), (index), (swizzle)
  9. #define LIGHT_COSATT "{}[{}].cosatt"
  10. #define LIGHT_COSATT_PARAMS(index) (I_LIGHTS), (index)
  11. #define LIGHT_DISTATT "{}[{}].distatt"
  12. #define LIGHT_DISTATT_PARAMS(index) (I_LIGHTS), (index)
  13. #define LIGHT_POS "{}[{}].pos"
  14. #define LIGHT_POS_PARAMS(index) (I_LIGHTS), (index)
  15. #define LIGHT_DIR "{}[{}].dir"
  16. #define LIGHT_DIR_PARAMS(index) (I_LIGHTS), (index)
  17. /**
  18. * Common uid data used for shader generators that use lighting calculations.
  19. */
  20. struct LightingUidData
  21. {
  22. u32 matsource : 4; // 4x1 bit
  23. u32 enablelighting : 4; // 4x1 bit
  24. u32 ambsource : 4; // 4x1 bit
  25. u32 diffusefunc : 8; // 4x2 bits
  26. u32 attnfunc : 8; // 4x2 bits
  27. u32 light_mask : 32; // 4x8 bits
  28. };
  29. constexpr char s_lighting_struct[] = "struct Light {\n"
  30. "\tint4 color;\n"
  31. "\tfloat4 cosatt;\n"
  32. "\tfloat4 distatt;\n"
  33. "\tfloat4 pos;\n"
  34. "\tfloat4 dir;\n"
  35. "};\n";
  36. void GenerateLightingShaderCode(ShaderCode& object, const LightingUidData& uid_data,
  37. std::string_view in_color_name, std::string_view dest);
  38. void GetLightingShaderUid(LightingUidData& uid_data);
  39. void GenerateCustomLightingHeaderDetails(ShaderCode* out, u32 enablelighting, u32 light_mask);
  40. void GenerateCustomLightingImplementation(ShaderCode* out, const LightingUidData& uid_data,
  41. std::string_view in_color_name);