(Feat): Initial Commit.
This commit is contained in:
170
include/lighting.h
Normal file
170
include/lighting.h
Normal file
@@ -0,0 +1,170 @@
|
||||
/**
|
||||
* @file lighting.h
|
||||
* @brief Advanced lighting system for ASCII 3D Renderer
|
||||
* @author ASCII3D Project
|
||||
* @version 2.0.0
|
||||
*/
|
||||
|
||||
#ifndef ASCII3D_LIGHTING_H
|
||||
#define ASCII3D_LIGHTING_H
|
||||
|
||||
#include "vec3.h"
|
||||
#include "config.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Light types
|
||||
*/
|
||||
typedef enum LightType {
|
||||
LIGHT_DIRECTIONAL = 0, /* Parallel rays (sun-like) */
|
||||
LIGHT_POINT, /* Point source with falloff */
|
||||
LIGHT_SPOT /* Cone-shaped spotlight */
|
||||
} LightType;
|
||||
|
||||
/**
|
||||
* @brief RGB Color structure
|
||||
*/
|
||||
typedef struct Color {
|
||||
float r, g, b;
|
||||
} Color;
|
||||
|
||||
/**
|
||||
* @brief Light source structure
|
||||
*/
|
||||
typedef struct Light {
|
||||
LightType type;
|
||||
Vec3 position; /* Position for point/spot lights */
|
||||
Vec3 direction; /* Direction for directional/spot lights */
|
||||
Color color; /* Light color */
|
||||
float intensity; /* Light intensity multiplier */
|
||||
float falloff; /* Attenuation for point lights */
|
||||
float spot_angle; /* Cone angle for spotlights (radians) */
|
||||
bool enabled;
|
||||
} Light;
|
||||
|
||||
/**
|
||||
* @brief Material properties for surfaces
|
||||
*/
|
||||
typedef struct Material {
|
||||
Color ambient; /* Ambient color */
|
||||
Color diffuse; /* Diffuse color */
|
||||
Color specular; /* Specular highlight color */
|
||||
float shininess; /* Specular exponent */
|
||||
float reflectivity; /* For future use */
|
||||
} Material;
|
||||
|
||||
/**
|
||||
* @brief Lighting system state
|
||||
*/
|
||||
typedef struct LightingSystem {
|
||||
Light lights[MAX_LIGHTS];
|
||||
int light_count;
|
||||
Color ambient_color;
|
||||
float ambient_intensity;
|
||||
Vec3 camera_position;
|
||||
} LightingSystem;
|
||||
|
||||
/**
|
||||
* @brief Initialize the lighting system with default lights
|
||||
* @param system Lighting system to initialize
|
||||
*/
|
||||
void lighting_init(LightingSystem *system);
|
||||
|
||||
/**
|
||||
* @brief Add a light to the system
|
||||
* @param system Lighting system
|
||||
* @param light Light to add
|
||||
* @return Index of added light, or -1 if full
|
||||
*/
|
||||
int lighting_add_light(LightingSystem *system, const Light *light);
|
||||
|
||||
/**
|
||||
* @brief Create a directional light
|
||||
* @param direction Light direction (will be normalized)
|
||||
* @param color Light color
|
||||
* @param intensity Light intensity
|
||||
* @return Configured light structure
|
||||
*/
|
||||
Light lighting_create_directional(Vec3 direction, Color color, float intensity);
|
||||
|
||||
/**
|
||||
* @brief Create a point light
|
||||
* @param position Light position
|
||||
* @param color Light color
|
||||
* @param intensity Light intensity
|
||||
* @param falloff Attenuation factor
|
||||
* @return Configured light structure
|
||||
*/
|
||||
Light lighting_create_point(Vec3 position, Color color, float intensity, float falloff);
|
||||
|
||||
/**
|
||||
* @brief Calculate lighting at a surface point (Phong model)
|
||||
* @param system Lighting system
|
||||
* @param point Surface point position
|
||||
* @param normal Surface normal (must be normalized)
|
||||
* @param material Surface material
|
||||
* @return Final illumination value (0.0 - 1.0+)
|
||||
*/
|
||||
float lighting_calculate(const LightingSystem *system, Vec3 point,
|
||||
Vec3 normal, const Material *material);
|
||||
|
||||
/**
|
||||
* @brief Calculate full color lighting
|
||||
* @param system Lighting system
|
||||
* @param point Surface point position
|
||||
* @param normal Surface normal
|
||||
* @param material Surface material
|
||||
* @return Final color
|
||||
*/
|
||||
Color lighting_calculate_color(const LightingSystem *system, Vec3 point,
|
||||
Vec3 normal, const Material *material);
|
||||
|
||||
/**
|
||||
* @brief Create default material
|
||||
* @return Default white material
|
||||
*/
|
||||
Material lighting_default_material(void);
|
||||
|
||||
/**
|
||||
* @brief Create a color
|
||||
* @param r Red (0-1)
|
||||
* @param g Green (0-1)
|
||||
* @param b Blue (0-1)
|
||||
* @return Color structure
|
||||
*/
|
||||
Color color_create(float r, float g, float b);
|
||||
|
||||
/**
|
||||
* @brief Multiply color by scalar
|
||||
*/
|
||||
Color color_scale(Color c, float s);
|
||||
|
||||
/**
|
||||
* @brief Add two colors
|
||||
*/
|
||||
Color color_add(Color a, Color b);
|
||||
|
||||
/**
|
||||
* @brief Multiply two colors component-wise
|
||||
*/
|
||||
Color color_multiply(Color a, Color b);
|
||||
|
||||
/**
|
||||
* @brief Clamp color components to 0-1 range
|
||||
*/
|
||||
Color color_clamp(Color c);
|
||||
|
||||
/**
|
||||
* @brief Convert color to grayscale intensity
|
||||
*/
|
||||
float color_to_intensity(Color c);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ASCII3D_LIGHTING_H */
|
||||
Reference in New Issue
Block a user