1 /* 2 * Copyright (C) Volition, Inc. 1999. All rights reserved. 3 * 4 * All source code herein is the property of Volition, Inc. You may not sell 5 * or otherwise commercially exploit the source or things you created based on the 6 * source. 7 * 8 */ 9 10 11 12 #ifndef _LIGHTING_H 13 #define _LIGHTING_H 14 15 // Light stuff works like this: 16 // At the start of the frame, call light_reset. 17 // For each light source, call light_add_??? functions. 18 // To calculate lighting, do: 19 // call light_filter_reset or light_filter. 20 // set up matrices with g3 functions 21 // call light_rotatate_all to rotate all valid 22 // lights into current coordinates. 23 // call light_apply to fill in lighting for a point. 24 25 #define LT_DIRECTIONAL 0 // A light like a sun 26 #define LT_POINT 1 // A point light, like an explosion 27 #define LT_TUBE 2 // A tube light, like a fluorescent light 28 29 30 typedef struct light { 31 int type; // What type of light this is 32 vec3d vec; // location in world space of a point light or the direction of a directional light or the first point on the tube for a tube light 33 vec3d vec2; // second point on a tube light 34 vec3d local_vec; // rotated light vector 35 vec3d local_vec2; // rotated 2nd light vector for a tube light 36 float intensity; // How bright the light is. 37 float rada, rada_squared; // How big of an area a point light affect. Is equal to l->intensity / MIN_LIGHT; 38 float radb, radb_squared; // How big of an area a point light affect. Is equal to l->intensity / MIN_LIGHT; 39 float r,g,b; // The color components of the light 40 float spec_r,spec_g,spec_b; // The specular color components of the light 41 int light_ignore_objnum; // Don't light this object. Used to optimize weapons casting light on parents. 42 int affected_objnum; // for "unique lights". ie, lights which only affect one object (trust me, its useful) 43 int instance; 44 } light; 45 46 void light_reset(); 47 void light_set_ambient(float ambient_light); 48 49 // Intensity - how strong the light is. 1.0 will cast light around 5meters or so. 50 // r,g,b - only used for colored lighting. Ignored currently. 51 void light_add_directional( vec3d *dir, float intensity, float r, float g, float b, float spec_r = 0.0f, float spec_g = 0.0f, float spec_b = 0.0f, bool specular = false ); 52 void light_add_point( vec3d * pos, float r1, float r2, float intensity, float r, float g, float b, int light_ignore_objnum, float spec_r = 0.0f, float spec_g = 0.0f, float spec_b = 0.0f, bool specular = false ); 53 void light_add_point_unique( vec3d * pos, float r1, float r2, float intensity, float r, float g, float b, int affected_objnum, float spec_r = 0.0f, float spec_g = 0.0f, float spec_b = 0.0f, bool specular = false); 54 void light_add_tube(vec3d *p0, vec3d *p1, float r1, float r2, float intensity, float r, float g, float b, int affected_objnum, float spec_r = 0.0f, float spec_g = 0.0f, float spec_b = 0.0f, bool specular = false); 55 void light_rotate_all(); 56 57 // Reset the list of lights to point to all lights. 58 void light_filter_reset(); 59 60 // Makes a list of only the lights that will affect 61 // the sphere specified by 'pos' and 'rad' and 'objnum'. 62 // Returns number of lights active. 63 int light_filter_push( int objnum, vec3d *pos, float rad ); 64 int light_filter_push_box( vec3d *min, vec3d *max ); 65 void light_filter_pop(); 66 67 // Applies light to a vertex. In order for this to work, 68 // it assumes that one of light_filter or light_filter_reset 69 // have been called. It only uses 'vert' to fill in it's light 70 // fields. 'pos' is position of point, 'norm' is the norm. 71 ubyte light_apply( vec3d *pos, vec3d * norm, float static_light_val ); 72 73 void light_apply_specular(ubyte *param_r, ubyte *param_g, ubyte *param_b, vec3d *pos, vec3d * norm, vec3d * cam); 74 75 // Same as above only does RGB. 76 void light_apply_rgb( ubyte *param_r, ubyte *param_g, ubyte *param_b, vec3d *pos, vec3d * norm, float static_light_val ); 77 78 // return the # of global light sources 79 int light_get_global_count(); 80 81 // Fills direction of global light source N in pos. 82 // Returns 0 if there is no global light. 83 int light_get_global_dir(vec3d *pos, int n); 84 85 // Set to non-zero if we're in a shadow. 86 void light_set_shadow( int state ); 87 88 extern int cell_shaded_lightmap; 89 90 #endif 91