FS2_Open
Open source remastering of the Freespace 2 engine
lighting.h
Go to the documentation of this file.
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 #define LT_CONE 3 // A cone light, like a flood light
29 
30 #define MAX_LIGHT_LEVELS 16
31 
32 typedef struct light {
33  int type; // What type of light this is
34  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
35  vec3d vec2; // second point on a tube light or direction of a cone light
36  vec3d local_vec; // rotated light vector
37  vec3d local_vec2; // rotated 2nd light vector for a tube light
38  float intensity; // How bright the light is.
39  float rada, rada_squared; // How big of an area a point light affect. Is equal to l->intensity / MIN_LIGHT;
40  float radb, radb_squared; // How big of an area a point light affect. Is equal to l->intensity / MIN_LIGHT;
41  float r,g,b; // The color components of the light
42  float spec_r,spec_g,spec_b; // The specular color components of the light
43  int light_ignore_objnum; // Don't light this object. Used to optimize weapons casting light on parents.
44  int affected_objnum; // for "unique lights". ie, lights which only affect one object (trust me, its useful)
45  float cone_angle; // angle for cone lights
46  float cone_inner_angle; // the inner angle for calculating falloff
47  bool dual_cone; // should the cone be shining in both directions?
48  int instance;
49 } light;
50 
52 
54 {
57 };
58 
60 {
61  SCP_vector<light> AllLights;
62 
63  SCP_vector<int> StaticLightIndices;
64 
65  SCP_vector<int> FilteredLights;
66 
67  SCP_vector<int> BufferedLights;
68 
69  int current_light_index;
70  int current_num_lights;
71 public:
73  {
75  }
76  void addLight(const light *light_ptr);
77  void setLightFilter(int objnum, const vec3d *pos, float rad);
78  bool setLights(const light_indexing_info *info);
79  void resetLightState();
80  int getNumStaticLights();
82 };
83 
84 extern void light_reset();
85 extern void light_set_ambient(float ambient_light);
86 
87 // Intensity - how strong the light is. 1.0 will cast light around 5meters or so.
88 // r,g,b - only used for colored lighting. Ignored currently.
89 extern void light_add_directional(const 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);
90 extern void light_add_point(const 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);
91 extern void light_add_point_unique(const 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);
92 extern void light_add_tube(const vec3d *p0, const 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);
93 extern void light_add_cone(const vec3d * pos, const vec3d * dir, float angle, float inner_angle, bool dual_cone, 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);
94 extern void light_rotate_all();
95 
96 // Makes a list of only the lights that will affect
97 // the sphere specified by 'pos' and 'rad' and 'objnum'.
98 // Returns number of lights active.
99 extern int light_filter_push( int objnum, const vec3d *pos, float rad );
100 extern int light_filter_push_box(const vec3d *min, const vec3d *max);
101 extern void light_filter_pop();
102 
103 // Applies light to a vertex. In order for this to work,
104 // it assumes that one of light_filter have been called.
105 // It only uses 'vert' to fill in it's light
106 // fields. 'pos' is position of point, 'norm' is the norm.
107 ubyte light_apply(const vec3d *pos, const vec3d *norm, float static_light_val);
108 
109 void light_apply_specular(ubyte *param_r, ubyte *param_g, ubyte *param_b, const vec3d *pos, const vec3d * norm, const vec3d * cam);
110 
111 // Same as above only does RGB.
112 void light_apply_rgb( ubyte *param_r, ubyte *param_g, ubyte *param_b, const vec3d *pos, const vec3d *norm, float static_light_val );
113 
114 // return the # of global light sources
115 extern int light_get_global_count();
116 
117 // Fills direction of global light source N in pos.
118 // Returns 0 if there is no global light.
119 extern int light_get_global_dir(vec3d *pos, int n);
120 
121 // Set to non-zero if we're in a shadow.
122 extern void light_set_shadow( int state );
123 
124 bool light_compare_by_type(const light &a, const light &b);
125 #endif
struct light light
void light_apply_specular(ubyte *param_r, ubyte *param_g, ubyte *param_b, const vec3d *pos, const vec3d *norm, const vec3d *cam)
Definition: lighting.cpp:749
int light_filter_push(int objnum, const vec3d *pos, float rad)
Definition: lighting.cpp:416
bool light_compare_by_type(const light &a, const light &b)
Definition: lighting.cpp:1101
int light_filter_push_box(const vec3d *min, const vec3d *max)
Definition: lighting.cpp:526
vec3d local_vec
Definition: lighting.h:36
Definition: pstypes.h:88
hull_check p0
Definition: lua.cpp:5051
bool dual_cone
Definition: lighting.h:47
vec3d local_vec2
Definition: lighting.h:37
void setLightFilter(int objnum, const vec3d *pos, float rad)
Definition: lighting.cpp:1117
GLclampf f
Definition: Glext.h:7097
void resetLightState()
Definition: lighting.cpp:1223
float rada_squared
Definition: lighting.h:39
float spec_b
Definition: lighting.h:42
GLfloat angle
Definition: Glext.h:10324
light_indexing_info bufferLights()
Definition: lighting.cpp:1193
void light_add_cone(const vec3d *pos, const vec3d *dir, float angle, float inner_angle, bool dual_cone, 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)
Definition: lighting.cpp:1050
vec3d vec2
Definition: lighting.h:35
GLdouble GLdouble GLdouble r
Definition: Glext.h:5337
float b
Definition: lighting.h:41
GLboolean GLboolean g
Definition: Glext.h:5781
scene_lights()
Definition: lighting.h:72
float g
Definition: lighting.h:41
GLboolean GLboolean GLboolean GLboolean a
Definition: Glext.h:5781
float rada
Definition: lighting.h:39
float spec_r
Definition: lighting.h:42
int getNumStaticLights()
Definition: lighting.cpp:1218
int light_get_global_count()
Definition: lighting.cpp:608
hull_check p1
Definition: lua.cpp:5052
float cone_angle
Definition: lighting.h:45
void light_add_directional(const 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)
Definition: lighting.cpp:209
bool setLights(const light_indexing_info *info)
Definition: lighting.cpp:1229
int instance
Definition: lighting.h:48
GLclampd n
Definition: Glext.h:7286
unsigned char ubyte
Definition: pstypes.h:62
void light_reset()
Definition: lighting.cpp:150
void light_add_point_unique(const 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)
Definition: lighting.cpp:300
int type
Definition: lighting.h:33
Definition: lighting.h:32
float radb_squared
Definition: lighting.h:40
GLboolean GLboolean GLboolean b
Definition: Glext.h:5781
void light_add_point(const 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)
Definition: lighting.cpp:253
float spec_g
Definition: lighting.h:42
void light_rotate_all()
Definition: lighting.cpp:585
vec3d vec
Definition: lighting.h:34
float radb
Definition: lighting.h:40
void light_apply_rgb(ubyte *param_r, ubyte *param_g, ubyte *param_b, const vec3d *pos, const vec3d *norm, float static_light_val)
Definition: lighting.cpp:899
int light_get_global_dir(vec3d *pos, int n)
Definition: lighting.cpp:621
void light_add_tube(const vec3d *p0, const 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)
Definition: lighting.cpp:343
hull_check pos
Definition: lua.cpp:5050
void light_set_ambient(float ambient_light)
Definition: lighting.cpp:205
void light_set_shadow(int state)
Definition: lighting.cpp:638
void light_filter_pop()
Definition: lighting.cpp:574
float intensity
Definition: lighting.h:38
float cone_inner_angle
Definition: lighting.h:46
ubyte light_apply(const vec3d *pos, const vec3d *norm, float static_light_val)
Definition: lighting.cpp:666
float r
Definition: lighting.h:41
int light_ignore_objnum
Definition: lighting.h:43
SCP_vector< light * > Static_light
Definition: lighting.cpp:36
void addLight(const light *light_ptr)
Definition: lighting.cpp:1106
int affected_objnum
Definition: lighting.h:44