Debian Codegraph @

Descent3/lighting.h

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * Lighting functions and variables
21 *
22 */
23
24 #ifndef _LIGHTING_H
25 #define _LIGHTING_H
26
27 #include "object.h"
28 #include "room.h"
29 #include "terrain.h"
30
31 #define MAX_LIGHT 1.0
32 #define LIGHTMAP_SPACING 5.0
33
34 #define VOLUME_SPACING 10.0
35
36 #define INVISIBLE_VOLUME_ELEMENT 0x01
37
38 #define MAX_SPECULAR_INCREMENTS 4096
39
40 extern float Specular_tables[3][MAX_SPECULAR_INCREMENTS];
41
42 struct dynamic_lightmap {
43 uint16_t *mem_ptr;
44 uint8_t used;
45 };
46
47 struct dynamic_face {
48 uint16_t lmi_handle;
49 };
50
51 struct dynamic_cell {
52 uint16_t cellnum;
53 uint8_t r, g, b;
54 };
55
56 // Sets up our dynamic lighting maps
57 void InitDynamicLighting();
58
59 // Returns the class index of a specified lightmap resolution
60 int GetLightmapClass(int res);
61
62 // Returns an index into the Dynamic_lightmaps array. Index returned is marked as unused
63 int FindFreeDynamicLightmap(int cl);
64
65 // Applies dynamic lighting to the room faces based on the light coming from
66 // an object
67 void ApplyLightingToRooms(vector *, int, float, float, float, float, vector *light_direction = NULL,
68 float dot_range = 0);
69
70 // Clears the used flag for the dynamic lightmaps
71 void ClearDynamicLightmaps();
72
73 // Changes the terrain shading to approximate lighting
74 void ApplyLightingToTerrain(vector *pos, int cellnum, float light_dist, float red_scale, float green_scale,
75 float blue_scale, vector *light_direction = NULL, float dot_range = 0);
76
77 // Gets the viewable lightmap elements
78 void FindValidLightmapElements(face *fp, dynamic_face *dynamic_fp, vector *light_pos, float light_dist);
79 // Does a quad tree algo to find what lightmap elements are viewable from our lightsource
80 int SearchLightQuadTree(face *fp, vector *rvec, vector *uvec, dynamic_face *dynamic_fp, vector *light_pos,
81 float light_dist);
82
83 // Given a float, returns the index into the Ubyte_float_table that this number
84 // corresponds to
85 uint8_t Float_to_ubyte(float fnum);
86
87 extern float Ubyte_to_float[];
88
89 // Draws the shadows that happen to be falling on a particular face
90 void DoShadowsForFace(room *rp, int facenum);
91
92 // Sets the num_timer_faces field in Room structure to correspond to the number of faces
93 // that have flickering lights
94 void CountFaceLights();
95
96 // Goes through all rooms and all faces and lights any faces that have their timer values
97 // set
98 void DoFaceLighting();
99
100 // Sets pulse parameters for an entire room
101 void SetRoomPulse(room *rp, uint8_t pulse_time, uint8_t pulse_offset);
102
103 // Returns the total number of bytes needed for volume lighting in this room
104 int GetVolumeSizeOfRoom(room *rp, int *w = NULL, int *h = NULL, int *d = NULL);
105
106 // Returns a lightmap that can be applied for specular lighting
107 int GetSpecularLightmapForFace(vector *pos, room *rp, face *fp);
108
109 // Kills the lighting that a face casts and dampens all the faces that light influences
110 void DestroyLight(int roomnum, int facenum);
111
112 // Adds to our list of destroyable lights that got destroyed this frame
113 void AddToDestroyableLightList(int roomnum, int facenum);
114
115 // Goes through our destroyable light list and actually kills all the lights
116 void DoDestroyedLightsForFrame();
117
118 // Blends all the edges that need blending for this frame
119 void BlendAllLightingEdges();
120
121 #endif