le3d - LightEngine 3D
A straightforward C++ 3D software engine for real-time graphics
flattexzcfog.h
Go to the documentation of this file.
1 
33 inline void LeRasterizer::fillFlatTexZCFog(int y, int x1, int x2, int w1, int w2, int u1, int u2, int v1, int v2)
34 {
35  uint8_t * sc = (uint8_t *)&curTriangle->solidColor;
36  uint8_t * fc = (uint8_t *)&curTrilist->fog.color;
37 
38  short d = x2 - x1;
39  if (d == 0) return;
40 
41  int au = (u2 - u1) / d;
42  int av = (v2 - v1) / d;
43  int aw = (w2 - w1) / d;
44 
45  const float sw = 0x1p8;
46  int32_t znear = (int32_t) (curTrilist->fog.near * sw);
47  int32_t zfar = (int32_t) (curTrilist->fog.far * sw);
48  int32_t zscale = (1 << 30) / (zfar - znear);
49 
50  uint8_t * p = (uint8_t *)(x1 + y * frame.tx + pixels);
51 
52  for (int x = x1; x <= x2; x++) {
53  int32_t z = (1 << 30) / (w1 >> 8);
54  uint32_t tu = (((int64_t) u1 * z) >> 24) & texMaskU;
55  uint32_t tv = (((int64_t) v1 * z) >> 24) & texMaskV;
56  uint8_t * t = (uint8_t *) &texDiffusePixels[tu + (tv << texSizeU)];
57 
58  int r = (t[0] * sc[0]) >> 8;
59  int g = (t[1] * sc[1]) >> 8;
60  int b = (t[2] * sc[2]) >> 8;
61 
62  int32_t ff = ((int64_t) (z - znear) * zscale) >> 15;
63  ff = cmmax(0, ff);
64  ff = cmmin((1 << 15), ff);
65  int fb = (ff * ff) >> (14 + 8);
66 
67  p[0] = r + (((fc[0] - r) * fb) >> 8);
68  p[1] = g + (((fc[1] - g) * fb) >> 8);
69  p[2] = b + (((fc[2] - b) * fb) >> 8);
70  p += 4;
71 
72  u1 += au;
73  v1 += av;
74  w1 += aw;
75  }
76 }
LeColor color
Definition: trilist.h:53
LeColor solidColor
Definition: trilist.h:83
#define cmmin(a, b)
Definition: global.h:45
int tx
Definition: bitmap.h:81
LeBitmap frame
Definition: rasterizer_float.h:61
float near
Definition: trilist.h:54
LeFog fog
Definition: trilist.h:103
float far
Definition: trilist.h:55
#define cmmax(a, b)
Definition: global.h:44