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