Ejemplo n.º 1
0
/* shades the drawn block with the given facemask, based on the
   lighting results from (x, y, z) */
static inline void
do_shading_with_mask(RenderPrimitiveLighting *self, RenderState *state,
                     int x, int y, int z, PyObject *mask) {
    unsigned char r, g, b;
    float comp_strength;
    
    /* check occlusion */
    if (lighting_is_face_occluded(state, self->skip_sides, x, y, z))
        return;
    
    get_lighting_color(self, state, x, y, z, &r, &g, &b);
    comp_strength = 1.0 - self->strength;
    
    r += (255 - r) * comp_strength;
    g += (255 - g) * comp_strength;
    b += (255 - b) * comp_strength;
    
    tint_with_mask(state->img, r, g, b, 255, mask, state->imgx, state->imgy, 0, 0);
}
static void
do_shading_with_rule(RenderModeSmoothLighting *self, RenderState *state, struct SmoothLightingFace face) {
    int i;
    RenderModeLighting *lighting = (RenderModeLighting *)self;
    int x = state->imgx, y = state->imgy;
    struct SmoothLightingCorner *pts = face.corners;
    float comp_shade_strength = 1.0 - lighting->shade_strength;
    unsigned char pts_r[4] = {0, 0, 0, 0};
    unsigned char pts_g[4] = {0, 0, 0, 0};
    unsigned char pts_b[4] = {0, 0, 0, 0};
    int cx = state->x + face.dx;
    int cy = state->y + face.dy;
    int cz = state->z + face.dz;
    
    /* first, check for occlusion if the block is in the local chunk */
    if (rendermode_lighting_is_face_occluded(state, 0, cx, cy, cz))
        return;
    
    /* calculate the lighting colors for each point */
    for (i = 0; i < 4; i++)
    {
        unsigned char r, g, b;
        unsigned int rgather = 0, ggather = 0, bgather = 0;
        
        get_lighting_color(lighting, state, cx, cy, cz,
                           &r, &g, &b);
        rgather += r; ggather += g; bgather += b;

        get_lighting_color(lighting, state,
                           cx+pts[i].dx1, cy+pts[i].dy1, cz+pts[i].dz1,
                           &r, &g, &b);
        rgather += r; ggather += g; bgather += b;

        get_lighting_color(lighting, state,
                           cx+pts[i].dx2, cy+pts[i].dy2, cz+pts[i].dz2,
                           &r, &g, &b);
        rgather += r; ggather += g; bgather += b;

        /* FIXME special far corner handling */
        get_lighting_color(lighting, state,
                           cx+pts[i].dx1+pts[i].dx2, cy+pts[i].dy1+pts[i].dy2, cz+pts[i].dz1+pts[i].dz2,
                           &r, &g, &b);
        rgather += r; ggather += g; bgather += b;
        
        rgather += (255*4 - rgather) * comp_shade_strength;
        ggather += (255*4 - ggather) * comp_shade_strength;
        bgather += (255*4 - bgather) * comp_shade_strength;
    
        pts_r[i] = rgather / 4;
        pts_g[i] = ggather / 4;
        pts_b[i] = bgather / 4;
    }
    
    /* draw the face */
    draw_triangle(state->img, 1,
                  x+pts[0].imgx, y+pts[0].imgy, pts_r[0], pts_g[0], pts_b[0],
                  x+pts[1].imgx, y+pts[1].imgy, pts_r[1], pts_g[1], pts_b[1],
                  x+pts[2].imgx, y+pts[2].imgy, pts_r[2], pts_g[2], pts_b[2],
                  x, y, face.touch_up_points, face.num_touch_up_points);
    draw_triangle(state->img, 0,
                  x+pts[0].imgx, y+pts[0].imgy, pts_r[0], pts_g[0], pts_b[0],
                  x+pts[2].imgx, y+pts[2].imgy, pts_r[2], pts_g[2], pts_b[2],
                  x+pts[3].imgx, y+pts[3].imgy, pts_r[3], pts_g[3], pts_b[3],
                  x, y, NULL, 0);
}