UV distort

Tonight I decided to try and use the derivative stuff I learned last week to distort an image. What I’ve ended up with gets the uv space derivative from a gradient and samples an input image based on it. I built it at first without normalizing the derivative vector and got some really strange results, but this was cool enough I decided I’d leave it as an option

non-normalized result



struct uv_shift{
    miColor        input_color;
    miScalar        gradient;
    miScalar    sample_dist;
    miScalar    shift;
    miInteger normalize;
DLLEXPORT miBoolean uv_shift(
    miColor *result,
    miState *state,
    struct uv_shift *param)
    miScalar  sample_dist =  *mi_eval_scalar(&param->sample_dist);
    miScalar  shift =  *mi_eval_scalar(&param->shift);
    miScalar   gradient = *mi_eval_scalar(&param->gradient);
    miInteger normalize = *mi_eval_integer(&param->normalize);
    state->tex_list[0].x+= sample_dist;
    miScalar   gradient_x = *mi_eval_scalar(&param->gradient);
    state->tex_list[0].x-= sample_dist;
    state->tex_list[0].y+= sample_dist;
    miScalar   gradient_y = *mi_eval_scalar(&param->gradient);
    state->tex_list[0].y -= sample_dist;
    miVector uv;
    uv.x = gradient_x-gradient;
    uv.y = gradient_y-gradient;
    uv.z = 0;
    if (normalize > .5)
    state->tex_list[0].x += uv.x*shift;
    state->tex_list[0].y += uv.y*shift;
    miColor input_color = *mi_eval_color(&param->input_color);
    result->r = input_color.r;
    result->g = input_color.g;
    result->b = input_color.b;
    result->a = input_color.a;


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: