Debian Codegraph @

editor/radiosity.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 * $Logfile: /DescentIII/Main/editor/radiosity.h $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003-08-26 03:57:38 $
23 * $Author: kevinb $
24 *
25 * Header for radiosity.cpp
26 *
27 * $Log: not supported by cvs2svn $
28 *
29 * 33 3/10/99 7:12p Jason
30 * added smooth specular shading for curved surfaces
31 *
32 * 32 8/10/98 11:25a Jason
33 * added better specular lighting
34 *
35 * 31 6/02/98 6:04p Jason
36 * added specular lightmaps
37 *
38 * 30 5/22/98 3:28p Jason
39 * added specular lighting
40 *
41 * 29 5/20/98 5:44p Jason
42 * incremental checkin for bumpmapping
43 *
44 * 28 5/19/98 2:36p Jason
45 * improved volume light casting
46 *
47 * 27 5/15/98 5:41p Jason
48 * implemented volume lighting system
49 *
50 * 26 3/11/98 5:14p Jason
51 * incremental lighting checkin
52 *
53 * 25 3/06/98 3:23p Jason
54 * added lighting from satellites to indoor rooms
55 *
56 * 24 2/05/98 4:20p Matt
57 * Fixed terrain lighting broken in roomnum/cellnum change
58 *
59 * 23 2/04/98 6:23p Matt
60 * Changed object room number to indicate a terrain cell via a flag. Got
61 * rid of the object flag which used to indicate terrain.
62 *
63 */
64
65 #ifndef RADIOSITY_H
66 #define RADIOSITY_H
67
68 #include "pserror.h"
69 #include "pstypes.h"
70 #include "3d.h"
71 #include "gr.h"
72
73 // Shooting methods
74 #define SM_HEMICUBE 0
75 #define SM_RAYCAST 1
76 // This method makes a switch from RAYCAST to HEMICUBE after all satellites have
77 // been used for lightsources
78 #define SM_SWITCH_AFTER_SATELLITES 2
79
80 #define MAX_VOLUME_ELEMENTS 500
81
82 struct spectra {
83 float r, g, b;
84 };
85
86 // element flags
87 #define EF_IGNORE 1
88 #define EF_SMALL 2 // Don't blend this one into the lightmap - it will corrupt!
89
90 struct rad_element {
91 vector *verts;
92 spectra exitance;
93 float area;
94 uint8_t num_verts;
95 uint8_t flags; // see above
96 };
97
98 #define VEF_REVERSE_SHOOT 1
99
100 struct volume_element {
101 spectra color;
102 vector pos;
103 uint8_t flags;
104 };
105
106 #define ST_ROOM 0 // This is a room surface
107 #define ST_TERRAIN 1 // This is a terrain surface
108 #define ST_SATELLITE 2 // This is a sun on the terrain
109 #define ST_PORTAL 3 // This surface is a portal, don't consider it
110 #define ST_ROOM_OBJECT 4 // This surface is part of an object
111 #define ST_TERRAIN_OBJECT 5 // This surface is part of terrain object
112 #define ST_EXTERNAL_ROOM 6 // This surface is a room outside
113
114 #define SF_TOUCHES_TERRAIN 1
115 #define SF_LIGHTSOURCE 2
116
117 struct rad_surface {
118 float area;
119 spectra emittance;
120 spectra exitance;
121 float reflectivity; // how much light bounces off
122 uint8_t xresolution; // how many elements (resolution x resolution) for this face
123 uint8_t yresolution;
124 rad_element *elements; // list of elements for this surface
125 vector normal; // normal of this surface
126 vector *verts;
127
128 uint8_t surface_type; // See ST_ types above
129
130 int facenum; // facenumber of room
131 int roomnum; // The roomnumber or terrain segment number
132 uint8_t num_verts;
133 uint8_t flags;
134
135 float surface_area, element_area;
136
137 uint8_t x1, y1, x2, y2; // Where in the lightmap our bounds are
138 };
139
140 struct rad_point {
141 vector pos;
142 uint8_t code;
143 };
144
145 extern float *Room_strongest_value[][4];
146
147 extern int Ignore_terrain;
148 extern int Ignore_satellites;
149
150 extern float Ignore_limit;
151 extern float rad_TotalFlux;
152 extern float rad_Convergence;
153
154 extern int rad_StepCount;
155 extern int rad_MaxStep;
156 extern int rad_DoneCalculating;
157
158 extern float rad_TotalUnsent;
159
160 extern rad_surface *rad_MaxSurface;
161
162 extern int rad_NumSurfaces;
163 extern int rad_NumElements;
164
165 extern float *rad_FormFactors;
166 extern rad_surface *rad_Surfaces;
167 extern volume_element *Volume_elements[];
168
169 extern int UseVolumeLights;
170 extern int Calculate_specular_lighting;
171
172 extern int Shoot_from_patch;
173
174 // Tells radiosity renderer to do volume lighting
175 extern int Do_volume_lighting;
176
177 int DoRadiosityRun(int method, rad_surface *light_surfaces, int count);
178 // Sets up our radiosity run
179 void InitRadiosityRun();
180
181 // Initializes the exitances for all surfaces
182 void InitExitance();
183
184 // Gets the spectral emittance for a surface
185 void GetEmittance(rad_surface *surf, spectra *dest);
186
187 // Sets all the elements of a surface to their initial exitance values
188 void SetExitanceForSurface(rad_surface *surf);
189
190 // Find the surface we want to shoot from
191 void UpdateUnsentValues();
192
193 // Does one iteration of ray-casting radiosity
194 int DoRadiosityIteration();
195
196 // Finds the world coordinate center of a element
197 void GetCenterOfElement(rad_element *ep, vector *dest);
198
199 // Finds the world coordinate center of a surface
200 void GetCenterOfSurface(rad_surface *ep, vector *dest);
201
202 // Returns 1 if a src vector can hit dest vector unobstructed
203 int ShootRayFromPoint(vector *src, vector *dest, rad_surface *src_surf, rad_surface *dest_surf);
204
205 // Shoots a ray from the center of the max surface to center of every other element
206 // Also updates the exitances of elements that get hit
207
208 void ShootMaxSurface();
209
210 // Does all the radiosity calculations until done
211 void CalculateRadiosity();
212
213 // returns the amount of unsent flux from a surface
214 float GetUnsentFlux(rad_surface *surface);
215
216 // Shuts down the radiosity stuff, freeing memory, etc
217 void CloseRadiosityRun();
218
219 // Initalizes memory for form factors
220 void SetupFormFactors();
221
222 // Calculates the area of the surfaces and elements in our environment
223 void CalculateArea();
224
225 // Counts the total number of elements we have to work with
226 void CountElements();
227
228 // Returns max color
229 float GetMaxColor(spectra *sp);
230
231 #endif