2 * $Logfile: /Freespace2/code/Nebula/Neb.cpp $
10 * Revision 1.1 2002/05/03 03:28:10 root
14 * 50 8/30/99 5:01p Dave
15 * Made d3d do less state changing in the nebula. Use new chat server for
18 * 49 8/10/99 6:54p Dave
19 * Mad optimizations. Added paging to the nebula effect.
21 * 48 8/05/99 2:05a Dave
24 * 47 7/30/99 10:55a Anoop
25 * Hmm. Fixed release build problem again, with area-rotated bitmaps.
27 * 46 7/29/99 10:47p Dave
28 * Standardized D3D fogging using vertex fog. Shook out Savage 4 bugs.
30 * 44 7/29/99 12:05a Dave
31 * Nebula speed optimizations.
33 * 43 7/19/99 7:20p Dave
34 * Beam tooling. Specialized player-killed-self messages. Fixed d3d nebula
37 * 42 7/18/99 5:20p Dave
38 * Jump node icon. Fixed debris fogging. Framerate warning stuff.
40 * 41 7/13/99 1:15p Dave
41 * 32 bit support. Whee!
43 * 40 7/09/99 5:54p Dave
44 * Seperated cruiser types into individual types. Added tons of new
45 * briefing icons. Campaign screen.
47 * 39 7/07/99 10:44a Jamesa
48 * Make sure the nebula regens properly after loading a mission.
50 * 38 6/11/99 2:32p Dave
51 * Toned down nebula brightness a bit.
53 * 37 5/26/99 3:39p Dave
54 * Fixed nebula regeneration problem. Removed optimizations from
57 * 36 5/26/99 11:46a Dave
58 * Added ship-blasting lighting and made the randomization of lighting
59 * much more customizable.
61 * 35 5/24/99 5:45p Dave
62 * Added detail levels to the nebula, with a decent speedup. Split nebula
63 * lightning into its own section.
77 #include "freespace.h"
80 #include "starfield.h"
85 #include "grinternal.h"
87 #include "alphacolors.h"
89 // --------------------------------------------------------------------------------------------------------
90 // NEBULA DEFINES/VARS
93 // #define NEB2_THUMBNAIL
96 3D CARDS THAT FOG PROPERLY
102 3D CARDS THAT DON'T FOG PROPERLY
107 // if nebula rendering is active (DCF stuff - not mission specific)
108 int Neb2_render_mode = NEB2_RENDER_NONE;
110 // array of neb2 poofs
111 char Neb2_poof_filenames[MAX_NEB2_POOFS][MAX_FILENAME_LEN] = {
112 "", "", "", "", "", ""
114 int Neb2_poofs[MAX_NEB2_POOFS] = { -1, -1, -1, -1, -1, -1 };
115 int Neb2_poof_flags = ( (1<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5) );
116 int Neb2_poof_count = 0;
118 // array of neb2 bitmaps
119 char Neb2_bitmap_filenames[MAX_NEB2_BITMAPS][MAX_FILENAME_LEN] = {
120 "", "", "", "", "", ""
122 int Neb2_bitmap[MAX_NEB2_BITMAPS] = { -1, -1, -1, -1, -1, -1 };
123 int Neb2_bitmap_count = 0;
125 // texture to use for this level
126 char Neb2_texture_name[MAX_FILENAME_LEN] = "";
129 #define NF_USED (1<<0) // if this nebula slot is used
131 float max_rotation = 3.75f;
132 float neb2_flash_fade = 0.3f;
134 // fog values for different ship types
135 float Neb_ship_fog_vals_glide[MAX_SHIP_TYPE_COUNTS][2] = {
136 {0.0f, 0.0f}, // SHIP_TYPE_NONE
137 {10.0f, 500.0f}, // SHIP_TYPE_CARGO
138 {10.0f, 500.0f}, // SHIP_TYPE_FIGHTER_BOMBER
139 {10.0f, 600.0f}, // SHIP_TYPE_CRUISER
140 {10.0f, 600.0f}, // SHIP_TYPE_FREIGHTER
141 {10.0f, 750.0f}, // SHIP_TYPE_CAPITAL
142 {10.0f, 500.0f}, // SHIP_TYPE_TRANSPORT
143 {10.0f, 500.0f}, // SHIP_TYPE_REPAIR_REARM
144 {10.0f, 500.0f}, // SHIP_TYPE_NAVBUOY
145 {10.0f, 500.0f}, // SHIP_TYPE_SENTRYGUN
146 {10.0f, 600.0f}, // SHIP_TYPE_ESCAPEPOD
147 {10.0f, 1000.0f}, // SHIP_TYPE_SUPERCAP
148 {10.0f, 500.0f}, // SHIP_TYPE_STEALTH
149 {10.0f, 500.0f}, // SHIP_TYPE_FIGHTER
150 {10.0f, 500.0f}, // SHIP_TYPE_BOMBER
151 {10.0f, 750.0f}, // SHIP_TYPE_DRYDOCK
152 {10.0f, 600.0f}, // SHIP_TYPE_AWACS
153 {10.0f, 600.0f}, // SHIP_TYPE_GAS_MINER
154 {10.0f, 600.0f}, // SHIP_TYPE_CORVETTE
155 {10.0f, 1000.0f}, // SHIP_TYPE_KNOSSOS_DEVICE
157 float Neb_ship_fog_vals_d3d[MAX_SHIP_TYPE_COUNTS][2] = {
158 {0.0f, 0.0f}, // SHIP_TYPE_NONE
159 {10.0f, 500.0f}, // SHIP_TYPE_CARGO
160 {10.0f, 500.0f}, // SHIP_TYPE_FIGHTER_BOMBER
161 {10.0f, 600.0f}, // SHIP_TYPE_CRUISER
162 {10.0f, 600.0f}, // SHIP_TYPE_FREIGHTER
163 {10.0f, 750.0f}, // SHIP_TYPE_CAPITAL
164 {10.0f, 500.0f}, // SHIP_TYPE_TRANSPORT
165 {10.0f, 500.0f}, // SHIP_TYPE_REPAIR_REARM
166 {10.0f, 500.0f}, // SHIP_TYPE_NAVBUOY
167 {10.0f, 500.0f}, // SHIP_TYPE_SENTRYGUN
168 {10.0f, 600.0f}, // SHIP_TYPE_ESCAPEPOD
169 {10.0f, 1000.0f}, // SHIP_TYPE_SUPERCAP
170 {10.0f, 500.0f}, // SHIP_TYPE_STEALTH
171 {10.0f, 500.0f}, // SHIP_TYPE_FIGHTER
172 {10.0f, 500.0f}, // SHIP_TYPE_BOMBER
173 {10.0f, 750.0f}, // SHIP_TYPE_DRYDOCK
174 {10.0f, 600.0f}, // SHIP_TYPE_AWACS
175 {10.0f, 600.0f}, // SHIP_TYPE_GAS_MINER
176 {10.0f, 600.0f}, // SHIP_TYPE_CORVETTE
177 {10.0f, 1000.0f}, // SHIP_TYPE_KNOSSOS_DEVICE
180 // fog near and far values for rendering the background nebula
181 #define NEB_BACKG_FOG_NEAR_GLIDE 2.5f
182 #define NEB_BACKG_FOG_NEAR_D3D 4.5f
183 #define NEB_BACKG_FOG_FAR_GLIDE 10.0f
184 #define NEB_BACKG_FOG_FAR_D3D 10.0f
185 float Neb_backg_fog_near = NEB_BACKG_FOG_NEAR_GLIDE;
186 float Neb_backg_fog_far = NEB_BACKG_FOG_FAR_GLIDE;
189 int pneb_tried = 0; // total pnebs tried to render
190 int pneb_tossed_alpha = 0; // pnebs tossed because of alpha optimization
191 int pneb_tossed_dot = 0; // pnebs tossed because of dot product
192 int pneb_tossed_off = 0; // pnebs tossed because of being offscree
193 int neb_tried = 0; // total nebs tried
194 int neb_tossed_alpha = 0; // nebs tossed because of alpha
195 int neb_tossed_dot = 0; // nebs tossed because of dot product
196 int neb_tossed_count = 0; // nebs tossed because of max render count
198 // the AWACS suppresion level for the nebula
199 float Neb2_awacs = -1.0f;
201 // how many "slices" are in the current player nebuls
204 cube_poof Neb2_cubes[MAX_CPTS][MAX_CPTS][MAX_CPTS];
206 // nebula detail level
207 typedef struct neb2_detail {
208 float max_alpha_glide; // max alpha for this detail level in Glide
209 float max_alpha_d3d; // max alpha for this detail level in D3d
210 float break_alpha; // break alpha (below which, poofs don't draw). this affects the speed and visual quality a lot
211 float break_x, break_y; // x and y alpha fade/break values. adjust alpha on the polys as they move offscreen
212 float cube_dim; // total dimension of player poof cube
213 float cube_inner; // inner radius of the player poof cube
214 float cube_outer; // outer radius of the player pood cube
215 float prad; // radius of the poofs
216 float wj, hj, dj; // width, height, depth jittering. best left at 1.0
218 neb2_detail Neb2_detail[MAX_DETAIL_LEVEL] = {
219 { // lowest detail level
220 0.575f, // max alpha for this detail level in Glide
221 0.71f, // max alpha for this detail level in D3d
222 0.13f, // break alpha (below which, poofs don't draw). this affects the speed and visual quality a lot
223 150.0f, 150.0f / 1.3333f, // x and y alpha fade/break values. adjust alpha on the polys as they move offscreen
224 510.0f, // total dimension of player poof cube
225 50.0f, // inner radius of the player poof cube
226 250.0f, // outer radius of the player pood cube
227 120.0f, // radius of the poofs
228 1.0f, 1.0f, 1.0f // width, height, depth jittering. best left at 1.0
230 { // 2nd lowest detail level
231 0.575f, // max alpha for this detail level in Glide
232 0.71f, // max alpha for this detail level in D3d
233 0.125f, // break alpha (below which, poofs don't draw). this affects the speed and visual quality a lot
234 300.0f, 300.0f / 1.3333f, // x and y alpha fade/break values. adjust alpha on the polys as they move offscreen
235 550.0f, // total dimension of player poof cube
236 100.0f, // inner radius of the player poof cube
237 250.0f, // outer radius of the player pood cube
238 125.0f, // radius of the poofs
239 1.0f, 1.0f, 1.0f // width, height, depth jittering. best left at 1.0
241 { // 2nd highest detail level
242 0.575f, // max alpha for this detail level in Glide
243 0.71f, // max alpha for this detail level in D3d
244 0.1f, // break alpha (below which, poofs don't draw). this affects the speed and visual quality a lot
245 300.0f, 300.0f / 1.3333f, // x and y alpha fade/break values. adjust alpha on the polys as they move offscreen
246 550.0f, // total dimension of player poof cube
247 150.0f, // inner radius of the player poof cube
248 250.0f, // outer radius of the player pood cube
249 125.0f, // radius of the poofs
250 1.0f, 1.0f, 1.0f // width, height, depth jittering. best left at 1.0
252 { // higest detail level
253 0.475f, // max alpha for this detail level in Glide
254 0.575f, // max alpha for this detail level in D3d
255 0.05f, // break alpha (below which, poofs don't draw). this affects the speed and visual quality a lot
256 200.0f, 200.0f / 1.3333f, // x and y alpha fade/break values. adjust alpha on the polys as they move offscreen
257 750.0f, // total dimension of player poof cube
258 200.0f, // inner radius of the player poof cube
259 360.0f, // outer radius of the player pood cube
260 150.0f, // radius of the poofs
261 1.0f, 1.0f, 1.0f // width, height, depth jittering. best left at 1.0
264 neb2_detail *Nd = &Neb2_detail[MAX_DETAIL_LEVEL - 2];
266 int Neb2_background_color[3] = {0, 0, 255}; // rgb background color (used for lame rendering)
270 // --------------------------------------------------------------------------------------------------------
271 // NEBULA FORWARD DECLARATIONS
274 // return the alpha the passed poof should be rendered with, for a 2 shell nebula
275 float neb2_get_alpha_2shell(float inner_radius, float outer_radius, float magic_num, vector *v);
277 // return an alpha value for a bitmap offscreen based upon "break" value
278 float neb2_get_alpha_offscreen(float sx, float sy, float incoming_alpha);
280 // do a pre-render of the background nebula
281 void neb2_pre_render(vector *eye_pos, matrix *eye_orient);
283 // fill in the position of the eye for this frame
284 void neb2_get_eye_pos(vector *eye);
286 // fill in the eye orient for this frame
287 void neb2_get_eye_orient(matrix *eye);
289 // get a (semi) random bitmap to use for a poof
290 int neb2_get_bitmap();
292 // regenerate the player nebula
296 // --------------------------------------------------------------------------------------------------------
300 // initialize neb2 stuff at game startup
305 // read in the nebula.tbl
306 read_file_text("nebula.tbl");
309 // background bitmaps
310 Neb2_bitmap_count = 0;
311 while(!optional_string("#end")){
313 required_string("+Nebula:");
314 stuff_string(name, F_NAME, NULL);
316 if(Neb2_bitmap_count < MAX_NEB2_BITMAPS){
317 strcpy(Neb2_bitmap_filenames[Neb2_bitmap_count++], name);
323 while(!optional_string("#end")){
325 required_string("+Poof:");
326 stuff_string(name, F_NAME, NULL);
328 if(Neb2_poof_count < MAX_NEB2_POOFS){
329 strcpy(Neb2_poof_filenames[Neb2_poof_count++], name);
333 // should always have 6 neb poofs
334 Assert(Neb2_poof_count == 6);
338 void neb2_set_detail_level(int level)
342 Nd = &Neb2_detail[0];
345 if(level >= MAX_DETAIL_LEVEL){
346 Nd = &Neb2_detail[MAX_DETAIL_LEVEL-1];
350 Nd = &Neb2_detail[level];
352 // regen the player neb
356 // initialize nebula stuff - call from game_post_level_init(), so the mission has been loaded
357 void neb2_level_init()
361 // standalone servers can bail here
362 if(Game_mode & GM_STANDALONE_SERVER){
366 // if the mission is not a fullneb mission, skip
367 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
368 Neb2_render_mode = NEB2_RENDER_NONE;
374 if(gr_screen.mode == GR_DIRECT3D){
375 max_alpha_player = NEB2_MAX_ALPHA_D3D;
377 max_alpha_player = NEB2_MAX_ALPHA_GLIDE;
381 // by default we'll use pof rendering
382 Neb2_render_mode = NEB2_RENDER_POF;
383 stars_set_background_model(BACKGROUND_MODEL_FILENAME, Neb2_texture_name);
385 // load in all nebula bitmaps
386 for(idx=0; idx<Neb2_poof_count; idx++){
387 if(Neb2_poofs[idx] < 0){
388 Neb2_poofs[idx] = bm_load(Neb2_poof_filenames[idx]);
393 pneb_tossed_alpha = 0;
396 neb_tossed_alpha = 0;
398 neb_tossed_count = 0;
400 // setup proper fogging values
401 switch(gr_screen.mode){
403 Neb_backg_fog_near = NEB_BACKG_FOG_NEAR_GLIDE;
404 Neb_backg_fog_far = NEB_BACKG_FOG_FAR_GLIDE;
407 Neb_backg_fog_near = NEB_BACKG_FOG_NEAR_D3D;
408 Neb_backg_fog_far = NEB_BACKG_FOG_FAR_D3D;
411 Assert(Fred_running);
421 // shutdown nebula stuff
422 void neb2_level_close()
426 // standalone servers can bail here
427 if(Game_mode & GM_STANDALONE_SERVER){
431 // if the mission is not a fullneb mission, skip
432 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
436 // unload all nebula bitmaps
437 for(idx=0; idx<Neb2_poof_count; idx++){
438 if(Neb2_poofs[idx] >= 0){
439 bm_unload(Neb2_poofs[idx]);
440 Neb2_poofs[idx] = -1;
444 // unflag the mission as being fullneb so stuff doesn't fog in the techdata room :D
445 The_mission.flags &= ~MISSION_FLAG_FULLNEB;
448 // call before beginning all rendering
449 void neb2_render_setup(vector *eye_pos, matrix *eye_orient)
451 // standalone servers can bail here
452 if(Game_mode & GM_STANDALONE_SERVER){
456 // if the mission is not a fullneb mission, skip
457 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
461 // pre-render the real background nebula
462 neb2_pre_render(eye_pos, eye_orient);
470 // load in all nebula bitmaps
471 for(idx=0; idx<Neb2_poof_count; idx++){
472 if((Neb2_poofs[idx] >= 0) && (Neb2_poof_flags & (1<<idx))){
473 bm_page_in_texture(Neb2_poofs[idx]);
478 // should we not render this object because its obscured by the nebula?
479 int neb_skip_opt = 1;
482 neb_skip_opt = !neb_skip_opt;
484 dc_printf("Using neb object skipping!\n");
486 dc_printf("Not using neb object skipping!\n");
489 int neb2_skip_render(object *objp, float z_depth)
491 float fog_near, fog_far;
493 // if we're never skipping
499 if(Neb2_render_mode == NEB2_RENDER_LAME){
503 // get near and far fog values based upon object type and rendering mode
504 neb2_get_fog_values(&fog_near, &fog_far, objp);
507 switch( objp->type ) {
508 // some objects we always render
516 // any weapon over 500 meters away
518 if(z_depth >= 500.0f){
523 // any small ship over the fog limit, or any cruiser 50% further than the fog limit
526 if((objp->instance >= 0) && (Ships[objp->instance].ship_info_index >= 0)){
527 sip = &Ship_info[Ships[objp->instance].ship_info_index];
532 // small ships over the fog limit by a small factor
533 if((sip->flags & SIF_SMALL_SHIP) && (z_depth >= (fog_far * 1.3f))){
538 if((sip->flags & SIF_BIG_SHIP) && (z_depth >= (fog_far * 2.0f))){
543 if((sip->flags & SIF_HUGE_SHIP) && (z_depth >= (fog_far * 3.0f))){
548 // any fireball over the fog limit for small ships
551 if(z_depth >= fog_far){
558 // any debris over the fog limit for small ships
561 if(z_depth >= fog_far){
568 // any asteroids 50% farther than the fog limit for small ships
570 if(z_depth >= (fog_far * 1.5f)){
575 // any countermeasures over 100 meters away
577 if(z_depth >= 100.0f){
582 // hmmm. unknown object type - should probably let it through
591 float neb2_get_lod_scale(int objnum)
597 if((objnum < 0) || (objnum >= MAX_OBJECTS) || (Objects[objnum].type != OBJ_SHIP) || (Objects[objnum].instance < 0) || (Objects[objnum].instance >= MAX_SHIPS)){
600 shipp = &Ships[Objects[objnum].instance];
601 sip = &Ship_info[shipp->ship_info_index];
604 if(sip->flags & SIF_SMALL_SHIP){
606 } else if(sip->flags & SIF_BIG_SHIP){
615 // --------------------------------------------------------------------------------------------------------
616 // NEBULA FORWARD DEFINITIONS
619 // return the alpha the passed poof should be rendered with, for a 2 shell nebula
620 float neb2_get_alpha_2shell(float inner_radius, float outer_radius, float magic_num, vector *v)
626 // get the eye position
627 neb2_get_eye_pos(&eye_pos);
629 // determine what alpha to draw this bitmap with
630 // higher alpha the closer the bitmap gets to the eye
631 dist = vm_vec_dist_quick(&eye_pos, v);
633 // if the point is inside the inner radius, alpha is based on distance to the player's eye,
634 // becoming more transparent as it gets close
635 if(dist <= inner_radius){
636 // alpha per meter between the magic # and the inner radius
637 alpha = Nd->max_alpha_glide / (inner_radius - magic_num);
639 // above value times the # of meters away we are
640 alpha *= (dist - magic_num);
641 return alpha < 0.0f ? 0.0f : alpha;
643 // if the point is outside the inner radius, it starts out as completely transparent at max
644 // outer radius, and becomes more opaque as it moves towards inner radius
645 else if(dist <= outer_radius){
646 // alpha per meter between the outer radius and the inner radius
647 alpha = Nd->max_alpha_glide / (outer_radius - inner_radius);
649 // above value times the range between the outer radius and the poof
650 return alpha < 0.0f ? 0.0f : alpha * (outer_radius - dist);
653 // otherwise transparent
657 // return an alpha value for a bitmap offscreen based upon "break" value
658 float neb2_get_alpha_offscreen(float sx, float sy, float incoming_alpha)
661 float per_pixel_x = incoming_alpha / (float)Nd->break_x;
662 float per_pixel_y = incoming_alpha / (float)Nd->break_y;
663 int off_x = ((sx < 0.0f) || (sx > (float)gr_screen.max_w));
664 int off_y = ((sy < 0.0f) || (sy > (float)gr_screen.max_h));
665 float off_x_amount = 0.0f;
666 float off_y_amount = 0.0f;
668 // determine how many pixels outside we are
671 off_x_amount = fl_abs(sx);
673 off_x_amount = sx - (float)gr_screen.max_w;
678 off_y_amount = fl_abs(sy);
680 off_y_amount = sy - (float)gr_screen.max_h;
686 // offscreen X and Y - and Y is greater
687 if(off_y && (off_y_amount > off_x_amount)){
688 alpha = incoming_alpha - (off_y_amount * per_pixel_y);
690 alpha = incoming_alpha - (off_x_amount * per_pixel_x);
695 alpha = incoming_alpha - (off_y_amount * per_pixel_y);
697 // should never get here
702 return alpha < 0.0f ? 0.0f : alpha;
705 // -------------------------------------------------------------------------------------------------
706 // WACKY LOCAL PLAYER NEBULA STUFF
714 float ws = Nd->cube_dim / (float)Neb2_slices;
715 float hs = Nd->cube_dim / (float)Neb2_slices;
716 float ds = Nd->cube_dim / (float)Neb2_slices;
718 // get the eye position
719 neb2_get_eye_pos(&eye_pos);
721 // check left, right (0, and 1, x and -x)
722 if(cube_cen.x - eye_pos.x > ws){
725 } else if(eye_pos.x - cube_cen.x > ws){
730 // check up, down (2, and 3, y and -y)
731 if(cube_cen.y - eye_pos.y > hs){
734 } else if(eye_pos.y - cube_cen.y > hs){
739 // check front, back (4, and 5, z and -z)
740 if(cube_cen.z - eye_pos.z > ds){
743 } else if(eye_pos.z - cube_cen.z > ds){
752 void neb2_copy(int xyz, int src, int dest)
758 for(idx1=0; idx1<Neb2_slices; idx1++){
759 for(idx2=0; idx2<Neb2_slices; idx2++){
760 Neb2_cubes[dest][idx1][idx2] = Neb2_cubes[src][idx1][idx2];
765 for(idx1=0; idx1<Neb2_slices; idx1++){
766 for(idx2=0; idx2<Neb2_slices; idx2++){
767 Neb2_cubes[idx1][dest][idx2] = Neb2_cubes[idx1][src][idx2];
772 for(idx1=0; idx1<Neb2_slices; idx1++){
773 for(idx2=0; idx2<Neb2_slices; idx2++){
774 Neb2_cubes[idx1][idx2][dest] = Neb2_cubes[idx1][idx2][src];
784 void neb2_gen_slice(int xyz, int src, vector *cube_center)
787 float h_incw, h_inch, h_incd;
792 ws = Nd->cube_dim / (float)Neb2_slices;
794 hs = Nd->cube_dim / (float)Neb2_slices;
796 ds = Nd->cube_dim / (float)Neb2_slices;
798 cube_corner = *cube_center;
799 cube_corner.x -= (Nd->cube_dim / 2.0f);
800 cube_corner.y -= (Nd->cube_dim / 2.0f);
801 cube_corner.z -= (Nd->cube_dim / 2.0f);
804 for(idx1=0; idx1<Neb2_slices; idx1++){
805 for(idx2=0; idx2<Neb2_slices; idx2++){
806 v = &Neb2_cubes[src][idx1][idx2].pt;
808 v->x = h_incw + (ws * (float)src) + frand_range(-Nd->wj, Nd->wj);
809 v->y = h_inch + (hs * (float)idx1) + frand_range(-Nd->hj, Nd->hj);
810 v->z = h_incd + (ds * (float)idx2) + frand_range(-Nd->dj, Nd->dj);
811 vm_vec_add2(v, &cube_corner);
814 Neb2_cubes[src][idx1][idx2].bmap = neb2_get_bitmap();
816 // set the rotation speed
817 Neb2_cubes[src][idx1][idx2].rot = 0.0f;
818 Neb2_cubes[src][idx1][idx2].rot_speed = frand_range(-max_rotation, max_rotation);
819 Neb2_cubes[src][idx1][idx2].flash = 0.0f;
824 for(idx1=0; idx1<Neb2_slices; idx1++){
825 for(idx2=0; idx2<Neb2_slices; idx2++){
826 v = &Neb2_cubes[idx1][src][idx2].pt;
828 v->x = h_incw + (ws * (float)idx1) + frand_range(-Nd->wj, Nd->wj);
829 v->y = h_inch + (hs * (float)src) + frand_range(-Nd->hj, Nd->hj);
830 v->z = h_incd + (ds * (float)idx2) + frand_range(-Nd->dj, Nd->dj);
831 vm_vec_add2(v, &cube_corner);
834 Neb2_cubes[idx1][src][idx2].bmap = neb2_get_bitmap();
836 // set the rotation speed
837 Neb2_cubes[idx1][src][idx2].rot = 0.0f;
838 Neb2_cubes[idx1][src][idx2].rot_speed = frand_range(-max_rotation, max_rotation);
839 Neb2_cubes[src][idx1][idx2].flash = 0.0f;
844 for(idx1=0; idx1<Neb2_slices; idx1++){
845 for(idx2=0; idx2<Neb2_slices; idx2++){
846 v = &Neb2_cubes[idx1][idx2][src].pt;
848 v->x = h_incw + (ws * (float)idx1) + frand_range(-Nd->wj, Nd->wj);
849 v->y = h_inch + (hs * (float)idx2) + frand_range(-Nd->hj, Nd->hj);
850 v->z = h_incd + (ds * (float)src) + frand_range(-Nd->dj, Nd->dj);
851 vm_vec_add2(v, &cube_corner);
854 Neb2_cubes[idx1][idx2][src].bmap = neb2_get_bitmap();
856 // set the rotation speed
857 Neb2_cubes[idx1][idx2][src].rot = 0.0f;
858 Neb2_cubes[idx1][idx2][src].rot_speed = frand_range(-max_rotation, max_rotation);
859 Neb2_cubes[src][idx1][idx2].flash = 0.0f;
869 // regenerate the player nebula
876 mprintf(("Regenerating local nebula!\n"));
878 // get eye position and orientation
879 neb2_get_eye_pos(&eye_pos);
880 neb2_get_eye_orient(&eye_orient);
882 // determine the corner of the cube
885 // generate slices of the cube
886 for(idx=0; idx<Neb2_slices; idx++){
887 neb2_gen_slice(0, idx, &cube_cen);
891 float max_area = 100000000.0f;
894 dc_get_arg(ARG_FLOAT);
895 max_area = Dc_arg_float;
898 float g3_draw_rotated_bitmap_area(vertex *pnt, float angle, float rad, uint tmap_flags, float area);
900 int frames_total = 0;
903 void neb2_render_player()
906 int idx1, idx2, idx3;
914 float frame_area = max_area;
915 float total_area = 0.0f;
918 // standalone servers can bail here
919 if(Game_mode & GM_STANDALONE_SERVER){
923 // if the mission is not a fullneb mission, skip
924 if(!(The_mission.flags & MISSION_FLAG_FULLNEB)){
933 // don't render in lame mode
934 if((Neb2_render_mode == NEB2_RENDER_LAME) || (Neb2_render_mode == NEB2_RENDER_NONE)){
938 // get eye position and orientation
939 neb2_get_eye_pos(&eye_pos);
940 neb2_get_eye_orient(&eye_orient);
942 // maybe swap stuff around if the player crossed a "border"
943 for(idx2=0; idx2<3; idx2++){
944 switch(crossed_border()){
949 cube_cen.x -= Nd->cube_dim / (float)Neb2_slices;
950 for(idx1=Neb2_slices-1; idx1>0; idx1--){
951 neb2_copy(0, idx1-1, idx1);
953 neb2_gen_slice(0, 0, &cube_cen);
957 cube_cen.x += Nd->cube_dim / (float)Neb2_slices;
958 for(idx1=0; idx1<Neb2_slices-1; idx1++){
959 neb2_copy(0, idx1+1, idx1);
961 neb2_gen_slice(0, Neb2_slices - 1, &cube_cen);
965 cube_cen.y -= Nd->cube_dim / (float)Neb2_slices;
966 for(idx1=Neb2_slices-1; idx1>0; idx1--){
967 neb2_copy(1, idx1-1, idx1);
969 neb2_gen_slice(1, 0, &cube_cen);
973 cube_cen.y += Nd->cube_dim / (float)Neb2_slices;
974 for(idx1=0; idx1<Neb2_slices-1; idx1++){
975 neb2_copy(1, idx1+1, idx1);
977 neb2_gen_slice(1, Neb2_slices - 1, &cube_cen);
981 cube_cen.z -= Nd->cube_dim / (float)Neb2_slices;
982 for(idx1=Neb2_slices-1; idx1>0; idx1--){
983 neb2_copy(2, idx1-1, idx1);
985 neb2_gen_slice(2, 0, &cube_cen);
989 cube_cen.z += Nd->cube_dim / (float)Neb2_slices;
990 for(idx1=0; idx1<Neb2_slices-1; idx1++){
991 neb2_copy(2, idx1+1, idx1);
993 neb2_gen_slice(2, Neb2_slices - 1, &cube_cen);
998 // if we've switched nebula rendering off
999 if(Neb2_render_mode == NEB2_RENDER_NONE){
1004 // render the nebula
1005 for(idx1=0; idx1<Neb2_slices; idx1++){
1006 for(idx2=0; idx2<Neb2_slices; idx2++){
1007 for(idx3=0; idx3<Neb2_slices; idx3++){
1011 Neb2_cubes[idx1][idx2][idx3].rot += (Neb2_cubes[idx1][idx2][idx3].rot_speed * flFrametime);
1012 if(Neb2_cubes[idx1][idx2][idx3].rot >= 360.0f){
1013 Neb2_cubes[idx1][idx2][idx3].rot = 0.0f;
1016 // optimization 1 - don't draw backfacing poly's
1018 if(vm_vec_dot_to_point(&eye_orient.fvec, &eye_pos, &Neb2_cubes[idx1][idx2][idx3].pt) <= 0.0f){
1023 // rotate and project the vertex into viewspace
1024 g3_rotate_vertex(&p, &Neb2_cubes[idx1][idx2][idx3].pt);
1026 g3_project_vertex(&ptemp);
1028 // get the proper alpha value
1029 alpha = neb2_get_alpha_2shell(Nd->cube_inner, Nd->cube_outer, Nd->prad/4.0f, &Neb2_cubes[idx1][idx2][idx3].pt);
1031 // optimization 2 - don't draw 0.0f or less poly's
1032 // this amounts to big savings
1033 if(alpha <= Nd->break_alpha){
1034 pneb_tossed_alpha++;
1038 // drop poly's which are offscreen at all
1039 // if the poly's are offscreen
1040 if((ptemp.sx < 0.0f) || (ptemp.sx > (float)gr_screen.max_w) || (ptemp.sy < 0.0f) || (ptemp.sy > (float)gr_screen.max_h) ){
1041 alpha = neb2_get_alpha_offscreen(ptemp.sx, ptemp.sy, alpha);
1044 // optimization 2 - don't draw 0.0f or less poly's
1045 // this amounts to big savings
1046 if(alpha <= Nd->break_alpha){
1047 pneb_tossed_alpha++;
1051 // set the bitmap and render
1052 gr_set_bitmap(Neb2_cubes[idx1][idx2][idx3].bmap, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, alpha + Neb2_cubes[idx1][idx2][idx3].flash);
1055 this_area = g3_draw_rotated_bitmap_area(&p, fl_radian(Neb2_cubes[idx1][idx2][idx3].rot), Nd->prad, TMAP_FLAG_TEXTURED, max_area);
1056 total_area += this_area;
1057 frame_area -= this_area;
1060 g3_draw_rotated_bitmap(&p, fl_radian(Neb2_cubes[idx1][idx2][idx3].rot), Nd->prad, TMAP_FLAG_TEXTURED);
1066 frames_total += frame_rendered;
1068 frame_avg = (float)frames_total / (float)frame_count;
1070 // gr_set_color_fast(&Color_bright_red);
1071 // gr_printf(30, 100, "Area %.3f", total_area);
1072 #ifdef NEB2_THUMBNAIL
1075 gr_set_bitmap(tbmap);
1081 // call this when the player's viewpoint has changed, this will cause the code to properly reset
1082 // the eye's local poofs
1083 void neb2_eye_changed()
1088 // get near and far fog values based upon object type and rendering mode
1089 void neb2_get_fog_values(float *fnear, float *ffar, object *objp)
1093 // default values in case something truly nasty happens
1097 // determine what fog index to use
1098 if(objp->type == OBJ_SHIP){
1099 Assert((objp->instance >= 0) && (objp->instance < MAX_SHIPS));
1100 if((objp->instance < 0) || (objp->instance >= MAX_SHIPS)){
1101 fog_index = SHIP_TYPE_FIGHTER_BOMBER;
1103 fog_index = ship_query_general_type(objp->instance);
1104 Assert(fog_index >= 0);
1106 fog_index = SHIP_TYPE_FIGHTER_BOMBER;
1110 // fog everything else like a fighter
1112 fog_index = SHIP_TYPE_FIGHTER_BOMBER;
1116 switch(gr_screen.mode){
1118 *fnear = Neb_ship_fog_vals_glide[fog_index][0];
1119 *ffar = Neb_ship_fog_vals_glide[fog_index][1];
1123 *fnear = Neb_ship_fog_vals_d3d[fog_index][0];
1124 *ffar = Neb_ship_fog_vals_d3d[fog_index][1];
1132 // given a position in space, return a value from 0.0 to 1.0 representing the fog level
1133 float neb2_get_fog_intensity(object *obj)
1135 float f_near, f_far, pct;
1137 // get near and far fog values based upon object type and rendering mode
1138 neb2_get_fog_values(&f_near, &f_far, obj);
1141 pct = vm_vec_dist_quick(&Eye_position, &obj->pos) / (f_far - f_near);
1144 } else if(pct > 1.0f){
1151 // fogging stuff --------------------------------------------------------------------
1153 // do a pre-render of the background nebula
1155 ubyte tpixels[ESIZE * ESIZE * 4]; // for 32 bits
1156 int last_esize = -1;
1157 int this_esize = ESIZE;
1158 extern float Viewer_zoom;
1159 float ex_scale, ey_scale;
1161 void neb2_pre_render(vector *eye_pos, matrix *eye_orient)
1163 // bail early in lame and poly modes
1164 if(Neb2_render_mode != NEB2_RENDER_POF){
1168 // set the view clip
1169 gr_screen.clip_width = this_esize;
1170 gr_screen.clip_height = this_esize;
1171 g3_start_frame(1); // Turn on zbuffering
1172 g3_set_view_matrix(eye_pos, eye_orient, Viewer_zoom);
1173 gr_set_clip(0, 0, this_esize, this_esize);
1175 // render the background properly
1176 // hack - turn off nebula stuff
1177 int neb_save = Neb2_render_mode;
1178 Neb2_render_mode = NEB2_RENDER_NONE;
1180 // draw background stuff nebula
1181 extern void stars_draw_background();
1182 stars_draw_background();
1184 Neb2_render_mode = neb_save;
1186 // HACK - flush d3d here so everything is rendered
1187 if(gr_screen.mode == GR_DIRECT3D){
1188 extern void d3d_flush();
1193 gr_get_region(0, this_esize, this_esize, (ubyte*)tpixels);
1195 #ifdef NEB2_THUMBNAIL
1197 tbmap = bm_create(16, this_esize, this_esize, tpixels, 0);
1198 bm_lock(tbmap, 16, 0);
1203 // maybe do some swizzling
1210 // HACK - flush d3d here so everything is properly cleared
1211 if(gr_screen.mode == GR_DIRECT3D){
1212 extern void d3d_flush();
1216 // if the size has changed between frames, make a new bitmap
1217 if(this_esize != last_esize){
1218 last_esize = this_esize;
1220 // recalculate ex_scale and ey_scale values for looking up color values
1221 ex_scale = (float)this_esize / (float)gr_screen.max_w;
1222 ey_scale = (float)this_esize / (float)gr_screen.max_h;
1225 // restore the game clip stuff
1226 extern void game_set_view_clip();
1227 game_set_view_clip();
1230 // wacky scheme for smoothing colors
1231 int wacky_scheme = 3;
1233 // get the color of the pixel in the small pre-rendered background nebula
1234 #define PIXEL_INDEX_SMALL(xv, yv) ( (this_esize * (yv) * gr_screen.bytes_per_pixel) + ((xv) * gr_screen.bytes_per_pixel) )
1235 void neb2_get_pixel(int x, int y, int *r, int *g, int *b)
1242 // if we're in lame rendering mode, return a constant value
1243 if(Neb2_render_mode == NEB2_RENDER_LAME){
1244 *r = Neb2_background_color[0];
1245 *g = Neb2_background_color[1];
1246 *b = Neb2_background_color[2];
1251 // get the proper pixel index to be looking up
1254 // select screen format
1255 BM_SELECT_SCREEN_FORMAT();
1257 // pixel plus all immediate neighbors (on the small screen - should be more effective than 2 or 1)
1258 xs = (int)(ex_scale * x);
1259 ys = (int)(ey_scale * y);
1261 // sometimes goes over by 1 in direct3d
1262 if(ys >= (this_esize - 1)){
1267 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs, ys)], &rv, &gv, &bv, NULL);
1273 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs - 1, ys)], &rv, &gv, &bv, NULL); // left
1279 if(xs < this_esize - 1){
1280 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs + 1, ys)], &rv, &gv, &bv, NULL); // right
1287 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs, ys - 1)], &rv, &gv, &bv, NULL); // top
1293 if(ys < this_esize - 2){
1294 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs, ys + 1)], &rv, &gv, &bv, NULL); // bottom
1301 if((xs > 0) && (ys > 0)){
1302 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs - 1, ys - 1)], &rv, &gv, &bv, NULL); // upper left
1308 if((xs < this_esize - 1) && (ys < this_esize - 1)){
1309 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs + 1, ys + 1)], &rv, &gv, &bv, NULL); // lower right
1315 if((ys > 0) && (xs < this_esize - 1)){
1316 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs + 1, ys - 1)], &rv, &gv, &bv, NULL); // lower left
1322 if((ys < this_esize - 1) && (xs > 0)){
1323 bm_get_components(&tpixels[PIXEL_INDEX_SMALL(xs - 1, ys + 1)], &rv, &gv, &bv, NULL); // upper right
1330 rv = (ubyte) (ra / avg_count);
1331 gv = (ubyte) (ga / avg_count);
1332 bv = (ubyte) (ba / avg_count);
1340 // get the color to fog the background color to
1341 void neb2_get_backg_color(int *r, int *g, int *b)
1343 *r = Neb2_background_color[0];
1344 *g = Neb2_background_color[1];
1345 *b = Neb2_background_color[2];
1348 // set the background color
1349 void neb2_set_backg_color(int r, int g, int b)
1351 Neb2_background_color[0] = r;
1352 Neb2_background_color[1] = g;
1353 Neb2_background_color[2] = b;
1356 // fill in the position of the eye for this frame
1357 void neb2_get_eye_pos(vector *eye)
1359 *eye = Eye_position;
1362 // fill in the eye orient for this frame
1363 void neb2_get_eye_orient(matrix *eye)
1368 // get a (semi) random bitmap to use for a poof
1369 int neb2_get_bitmap()
1373 static int neb2_choose = 0;
1375 // get a random count
1376 count = (int)frand_range(1.0f, 5.0f);
1380 // don't cycle too many times
1383 if(neb2_choose == MAX_NEB2_POOFS - 1){
1390 } while(!(Neb2_poof_flags & (1<<neb2_choose)) && (huh < 10));
1396 if(Neb2_poofs[neb2_choose] < 0){
1397 return Neb2_poofs[0];
1399 return Neb2_poofs[neb2_choose];
1402 // nebula DCF functions ------------------------------------------------------
1404 DCF(neb2, "list nebula console commands")
1406 dc_printf("neb2_fog <X> <float> <float> : set near and far fog planes for ship type X\n");
1407 dc_printf("where X is an integer from 1 - 11\n");
1408 dc_printf("1 = cargo containers, 2 = fighters/bombers, 3 = cruisers\n");
1409 dc_printf("4 = freighters, 5 = capital ships, 6 = transports, 7 = support ships\n");
1410 dc_printf("8 = navbuoys, 9 = sentryguns, 10 = escape pods, 11 = background nebula polygons\n\n");
1412 dc_printf("neb2_max_alpha : max alpha value (0.0 to 1.0) for cloud poofs. 0.0 is completely transparent\n");
1413 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");
1414 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");
1415 dc_printf("neb2_smooth : magic fog smoothing modes (0 - 3)\n");
1416 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");
1417 dc_printf("neb2_rot : set max rotation speed for poofs\n");
1418 dc_printf("neb2_prad : set cloud poof radius\n");
1419 dc_printf("neb2_cdim : poof cube dimension\n");
1420 dc_printf("neb2_cinner : poof cube inner dimension\n");
1421 dc_printf("neb2_couter : poof cube outer dimension\n");
1422 dc_printf("neb2_jitter : poof jitter\n");
1423 dc_printf("neb2_mode : switch between no nebula, polygon background, amd pof background (0, 1 and 2 respectively)\n\n");
1424 dc_printf("neb2_ff : flash fade/sec\n");
1425 dc_printf("neb2_background : rgb background color\n");
1427 dc_printf("neb2_fog_vals : display all the current settings for all above values\n");
1432 dc_get_arg(ARG_FLOAT);
1433 Nd->prad = Dc_arg_float;
1437 dc_get_arg(ARG_FLOAT);
1438 Nd->cube_dim = Dc_arg_float;
1441 DCF(neb2_cinner, "")
1443 dc_get_arg(ARG_FLOAT);
1444 Nd->cube_inner = Dc_arg_float;
1447 DCF(neb2_couter, "")
1449 dc_get_arg(ARG_FLOAT);
1450 Nd->cube_outer = Dc_arg_float;
1453 DCF(neb2_jitter, "")
1455 dc_get_arg(ARG_FLOAT);
1456 Nd->hj = Nd->dj = Nd->wj = Dc_arg_float;
1463 dc_get_arg(ARG_INT);
1465 dc_get_arg(ARG_FLOAT);
1466 fnear = Dc_arg_float;
1467 dc_get_arg(ARG_FLOAT);
1468 ffar = Dc_arg_float;
1470 if((index >= 1) && (index <= 11) && (fnear >= 0.0f) && (ffar >= 0.0f) && (ffar > fnear)){
1472 Neb_backg_fog_near = fnear;
1473 Neb_backg_fog_far = ffar;
1475 if(gr_screen.mode == GR_GLIDE){
1476 Neb_ship_fog_vals_glide[index][0] = fnear;
1477 Neb_ship_fog_vals_glide[index][1] = ffar;
1479 Assert(gr_screen.mode == GR_DIRECT3D);
1480 Neb_ship_fog_vals_d3d[index][0] = fnear;
1481 Neb_ship_fog_vals_d3d[index][1] = ffar;
1487 DCF(neb2_max_alpha, "")
1489 dc_get_arg(ARG_FLOAT);
1490 Nd->max_alpha_glide = Dc_arg_float;
1493 DCF(neb2_break_alpha, "")
1495 dc_get_arg(ARG_FLOAT);
1496 Nd->break_alpha = Dc_arg_float;
1499 DCF(neb2_break_off, "")
1501 dc_get_arg(ARG_INT);
1502 Nd->break_y = (float)Dc_arg_int;
1503 Nd->break_x = Nd->break_y * 1.3333f;
1506 DCF(neb2_smooth, "")
1509 dc_get_arg(ARG_INT);
1511 if((index >= 0) && (index <= 3)){
1512 wacky_scheme = index;
1516 DCF(neb2_select, "")
1518 dc_get_arg(ARG_INT);
1519 int bmap = Dc_arg_int;
1520 if((bmap >= 0) && (bmap < Neb2_poof_count)){
1521 dc_get_arg(ARG_INT);
1524 Neb2_poof_flags |= (1<<bmap);
1526 Neb2_poof_flags &= ~(1<<bmap);
1533 dc_get_arg(ARG_FLOAT);
1534 max_rotation = Dc_arg_float;
1539 dc_get_arg(ARG_FLOAT);
1540 neb2_flash_fade = Dc_arg_float;
1545 dc_get_arg(ARG_INT);
1548 case NEB2_RENDER_NONE:
1549 Neb2_render_mode = NEB2_RENDER_NONE;
1552 case NEB2_RENDER_POLY:
1553 Neb2_render_mode = NEB2_RENDER_POLY;
1556 case NEB2_RENDER_POF:
1557 Neb2_render_mode = NEB2_RENDER_POF;
1558 stars_set_background_model(BACKGROUND_MODEL_FILENAME, "Eraseme3");
1561 case NEB2_RENDER_LAME:
1562 Neb2_render_mode = NEB2_RENDER_LAME;
1567 DCF(neb2_slices, "")
1569 dc_get_arg(ARG_INT);
1570 Neb2_slices = Dc_arg_int;
1574 DCF(neb2_background, "")
1578 dc_get_arg(ARG_INT);
1580 dc_get_arg(ARG_INT);
1582 dc_get_arg(ARG_INT);
1585 Neb2_background_color[0] = r;
1586 Neb2_background_color[1] = g;
1587 Neb2_background_color[2] = b;
1590 DCF(neb2_fog_vals, "")
1592 dc_printf("neb2_fog : \n");
1593 if(gr_screen.mode == GR_GLIDE){
1594 dc_printf("(1)cargo containers : %f, %f\n", Neb_ship_fog_vals_glide[1][0], Neb_ship_fog_vals_glide[1][1]);
1595 dc_printf("(2)fighters/bombers : %f, %f\n", Neb_ship_fog_vals_glide[2][0], Neb_ship_fog_vals_glide[2][1]);
1596 dc_printf("(3)cruisers : %f, %f\n", Neb_ship_fog_vals_glide[3][0], Neb_ship_fog_vals_glide[3][1]);
1597 dc_printf("(4)freighters : %f, %f\n", Neb_ship_fog_vals_glide[4][0], Neb_ship_fog_vals_glide[4][1]);
1598 dc_printf("(5)cap ships : %f, %f\n", Neb_ship_fog_vals_glide[5][0], Neb_ship_fog_vals_glide[5][1]);
1599 dc_printf("(6)transports : %f, %f\n", Neb_ship_fog_vals_glide[6][0], Neb_ship_fog_vals_glide[6][1]);
1600 dc_printf("(7)support ships : %f, %f\n", Neb_ship_fog_vals_glide[7][0], Neb_ship_fog_vals_glide[7][1]);
1601 dc_printf("(8)navbuoys : %f, %f\n", Neb_ship_fog_vals_glide[8][0], Neb_ship_fog_vals_glide[8][1]);
1602 dc_printf("(9)sentry guns : %f, %f\n", Neb_ship_fog_vals_glide[9][0], Neb_ship_fog_vals_glide[9][1]);
1603 dc_printf("(10)escape pods : %f, %f\n", Neb_ship_fog_vals_glide[10][0], Neb_ship_fog_vals_glide[10][1]);
1604 dc_printf("(11)background polys : %f, %f\n\n", Neb_backg_fog_near, Neb_backg_fog_far);
1607 Assert(gr_screen.mode == GR_DIRECT3D);
1608 dc_printf("(1)cargo containers : %f, %f\n", Neb_ship_fog_vals_d3d[1][0], Neb_ship_fog_vals_d3d[1][1]);
1609 dc_printf("(2)fighters/bombers : %f, %f\n", Neb_ship_fog_vals_d3d[2][0], Neb_ship_fog_vals_d3d[2][1]);
1610 dc_printf("(3)cruisers : %f, %f\n", Neb_ship_fog_vals_d3d[3][0], Neb_ship_fog_vals_d3d[3][1]);
1611 dc_printf("(4)freighters : %f, %f\n", Neb_ship_fog_vals_d3d[4][0], Neb_ship_fog_vals_d3d[4][1]);
1612 dc_printf("(5)cap ships : %f, %f\n", Neb_ship_fog_vals_d3d[5][0], Neb_ship_fog_vals_d3d[5][1]);
1613 dc_printf("(6)transports : %f, %f\n", Neb_ship_fog_vals_d3d[6][0], Neb_ship_fog_vals_d3d[6][1]);
1614 dc_printf("(7)support ships : %f, %f\n", Neb_ship_fog_vals_d3d[7][0], Neb_ship_fog_vals_d3d[7][1]);
1615 dc_printf("(8)navbuoys : %f, %f\n", Neb_ship_fog_vals_d3d[8][0], Neb_ship_fog_vals_d3d[8][1]);
1616 dc_printf("(9)sentry guns : %f, %f\n", Neb_ship_fog_vals_d3d[9][0], Neb_ship_fog_vals_d3d[9][1]);
1617 dc_printf("(10)escape pods : %f, %f\n", Neb_ship_fog_vals_d3d[10][0], Neb_ship_fog_vals_d3d[10][1]);
1618 dc_printf("(11)background polys : %f, %f\n\n", Neb_backg_fog_near, Neb_backg_fog_far);
1620 dc_printf("neb2_max_alpha : %f\n", Nd->max_alpha_glide);
1621 dc_printf("neb2_break_alpha : %f\n", Nd->break_alpha);
1622 dc_printf("neb2_break_off : %d\n", (int)Nd->break_y);
1623 dc_printf("neb2_smooth : %d\n", wacky_scheme);
1624 dc_printf("neb2_toggle : %s\n", Neb2_render_mode ? "on" : "off");
1625 dc_printf("neb2_rot : %f\n", max_rotation);
1626 dc_printf("neb2_prad : %f\n", Nd->prad);
1627 dc_printf("neb2_cdim : %f\n", Nd->cube_dim);
1628 dc_printf("neb2_couter : %f\n", Nd->cube_outer);
1629 dc_printf("neb2_cinner : %f\n", Nd->cube_inner);
1630 dc_printf("neb2_jitter : %f\n", Nd->wj);
1631 dc_printf("neb2_ff : %f\n", neb2_flash_fade);
1632 dc_printf("neb2_background : %d %d %d\n", Neb2_background_color[0], Neb2_background_color[1], Neb2_background_color[2]);
1636 DCF(neb2_create, "create a basic nebula")
1642 dc_get_arg(ARG_INT);
1643 if(Dc_arg_type & ARG_INT){
1644 points = Dc_arg_int;
1646 dc_get_arg(ARG_FLOAT);
1647 if(Dc_arg_type & ARG_FLOAT){
1648 rad1 = Dc_arg_float;
1650 dc_get_arg(ARG_FLOAT);
1651 if(Dc_arg_type & ARG_FLOAT){
1652 rad2 = Dc_arg_float;
1654 neb2_create(&vmd_zero_vector, points, rad1, -1.0f, rad2);
1657 DCF(neb2_del, "delete existing nebulae")
1659 for(int idx=0; idx<MAX_OBJECTS; idx++){
1660 if(Objects[idx].type == OBJ_NEB2){
1667 float magic1 = 1000.0f;
1668 float magic2 = -1.0f;
1669 float magic3 = 700.0f;
1670 DCF(neb2_def, "create a default nebula")
1673 vm_vec_make(&a, 0.0f, 0.0f, 0.0f);
1674 vm_vec_make(&b, 3600.0f, 700.0f, 0.0f);
1675 vm_vec_make(&c, -3000.0f, 20.0f, 480.0f);
1676 vm_vec_make(&d, -4000.0f, 100.0f, 100.0f);
1677 vm_vec_make(&e, 0.0f, 3000.0f, -400.0f);
1678 vm_vec_make(&f, 670.0f, -2500.0f, -1600.0f);
1680 neb2_create(&a, magic0, magic1, magic2, magic3);
1681 neb2_create(&b, magic0, magic1, magic2, magic3);
1682 neb2_create(&c, magic0, magic1, magic2, magic3);
1683 neb2_create(&d, magic0, magic1, magic2, magic3);
1684 neb2_create(&e, magic0, magic1, magic2, magic3);
1685 neb2_create(&f, magic0, magic1, magic2, magic3);
1688 DCF(neb2_plr, "regenerate the player's nebula")
1693 DCF(neb2_stats, "display info about the nebula rendering")
1695 dc_printf("Player poofs tried : %d\n", pneb_tried);
1696 dc_printf("Player poofs tossed (alpha): %d\n", pneb_tossed_alpha);
1697 dc_printf("Player poofs tossed (dot): %d\n", pneb_tossed_dot);
1698 dc_printf("Player poofs tossed (off): %d\n", pneb_tossed_off);
1700 dc_printf("Poofs tried : %d\n", neb_tried);
1701 dc_printf("Poofs tossed (alpha): %d\n", neb_tossed_alpha);
1702 dc_printf("Poofs tossed (dot): %d\n", neb_tossed_dot);
1703 dc_printf("Poofs tossed (count): %d\n", neb_tossed_count);
1705 dc_printf("Avg poofs/frame: %f\n", frame_avg);
1708 // create a nebula object, return objnum of the nebula or -1 on fail
1709 // NOTE : in most cases you will want to pass -1.0f for outer_radius. Trust me on this
1710 int neb2_create(vector *offset, int num_poofs, float inner_radius, float outer_radius, float max_poof_radius)
1716 // delete a nebula object
1717 void neb2_delete(object *objp)
1722 // renders a nebula object
1723 void neb2_render(object *objp)
1728 // preprocess the nebula object before simulation
1729 void neb2_process_pre(object *objp)
1734 // process the nebula object after simulating, but before rendering
1735 void neb2_process_post(object *objp)
1742 // add N poofs to the inner shell of the nebula
1743 // if orient and ang are specified, generate the poofs so that they are "visible" around
1744 // the orient fvec in a cone of ang degrees
1745 void neb2_add_inner(neb2 *neb, int num_poofs, matrix *orient, float ang)
1748 vector pt, pt2, pt3;
1749 int final_index = (neb->num_poofs + num_poofs) > neb->max_poofs ? neb->max_poofs : (neb->num_poofs + num_poofs);
1751 // add the points a pick a random bitmap
1752 for(idx=neb->num_poofs; idx<final_index; idx++){
1754 // put a point directly in front of the player, between 0 and inner_radius distance away
1755 vm_vec_copy_scale(&pt, &orient->fvec, frand_range(neb->magic_num, neb->inner_radius));
1757 // rotate the point by -ang <-> ang around the up vector
1758 vm_rot_point_around_line(&pt2, &pt, fl_radian(frand_range(-ang, ang)), &vmd_zero_vector, &orient->uvec);
1760 // rotate the point by -ang <-> ang around the right vector
1761 vm_rot_point_around_line(&pt3, &pt2, fl_radian(frand_range(-ang, ang)), &vmd_zero_vector, &orient->rvec);
1763 // now add in the center of the nebula so its placed properly (ie, not around the origin)
1764 vm_vec_add(&neb->pts[idx], &pt3, &Objects[neb->objnum].pos);
1766 neb->pts[idx].x = frand_range(-1.0f * neb->inner_radius, neb->inner_radius) + Objects[neb->objnum].pos.x;
1767 neb->pts[idx].y = frand_range(-1.0f * neb->inner_radius, neb->inner_radius) + Objects[neb->objnum].pos.y;
1768 neb->pts[idx].z = frand_range(-1.0f * neb->inner_radius, neb->inner_radius) + Objects[neb->objnum].pos.z;
1771 neb->bmaps[idx] = (int)frand_range(0.0f, (float)2);
1776 // add N poofs to the outer shell of the nebula
1777 // if orient and ang are specified, generate the poofs so that they are "visible" around
1778 // the orient fvec in a cone of ang degrees
1779 void neb2_add_outer(neb2 *neb, int num_poofs, matrix *orient, float ang)
1783 vector pt, pt2, pt3;
1784 int final_index = (neb->num_poofs + num_poofs) > neb->max_poofs ? neb->max_poofs : (neb->num_poofs + num_poofs);
1786 // add the points a pick a random bitmap
1787 for(idx=neb->num_poofs; idx<final_index; idx++){
1789 // put a point directly in front of the player, at outer_radius distance away
1790 vm_vec_copy_scale(&pt, &orient->fvec, neb->outer_radius);
1792 // rotate the point by -ang <-> ang around the up vector
1793 vm_rot_point_around_line(&pt2, &pt, fl_radian(frand_range(-ang, ang)), &vmd_zero_vector, &orient->uvec);
1795 // rotate the point by -ang <-> ang around the right vector
1796 vm_rot_point_around_line(&pt3, &pt2, fl_radian(frand_range(-ang, ang)), &vmd_zero_vector, &orient->rvec);
1798 // now add in the center of the nebula so its placed properly (ie, not around the origin)
1799 vm_vec_add(&neb->pts[idx], &pt, &Objects[neb->objnum].pos);
1801 // get a random point on the very outer radius, using spherical coords
1802 phi = fl_radian(frand_range(0.0f, 360.0f));
1803 theta = fl_radian(frand_range(0.0f, 360.f));
1805 neb->pts[idx].x = neb->outer_radius * (float)sin(phi) * (float)cos(theta);
1806 neb->pts[idx].y = neb->outer_radius * (float)sin(phi) * (float)sin(theta);
1807 neb->pts[idx].z = neb->outer_radius * (float)cos(phi);
1810 // pick a random bitmap and increment the # of poofs
1811 neb->bmaps[idx] = (int)frand_range(0.0f, (float)2);
1816 // return the alpha the passed poof should be rendered with, for a 1 shell nebula
1817 float neb2_get_alpha_1shell(neb2 *neb, int poof_index)
1823 // get the eye position
1824 neb2_get_eye_pos(&eye_pos);
1826 // determine what alpha to draw this bitmap with
1827 // higher alpha the closer the bitmap gets to the eye
1828 dist = vm_vec_dist_quick(&eye_pos, &neb->pts[poof_index]);
1830 // at poof radius or greater, alpha should be 1.0
1831 // scale from 0.0 to 1.0 between radius and magic
1832 if(dist >= neb->max_poof_radius){
1833 return max_alpha - 0.0001f;
1834 } else if(dist > neb->magic_num){
1835 // alpha per meter between the magic # and the max radius
1836 alpha = max_alpha / (neb->max_poof_radius - neb->magic_num);
1838 // above value times the # of meters away we are
1839 return alpha * (dist - neb->magic_num);
1842 // otherwise transparent