Here I will combine my two previous posts into one shader, the uv_as_colors_banding shader. I'll implement the rounding function as demonstrated in the wikipedia article. I did not understand some of the source code from the book
Methodology
1. Implement uv as colors
2. Define u_count, which is the amount of banding in the u direction
3. Define v_count, which is the amount of banding in the v direction
4. Implement the quantize function.
MI Source
declare shader color "uv_as_colors_banding" ( integer "u_count" default 4, integer "v_count" default 4, ) apply material end declare
C Source
#include "shader.h"
struct uv_as_colors_banding{
miInteger u_count;
miInteger v_count;
};
miScalar quantize(miScalar value, miInteger m) {
miScalar q = (miScalar)m;
return (miScalar)(((int)(value * q)) / q);
}
miBoolean uv_as_colors_banding(miColor *result, miState *state, struct uv_as_colors_banding *params) {
result->r = quantize(state->tex_list[0].x, *mi_eval_integer(¶ms->u_count));
result->g = quantize(state->tex_list[0].y, *mi_eval_integer(¶ms->v_count));
result->b = 0;
return miTRUE;
}

0 comments:
Post a Comment