1 /*
2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
3 *
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 the
6 * source.
7 *
8 */
9
10
11
12
13 #include "cmdline/cmdline.h"
14 #include "globalincs/pstypes.h"
15 #include "graphics/tmapper.h"
16 #include "math/vecmat.h"
17 #include "mission/missionparse.h"
18 #include "model/model.h"
19 #include "nebula/neb.h"
20 #include "render/3d.h"
21 #include "render/batching.h"
22 #include "ship/ship.h"
23
warpin_batch_draw_face(int texture,vertex * v1,vertex * v2,vertex * v3)24 void warpin_batch_draw_face( int texture, vertex *v1, vertex *v2, vertex *v3 )
25 {
26 vec3d norm;
27 vertex vertlist[3];
28
29 vm_vec_perp(&norm,&v1->world, &v2->world, &v3->world);
30 if ( vm_vec_dot(&norm, &v1->world ) >= 0.0 ) {
31 vertlist[0] = *v3;
32 vertlist[1] = *v2;
33 vertlist[2] = *v1;
34 } else {
35 vertlist[0] = *v1;
36 vertlist[1] = *v2;
37 vertlist[2] = *v3;
38 }
39
40 // batch_add_tri(texture, TMAP_FLAG_TEXTURED | TMAP_HTL_3D_UNLIT | TMAP_FLAG_EMISSIVE, vertlist, 1.0f);
41 batching_add_tri(texture, vertlist); // TODO render as emissive
42 }
43
warpin_queue_render(model_draw_list * scene,object * obj,matrix * orient,vec3d * pos,int texture_bitmap_num,float radius,float life_percent,float max_radius,bool warp_3d,int warp_glow_bitmap,int warp_ball_bitmap,int warp_model_id)44 void warpin_queue_render(model_draw_list *scene, object *obj, matrix *orient, vec3d *pos, int texture_bitmap_num, float radius, float life_percent, float max_radius, bool warp_3d, int warp_glow_bitmap, int warp_ball_bitmap, int warp_model_id)
45 {
46 vec3d center;
47 vec3d vecs[5];
48 vertex verts[5];
49
50 vm_vec_scale_add( ¢er, pos, &orient->vec.fvec, -(max_radius/2.5f)/3.0f );
51
52 // Cyborg17, Initialize the *whole* struct, set some starting values and share with the rest of the array.
53 verts[0] = {};
54 verts[0].r = verts[0].g = verts[0].b = verts[0].a = 255;
55 verts[1] = verts[2] = verts[3] = verts[4] = verts[0];
56
57 if (warp_glow_bitmap >= 0) {
58 float r = radius;
59 bool render_it = true;
60
61 #define OUT_PERCENT1 0.80f
62 #define OUT_PERCENT2 0.90f
63
64 #define IN_PERCENT1 0.10f
65 #define IN_PERCENT2 0.20f
66
67 if (Cmdline_warp_flash)
68 {
69 if ( (life_percent >= IN_PERCENT1) && (life_percent < IN_PERCENT2) ) {
70 r *= (life_percent - IN_PERCENT1) / (IN_PERCENT2 - IN_PERCENT1);
71 //render_it = true;
72 } else if ( (life_percent >= OUT_PERCENT1) && (life_percent < OUT_PERCENT2) ) {
73 r *= (OUT_PERCENT2 - life_percent) / (OUT_PERCENT2 - OUT_PERCENT1);
74 //render_it = true;
75 }
76 }
77
78 if (render_it) {
79 // Add in noise
80 int noise_frame = fl2i(Missiontime/15.0f) % NOISE_NUM_FRAMES;
81
82 r *= (0.40f + Noise[noise_frame] * 0.30f);
83
84 // Bobboau's warp thingie, toggled by cmdline
85 if (Cmdline_warp_flash) {
86 r += powf((2.0f * life_percent) - 1.0f, 24.0f) * max_radius * 1.5f;
87 }
88
89 vecs[4] = center;
90 verts[4].texture_position.u = 0.5f; verts[4].texture_position.v = 0.5f;
91
92 g3_transfer_vertex( &verts[4], &vecs[4] );
93
94 float alpha = (The_mission.flags[Mission::Mission_Flags::Fullneb]) ? neb2_get_fog_visibility(&obj->pos, 1.0f) : 1.0f;
95
96 //batch_add_bitmap(warp_glow_bitmap, TMAP_FLAG_TEXTURED | TMAP_HTL_3D_UNLIT, &verts[4], 0, r, alpha);
97 batching_add_bitmap(warp_glow_bitmap, &verts[4], 0, r, alpha);
98 }
99 }
100
101 if ( (warp_model_id >= 0) && (warp_3d || Fireball_use_3d_warp) ) {
102 model_render_params render_info;
103
104 float scale = radius / 25.0f;
105
106 vec3d warp_scale;
107
108 warp_scale.xyz.x = warp_scale.xyz.y = warp_scale.xyz.z = scale;
109
110 float dist = vm_vec_dist_quick( pos, &Eye_position );
111
112 render_info.set_warp_params(texture_bitmap_num, radius/max_radius, warp_scale);
113 render_info.set_detail_level_lock((int)(dist / (radius * 10.0f)));
114 render_info.set_flags(MR_NO_LIGHTING | MR_NORMAL | MR_NO_FOGGING | MR_NO_CULL | MR_NO_BATCH);
115
116 model_render_queue( &render_info, scene, warp_model_id, orient, pos);
117 } else {
118 float Grid_depth = radius/2.5f;
119
120 // gr_set_bitmap( texture_bitmap_num, GR_ALPHABLEND_FILTER, GR_BITBLT_MODE_NORMAL, 1.0f );
121
122 vm_vec_scale_add( &vecs[0], ¢er, &orient->vec.uvec, radius );
123 vm_vec_scale_add2( &vecs[0], &orient->vec.rvec, -radius );
124 vm_vec_scale_add2( &vecs[0], &orient->vec.fvec, Grid_depth );
125
126 vm_vec_scale_add( &vecs[1], ¢er, &orient->vec.uvec, radius );
127 vm_vec_scale_add2( &vecs[1], &orient->vec.rvec, radius );
128 vm_vec_scale_add2( &vecs[1], &orient->vec.fvec, Grid_depth );
129
130 vm_vec_scale_add( &vecs[2], ¢er, &orient->vec.uvec, -radius );
131 vm_vec_scale_add2( &vecs[2], &orient->vec.rvec, radius );
132 vm_vec_scale_add2( &vecs[2], &orient->vec.fvec, Grid_depth );
133
134 vm_vec_scale_add( &vecs[3], ¢er, &orient->vec.uvec, -radius );
135 vm_vec_scale_add2( &vecs[3], &orient->vec.rvec, -radius );
136 vm_vec_scale_add2( &vecs[3], &orient->vec.fvec, Grid_depth );
137
138 // vm_vec_scale_add( &vecs[4], center, &orient->vec.fvec, -Grid_depth );
139 vecs[4] = center;
140
141 verts[0].texture_position.u = 0.01f;
142 verts[0].texture_position.v = 0.01f;
143
144 verts[1].texture_position.u = 0.99f;
145 verts[1].texture_position.v = 0.01f;
146
147 verts[2].texture_position.u = 0.99f;
148 verts[2].texture_position.v = 0.99f;
149
150 verts[3].texture_position.u = 0.01f;
151 verts[3].texture_position.v = 0.99f;
152
153 verts[4].texture_position.u = 0.5f;
154 verts[4].texture_position.v = 0.5f;
155
156 g3_transfer_vertex( &verts[0], &vecs[0] );
157 g3_transfer_vertex( &verts[1], &vecs[1] );
158 g3_transfer_vertex( &verts[2], &vecs[2] );
159 g3_transfer_vertex( &verts[3], &vecs[3] );
160 g3_transfer_vertex( &verts[4], &vecs[4] );
161
162 warpin_batch_draw_face( texture_bitmap_num, &verts[0], &verts[4], &verts[1] );
163 warpin_batch_draw_face( texture_bitmap_num, &verts[1], &verts[4], &verts[2] );
164 warpin_batch_draw_face( texture_bitmap_num, &verts[4], &verts[3], &verts[2] );
165 warpin_batch_draw_face( texture_bitmap_num, &verts[0], &verts[3], &verts[4] );
166 }
167
168 if (warp_ball_bitmap >= 0 && Cmdline_warp_flash) {
169 flash_ball warp_ball(20, .1f,.25f, &orient->vec.fvec, pos, 4.0f, 0.5f);
170
171 float adg = (2.0f * life_percent) - 1.0f;
172 float pct = (powf(adg, 4.0f) - powf(adg, 128.0f)) * 4.0f;
173
174 if (pct > 0.00001f) {
175 warp_ball.render(warp_ball_bitmap, max_radius * pct * 0.5f, adg * adg, adg * adg * 6.0f);
176 }
177 }
178 }
179