light.c 589 B

123456789101112131415161718192021222324
  1. /*
  2. * 3D Engine
  3. * light.c:
  4. * Based on pikuma.com 3D software renderer in C
  5. * Copyright (c) 2021 986-Studio. All rights reserved.
  6. *
  7. * Created by Manoël Trapier on 06/03/2021.
  8. */
  9. #include <display.h>
  10. #include <vector.h>
  11. #include <light.h>
  12. colour_t applyLight(colour_t c, double lightLevel)
  13. {
  14. if (lightLevel < 0) { lightLevel = 0; }
  15. if (lightLevel > 1) { lightLevel = 1; }
  16. uint8_t r = round(((c >> 16) & 0xFF) * lightLevel);
  17. uint8_t g = round(((c >> 8) & 0xFF) * lightLevel);
  18. uint8_t b = round(((c ) & 0xFF) * lightLevel);
  19. return MAKE_RGB(r, g, b);
  20. }