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, float x1, float x2, float w1, float w2, float u1, float u2, float v1, float v2)
34 {
35  uint8_t * sc = (uint8_t *)&curTriangle->solidColor;
36  uint8_t * fc = (uint8_t *)&curTrilist->fog.color;
37 
38  float d = x2 - x1;
39  if (d == 0.0f) return;
40 
41  float au = (u2 - u1) / d;
42  float av = (v2 - v1) / d;
43  float aw = (w2 - w1) / d;
44 
45  float znear = curTrilist->fog.near;
46  float zfar = curTrilist->fog.far;
47  float zscale = -1.0f / (znear - zfar);
48 
49  int xb = (int)(x1);
50  int xe = (int)(x2 + 1.9999f);
51  if (xe > frame.tx) xe = frame.tx;
52 
53  uint8_t * p = (uint8_t *)(xb + ((int)y) * frame.tx + pixels);
54 
55  for (int x = xb; x < xe; x++) {
56  float z = 1.0f / w1;
57  uint32_t tu = ((int32_t)(u1 * z)) & texMaskU;
58  uint32_t tv = ((int32_t)(v1 * z)) & texMaskV;
59  uint8_t * t = (uint8_t *)&texDiffusePixels[tu + (tv << texSizeU)];
60 
61  float ff = (z - znear) * zscale;
62  ff = cmmax(0.0f, ff);
63  ff = cmmin(1.0f, ff);
64  ff = 256.0f * ff * ff;
65  int fb = (int) ff;
66 
67  int n = t[3];
68  int a = 256 - n;
69 
70  int r = t[0] * sc[0];
71  int g = t[1] * sc[1];
72  int b = t[2] * sc[2];
73  r = r + (((fc[0] * n - r) * fb) >> 8);
74  g = g + (((fc[1] * n - g) * fb) >> 8);
75  b = b + (((fc[2] * n - b) * fb) >> 8);
76 
77  p[0] = (p[0] * a + r) >> 8;
78  p[1] = (p[1] * a + g) >> 8;
79  p[2] = (p[2] * a + b) >> 8;
80  p += 4;
81 
82  u1 += au;
83  v1 += av;
84  w1 += aw;
85  }
86 }
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