Quake II RTX doxygen  1.0 dev
part.c File Reference
#include "sw.h"

Go to the source code of this file.

Classes

struct  partparms_t
 

Functions

static void R_DrawParticle (void)
 
void R_DrawParticles (void)
 

Variables

static partparms_t partparms
 

Function Documentation

◆ R_DrawParticle()

static void R_DrawParticle ( void  )
static

Definition at line 43 of file part.c.

44 {
45  vec3_t local, transformed;
46  float zi;
47  byte *pdest;
48  short *pz;
49  int i, izi, pix, count, u, v;
50 
51  /*
52  ** transform the particle
53  */
54  VectorSubtract(partparms.particle->origin, r_origin, local);
55 
56  transformed[0] = DotProduct(local, partparms.right);
57  transformed[1] = DotProduct(local, partparms.up);
58  transformed[2] = DotProduct(local, partparms.pn);
59 
60  if (transformed[2] < PARTICLE_Z_CLIP)
61  return;
62 
63  /*
64  ** project the point
65  */
66  // FIXME: preadjust xcenter and ycenter
67  zi = 1.0 / transformed[2];
68  u = (int)(r_refdef.xcenter + zi * transformed[0] + 0.5);
69  v = (int)(r_refdef.ycenter - zi * transformed[1] + 0.5);
70 
73  v < r_refdef.vrect.y ||
74  u < r_refdef.vrect.x) {
75  return;
76  }
77 
78  /*
79  ** compute addresses of zbuffer, framebuffer, and
80  ** compute the Z-buffer reference value.
81  */
82  pz = d_zspantable[v] + u;
83  pdest = d_spantable[v] + u * VID_BYTES;
84  izi = (int)(zi * 0x8000);
85 
86  /*
87  ** determine the screen area covered by the particle,
88  ** which also means clamping to a min and max
89  */
90  pix = izi >> r_refdef.pix_shift;
91  if (pix < r_refdef.pix_min)
92  pix = r_refdef.pix_min;
93  else if (pix > r_refdef.pix_max)
94  pix = r_refdef.pix_max;
95 
96  /*
97  ** render the appropriate pixels
98  */
99  for (count = pix; count; count--, pz += d_zwidth, pdest += d_screenrowbytes) {
100  for (i = 0; i < pix; i++) {
101  if (pz[i] <= izi) {
102  pz[i] = izi;
103  pdest[i * VID_BYTES + 0] = (pdest[i * VID_BYTES + 0] * partparms.one_minus_alpha + partparms.color[2]) >> 8;
104  pdest[i * VID_BYTES + 1] = (pdest[i * VID_BYTES + 1] * partparms.one_minus_alpha + partparms.color[1]) >> 8;
105  pdest[i * VID_BYTES + 2] = (pdest[i * VID_BYTES + 2] * partparms.one_minus_alpha + partparms.color[0]) >> 8;
106  }
107  }
108  }
109 }

Referenced by R_DrawParticles().

◆ R_DrawParticles()

void R_DrawParticles ( void  )

Definition at line 119 of file part.c.

120 {
121  particle_t *p;
122  int i;
123  int alpha;
124 
125  VectorScale(vright, r_refdef.xscaleshrink, partparms.right);
126  VectorScale(vup, r_refdef.yscaleshrink, partparms.up);
127  VectorCopy(vpn, partparms.pn);
128 
129  for (p = r_newrefdef.particles, i = 0; i < r_newrefdef.num_particles; i++, p++) {
130  partparms.particle = p;
131 
132  alpha = 255 * p->alpha;
133  partparms.one_minus_alpha = 255 - alpha;
134 
135  if (p->color == -1) {
136  partparms.color[0] = p->rgba.u8[0] * alpha;
137  partparms.color[1] = p->rgba.u8[1] * alpha;
138  partparms.color[2] = p->rgba.u8[2] * alpha;
139  } else {
140  color_t color;
141 
142  color.u32 = d_8to24table[p->color & 0xff];
143  partparms.color[0] = color.u8[0] * alpha;
144  partparms.color[1] = color.u8[1] * alpha;
145  partparms.color[2] = color.u8[2] * alpha;
146  }
147 
148  R_DrawParticle();
149  }
150 }

Referenced by R_RenderFrame().

Variable Documentation

◆ partparms

partparms_t partparms
static

Definition at line 28 of file part.c.

Referenced by R_DrawParticle(), and R_DrawParticles().

oldrefdef_t::xcenter
float xcenter
Definition: sw.h:145
r_origin
vec3_t r_origin
Definition: main.c:52
r_newrefdef
refdef_t r_newrefdef
Definition: main.c:28
d_screenrowbytes
int d_screenrowbytes
Definition: main.c:126
R_DrawParticle
static void R_DrawParticle(void)
Definition: part.c:43
partparms_t::right
vec3_t right
Definition: part.c:25
r_refdef
oldrefdef_t r_refdef
Definition: main.c:57
d_8to24table
uint32_t d_8to24table[256]
Definition: images.c:654
oldrefdef_t::xscaleshrink
float xscaleshrink
Definition: sw.h:148
partparms_t::one_minus_alpha
int one_minus_alpha
Definition: part.c:24
oldrefdef_t::vrectright_particle
int vrectright_particle
Definition: sw.h:152
vup
vec3_t vup
Definition: main.c:49
partparms_t::particle
particle_t * particle
Definition: part.c:22
partparms_t::pn
vec3_t pn
Definition: part.c:25
partparms_t::color
fixed8_t color[3]
Definition: part.c:23
oldrefdef_t::pix_min
int pix_min
Definition: sw.h:153
vpn
vec3_t vpn
Definition: main.c:50
PARTICLE_Z_CLIP
#define PARTICLE_Z_CLIP
Definition: sw.h:67
d_spantable
byte * d_spantable[MAXHEIGHT]
Definition: main.c:130
d_zwidth
int d_zwidth
Definition: main.c:129
d_zspantable
short * d_zspantable[MAXHEIGHT]
Definition: main.c:131
partparms_t::up
vec3_t up
Definition: part.c:25
VID_BYTES
#define VID_BYTES
Definition: sw.h:49
oldrefdef_t::vrect
vrect_t vrect
Definition: sw.h:132
oldrefdef_t::yscaleshrink
float yscaleshrink
Definition: sw.h:148
oldrefdef_t::vrectbottom_particle
int vrectbottom_particle
Definition: sw.h:152
oldrefdef_t::pix_shift
int pix_shift
Definition: sw.h:153
oldrefdef_t::pix_max
int pix_max
Definition: sw.h:153
color
static vec4_t color
Definition: mesh.c:33
oldrefdef_t::ycenter
float ycenter
Definition: sw.h:145
int
CONST PIXELFORMATDESCRIPTOR int
Definition: wgl.c:26
partparms
static partparms_t partparms
Definition: part.c:28
vright
vec3_t vright
Definition: main.c:51