/*
 * 3D Engine 
 * light.c: 
 * Based on pikuma.com 3D software renderer in C
 * Copyright (c) 2021 986-Studio. All rights reserved.
 *
 * Created by Manoël Trapier on 06/03/2021.
 */

#include <display.h>
#include <vector.h>
#include <light.h>

colour_t applyLight(colour_t c, double lightLevel)
{
    if (lightLevel < 0) { lightLevel = 0; }
    if (lightLevel > 1) { lightLevel = 1; }

    uint8_t r = round(((c >> 16) & 0xFF) * lightLevel);
    uint8_t g = round(((c >>  8) & 0xFF) * lightLevel);
    uint8_t b = round(((c     ) & 0xFF) * lightLevel);

    return MAKE_RGB(r, g, b);
}