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