Files
ASCIIRenderer/include/lighting.h

82 lines
1.9 KiB
C

#ifndef ASCII3D_LIGHTING_H
#define ASCII3D_LIGHTING_H
#include "config.h"
#include "vec3.h"
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum LightType {
LIGHT_DIRECTIONAL = 0,
LIGHT_POINT,
LIGHT_SPOT
} LightType;
typedef struct Color {
float r, g, b;
} Color;
typedef struct Light {
LightType type;
Vec3 position;
Vec3 direction;
Color color;
float intensity;
float falloff;
float spot_angle;
bool enabled;
} Light;
// PBR surface components
typedef struct Material {
Color ambient;
Color diffuse;
Color specular;
float shininess;
float reflectivity;
} Material;
// Encapsulates the entire render context's virtual ecosystem
typedef struct LightingSystem {
Light lights[MAX_LIGHTS];
int light_count;
Color ambient_color;
float ambient_intensity;
Vec3 camera_position;
} LightingSystem;
// Instantiates default 3-point portrait lighting scheme
void lighting_init(LightingSystem *system);
// Registers a new light emitter into the system context
int lighting_add_light(LightingSystem *system, const Light *light);
Light lighting_create_directional(Vec3 direction, Color color, float intensity);
Light lighting_create_point(Vec3 position, Color color, float intensity,
float falloff);
// Computes monochrome or RGB shading based on surface interactions
float lighting_calculate(const LightingSystem *system, Vec3 point, Vec3 normal,
const Material *material);
Color lighting_calculate_color(const LightingSystem *system, Vec3 point,
Vec3 normal, const Material *material);
Material lighting_default_material(void);
// Floating point color combinators
Color color_create(float r, float g, float b);
Color color_scale(Color c, float s);
Color color_add(Color a, Color b);
Color color_multiply(Color a, Color b);
Color color_clamp(Color c);
float color_to_intensity(Color c);
#ifdef __cplusplus
}
#endif
#endif