light.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Light header
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #ifndef DORAYME_LIGHT_H
  10. #define DORAYME_LIGHT_H
  11. #include <tuple.h>
  12. #include <colour.h>
  13. #include <renderstat.h>
  14. #include <sequence.h>
  15. #include <stdio.h>
  16. class World;
  17. enum LightType
  18. {
  19. POINT_LIGHT = 0,
  20. AREA_LIGHT,
  21. };
  22. class Light
  23. {
  24. public:
  25. Colour intensity;
  26. Tuple position;
  27. LightType type;
  28. /* For area light */
  29. Tuple corner;
  30. Tuple uVec;
  31. Tuple vVec;
  32. uint32_t samples;
  33. uint32_t uSteps;
  34. uint32_t vSteps;
  35. bool jitter;
  36. Sequence jitterBy;
  37. public:
  38. Light(LightType type = POINT_LIGHT, Tuple position=Point(0, 0, 0),
  39. Colour intensity=Colour(1, 1, 1)) : type(type), position(position), intensity(intensity)
  40. { stats.addLight(); };
  41. Light(LightType type, Tuple corner, Tuple fullUVec, uint32_t uSteps, Tuple fullVVec, uint32_t vSteps,
  42. Colour intensity, bool jitter = false): type(type), corner(corner), uVec(fullUVec / uSteps), uSteps(uSteps),
  43. vVec(fullVVec / vSteps), vSteps(vSteps), intensity(intensity), jitter(jitter)
  44. {
  45. this->samples = this->vSteps * this->uSteps;
  46. this->position = this->corner + ((fullUVec + fullVVec) / 2);
  47. stats.addLight();
  48. };
  49. double intensityAt(World &w, Tuple point);
  50. bool operator==(const Light &b) const { return this->intensity == b.intensity &&
  51. this->position == b.position &&
  52. this->type == b.type; };
  53. Tuple pointOnLight(uint32_t u, uint32_t v);
  54. void dumpMe(FILE *fp);
  55. };
  56. #endif /* DORAYME_LIGHT_H */