crt/lightmap.hpp
#pragma once
#include "img.hpp"
#include "common.hpp"
typedef float light_t;
class LightValue {
private:
light_t r, g, b;
public:
LightValue(): r(0.0), g(0.0), b(0.0) {}
void set(const LightValue&);
void add(const LightValue&);
void add(const LightValue& o, light_t weight);
void add(light_t);
void add(Img::rgb_t c, light_t l);
void mul(light_t);
void finalize(Img::rgb_t&);
};
class LightMap {
public:
typedef enum {SIDE_A=0, SIDE_B=1} side_t;
private:
LightValue* const buf;
public:
const unsigned w, h;
const bool sided;
LightMap(bool, unsigned, unsigned);
~LightMap();
void to_uv(unsigned, unsigned, coord_t&, coord_t&) const;
LightValue& at(side_t, unsigned, unsigned);
const LightValue& at(side_t, unsigned, unsigned) const;
void at_uv(side_t, coord_t, coord_t, LightValue&) const;
};