2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
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
10 * $Logfile: /Freespace2/code/Nebula/Neb.cpp $
18 * Revision 1.6 2002/06/09 04:41:23 relnev
19 * added copyright header
21 * Revision 1.5 2002/06/01 03:32:00 relnev
22 * fix texture loading mistake.
24 * enable some d3d stuff for opengl also
26 * Revision 1.4 2002/05/26 20:22:48 theoddone33
27 * Most of network/ works
29 * Revision 1.3 2002/05/07 03:16:47 theoddone33
30 * The Great Newline Fix
32 * Revision 1.2 2002/05/04 04:36:56 theoddone33
33 * More changes, took out a lot of the sound stuff which will bite later but
36 * Revision 1.1.1.1 2002/05/03 03:28:10 root
40 * 50 8/30/99 5:01p Dave
41 * Made d3d do less state changing in the nebula. Use new chat server for
44 * 49 8/10/99 6:54p Dave
45 * Mad optimizations. Added paging to the nebula effect.
47 * 48 8/05/99 2:05a Dave
50 * 47 7/30/99 10:55a Anoop
51 * Hmm. Fixed release build problem again, with area-rotated bitmaps.
53 * 46 7/29/99 10:47p Dave
54 * Standardized D3D fogging using vertex fog. Shook out Savage 4 bugs.
56 * 44 7/29/99 12:05a Dave
57 * Nebula speed optimizations.
59 * 43 7/19/99 7:20p Dave
60 * Beam tooling. Specialized player-killed-self messages. Fixed d3d nebula
63 * 42 7/18/99 5:20p Dave
64 * Jump node icon. Fixed debris fogging. Framerate warning stuff.
66 * 41 7/13/99 1:15p Dave
67 * 32 bit support. Whee!
69 * 40 7/09/99 5:54p Dave
70 * Seperated cruiser types into individual types. Added tons of new
71 * briefing icons. Campaign screen.
73 * 39 7/07/99 10:44a Jamesa
74 * Make sure the nebula regens properly after loading a mission.
76 * 38 6/11/99 2:32p Dave
77 * Toned down nebula brightness a bit.
79 * 37 5/26/99 3:39p Dave
80 * Fixed nebula regeneration problem. Removed optimizations from
83 * 36 5/26/99 11:46a Dave
84 * Added ship-blasting lighting and made the randomization of lighting
85 * much more customizable.
87 * 35 5/24/99 5:45p Dave
88 * Added detail levels to the nebula, with a decent speedup. Split nebula
89 * lightning into its own section.
105 #include "freespace.h"
108 #include "starfield.h"
113 #include "grinternal.h"
115 #include "alphacolors.h"
117 // --------------------------------------------------------------------------------------------------------
118 // NEBULA DEFINES/VARS
121 // #define NEB2_THUMBNAIL
124 3D CARDS THAT FOG PROPERLY
130 3D CARDS THAT DON'T FOG PROPERLY
135 // if nebula rendering is active (DCF stuff - not mission specific)
136 int Neb2_render_mode = NEB2_RENDER_NONE;
138 // array of neb2 poofs
139 char Neb2_poof_filenames[MAX_NEB2_POOFS][MAX_FILENAME_LEN] = {
140 "", "", "", "", "", ""
142 int Neb2_poofs[MAX_NEB2_POOFS] = { -1, -1, -1, -1, -1, -1 };
143 int Neb2_poof_flags = ( (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5) );
144 int Neb2_poof_count = 0;
146 // array of neb2 bitmaps
147 char Neb2_bitmap_filenames[MAX_NEB2_BITMAPS][MAX_FILENAME_LEN] = {
148 "", "", "", "", "", ""
150 int Neb2_bitmap[MAX_NEB2_BITMAPS] = { -1, -1, -1, -1, -1, -1 };
151 int Neb2_bitmap_count = 0;
153 // texture to use for this level
154 char Neb2_texture_name[MAX_FILENAME_LEN] = "";
157 #define NF_USED (1<<0) // if this nebula slot is used
159 float max_rotation = 3.75f;
160 float neb2_flash_fade = 0.3f;
162 // fog values for different ship types
163 float Neb_ship_fog_vals_glide[MAX_SHIP_TYPE_COUNTS][2] = {
164 {0.0f, 0.0f}, // SHIP_TYPE_NONE
165 {10.0f, 500.0f}, // SHIP_TYPE_CARGO
166 {10.0f, 500.0f}, // SHIP_TYPE_FIGHTER_BOMBER
167 {10.0f, 600.0f}, // SHIP_TYPE_CRUISER
168 {10.0f, 600.0f}, // SHIP_TYPE_FREIGHTER
169 {10.0f, 750.0f}, // SHIP_TYPE_CAPITAL
170 {10.0f, 500.0f}, // SHIP_TYPE_TRANSPORT
171 {10.0f, 500.0f}, // SHIP_TYPE_REPAIR_REARM
172 {10.0f, 500.0f}, // SHIP_TYPE_NAVBUOY
173 {10.0f, 500.0f}, // SHIP_TYPE_SENTRYGUN
174 {10.0f, 600.0f}, // SHIP_TYPE_ESCAPEPOD
175 {10.0f, 1000.0f}, // SHIP_TYPE_SUPERCAP
176 {10.0f, 500.0f}, // SHIP_TYPE_STEALTH
177 {10.0f, 500.0f}, // SHIP_TYPE_FIGHTER
178 {10.0f, 500.0f}, // SHIP_TYPE_BOMBER
179 {10.0f, 750.0f}, // SHIP_TYPE_DRYDOCK
180 {10.0f, 600.0f}, // SHIP_TYPE_AWACS
181 {10.0f, 600.0f}, // SHIP_TYPE_GAS_MINER
182 {10.0f, 600.0f}, // SHIP_TYPE_CORVETTE
183 {10.0f, 1000.0f}, // SHIP_TYPE_KNOSSOS_DEVICE
185 float Neb_ship_fog_vals_d3d[MAX_SHIP_TYPE_COUNTS][2] = {
186 {0.0f, 0.0f}, // SHIP_TYPE_NONE
187 {10.0f, 500.0f}, // SHIP_TYPE_CARGO
188 {10.0f, 500.0f}, // SHIP_TYPE_FIGHTER_BOMBER
189 {10.0f, 600.0f}, // SHIP_TYPE_CRUISER
190 {10.0f, 600.0f}, // SHIP_TYPE_FREIGHTER
191 {10.0f, 750.0f}, // SHIP_TYPE_CAPITAL
192 {10.0f, 500.0f}, // SHIP_TYPE_TRANSPORT
193 {10.0f, 500.0f}, // SHIP_TYPE_REPAIR_REARM
194 {10.0f, 500.0f}, // SHIP_TYPE_NAVBUOY
195 {10.0f, 500.0f}, // SHIP_TYPE_SENTRYGUN
196 {10.0f, 600.0f}, // SHIP_TYPE_ESCAPEPOD
197 {10.0f, 1000.0f}, // SHIP_TYPE_SUPERCAP
198 {10.0f, 500.0f}, // SHIP_TYPE_STEALTH
199 {10.0f, 500.0f}, // SHIP_TYPE_FIGHTER
200 {10.0f, 500.0f}, // SHIP_TYPE_BOMBER
201 {10.0f, 750.0f}, // SHIP_TYPE_DRYDOCK
202 {10.0f, 600.0f}, // SHIP_TYPE_AWACS
203 {10.0f, 600.0f}, // SHIP_TYPE_GAS_MINER
204 {10.0f, 600.0f}, // SHIP_TYPE_CORVETTE
205 {10.0f, 1000.0f}, // SHIP_TYPE_KNOSSOS_DEVICE
208 // fog near and far values for rendering the background nebula
209 #define NEB_BACKG_FOG_NEAR_GLIDE 2.5f
210 #define NEB_BACKG_FOG_NEAR_D3D 4.5f
211 #define NEB_BACKG_FOG_FAR_GLIDE 10.0f
212 #define NEB_BACKG_FOG_FAR_D3D 10.0f
213 float Neb_backg_fog_near = NEB_BACKG_FOG_NEAR_GLIDE;
214 float Neb_backg_fog_far = NEB_BACKG_FOG_FAR_GLIDE;
217 int pneb_tried = 0; // total pnebs tried to render
218 int pneb_tossed_alpha = 0; // pnebs tossed because of alpha optimization
219 int pneb_tossed_dot = 0; // pnebs tossed because of dot product
220 int pneb_tossed_off = 0; // pnebs tossed because of being offscree
221 int neb_tried = 0; // total nebs tried
222 int neb_tossed_alpha = 0; // nebs tossed because of alpha
223 int neb_tossed_dot = 0; // nebs tossed because of dot product
224 int neb_tossed_count = 0; // nebs tossed because of max render count
226 // the AWACS suppresion level for the nebula
227 float Neb2_awacs = -1.0f;
229 // how many "slices" are in the current player nebuls
232 cube_poof Neb2_cubes[MAX_CPTS][MAX_CPTS][MAX_CPTS];
234 // nebula detail level
235 typedef struct neb2_detail {
236 float max_alpha_glide; // max alpha for this detail level in Glide
237 float max_alpha_d3d; // max alpha for this detail level in D3d
238 float break_alpha; // break alpha (below which, poofs don't draw). this affects the speed and visual quality a lot
239 float break_x, break_y; // x and y alpha fade/break values. adjust alpha on the polys as they move offscreen
240 float cube_dim; // total dimension of player poof cube
241 float cube_inner; // inner radius of the player poof cube
242 float cube_outer; // outer radius of the player pood cube
243 float prad; // radius of the poofs
244 float wj, hj, dj; // width, height, depth jittering. best left at 1.0
246 neb2_detail Neb2_detail[MAX_DETAIL_LEVEL] = {
247 { // lowest detail level
248 0.575f, // max alpha for this detail level in Glide
249 0.71f, // max alpha for this detail level in D3d
250 0.13f, // break alpha (below which, poofs don't draw). this affects the speed and visual quality a lot
251 150.0f, 150.0f / 1.3333f, // x and y alpha fade/break values. adjust alpha on the polys as they move offscreen
252 510.0f, // total dimension of player poof cube
253 50.0f, // inner radius of the player poof cube
254 250.0f, // outer radius of the player pood cube
255 120.0f, // radius of the poofs
256 1.0f, 1.0f, 1.0f // width, height, depth jittering. best left at 1.0
258 { // 2nd lowest detail level
259 0.575f, // max alpha for this detail level in Glide
260 0.71f, // max alpha for this detail level in D3d
261 0.125f, // break alpha (below which, poofs don't draw). this affects the speed and visual quality a lot
262 300.0f, 300.0f / 1.3333f, // x and y alpha fade/break values. adjust alpha on the polys as they move offscreen
263 550.0f, // total dimension of player poof cube
264 100.0f, // inner radius of the player poof cube
265 250.0f, // outer radius of the player pood cube
266 125.0f, // radius of the poofs
267 1.0f, 1.0f, 1.0f // width, height, depth jittering. best left at 1.0
269 { // 2nd highest detail level
270 0.575f, // max alpha for this detail level in Glide
271 0.71f, // max alpha for this detail level in D3d
272 0.1f, // break alpha (below which, poofs don't draw). this affects the speed and visual quality a lot
273 300.0f, 300.0f / 1.3333f, // x and y alpha fade/break values. adjust alpha on the polys as they move offscreen
274 550.0f, // total dimension of player poof cube
275 150.0f, // inner radius of the player poof cube
276 250.0f, // outer radius of the player pood cube
277 125.0f, // radius of the poofs
278 1.0f, 1.0f, 1.0f // width, height, depth jittering. best left at 1.0
280 { // higest detail level
281 0.475f, // max alpha for this detail level in Glide
282 0.575f, // max alpha for this detail level in D3d
283 0.05f, // break alpha (below which, poofs don't draw). this affects the speed and visual quality a lot
284 200.0f, 200.0f / 1.3333f, // x and y alpha fade/break values. adjust alpha on the polys as they move offscreen
285 750.0f, // total dimension of player poof cube
286 200.0f, // inner radius of the player poof cube
287 360.0f, // outer radius of the player pood cube
288 150.0f, // radius of the poofs
289 1.0f, 1.0f, 1.0f // width, height, depth jittering. best left at 1.0
292 neb2_detail *Nd = &Neb2_detail[MAX_DETAIL_LEVEL - 2];
294 int Neb2_background_color[3] = {0, 0, 255}; // rgb background color (used for lame rendering)
298 // --------------------------------------------------------------------------------------------------------
299 // NEBULA FORWARD DECLARATIONS
302 // return the alpha the passed poof should be rendered with, for a 2 shell nebula
303 float neb2_get_alpha_2shell(float inner_radius, float outer_radius, float magic_num, vector *v);
305 // return an alpha value for a bitmap offscreen based upon "break" value
306 float neb2_get_alpha_offscreen(float sx, float sy, float incoming_alpha);
308 // do a pre-render of the background nebula
309 void neb2_pre_render(vector *eye_pos, matrix *eye_orient);
311 // fill in the position of the eye for this frame
312 void neb2_get_eye_pos(vector *eye);
314 // fill in the eye orient for this frame
315 void neb2_get_eye_orient(matrix *eye);
317 // get a (semi) random bitmap to use for a poof
318 int neb2_get_bitmap();
320 // regenerate the player nebula
324 // --------------------------------------------------------------------------------------------------------
328 // initialize neb2 stuff at game startup
333 // read in the nebula.tbl
334 read_file_text("nebula.tbl");
337 // background bitmaps
338 Neb2_bitmap_count = 0;
339 while(!optional_string("#end")){
341 required_string("+Nebula:");
342 stuff_string(name, F_NAME, NULL);
344 if(Neb2_bitmap_count < MAX_NEB2_BITMAPS){
345 strcpy(Neb2_bitmap_filenames[Neb2_bitmap_count++], name);
351 while(!optional_string("#end")){
353 required_string("+Poof:");
354 stuff_string(name, F_NAME, NULL);
356 if(Neb2_poof_count < MAX_NEB2_POOFS){
357 strcpy(Neb2_poof_filenames[Neb2_poof_count++], name);
361 // should always have 6 neb poofs
362 Assert(Neb2_poof_count == 6);
366 void neb2_set_detail_level(int level)
370 Nd = &Neb2_detail[0];
373 if(level >= MAX_DETAIL_LEVEL){
374 Nd = &Neb2_detail[MAX_DETAIL_LEVEL-1];
378 Nd = &Neb2_detail[level];
380 // regen the player neb
384 // initialize nebula stuff - call from game_post_level_init(), so the mission has been loaded
385 void neb2_level_init()
389 // standalone servers can bail here
390 if(Game_mode & GM_STANDALONE_SERVER){
394 // if the mission is not a fullneb mission, skip
395 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
396 Neb2_render_mode = NEB2_RENDER_NONE;
402 if(gr_screen.mode == GR_DIRECT3D){
403 max_alpha_player = NEB2_MAX_ALPHA_D3D;
405 max_alpha_player = NEB2_MAX_ALPHA_GLIDE;
409 // by default we'll use pof rendering
410 Neb2_render_mode = NEB2_RENDER_POF;
411 stars_set_background_model(BACKGROUND_MODEL_FILENAME, Neb2_texture_name);
413 // load in all nebula bitmaps
414 for(idx=0; idx<Neb2_poof_count; idx++){
415 if(Neb2_poofs[idx] < 0){
416 Neb2_poofs[idx] = bm_load(Neb2_poof_filenames[idx]);
421 pneb_tossed_alpha = 0;
424 neb_tossed_alpha = 0;
426 neb_tossed_count = 0;
428 // setup proper fogging values
429 switch(gr_screen.mode){
431 Neb_backg_fog_near = NEB_BACKG_FOG_NEAR_GLIDE;
432 Neb_backg_fog_far = NEB_BACKG_FOG_FAR_GLIDE;
436 Neb_backg_fog_near = NEB_BACKG_FOG_NEAR_D3D;
437 Neb_backg_fog_far = NEB_BACKG_FOG_FAR_D3D;
440 Assert(Fred_running);
450 // shutdown nebula stuff
451 void neb2_level_close()
455 // standalone servers can bail here
456 if(Game_mode & GM_STANDALONE_SERVER){
460 // if the mission is not a fullneb mission, skip
461 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
465 // unload all nebula bitmaps
466 for(idx=0; idx<Neb2_poof_count; idx++){
467 if(Neb2_poofs[idx] >= 0){
468 bm_unload(Neb2_poofs[idx]);
469 Neb2_poofs[idx] = -1;
473 // unflag the mission as being fullneb so stuff doesn't fog in the techdata room :D
474 The_mission.flags &= ~MISSION_FLAG_FULLNEB;
477 // call before beginning all rendering
478 void neb2_render_setup(vector *eye_pos, matrix *eye_orient)
480 // standalone servers can bail here
481 if(Game_mode & GM_STANDALONE_SERVER){
485 // if the mission is not a fullneb mission, skip
486 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
490 // pre-render the real background nebula
491 neb2_pre_render(eye_pos, eye_orient);
499 // load in all nebula bitmaps
500 for(idx=0; idx<Neb2_poof_count; idx++){
501 if((Neb2_poofs[idx] >= 0) && (Neb2_poof_flags & (1<<idx))){
502 bm_page_in_texture(Neb2_poofs[idx]);
507 // should we not render this object because its obscured by the nebula?
508 int neb_skip_opt = 1;
511 neb_skip_opt = !neb_skip_opt;
513 dc_printf("Using neb object skipping!\n");
515 dc_printf("Not using neb object skipping!\n");
518 int neb2_skip_render(object *objp, float z_depth)
520 float fog_near, fog_far;
522 // if we're never skipping
528 if(Neb2_render_mode == NEB2_RENDER_LAME){
532 // get near and far fog values based upon object type and rendering mode
533 neb2_get_fog_values(&fog_near, &fog_far, objp);
536 switch( objp->type ) {
537 // some objects we always render
545 // any weapon over 500 meters away
547 if(z_depth >= 500.0f){
552 // any small ship over the fog limit, or any cruiser 50% further than the fog limit
555 if((objp->instance >= 0) && (Ships[objp->instance].ship_info_index >= 0)){
556 sip = &Ship_info[Ships[objp->instance].ship_info_index];
561 // small ships over the fog limit by a small factor
562 if((sip->flags & SIF_SMALL_SHIP) && (z_depth >= (fog_far * 1.3f))){
567 if((sip->flags & SIF_BIG_SHIP) && (z_depth >= (fog_far * 2.0f))){
572 if((sip->flags & SIF_HUGE_SHIP) && (z_depth >= (fog_far * 3.0f))){
577 // any fireball over the fog limit for small ships
580 if(z_depth >= fog_far){
587 // any debris over the fog limit for small ships
590 if(z_depth >= fog_far){
597 // any asteroids 50% farther than the fog limit for small ships
599 if(z_depth >= (fog_far * 1.5f)){
604 // any countermeasures over 100 meters away
606 if(z_depth >= 100.0f){
611 // hmmm. unknown object type - should probably let it through
620 float neb2_get_lod_scale(int objnum)
626 if((objnum < 0) || (objnum >= MAX_OBJECTS) || (Objects[objnum].type != OBJ_SHIP) || (Objects[objnum].instance < 0) || (Objects[objnum].instance >= MAX_SHIPS)){
629 shipp = &Ships[Objects[objnum].instance];
630 sip = &Ship_info[shipp->ship_info_index];
633 if(sip->flags & SIF_SMALL_SHIP){
635 } else if(sip->flags & SIF_BIG_SHIP){
644 // --------------------------------------------------------------------------------------------------------
645 // NEBULA FORWARD DEFINITIONS
648 // return the alpha the passed poof should be rendered with, for a 2 shell nebula
649 float neb2_get_alpha_2shell(float inner_radius, float outer_radius, float magic_num, vector *v)
655 // get the eye position
656 neb2_get_eye_pos(&eye_pos);
658 // determine what alpha to draw this bitmap with
659 // higher alpha the closer the bitmap gets to the eye
660 dist = vm_vec_dist_quick(&eye_pos, v);
662 // if the point is inside the inner radius, alpha is based on distance to the player's eye,
663 // becoming more transparent as it gets close
664 if(dist <= inner_radius){
665 // alpha per meter between the magic # and the inner radius
666 alpha = Nd->max_alpha_glide / (inner_radius - magic_num);
668 // above value times the # of meters away we are
669 alpha *= (dist - magic_num);
670 return alpha < 0.0f ? 0.0f : alpha;
672 // if the point is outside the inner radius, it starts out as completely transparent at max
673 // outer radius, and becomes more opaque as it moves towards inner radius
674 else if(dist <= outer_radius){
675 // alpha per meter between the outer radius and the inner radius
676 alpha = Nd->max_alpha_glide / (outer_radius - inner_radius);
678 // above value times the range between the outer radius and the poof
679 return alpha < 0.0f ? 0.0f : alpha * (outer_radius - dist);
682 // otherwise transparent
686 // return an alpha value for a bitmap offscreen based upon "break" value
687 float neb2_get_alpha_offscreen(float sx, float sy, float incoming_alpha)
690 float per_pixel_x = incoming_alpha / (float)Nd->break_x;
691 float per_pixel_y = incoming_alpha / (float)Nd->break_y;
692 int off_x = ((sx < 0.0f) || (sx > (float)gr_screen.max_w));
693 int off_y = ((sy < 0.0f) || (sy > (float)gr_screen.max_h));
694 float off_x_amount = 0.0f;
695 float off_y_amount = 0.0f;
697 // determine how many pixels outside we are
700 off_x_amount = fl_abs(sx);
702 off_x_amount = sx - (float)gr_screen.max_w;
707 off_y_amount = fl_abs(sy);
709 off_y_amount = sy - (float)gr_screen.max_h;
715 // offscreen X and Y - and Y is greater
716 if(off_y && (off_y_amount > off_x_amount)){
717 alpha = incoming_alpha - (off_y_amount * per_pixel_y);
719 alpha = incoming_alpha - (off_x_amount * per_pixel_x);
724 alpha = incoming_alpha - (off_y_amount * per_pixel_y);
726 // should never get here
731 return alpha < 0.0f ? 0.0f : alpha;
734 // -------------------------------------------------------------------------------------------------
735 // WACKY LOCAL PLAYER NEBULA STUFF
743 float ws = Nd->cube_dim / (float)Neb2_slices;
744 float hs = Nd->cube_dim / (float)Neb2_slices;
745 float ds = Nd->cube_dim / (float)Neb2_slices;
747 // get the eye position
748 neb2_get_eye_pos(&eye_pos);
750 // check left, right (0, and 1, x and -x)
751 if(cube_cen.x - eye_pos.x > ws){
754 } else if(eye_pos.x - cube_cen.x > ws){
759 // check up, down (2, and 3, y and -y)
760 if(cube_cen.y - eye_pos.y > hs){
763 } else if(eye_pos.y - cube_cen.y > hs){
768 // check front, back (4, and 5, z and -z)
769 if(cube_cen.z - eye_pos.z > ds){
772 } else if(eye_pos.z - cube_cen.z > ds){
781 void neb2_copy(int xyz, int src, int dest)
787 for(idx1=0; idx1<Neb2_slices; idx1++){
788 for(idx2=0; idx2<Neb2_slices; idx2++){
789 Neb2_cubes[dest][idx1][idx2] = Neb2_cubes[src][idx1][idx2];
794 for(idx1=0; idx1<Neb2_slices; idx1++){
795 for(idx2=0; idx2<Neb2_slices; idx2++){
796 Neb2_cubes[idx1][dest][idx2] = Neb2_cubes[idx1][src][idx2];
801 for(idx1=0; idx1<Neb2_slices; idx1++){
802 for(idx2=0; idx2<Neb2_slices; idx2++){
803 Neb2_cubes[idx1][idx2][dest] = Neb2_cubes[idx1][idx2][src];
813 void neb2_gen_slice(int xyz, int src, vector *cube_center)
816 float h_incw, h_inch, h_incd;
821 ws = Nd->cube_dim / (float)Neb2_slices;
823 hs = Nd->cube_dim / (float)Neb2_slices;
825 ds = Nd->cube_dim / (float)Neb2_slices;
827 cube_corner = *cube_center;
828 cube_corner.x -= (Nd->cube_dim / 2.0f);
829 cube_corner.y -= (Nd->cube_dim / 2.0f);
830 cube_corner.z -= (Nd->cube_dim / 2.0f);
833 for(idx1=0; idx1<Neb2_slices; idx1++){
834 for(idx2=0; idx2<Neb2_slices; idx2++){
835 v = &Neb2_cubes[src][idx1][idx2].pt;
837 v->x = h_incw + (ws * (float)src) + frand_range(-Nd->wj, Nd->wj);
838 v->y = h_inch + (hs * (float)idx1) + frand_range(-Nd->hj, Nd->hj);
839 v->z = h_incd + (ds * (float)idx2) + frand_range(-Nd->dj, Nd->dj);
840 vm_vec_add2(v, &cube_corner);
843 Neb2_cubes[src][idx1][idx2].bmap = neb2_get_bitmap();
845 // set the rotation speed
846 Neb2_cubes[src][idx1][idx2].rot = 0.0f;
847 Neb2_cubes[src][idx1][idx2].rot_speed = frand_range(-max_rotation, max_rotation);
848 Neb2_cubes[src][idx1][idx2].flash = 0.0f;
853 for(idx1=0; idx1<Neb2_slices; idx1++){
854 for(idx2=0; idx2<Neb2_slices; idx2++){
855 v = &Neb2_cubes[idx1][src][idx2].pt;
857 v->x = h_incw + (ws * (float)idx1) + frand_range(-Nd->wj, Nd->wj);
858 v->y = h_inch + (hs * (float)src) + frand_range(-Nd->hj, Nd->hj);
859 v->z = h_incd + (ds * (float)idx2) + frand_range(-Nd->dj, Nd->dj);
860 vm_vec_add2(v, &cube_corner);
863 Neb2_cubes[idx1][src][idx2].bmap = neb2_get_bitmap();
865 // set the rotation speed
866 Neb2_cubes[idx1][src][idx2].rot = 0.0f;
867 Neb2_cubes[idx1][src][idx2].rot_speed = frand_range(-max_rotation, max_rotation);
868 Neb2_cubes[src][idx1][idx2].flash = 0.0f;
873 for(idx1=0; idx1<Neb2_slices; idx1++){
874 for(idx2=0; idx2<Neb2_slices; idx2++){
875 v = &Neb2_cubes[idx1][idx2][src].pt;
877 v->x = h_incw + (ws * (float)idx1) + frand_range(-Nd->wj, Nd->wj);
878 v->y = h_inch + (hs * (float)idx2) + frand_range(-Nd->hj, Nd->hj);
879 v->z = h_incd + (ds * (float)src) + frand_range(-Nd->dj, Nd->dj);
880 vm_vec_add2(v, &cube_corner);
883 Neb2_cubes[idx1][idx2][src].bmap = neb2_get_bitmap();
885 // set the rotation speed
886 Neb2_cubes[idx1][idx2][src].rot = 0.0f;
887 Neb2_cubes[idx1][idx2][src].rot_speed = frand_range(-max_rotation, max_rotation);
888 Neb2_cubes[src][idx1][idx2].flash = 0.0f;
898 // regenerate the player nebula
905 mprintf(("Regenerating local nebula!\n"));
907 // get eye position and orientation
908 neb2_get_eye_pos(&eye_pos);
909 neb2_get_eye_orient(&eye_orient);
911 // determine the corner of the cube
914 // generate slices of the cube
915 for(idx=0; idx<Neb2_slices; idx++){
916 neb2_gen_slice(0, idx, &cube_cen);
920 float max_area = 100000000.0f;
923 dc_get_arg(ARG_FLOAT);
924 max_area = Dc_arg_float;
927 float g3_draw_rotated_bitmap_area(vertex *pnt, float angle, float rad, uint tmap_flags, float area);
929 int frames_total = 0;
932 void neb2_render_player()
935 int idx1, idx2, idx3;
943 float frame_area = max_area;
944 float total_area = 0.0f;
947 // standalone servers can bail here
948 if(Game_mode & GM_STANDALONE_SERVER){
952 // if the mission is not a fullneb mission, skip
953 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
962 // don't render in lame mode
963 if((Neb2_render_mode == NEB2_RENDER_LAME) || (Neb2_render_mode == NEB2_RENDER_NONE)){
967 // get eye position and orientation
968 neb2_get_eye_pos(&eye_pos);
969 neb2_get_eye_orient(&eye_orient);
971 // maybe swap stuff around if the player crossed a "border"
972 for(idx2=0; idx2<3; idx2++){
973 switch(crossed_border()){
978 cube_cen.x -= Nd->cube_dim / (float)Neb2_slices;
979 for(idx1=Neb2_slices-1; idx1>0; idx1--){
980 neb2_copy(0, idx1-1, idx1);
982 neb2_gen_slice(0, 0, &cube_cen);
986 cube_cen.x += Nd->cube_dim / (float)Neb2_slices;
987 for(idx1=0; idx1<Neb2_slices-1; idx1++){
988 neb2_copy(0, idx1+1, idx1);
990 neb2_gen_slice(0, Neb2_slices - 1, &cube_cen);
994 cube_cen.y -= Nd->cube_dim / (float)Neb2_slices;
995 for(idx1=Neb2_slices-1; idx1>0; idx1--){
996 neb2_copy(1, idx1-1, idx1);
998 neb2_gen_slice(1, 0, &cube_cen);
1002 cube_cen.y += Nd->cube_dim / (float)Neb2_slices;
1003 for(idx1=0; idx1<Neb2_slices-1; idx1++){
1004 neb2_copy(1, idx1+1, idx1);
1006 neb2_gen_slice(1, Neb2_slices - 1, &cube_cen);
1010 cube_cen.z -= Nd->cube_dim / (float)Neb2_slices;
1011 for(idx1=Neb2_slices-1; idx1>0; idx1--){
1012 neb2_copy(2, idx1-1, idx1);
1014 neb2_gen_slice(2, 0, &cube_cen);
1018 cube_cen.z += Nd->cube_dim / (float)Neb2_slices;
1019 for(idx1=0; idx1<Neb2_slices-1; idx1++){
1020 neb2_copy(2, idx1+1, idx1);
1022 neb2_gen_slice(2, Neb2_slices - 1, &cube_cen);
1027 // if we've switched nebula rendering off
1028 if(Neb2_render_mode == NEB2_RENDER_NONE){
1033 // render the nebula
1034 for(idx1=0; idx1<Neb2_slices; idx1++){
1035 for(idx2=0; idx2<Neb2_slices; idx2++){
1036 for(idx3=0; idx3<Neb2_slices; idx3++){
1040 Neb2_cubes[idx1][idx2][idx3].rot += (Neb2_cubes[idx1][idx2][idx3].rot_speed * flFrametime);
1041 if(Neb2_cubes[idx1][idx2][idx3].rot >= 360.0f){
1042 Neb2_cubes[idx1][idx2][idx3].rot = 0.0f;
1045 // optimization 1 - don't draw backfacing poly's
1047 if(vm_vec_dot_to_point(&eye_orient.fvec, &eye_pos, &Neb2_cubes[idx1][idx2][idx3].pt) <= 0.0f){
1052 // rotate and project the vertex into viewspace
1053 g3_rotate_vertex(&p, &Neb2_cubes[idx1][idx2][idx3].pt);
1055 g3_project_vertex(&ptemp);
1057 // get the proper alpha value
1058 alpha = neb2_get_alpha_2shell(Nd->cube_inner, Nd->cube_outer, Nd->prad/4.0f, &Neb2_cubes[idx1][idx2][idx3].pt);
1060 // optimization 2 - don't draw 0.0f or less poly's
1061 // this amounts to big savings
1062 if(alpha <= Nd->break_alpha){
1063 pneb_tossed_alpha++;
1067 // drop poly's which are offscreen at all
1068 // if the poly's are offscreen
1069 if((ptemp.sx < 0.0f) || (ptemp.sx > (float)gr_screen.max_w) || (ptemp.sy < 0.0f) || (ptemp.sy > (float)gr_screen.max_h) ){
1070 alpha = neb2_get_alpha_offscreen(ptemp.sx, ptemp.sy, alpha);
1073 // optimization 2 - don't draw 0.0f or less poly's
1074 // this amounts to big savings
1075 if(alpha <= Nd->break_alpha){
1076 pneb_tossed_alpha++;
1080 // set the bitmap and render
1081 gr_set_bitmap(Neb2_cubes[idx1][idx2][idx3].bmap, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, alpha + Neb2_cubes[idx1][idx2][idx3].flash);
1084 this_area = g3_draw_rotated_bitmap_area(&p, fl_radian(Neb2_cubes[idx1][idx2][idx3].rot), Nd->prad, TMAP_FLAG_TEXTURED, max_area);
1085 total_area += this_area;
1086 frame_area -= this_area;
1089 g3_draw_rotated_bitmap(&p, fl_radian(Neb2_cubes[idx1][idx2][idx3].rot), Nd->prad, TMAP_FLAG_TEXTURED);
1095 frames_total += frame_rendered;
1097 frame_avg = (float)frames_total / (float)frame_count;
1099 // gr_set_color_fast(&Color_bright_red);
1100 // gr_printf(30, 100, "Area %.3f", total_area);
1101 #ifdef NEB2_THUMBNAIL
1104 gr_set_bitmap(tbmap);
1110 // call this when the player's viewpoint has changed, this will cause the code to properly reset
1111 // the eye's local poofs
1112 void neb2_eye_changed()
1117 // get near and far fog values based upon object type and rendering mode
1118 void neb2_get_fog_values(float *fnear, float *ffar, object *objp)
1122 // default values in case something truly nasty happens
1126 // determine what fog index to use
1127 if(objp->type == OBJ_SHIP){
1128 Assert((objp->instance >= 0) && (objp->instance < MAX_SHIPS));
1129 if((objp->instance < 0) || (objp->instance >= MAX_SHIPS)){
1130 fog_index = SHIP_TYPE_FIGHTER_BOMBER;
1132 fog_index = ship_query_general_type(objp->instance);
1133 Assert(fog_index >= 0);
1135 fog_index = SHIP_TYPE_FIGHTER_BOMBER;
1139 // fog everything else like a fighter
1141 fog_index = SHIP_TYPE_FIGHTER_BOMBER;
1145 switch(gr_screen.mode){
1147 *fnear = Neb_ship_fog_vals_glide[fog_index][0];
1148 *ffar = Neb_ship_fog_vals_glide[fog_index][1];
1153 *fnear = Neb_ship_fog_vals_d3d[fog_index][0];
1154 *ffar = Neb_ship_fog_vals_d3d[fog_index][1];
1162 // given a position in space, return a value from 0.0 to 1.0 representing the fog level
1163 float neb2_get_fog_intensity(object *obj)
1165 float f_near, f_far, pct;
1167 // get near and far fog values based upon object type and rendering mode
1168 neb2_get_fog_values(&f_near, &f_far, obj);
1171 pct = vm_vec_dist_quick(&Eye_position, &obj->pos) / (f_far - f_near);
1174 } else if(pct > 1.0f){
1181 // fogging stuff --------------------------------------------------------------------
1183 // do a pre-render of the background nebula
1185 ubyte tpixels[ESIZE * ESIZE * 4]; // for 32 bits
1186 int last_esize = -1;
1187 int this_esize = ESIZE;
1188 extern float Viewer_zoom;
1189 float ex_scale, ey_scale;
1191 void neb2_pre_render(vector *eye_pos, matrix *eye_orient)
1193 // bail early in lame and poly modes
1194 if(Neb2_render_mode != NEB2_RENDER_POF){
1198 // set the view clip
1199 gr_screen.clip_width = this_esize;
1200 gr_screen.clip_height = this_esize;
1201 g3_start_frame(1); // Turn on zbuffering
1202 g3_set_view_matrix(eye_pos, eye_orient, Viewer_zoom);
1203 gr_set_clip(0, 0, this_esize, this_esize);
1205 // render the background properly
1206 // hack - turn off nebula stuff
1207 int neb_save = Neb2_render_mode;
1208 Neb2_render_mode = NEB2_RENDER_NONE;
1210 // draw background stuff nebula
1211 extern void stars_draw_background();
1212 stars_draw_background();
1214 Neb2_render_mode = neb_save;
1216 // HACK - flush d3d here so everything is rendered
1217 if(gr_screen.mode == GR_DIRECT3D){
1218 extern void d3d_flush();
1223 gr_get_region(0, this_esize, this_esize, (ubyte*)tpixels);
1225 #ifdef NEB2_THUMBNAIL
1227 tbmap = bm_create(16, this_esize, this_esize, tpixels, 0);
1228 bm_lock(tbmap, 16, 0);
1233 // maybe do some swizzling
1240 // HACK - flush d3d here so everything is properly cleared
1241 if(gr_screen.mode == GR_DIRECT3D){
1242 extern void d3d_flush();
1246 // if the size has changed between frames, make a new bitmap
1247 if(this_esize != last_esize){
1248 last_esize = this_esize;
1250 // recalculate ex_scale and ey_scale values for looking up color values
1251 ex_scale = (float)this_esize / (float)gr_screen.max_w;
1252 ey_scale = (float)this_esize / (float)gr_screen.max_h;
1255 // restore the game clip stuff
1256 extern void game_set_view_clip();
1257 game_set_view_clip();
1260 // wacky scheme for smoothing colors
1261 int wacky_scheme = 3;
1263 // get the color of the pixel in the small pre-rendered background nebula
1264 #define PIXEL_INDEX_SMALL(xv, yv) ( (this_esize * (yv) * gr_screen.bytes_per_pixel) + ((xv) * gr_screen.bytes_per_pixel) )
1265 void neb2_get_pixel(int x, int y, int *r, int *g, int *b)
1272 // if we're in lame rendering mode, return a constant value
1273 if(Neb2_render_mode == NEB2_RENDER_LAME){
1274 *r = Neb2_background_color[0];
1275 *g = Neb2_background_color[1];
1276 *b = Neb2_background_color[2];
1281 // get the proper pixel index to be looking up
1284 // select screen format
1285 BM_SELECT_SCREEN_FORMAT();
1287 // pixel plus all immediate neighbors (on the small screen - should be more effective than 2 or 1)
1288 xs = (int)(ex_scale * x);
1289 ys = (int)(ey_scale * y);
1291 // sometimes goes over by 1 in direct3d
1292 if(ys >= (this_esize - 1)){
1297 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs, ys)], &rv, &gv, &bv, NULL);
1303 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs - 1, ys)], &rv, &gv, &bv, NULL); // left
1309 if(xs < this_esize - 1){
1310 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs + 1, ys)], &rv, &gv, &bv, NULL); // right
1317 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs, ys - 1)], &rv, &gv, &bv, NULL); // top
1323 if(ys < this_esize - 2){
1324 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs, ys + 1)], &rv, &gv, &bv, NULL); // bottom
1331 if((xs > 0) && (ys > 0)){
1332 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs - 1, ys - 1)], &rv, &gv, &bv, NULL); // upper left
1338 if((xs < this_esize - 1) && (ys < this_esize - 1)){
1339 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs + 1, ys + 1)], &rv, &gv, &bv, NULL); // lower right
1345 if((ys > 0) && (xs < this_esize - 1)){
1346 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs + 1, ys - 1)], &rv, &gv, &bv, NULL); // lower left
1352 if((ys < this_esize - 1) && (xs > 0)){
1353 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs - 1, ys + 1)], &rv, &gv, &bv, NULL); // upper right
1360 rv = (ubyte) (ra / avg_count);
1361 gv = (ubyte) (ga / avg_count);
1362 bv = (ubyte) (ba / avg_count);
1370 // get the color to fog the background color to
1371 void neb2_get_backg_color(int *r, int *g, int *b)
1373 *r = Neb2_background_color[0];
1374 *g = Neb2_background_color[1];
1375 *b = Neb2_background_color[2];
1378 // set the background color
1379 void neb2_set_backg_color(int r, int g, int b)
1381 Neb2_background_color[0] = r;
1382 Neb2_background_color[1] = g;
1383 Neb2_background_color[2] = b;
1386 // fill in the position of the eye for this frame
1387 void neb2_get_eye_pos(vector *eye)
1389 *eye = Eye_position;
1392 // fill in the eye orient for this frame
1393 void neb2_get_eye_orient(matrix *eye)
1398 // get a (semi) random bitmap to use for a poof
1399 int neb2_get_bitmap()
1403 static int neb2_choose = 0;
1405 // get a random count
1406 count = (int)frand_range(1.0f, 5.0f);
1410 // don't cycle too many times
1413 if(neb2_choose == MAX_NEB2_POOFS - 1){
1420 } while(!(Neb2_poof_flags & (1<<neb2_choose)) && (huh < 10));
1426 if(Neb2_poofs[neb2_choose] < 0){
1427 return Neb2_poofs[0];
1429 return Neb2_poofs[neb2_choose];
1432 // nebula DCF functions ------------------------------------------------------
1434 DCF(neb2, "list nebula console commands")
1436 dc_printf("neb2_fog <X> <float> <float> : set near and far fog planes for ship type X\n");
1437 dc_printf("where X is an integer from 1 - 11\n");
1438 dc_printf("1 = cargo containers, 2 = fighters/bombers, 3 = cruisers\n");
1439 dc_printf("4 = freighters, 5 = capital ships, 6 = transports, 7 = support ships\n");
1440 dc_printf("8 = navbuoys, 9 = sentryguns, 10 = escape pods, 11 = background nebula polygons\n\n");
1442 dc_printf("neb2_max_alpha : max alpha value (0.0 to 1.0) for cloud poofs. 0.0 is completely transparent\n");
1443 dc_printf("neb2_break_alpha : alpha value (0.0 to 1.0) at which faded polygons are not drawn. higher values generally equals higher framerate, with more visual cloud popping\n");
1444 dc_printf("neb2_break_off : how many pixels offscreen (left, right, top, bottom) when a cloud poof becomes fully transparent. Lower values cause quicker fading\n");
1445 dc_printf("neb2_smooth : magic fog smoothing modes (0 - 3)\n");
1446 dc_printf("neb2_select : <int> <int> where the first # is the bitmap to be adjusting (0 through 5), and the second int is a 0 or 1, to turn off and on\n");
1447 dc_printf("neb2_rot : set max rotation speed for poofs\n");
1448 dc_printf("neb2_prad : set cloud poof radius\n");
1449 dc_printf("neb2_cdim : poof cube dimension\n");
1450 dc_printf("neb2_cinner : poof cube inner dimension\n");
1451 dc_printf("neb2_couter : poof cube outer dimension\n");
1452 dc_printf("neb2_jitter : poof jitter\n");
1453 dc_printf("neb2_mode : switch between no nebula, polygon background, amd pof background (0, 1 and 2 respectively)\n\n");
1454 dc_printf("neb2_ff : flash fade/sec\n");
1455 dc_printf("neb2_background : rgb background color\n");
1457 dc_printf("neb2_fog_vals : display all the current settings for all above values\n");
1462 dc_get_arg(ARG_FLOAT);
1463 Nd->prad = Dc_arg_float;
1467 dc_get_arg(ARG_FLOAT);
1468 Nd->cube_dim = Dc_arg_float;
1471 DCF(neb2_cinner, "")
1473 dc_get_arg(ARG_FLOAT);
1474 Nd->cube_inner = Dc_arg_float;
1477 DCF(neb2_couter, "")
1479 dc_get_arg(ARG_FLOAT);
1480 Nd->cube_outer = Dc_arg_float;
1483 DCF(neb2_jitter, "")
1485 dc_get_arg(ARG_FLOAT);
1486 Nd->hj = Nd->dj = Nd->wj = Dc_arg_float;
1493 dc_get_arg(ARG_INT);
1495 dc_get_arg(ARG_FLOAT);
1496 fnear = Dc_arg_float;
1497 dc_get_arg(ARG_FLOAT);
1498 ffar = Dc_arg_float;
1500 if((index >= 1) && (index <= 11) && (fnear >= 0.0f) && (ffar >= 0.0f) && (ffar > fnear)){
1502 Neb_backg_fog_near = fnear;
1503 Neb_backg_fog_far = ffar;
1505 if(gr_screen.mode == GR_GLIDE){
1506 Neb_ship_fog_vals_glide[index][0] = fnear;
1507 Neb_ship_fog_vals_glide[index][1] = ffar;
1509 Assert(gr_screen.mode == GR_DIRECT3D || gr_screen.mode == GR_OPENGL);
1510 Neb_ship_fog_vals_d3d[index][0] = fnear;
1511 Neb_ship_fog_vals_d3d[index][1] = ffar;
1517 DCF(neb2_max_alpha, "")
1519 dc_get_arg(ARG_FLOAT);
1520 Nd->max_alpha_glide = Dc_arg_float;
1523 DCF(neb2_break_alpha, "")
1525 dc_get_arg(ARG_FLOAT);
1526 Nd->break_alpha = Dc_arg_float;
1529 DCF(neb2_break_off, "")
1531 dc_get_arg(ARG_INT);
1532 Nd->break_y = (float)Dc_arg_int;
1533 Nd->break_x = Nd->break_y * 1.3333f;
1536 DCF(neb2_smooth, "")
1539 dc_get_arg(ARG_INT);
1541 if((index >= 0) && (index <= 3)){
1542 wacky_scheme = index;
1546 DCF(neb2_select, "")
1548 dc_get_arg(ARG_INT);
1549 int bmap = Dc_arg_int;
1550 if((bmap >= 0) && (bmap < Neb2_poof_count)){
1551 dc_get_arg(ARG_INT);
1554 Neb2_poof_flags |= (1<<bmap);
1556 Neb2_poof_flags &= ~(1<<bmap);
1563 dc_get_arg(ARG_FLOAT);
1564 max_rotation = Dc_arg_float;
1569 dc_get_arg(ARG_FLOAT);
1570 neb2_flash_fade = Dc_arg_float;
1575 dc_get_arg(ARG_INT);
1578 case NEB2_RENDER_NONE:
1579 Neb2_render_mode = NEB2_RENDER_NONE;
1582 case NEB2_RENDER_POLY:
1583 Neb2_render_mode = NEB2_RENDER_POLY;
1586 case NEB2_RENDER_POF:
1587 Neb2_render_mode = NEB2_RENDER_POF;
1588 stars_set_background_model(BACKGROUND_MODEL_FILENAME, "Eraseme3");
1591 case NEB2_RENDER_LAME:
1592 Neb2_render_mode = NEB2_RENDER_LAME;
1597 DCF(neb2_slices, "")
1599 dc_get_arg(ARG_INT);
1600 Neb2_slices = Dc_arg_int;
1604 DCF(neb2_background, "")
1608 dc_get_arg(ARG_INT);
1610 dc_get_arg(ARG_INT);
1612 dc_get_arg(ARG_INT);
1615 Neb2_background_color[0] = r;
1616 Neb2_background_color[1] = g;
1617 Neb2_background_color[2] = b;
1620 DCF(neb2_fog_vals, "")
1622 dc_printf("neb2_fog : \n");
1623 if(gr_screen.mode == GR_GLIDE){
1624 dc_printf("(1)cargo containers : %f, %f\n", Neb_ship_fog_vals_glide[1][0], Neb_ship_fog_vals_glide[1][1]);
1625 dc_printf("(2)fighters/bombers : %f, %f\n", Neb_ship_fog_vals_glide[2][0], Neb_ship_fog_vals_glide[2][1]);
1626 dc_printf("(3)cruisers : %f, %f\n", Neb_ship_fog_vals_glide[3][0], Neb_ship_fog_vals_glide[3][1]);
1627 dc_printf("(4)freighters : %f, %f\n", Neb_ship_fog_vals_glide[4][0], Neb_ship_fog_vals_glide[4][1]);
1628 dc_printf("(5)cap ships : %f, %f\n", Neb_ship_fog_vals_glide[5][0], Neb_ship_fog_vals_glide[5][1]);
1629 dc_printf("(6)transports : %f, %f\n", Neb_ship_fog_vals_glide[6][0], Neb_ship_fog_vals_glide[6][1]);
1630 dc_printf("(7)support ships : %f, %f\n", Neb_ship_fog_vals_glide[7][0], Neb_ship_fog_vals_glide[7][1]);
1631 dc_printf("(8)navbuoys : %f, %f\n", Neb_ship_fog_vals_glide[8][0], Neb_ship_fog_vals_glide[8][1]);
1632 dc_printf("(9)sentry guns : %f, %f\n", Neb_ship_fog_vals_glide[9][0], Neb_ship_fog_vals_glide[9][1]);
1633 dc_printf("(10)escape pods : %f, %f\n", Neb_ship_fog_vals_glide[10][0], Neb_ship_fog_vals_glide[10][1]);
1634 dc_printf("(11)background polys : %f, %f\n\n", Neb_backg_fog_near, Neb_backg_fog_far);
1637 Assert(gr_screen.mode == GR_DIRECT3D || gr_screen.mode == GR_OPENGL);
1638 dc_printf("(1)cargo containers : %f, %f\n", Neb_ship_fog_vals_d3d[1][0], Neb_ship_fog_vals_d3d[1][1]);
1639 dc_printf("(2)fighters/bombers : %f, %f\n", Neb_ship_fog_vals_d3d[2][0], Neb_ship_fog_vals_d3d[2][1]);
1640 dc_printf("(3)cruisers : %f, %f\n", Neb_ship_fog_vals_d3d[3][0], Neb_ship_fog_vals_d3d[3][1]);
1641 dc_printf("(4)freighters : %f, %f\n", Neb_ship_fog_vals_d3d[4][0], Neb_ship_fog_vals_d3d[4][1]);
1642 dc_printf("(5)cap ships : %f, %f\n", Neb_ship_fog_vals_d3d[5][0], Neb_ship_fog_vals_d3d[5][1]);
1643 dc_printf("(6)transports : %f, %f\n", Neb_ship_fog_vals_d3d[6][0], Neb_ship_fog_vals_d3d[6][1]);
1644 dc_printf("(7)support ships : %f, %f\n", Neb_ship_fog_vals_d3d[7][0], Neb_ship_fog_vals_d3d[7][1]);
1645 dc_printf("(8)navbuoys : %f, %f\n", Neb_ship_fog_vals_d3d[8][0], Neb_ship_fog_vals_d3d[8][1]);
1646 dc_printf("(9)sentry guns : %f, %f\n", Neb_ship_fog_vals_d3d[9][0], Neb_ship_fog_vals_d3d[9][1]);
1647 dc_printf("(10)escape pods : %f, %f\n", Neb_ship_fog_vals_d3d[10][0], Neb_ship_fog_vals_d3d[10][1]);
1648 dc_printf("(11)background polys : %f, %f\n\n", Neb_backg_fog_near, Neb_backg_fog_far);
1650 dc_printf("neb2_max_alpha : %f\n", Nd->max_alpha_glide);
1651 dc_printf("neb2_break_alpha : %f\n", Nd->break_alpha);
1652 dc_printf("neb2_break_off : %d\n", (int)Nd->break_y);
1653 dc_printf("neb2_smooth : %d\n", wacky_scheme);
1654 dc_printf("neb2_toggle : %s\n", Neb2_render_mode ? "on" : "off");
1655 dc_printf("neb2_rot : %f\n", max_rotation);
1656 dc_printf("neb2_prad : %f\n", Nd->prad);
1657 dc_printf("neb2_cdim : %f\n", Nd->cube_dim);
1658 dc_printf("neb2_couter : %f\n", Nd->cube_outer);
1659 dc_printf("neb2_cinner : %f\n", Nd->cube_inner);
1660 dc_printf("neb2_jitter : %f\n", Nd->wj);
1661 dc_printf("neb2_ff : %f\n", neb2_flash_fade);
1662 dc_printf("neb2_background : %d %d %d\n", Neb2_background_color[0], Neb2_background_color[1], Neb2_background_color[2]);
1666 DCF(neb2_create, "create a basic nebula")
1672 dc_get_arg(ARG_INT);
1673 if(Dc_arg_type & ARG_INT){
1674 points = Dc_arg_int;
1676 dc_get_arg(ARG_FLOAT);
1677 if(Dc_arg_type & ARG_FLOAT){
1678 rad1 = Dc_arg_float;
1680 dc_get_arg(ARG_FLOAT);
1681 if(Dc_arg_type & ARG_FLOAT){
1682 rad2 = Dc_arg_float;
1684 neb2_create(&vmd_zero_vector, points, rad1, -1.0f, rad2);
1687 DCF(neb2_del, "delete existing nebulae")
1689 for(int idx=0; idx<MAX_OBJECTS; idx++){
1690 if(Objects[idx].type == OBJ_NEB2){
1697 float magic1 = 1000.0f;
1698 float magic2 = -1.0f;
1699 float magic3 = 700.0f;
1700 DCF(neb2_def, "create a default nebula")
1703 vm_vec_make(&a, 0.0f, 0.0f, 0.0f);
1704 vm_vec_make(&b, 3600.0f, 700.0f, 0.0f);
1705 vm_vec_make(&c, -3000.0f, 20.0f, 480.0f);
1706 vm_vec_make(&d, -4000.0f, 100.0f, 100.0f);
1707 vm_vec_make(&e, 0.0f, 3000.0f, -400.0f);
1708 vm_vec_make(&f, 670.0f, -2500.0f, -1600.0f);
1710 neb2_create(&a, magic0, magic1, magic2, magic3);
1711 neb2_create(&b, magic0, magic1, magic2, magic3);
1712 neb2_create(&c, magic0, magic1, magic2, magic3);
1713 neb2_create(&d, magic0, magic1, magic2, magic3);
1714 neb2_create(&e, magic0, magic1, magic2, magic3);
1715 neb2_create(&f, magic0, magic1, magic2, magic3);
1718 DCF(neb2_plr, "regenerate the player's nebula")
1723 DCF(neb2_stats, "display info about the nebula rendering")
1725 dc_printf("Player poofs tried : %d\n", pneb_tried);
1726 dc_printf("Player poofs tossed (alpha): %d\n", pneb_tossed_alpha);
1727 dc_printf("Player poofs tossed (dot): %d\n", pneb_tossed_dot);
1728 dc_printf("Player poofs tossed (off): %d\n", pneb_tossed_off);
1730 dc_printf("Poofs tried : %d\n", neb_tried);
1731 dc_printf("Poofs tossed (alpha): %d\n", neb_tossed_alpha);
1732 dc_printf("Poofs tossed (dot): %d\n", neb_tossed_dot);
1733 dc_printf("Poofs tossed (count): %d\n", neb_tossed_count);
1735 dc_printf("Avg poofs/frame: %f\n", frame_avg);
1738 // create a nebula object, return objnum of the nebula or -1 on fail
1739 // NOTE : in most cases you will want to pass -1.0f for outer_radius. Trust me on this
1740 int neb2_create(vector *offset, int num_poofs, float inner_radius, float outer_radius, float max_poof_radius)
1746 // delete a nebula object
1747 void neb2_delete(object *objp)
1752 // renders a nebula object
1753 void neb2_render(object *objp)
1758 // preprocess the nebula object before simulation
1759 void neb2_process_pre(object *objp)
1764 // process the nebula object after simulating, but before rendering
1765 void neb2_process_post(object *objp)
1772 // add N poofs to the inner shell of the nebula
1773 // if orient and ang are specified, generate the poofs so that they are "visible" around
1774 // the orient fvec in a cone of ang degrees
1775 void neb2_add_inner(neb2 *neb, int num_poofs, matrix *orient, float ang)
1778 vector pt, pt2, pt3;
1779 int final_index = (neb->num_poofs + num_poofs) > neb->max_poofs ? neb->max_poofs : (neb->num_poofs + num_poofs);
1781 // add the points a pick a random bitmap
1782 for(idx=neb->num_poofs; idx<final_index; idx++){
1784 // put a point directly in front of the player, between 0 and inner_radius distance away
1785 vm_vec_copy_scale(&pt, &orient->fvec, frand_range(neb->magic_num, neb->inner_radius));
1787 // rotate the point by -ang <-> ang around the up vector
1788 vm_rot_point_around_line(&pt2, &pt, fl_radian(frand_range(-ang, ang)), &vmd_zero_vector, &orient->uvec);
1790 // rotate the point by -ang <-> ang around the right vector
1791 vm_rot_point_around_line(&pt3, &pt2, fl_radian(frand_range(-ang, ang)), &vmd_zero_vector, &orient->rvec);
1793 // now add in the center of the nebula so its placed properly (ie, not around the origin)
1794 vm_vec_add(&neb->pts[idx], &pt3, &Objects[neb->objnum].pos);
1796 neb->pts[idx].x = frand_range(-1.0f * neb->inner_radius, neb->inner_radius) + Objects[neb->objnum].pos.x;
1797 neb->pts[idx].y = frand_range(-1.0f * neb->inner_radius, neb->inner_radius) + Objects[neb->objnum].pos.y;
1798 neb->pts[idx].z = frand_range(-1.0f * neb->inner_radius, neb->inner_radius) + Objects[neb->objnum].pos.z;
1801 neb->bmaps[idx] = (int)frand_range(0.0f, (float)2);
1806 // add N poofs to the outer shell of the nebula
1807 // if orient and ang are specified, generate the poofs so that they are "visible" around
1808 // the orient fvec in a cone of ang degrees
1809 void neb2_add_outer(neb2 *neb, int num_poofs, matrix *orient, float ang)
1813 vector pt, pt2, pt3;
1814 int final_index = (neb->num_poofs + num_poofs) > neb->max_poofs ? neb->max_poofs : (neb->num_poofs + num_poofs);
1816 // add the points a pick a random bitmap
1817 for(idx=neb->num_poofs; idx<final_index; idx++){
1819 // put a point directly in front of the player, at outer_radius distance away
1820 vm_vec_copy_scale(&pt, &orient->fvec, neb->outer_radius);
1822 // rotate the point by -ang <-> ang around the up vector
1823 vm_rot_point_around_line(&pt2, &pt, fl_radian(frand_range(-ang, ang)), &vmd_zero_vector, &orient->uvec);
1825 // rotate the point by -ang <-> ang around the right vector
1826 vm_rot_point_around_line(&pt3, &pt2, fl_radian(frand_range(-ang, ang)), &vmd_zero_vector, &orient->rvec);
1828 // now add in the center of the nebula so its placed properly (ie, not around the origin)
1829 vm_vec_add(&neb->pts[idx], &pt, &Objects[neb->objnum].pos);
1831 // get a random point on the very outer radius, using spherical coords
1832 phi = fl_radian(frand_range(0.0f, 360.0f));
1833 theta = fl_radian(frand_range(0.0f, 360.f));
1835 neb->pts[idx].x = neb->outer_radius * (float)sin(phi) * (float)cos(theta);
1836 neb->pts[idx].y = neb->outer_radius * (float)sin(phi) * (float)sin(theta);
1837 neb->pts[idx].z = neb->outer_radius * (float)cos(phi);
1840 // pick a random bitmap and increment the # of poofs
1841 neb->bmaps[idx] = (int)frand_range(0.0f, (float)2);
1846 // return the alpha the passed poof should be rendered with, for a 1 shell nebula
1847 float neb2_get_alpha_1shell(neb2 *neb, int poof_index)
1853 // get the eye position
1854 neb2_get_eye_pos(&eye_pos);
1856 // determine what alpha to draw this bitmap with
1857 // higher alpha the closer the bitmap gets to the eye
1858 dist = vm_vec_dist_quick(&eye_pos, &neb->pts[poof_index]);
1860 // at poof radius or greater, alpha should be 1.0
1861 // scale from 0.0 to 1.0 between radius and magic
1862 if(dist >= neb->max_poof_radius){
1863 return max_alpha - 0.0001f;
1864 } else if(dist > neb->magic_num){
1865 // alpha per meter between the magic # and the max radius
1866 alpha = max_alpha / (neb->max_poof_radius - neb->magic_num);
1868 // above value times the # of meters away we are
1869 return alpha * (dist - neb->magic_num);
1872 // otherwise transparent