Shader.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // zlib open source license
  2. //
  3. // Copyright (c) 2017 to 2023 David Forsgren Piuva
  4. //
  5. // This software is provided 'as-is', without any express or implied
  6. // warranty. In no event will the authors be held liable for any damages
  7. // arising from the use of this software.
  8. //
  9. // Permission is granted to anyone to use this software for any purpose,
  10. // including commercial applications, and to alter it and redistribute it
  11. // freely, subject to the following restrictions:
  12. //
  13. // 1. The origin of this software must not be misrepresented; you must not
  14. // claim that you wrote the original software. If you use this software
  15. // in a product, an acknowledgment in the product documentation would be
  16. // appreciated but is not required.
  17. //
  18. // 2. Altered source versions must be plainly marked as such, and must not be
  19. // misrepresented as being the original software.
  20. //
  21. // 3. This notice may not be removed or altered from any source
  22. // distribution.
  23. #ifndef DFPSR_RENDER_RENDERING
  24. #define DFPSR_RENDER_RENDERING
  25. #include <cstdint>
  26. #include "../../image/PackOrder.h"
  27. #include "../../image/Image.h"
  28. #include "../../image/Texture.h"
  29. #include "../ITriangle2D.h"
  30. #include "shaderMethods.h"
  31. #include "shaderTypes.h"
  32. namespace dsr {
  33. struct TriangleTexCoords {
  34. FVector3D u1, v1, u2, v2;
  35. TriangleTexCoords() {}
  36. TriangleTexCoords(const FVector3D &u1, const FVector3D &v1, const FVector3D &u2, const FVector3D &v2) :
  37. u1(u1), v1(v1), u2(u2), v2(v2) {}
  38. TriangleTexCoords(const FVector4D &a, const FVector4D &b, const FVector4D &c) :
  39. u1(FVector3D(a.x, b.x, c.x)), v1(FVector3D(a.y, b.y, c.y)), u2(FVector3D(a.z, b.z, c.z)), v2(FVector3D(a.w, b.w, c.w)) {}
  40. };
  41. struct TriangleColors {
  42. FVector3D red, green, blue, alpha;
  43. TriangleColors() {}
  44. explicit TriangleColors(float monochrome) : red(monochrome), green(monochrome), blue(monochrome), alpha(monochrome) {}
  45. TriangleColors(const FVector3D &red, const FVector3D &green, const FVector3D &blue, const FVector3D &alpha) : red(red), green(green), blue(blue), alpha(alpha) {}
  46. TriangleColors(const FVector4D &a, const FVector4D &b, const FVector4D &c) :
  47. red(FVector3D(a.x, b.x, c.x)), green(FVector3D(a.y, b.y, c.y)), blue(FVector3D(a.z, b.z, c.z)), alpha(FVector3D(a.w, b.w, c.w)) {}
  48. TriangleColors getScaled(float scalar) const {
  49. return TriangleColors(this->red * scalar, this->green * scalar, this->blue * scalar, this->alpha * scalar);
  50. }
  51. };
  52. struct TriangleInput {
  53. const TextureRgbaU8 *diffuseMap;
  54. const TextureRgbaU8 *lightMap;
  55. const TriangleTexCoords texCoords;
  56. const TriangleColors colors;
  57. TriangleInput(const TextureRgbaU8 *diffuseMap, const TextureRgbaU8 *lightMap, const TriangleTexCoords &texCoords, const TriangleColors &colors)
  58. : diffuseMap(diffuseMap), lightMap(lightMap), texCoords(texCoords), colors(colors) {}
  59. };
  60. // The template for function pointers doing the work
  61. inline void drawCallbackTemplate(const TriangleInput &triangleInput, ImageRgbaU8 *colorBuffer, ImageF32 *depthBuffer, const ITriangle2D &triangle, const Projection &projection, const RowShape &shape, Filter filter) {}
  62. using DRAW_CALLBACK_TYPE = decltype(&drawCallbackTemplate);
  63. }
  64. #endif