light.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 <stdio.h>
  15. class World;
  16. enum LightType
  17. {
  18. POINT_LIGHT = 0,
  19. AREA_LIGHT,
  20. };
  21. class Light
  22. {
  23. public:
  24. Colour intensity;
  25. Tuple position;
  26. LightType type;
  27. /* For area light */
  28. Tuple corner;
  29. Tuple uVec;
  30. Tuple vVec;
  31. uint32_t samples;
  32. uint32_t uSteps;
  33. uint32_t vSteps;
  34. public:
  35. Light(LightType type = POINT_LIGHT, Tuple position=Point(0, 0, 0),
  36. Colour intensity=Colour(1, 1, 1)) : type(type), position(position), intensity(intensity)
  37. { stats.addLight(); };
  38. Light(LightType type, Tuple corner, Tuple fullUVec, uint32_t uSteps, Tuple fullVVec, uint32_t vSteps,
  39. Colour intensity, bool jitter = false): type(type), corner(corner), uVec(fullUVec / uSteps), uSteps(uSteps),
  40. vVec(fullVVec / vSteps), vSteps(vSteps), intensity(intensity)
  41. {
  42. this->samples = this->vSteps * this->uSteps;
  43. this->position = this->corner + ((fullUVec + fullVVec) / 2);
  44. stats.addLight();
  45. };
  46. double intensityAt(World &w, Tuple point);
  47. bool operator==(const Light &b) const { return this->intensity == b.intensity &&
  48. this->position == b.position &&
  49. this->type == b.type; };
  50. Tuple pointOnLight(uint32_t u, uint32_t v);
  51. void dumpMe(FILE *fp);
  52. };
  53. #endif /* DORAYME_LIGHT_H */