1 #pragma once 2 3 //******************************************************************************************** 4 //* 5 //* This file is part of Egoboo. 6 //* 7 //* Egoboo is free software: you can redistribute it and/or modify it 8 //* under the terms of the GNU General Public License as published by 9 //* the Free Software Foundation, either version 3 of the License, or 10 //* (at your option) any later version. 11 //* 12 //* Egoboo is distributed in the hope that it will be useful, but 13 //* WITHOUT ANY WARRANTY; without even the implied warranty of 14 //* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 //* General Public License for more details. 16 //* 17 //* You should have received a copy of the GNU General Public License 18 //* along with Egoboo. If not, see <http://www.gnu.org/licenses/>. 19 //* 20 //******************************************************************************************** 21 22 /// @file lighting.h 23 24 #include "physics.h" 25 #include "egoboo_math.h" 26 27 //-------------------------------------------------------------------------------------------- 28 //-------------------------------------------------------------------------------------------- 29 enum 30 { 31 LVEC_PX, ///< light from +x 32 LVEC_MX, ///< light from -x 33 34 LVEC_PY, ///< light from +y 35 LVEC_MY, ///< light from -y 36 37 LVEC_PZ, ///< light from +z 38 LVEC_MZ, ///< light from -z 39 40 LVEC_AMB, ///< light from ambient 41 42 LIGHTING_VEC_SIZE 43 }; 44 45 typedef float lighting_vector_t[LIGHTING_VEC_SIZE]; 46 47 void lighting_vector_evaluate( lighting_vector_t lvec, fvec3_base_t nrm, float * direct, float * amb ); 48 void lighting_vector_sum( lighting_vector_t lvec, fvec3_base_t nrm, float direct, float ambient ); 49 50 //-------------------------------------------------------------------------------------------- 51 struct s_lighting_cache_base 52 { 53 float max_light; ///< max amplitude of direct light 54 float max_delta; ///< max change in the light amplitude 55 lighting_vector_t lighting; ///< light from +x,-x, +y,-y, +z,-z, ambient 56 }; 57 typedef struct s_lighting_cache_base lighting_cache_base_t; 58 59 lighting_cache_base_t * lighting_cache_base_init( lighting_cache_base_t * pdata ); 60 bool_t lighting_cache_base_max_light( lighting_cache_base_t * cache ); 61 bool_t lighting_cache_base_blend( lighting_cache_base_t * cache, lighting_cache_base_t * cnew, float keep ); 62 63 //-------------------------------------------------------------------------------------------- 64 struct s_lighting_cache 65 { 66 float max_light; ///< max amplitude of direct light 67 float max_delta; ///< max change in amplitude of all light 68 69 lighting_cache_base_t low; 70 lighting_cache_base_t hgh; 71 }; 72 typedef struct s_lighting_cache lighting_cache_t; 73 74 lighting_cache_t * lighting_cache_init( lighting_cache_t * pdata ); 75 bool_t lighting_cache_max_light( lighting_cache_t * cache ); 76 bool_t lighting_cache_blend( lighting_cache_t * cache, lighting_cache_t * cnew, float keep ); 77 //-------------------------------------------------------------------------------------------- 78 #define MAXDYNADIST 2700 // Leeway for offscreen lights 79 #define TOTAL_MAX_DYNA 64 // Absolute max number of dynamic lights 80 81 /// A definition of a single in-game dynamic light 82 struct s_dynalight 83 { 84 float distance; ///< The distance from the center of the camera view 85 fvec3_t pos; ///< Light position 86 float level; ///< Light intensity 87 float falloff; ///< Light radius 88 }; 89 90 typedef struct s_dynalight dynalight_t; 91 92 //-------------------------------------------------------------------------------------------- 93 //-------------------------------------------------------------------------------------------- 94 extern float light_a, light_d, light_nrm[3]; 95 96 //-------------------------------------------------------------------------------------------- 97 //-------------------------------------------------------------------------------------------- 98 bool_t lighting_project_cache( lighting_cache_t * dst, lighting_cache_t * src, fmat_4x4_t mat ); 99 bool_t lighting_cache_interpolate( lighting_cache_t * dst, lighting_cache_t * src[], float u, float v ); 100 float lighting_cache_test( lighting_cache_t * src[], float u, float v, float * low_max_diff, float * hgh_max_diff ); 101 102 float lighting_evaluate_cache( lighting_cache_t * src, fvec3_base_t nrm, float z, aabb_t bbox, float * light_amb, float * light_dir ); 103 104 bool_t sum_dyna_lighting( dynalight_t * pdyna, lighting_vector_t lighting, fvec3_base_t nrm ); 105 float dyna_lighting_intensity( dynalight_t * pdyna, fvec3_base_t diff );