0

normal mode height fading (a la Fenixin's formula, Issue #147)

This commit is contained in:
Aaron Griffith
2011-06-19 13:34:16 -04:00
parent f8b005d079
commit 7e5f518958
2 changed files with 31 additions and 1 deletions

View File

@@ -36,6 +36,15 @@ rendermode_normal_start(void *data, RenderState *state, PyObject *options) {
if (!render_mode_parse_option(options, "max_depth", "I", &(self->max_depth))) if (!render_mode_parse_option(options, "max_depth", "I", &(self->max_depth)))
return 1; return 1;
self->height_fading = 0;
if (!render_mode_parse_option(options, "height_fading", "i", &(self->height_fading)))
return 1;
if (self->height_fading) {
self->black_color = PyObject_GetAttrString(state->chunk, "black_color");
self->white_color = PyObject_GetAttrString(state->chunk, "white_color");
}
chunk_x_py = PyObject_GetAttrString(state->self, "chunkX"); chunk_x_py = PyObject_GetAttrString(state->self, "chunkX");
chunk_y_py = PyObject_GetAttrString(state->self, "chunkY"); chunk_y_py = PyObject_GetAttrString(state->self, "chunkY");
@@ -120,6 +129,8 @@ rendermode_normal_finish(void *data, RenderState *state) {
Py_XDECREF(self->tall_grass_texture); Py_XDECREF(self->tall_grass_texture);
Py_XDECREF(self->tall_fern_texture); Py_XDECREF(self->tall_fern_texture);
Py_XDECREF(self->facemask_top); Py_XDECREF(self->facemask_top);
Py_XDECREF(self->black_color);
Py_XDECREF(self->white_color);
} }
static int static int
@@ -216,7 +227,21 @@ rendermode_normal_draw(void *data, RenderState *state, PyObject *src, PyObject *
tint_with_mask(state->img, r, g, b, 255, facemask, state->imgx, state->imgy, 0, 0); tint_with_mask(state->img, r, g, b, 255, facemask, state->imgx, state->imgy, 0, 0);
} }
} }
if (self->height_fading) {
/* do some height fading */
PyObject *height_color = self->white_color;
/* negative alpha => darkness, positive => light */
float alpha = (1.0 / (1 + expf((70 - state->z) / 11.0))) * 0.6 - 0.55;
if (alpha < 0.0) {
alpha *= -1;
height_color = self->black_color;
}
alpha_over_full(state->img, height_color, mask_light, alpha, state->imgx, state->imgy, 0, 0);
}
/* Draw some edge lines! */ /* Draw some edge lines! */
// draw.line(((imgx+12,imgy+increment), (imgx+22,imgy+5+increment)), fill=(0,0,0), width=1) // draw.line(((imgx+12,imgy+increment), (imgx+22,imgy+5+increment)), fill=(0,0,0), width=1)
@@ -267,6 +292,7 @@ const RenderModeOption rendermode_normal_options[] = {
{"edge_opacity", "darkness of the edge lines, from 0.0 to 1.0 (default: 0.15)"}, {"edge_opacity", "darkness of the edge lines, from 0.0 to 1.0 (default: 0.15)"},
{"min_depth", "lowest level of blocks to render (default: 0)"}, {"min_depth", "lowest level of blocks to render (default: 0)"},
{"max_depth", "highest level of blocks to render (default: 127)"}, {"max_depth", "highest level of blocks to render (default: 127)"},
{"height_fading", "darken or lighten blocks based on height (default: False)"},
{NULL, NULL} {NULL, NULL}
}; };

View File

@@ -110,9 +110,13 @@ typedef struct {
/* top facemask for grass biome tinting */ /* top facemask for grass biome tinting */
PyObject *facemask_top; PyObject *facemask_top;
/* black and white colors for height fading */
PyObject *black_color, *white_color;
float edge_opacity; float edge_opacity;
unsigned int min_depth; unsigned int min_depth;
unsigned int max_depth; unsigned int max_depth;
int height_fading;
} RenderModeNormal; } RenderModeNormal;
extern RenderModeInterface rendermode_normal; extern RenderModeInterface rendermode_normal;