Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
dazzle.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
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
19#if defined(_MSC_VER)
20#pragma once
21#endif
22
23#ifndef DAZZLE_H
24#define DAZZLE_H
25
26#include "always.h"
27#include "vector3.h"
28#include "matrix3d.h"
29#include "rendobj.h"
30#include "wwstring.h"
31#include "proto.h"
32#include "w3derr.h"
33#include "shader.h"
34#include "matrix4.h"
35
36class CameraClass;
39
71
73{
74public:
76 :
78 flare_sizes(0),
79 flare_colors(0),
80 flare_uv(0)
81 {
82 }
83
105
107 {
108 delete[] flare_locations;
109 delete[] flare_sizes;
110 delete[] flare_colors;
111 delete[] flare_uv;
112 }
113
114 unsigned type;
121
122};
123
125class DazzleLayerClass;
126class DazzleTypeClass
127{
128 friend DazzleRenderObjClass;
129 friend DazzleLayerClass;
130
131 TextureClass* primary_texture;
132 TextureClass* secondary_texture;
134 float fadeout_end_sqr;
135 float fadeout_start_sqr;
136 StringClass name;
137 unsigned dazzle_test_color_integer;
138 unsigned dazzle_test_mask_integer;
139 unsigned lensflare_id;
140
141 ShaderClass dazzle_shader;
142 ShaderClass halo_shader;
143
144 float radius;
145
146 DazzleTypeClass(const DazzleInitClass& is);
147 virtual ~DazzleTypeClass();
148public:
149
150 virtual void Calculate_Intensities(
151 float& dazzle_intensity,
152 float& dazzle_size,
153 float& halo_intensity,
154 const Vector3& camera_dir,
155 const Vector3& dazzle_dir,
156 const Vector3& dir_to_dazzle,
157 float distance) const;
158
159 void Set_Dazzle_Shader(const ShaderClass& s); // Set shader for the dazzle type
160 void Set_Halo_Shader(const ShaderClass& s); // Set shader for the dazzle type
161
164
165};
166
167
168// The DazzleLayerClass is for all the dazzles being rendered with a given
169// group of camera settings: for example, different scenes may use different
170// z-buffer settings and in such a case each scene should have a dazzle layer
171// associated with it. (In some special cases a scene may have more than one
172// dazzle layer). A dazzle layer contains visible and invisible lists for
173// each dazzle type. During rendering each dazzle is put on the correct list
174// (a "current dazzle layer" static variable is set before rendering the
175// appropriate scenes to ensure this). After all scenes are rendered, the
176// dazzle layers are rendered one by one with the correct camera settings.
177// NOTE: dazzle layers must be constructed AFTER all the dazzle types have
178// been initialized, since the constructor needs to know how many dazzle types
179// there are.
181
182 friend DazzleRenderObjClass;
183
184 public:
185
186 DazzleLayerClass(void);
187 ~DazzleLayerClass(void);
188
189 // Render all dazzles in this layer (DazzleRenderObj::Render() only sets visibility)
190 void Render(CameraClass* camera);
191
192 private:
193
194 virtual int Get_Visible_Item_Count(unsigned int type) const; // Return visible item count
195// virtual void Get_Visible_Item_Locations(unsigned int type, Vector3* locations) const; // Copy locations of visible items to buffer
196 virtual void Clear_Visible_List(unsigned int type);
197
198 // We have an array of visible lists (one for each dazzle type).
199 DazzleRenderObjClass** visible_lists;
200
201};
202
203class LensflareTypeClass
204{
205 friend DazzleLayerClass;
206 friend DazzleRenderObjClass;
207
208 TextureClass* texture;
210 StringClass name;
211
212 LensflareTypeClass(const LensflareInitClass& is);
213 virtual ~LensflareTypeClass();
214public:
216
218 VertexFormatXYZNDUV2* vertex,
219 int& vertex_count,
220 float screen_x_scale,
221 float screen_y_scale,
222 float dazzle_intensity,
223 const Vector4& transformed_location);
224
226 const Vector4* vertex_coordinates,
227 const Vector2* uv_coordinates,
228 const Vector3* color,
229 int vertex_count,
230 int halo_vertex_count,
231 const Vector2* texture_coordinates);
232
233};
234
235class INIClass;
236
238{
239 friend DazzleLayerClass;
240
242 unsigned type;
243 float current_dazzle_intensity;
244 float current_dazzle_size;
245 float current_halo_intensity;
246 float current_distance;
247 Vector4 transformed_loc;
248 Vector3 current_vloc;
249 Vector3 current_dir;
250 Vector3 dazzle_color;
251 Vector3 halo_color;
252 float lensflare_intensity;
253 float current_scale;
254 float visibility;
255 bool on_list; // This is used to avoid insterting a dazzle into a list twice.
256 float radius; // Used to cast rays against
257 unsigned int creation_time;
258
259 static bool _dazzle_rendering_enabled;
260
261// static void Draw_Debug_Dazzle(int idx);
262 void vis_render_dazzle(SpecialRenderInfoClass & rinfo);
263
264 void Render_Dazzle(CameraClass* camera);
265
266public:
267
268 DazzleRenderObjClass(unsigned type);
269 DazzleRenderObjClass(const char* type_name);
272
273 DazzleRenderObjClass* Succ() { return succ; }
274 const DazzleRenderObjClass* Succ() const { return succ; }
275
277 // Render Object Interface
279 virtual RenderObjClass * Clone(void) const;
280 virtual int Class_ID(void) const { return CLASSID_DAZZLE; }
281
282 virtual void Render(RenderInfoClass & rinfo);
283 virtual void Special_Render(SpecialRenderInfoClass & rinfo);
284 virtual void Set_Transform(const Matrix3D &m);
285 virtual void Get_Obj_Space_Bounding_Sphere(SphereClass & sphere) const;
286 virtual void Get_Obj_Space_Bounding_Box(AABoxClass & box) const;
287 virtual void Scale(float scale) { current_scale*=scale; };
288
289 void Set_Dazzle_Color(const Vector3& col) { dazzle_color=col; }
290 void Set_Halo_Color(const Vector3& col) { halo_color=col; }
291 void Set_Lensflare_Intensity (float intensity) {lensflare_intensity=intensity;}
292
293 unsigned int Get_Dazzle_Type(void) { return type; }
294
295 // Usually, a DazzleRenderObj adds itself to the appropriate visible list
296 // (determined by the current layer) when it is rendered. This does not
297 // work for dazzles with "camera transform off", since they are located in
298 // camera space and the standard worldspace visibility algo will give
299 // unpredictable results for them (they may never have a Render() call).
300 // So for these dazzles, you need to call Set_Layer() after constructing
301 // them (this is instead of putting them in a scene). This function adds
302 // the dazzle to the appropriate visible list. NOTE: It is also called
303 // internally by the Render() function.
304 void Set_Layer(DazzleLayerClass *layer);
305
306 // Persistant object save-load interface
307 // Dazzles save their "dazzle-type" and transform
308 virtual const PersistFactoryClass & Get_Factory (void) const;
309
310 // Set the static "current layer" variable. This variable is used in the
311 // Render() call so that the dazzle knows which list to add itself to if
312 // it is visible. This function must be called before rendering the
313 // scene(s) in which the dazzles are present.
314 static void Set_Current_Dazzle_Layer(DazzleLayerClass *layer);
315
316 static void Init_Type(const DazzleInitClass& i);
317 static void Init_Lensflare(const LensflareInitClass& i);
318 static void Init_From_INI(const INIClass* ini);
319 static unsigned Get_Type_ID(const char* name); // Return the ID of type with given name, or INT_MAX if failed
320 static const char * Get_Type_Name(unsigned int id); // Return the name of the type with the given ID
321 static DazzleTypeClass* Get_Type_Class(unsigned id); // Return dazzle type class pointer, or NULL if not found
322 // The pointer is NOT refcounted - all types are deinitialised
323 // when exiting the level.
324 static unsigned Get_Lensflare_ID(const char* name); // Return the ID of lensflare with given name, or INT_MAX if failed
325 static LensflareTypeClass* Get_Lensflare_Class(unsigned id); // Return lensflare type class pointer, or NULL if not found
326
327 static void Deinit();
328
329 // Install a class derived from DazzleVisibilityClass to add app-specific
330 // visibility determination. The default behavior will ask the scene which
331 // the dazzle is a member of to compute its visibility.
332 static void Install_Dazzle_Visibility_Handler(const DazzleVisibilityClass * visibility_handler);
333
334 // Globally disable/enable dazzle rendering
335 static void Enable_Dazzle_Rendering(bool onoff) { _dazzle_rendering_enabled = onoff; }
336 static bool Is_Dazzle_Rendering_Enabled(void) { return _dazzle_rendering_enabled; }
337};
338
339
347{
348public:
349 virtual float Compute_Dazzle_Visibility( RenderInfoClass & rinfo,
350 DazzleRenderObjClass * dazzle,
351 const Vector3 & point) const;
352};
353
354
362{
364public:
365 DazzlePrototypeClass(void) : DazzleType(0) { }
366
367 virtual const char * Get_Name(void) const { return Name; }
368 virtual int Get_Class_ID(void) const { return RenderObjClass::CLASSID_DAZZLE; }
369 virtual RenderObjClass * Create(void);
370 virtual void DeleteSelf() { delete this; }
371
373
374private:
375
376 StringClass Name;
377 int DazzleType;
378};
379
380
387{
388public:
391
392 virtual int Chunk_Type(void) { return W3D_CHUNK_DAZZLE; }
393 virtual PrototypeClass * Load_W3D(ChunkLoadClass & cload);
394};
395
397
398#endif
Color scale(const Color &a, const Color &b)
Definition GameMtl.cpp:722
@ W3D_CHUNK_DAZZLE
Definition w3d_file.h:483
#define W3DNEWARRAY
Definition always.h:110
#define W3DMPO_GLUE(ARGCLASS)
Definition always.h:120
float dazzle_area
Definition dazzle.h:55
float halo_scale_x
Definition dazzle.h:50
bool use_camera_translation
Definition dazzle.h:44
float dazzle_scale_y
Definition dazzle.h:62
float halo_intensity_pow
Definition dazzle.h:49
Vector3 dazzle_test_color
Definition dazzle.h:58
float dazzle_size_pow
Definition dazzle.h:52
unsigned type
Definition dazzle.h:43
Vector3 halo_color
Definition dazzle.h:60
float dazzle_scale_x
Definition dazzle.h:61
StringClass primary_texture_name
Definition dazzle.h:45
float halo_scale_y
Definition dazzle.h:51
float size_optimization_limit
Definition dazzle.h:65
float radius
Definition dazzle.h:67
float dazzle_intensity
Definition dazzle.h:54
Vector3 dazzle_color
Definition dazzle.h:59
float history_weight
Definition dazzle.h:66
float fadeout_end
Definition dazzle.h:64
float fadeout_start
Definition dazzle.h:63
float halo_intensity
Definition dazzle.h:48
float blink_period
Definition dazzle.h:68
StringClass secondary_texture_name
Definition dazzle.h:46
float blink_on_time
Definition dazzle.h:69
float dazzle_intensity_pow
Definition dazzle.h:53
Vector3 dazzle_direction
Definition dazzle.h:57
float dazzle_direction_area
Definition dazzle.h:56
StringClass lensflare_name
Definition dazzle.h:47
~DazzleLayerClass(void)
Definition dazzle.cpp:1568
void Render(CameraClass *camera)
Definition dazzle.cpp:1580
DazzleLayerClass(void)
Definition dazzle.cpp:1551
virtual PrototypeClass * Load_W3D(ChunkLoadClass &cload)
Definition dazzle.cpp:1727
DazzleLoaderClass(void)
Definition dazzle.h:389
virtual int Chunk_Type(void)
Definition dazzle.h:392
~DazzleLoaderClass(void)
Definition dazzle.h:390
virtual void DeleteSelf()
Definition dazzle.h:370
DazzlePrototypeClass(void)
Definition dazzle.h:365
WW3DErrorType Load_W3D(ChunkLoadClass &cload)
Definition dazzle.cpp:1697
virtual RenderObjClass * Create(void)
Definition dazzle.cpp:1691
virtual const char * Get_Name(void) const
Definition dazzle.h:367
virtual int Get_Class_ID(void) const
Definition dazzle.h:368
static void Init_Lensflare(const LensflareInitClass &i)
Definition dazzle.cpp:703
static void Set_Current_Dazzle_Layer(DazzleLayerClass *layer)
Definition dazzle.cpp:892
DazzleRenderObjClass * Succ()
Definition dazzle.h:273
virtual int Class_ID(void) const
Definition dazzle.h:280
static bool Is_Dazzle_Rendering_Enabled(void)
Definition dazzle.h:336
virtual void Get_Obj_Space_Bounding_Box(AABoxClass &box) const
Definition dazzle.cpp:864
DazzleRenderObjClass(unsigned type)
Definition dazzle.cpp:767
void Set_Lensflare_Intensity(float intensity)
Definition dazzle.h:291
virtual void Special_Render(SpecialRenderInfoClass &rinfo)
Definition dazzle.cpp:1412
void Set_Halo_Color(const Vector3 &col)
Definition dazzle.h:290
virtual void Render(RenderInfoClass &rinfo)
Definition dazzle.cpp:915
static unsigned Get_Lensflare_ID(const char *name)
Definition dazzle.cpp:1323
void Set_Dazzle_Color(const Vector3 &col)
Definition dazzle.h:289
DazzleRenderObjClass & operator=(const DazzleRenderObjClass &)
Definition dazzle.cpp:842
static void Init_From_INI(const INIClass *ini)
Definition dazzle.cpp:565
static void Init_Type(const DazzleInitClass &i)
Definition dazzle.cpp:680
static unsigned Get_Type_ID(const char *name)
Definition dazzle.cpp:1276
static void Enable_Dazzle_Rendering(bool onoff)
Definition dazzle.h:335
static LensflareTypeClass * Get_Lensflare_Class(unsigned id)
Definition dazzle.cpp:1339
const DazzleRenderObjClass * Succ() const
Definition dazzle.h:274
virtual void Set_Transform(const Matrix3D &m)
Definition dazzle.cpp:1261
static const char * Get_Type_Name(unsigned int id)
Definition dazzle.cpp:1293
virtual const PersistFactoryClass & Get_Factory(void) const
Definition dazzle.cpp:1539
virtual RenderObjClass * Clone(void) const
Definition dazzle.cpp:901
void Set_Layer(DazzleLayerClass *layer)
Definition dazzle.cpp:871
static void Deinit()
Definition dazzle.cpp:726
virtual void Get_Obj_Space_Bounding_Sphere(SphereClass &sphere) const
Definition dazzle.cpp:858
static void Install_Dazzle_Visibility_Handler(const DazzleVisibilityClass *visibility_handler)
Definition dazzle.cpp:750
unsigned int Get_Dazzle_Type(void)
Definition dazzle.h:293
virtual void Scale(float scale)
Definition dazzle.h:287
static DazzleTypeClass * Get_Type_Class(unsigned id)
Definition dazzle.cpp:1310
void Set_Dazzle_Shader(const ShaderClass &s)
Definition dazzle.cpp:461
TextureClass * Get_Dazzle_Texture()
Definition dazzle.cpp:475
TextureClass * Get_Halo_Texture()
Definition dazzle.cpp:488
virtual void Calculate_Intensities(float &dazzle_intensity, float &dazzle_size, float &halo_intensity, const Vector3 &camera_dir, const Vector3 &dazzle_dir, const Vector3 &dir_to_dazzle, float distance) const
Definition dazzle.cpp:501
void Set_Halo_Shader(const ShaderClass &s)
Definition dazzle.cpp:468
virtual float Compute_Dazzle_Visibility(RenderInfoClass &rinfo, DazzleRenderObjClass *dazzle, const Vector3 &point) const
Definition dazzle.cpp:1656
Definition INI.H:80
Vector4 * flare_uv
Definition dazzle.h:120
StringClass texture_name
Definition dazzle.h:115
float * flare_sizes
Definition dazzle.h:118
unsigned type
Definition dazzle.h:114
LensflareInitClass(const LensflareInitClass &lic)
Definition dazzle.h:84
Vector3 * flare_colors
Definition dazzle.h:119
float * flare_locations
Definition dazzle.h:117
void Render_Arrays(const Vector4 *vertex_coordinates, const Vector2 *uv_coordinates, const Vector3 *color, int vertex_count, int halo_vertex_count, const Vector2 *texture_coordinates)
TextureClass * Get_Texture()
Definition dazzle.cpp:358
void Generate_Vertex_Buffers(VertexFormatXYZNDUV2 *vertex, int &vertex_count, float screen_x_scale, float screen_y_scale, float dazzle_intensity, const Vector4 &transformed_location)
Definition dazzle.cpp:367
PrototypeClass(void)
Definition proto.h:90
PrototypeLoaderClass(void)
Definition proto.h:139
RenderObjClass(void)
Definition rendobj.cpp:170
DazzleLoaderClass _DazzleLoader
Definition dazzle.cpp:228
WW3DErrorType
Definition w3derr.h:51