+
+void vox_sky_grad(struct voxscape *vox, uint32_t chor, uint32_t ctop)
+{
+ int i, j, colheight, t;
+ int r0, g0, b0, r1, g1, b1;
+ int d = vox->fbheight - vox->horizon;
+ uint32_t *grad, *fbptr;
+
+ grad = alloca(vox->fbheight * sizeof *grad);
+
+ b0 = ctop >> 16;
+ g0 = (ctop >> 8) & 0xff;
+ r0 = ctop & 0xff;
+ b1 = chor >> 16;
+ g1 = (chor >> 8) & 0xff;
+ r1 = chor & 0xff;
+
+ for(i=0; i<d; i++) {
+ t = (i << 16) / d;
+ grad[i] = lerp_rgb(r0, g0, b0, r1, g1, b1, t);
+ }
+ for(i=d; i<vox->fbheight; i++) {
+ grad[i] = chor;
+ }
+
+ for(i=0; i<vox->fbwidth; i++) {
+ fbptr = vox->fb + i;
+ colheight = vox->fbheight - vox->coltop[i];
+ for(j=0; j<colheight; j++) {
+ *fbptr = grad[j];
+ fbptr += vox->fbwidth;
+ }
+ }
+}
+
+static uint32_t lerp_rgb(int r0, int g0, int b0, int r1, int g1, int b1, int32_t t)
+{
+ int r = XLERP(r0, r1, t, 16);
+ int g = XLERP(g0, g1, t, 16);
+ int b = XLERP(b0, b1, t, 16);
+ return (b << 16) | (g << 8) | r;
+}
+
+static uint32_t lerp_color(uint32_t ca, uint32_t cb, int32_t t)
+{
+ int r0, g0, b0, r1, g1, b1;
+
+ b0 = ca >> 16;
+ g0 = (ca >> 8) & 0xff;
+ r0 = ca & 0xff;
+ b1 = cb >> 16;
+ g1 = (cb >> 8) & 0xff;
+ r1 = cb & 0xff;
+
+ return lerp_rgb(r0, g0, b0, r1, g1, b1, t);
+}
+
+static uint32_t lerp_pcol_rgb(uint32_t pcol, int r, int g, int b, int32_t t)
+{
+ int b0 = pcol >> 16;
+ int g0 = (pcol >> 8) & 0xff;
+ int r0 = pcol & 0xff;
+
+ return lerp_rgb(r0, g0, b0, r, g, b, t);
+}
+