diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2013-03-25 05:00:16 +0400 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2013-03-25 05:00:16 +0400 |
commit | ceb3225db77c5a86b8cb8cce555251c1dffdd033 (patch) | |
tree | 8f709801c59f683c2cb50ea67841c5f15861b075 /source/blender/blenkernel | |
parent | 48a256c910e85405747ad47a62bcb70159aee638 (diff) |
Alpha mask textures porting part 1: Support for projective texturing.
Also add random mapping to brushes.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_blender.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_brush.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/brush.c | 66 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/texture.c | 11 |
4 files changed, 79 insertions, 2 deletions
diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h index c6b02bc8361..2d10b76378a 100644 --- a/source/blender/blenkernel/BKE_blender.h +++ b/source/blender/blenkernel/BKE_blender.h @@ -42,7 +42,7 @@ extern "C" { * and keep comment above the defines. * Use STRINGIFY() rather than defining with quotes */ #define BLENDER_VERSION 266 -#define BLENDER_SUBVERSION 3 +#define BLENDER_SUBVERSION 4 /* 262 was the last editmesh release but it has compatibility code for bmesh data */ #define BLENDER_MINVERSION 262 diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h index e0afb1929a5..e123a0a94c0 100644 --- a/source/blender/blenkernel/BKE_brush.h +++ b/source/blender/blenkernel/BKE_brush.h @@ -78,6 +78,8 @@ float BKE_brush_sample_tex_3D(const Scene *scene, struct Brush *br, const float float rgba[4], const int thread, struct ImagePool *pool); float BKE_brush_sample_tex_2D(const struct Scene *scene, struct Brush *brush, const float xy[2], float rgba[4]); +float BKE_brush_sample_masktex (const Scene *scene, struct Brush *br,const float point[3], + const int thread, struct ImagePool *pool); void BKE_brush_imbuf_new(const struct Scene *scene, struct Brush *brush, short flt, short texfalloff, int size, struct ImBuf **imbuf, int use_color_correction); diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index d6cd7290038..7700538af28 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -107,6 +107,7 @@ static void brush_defaults(Brush *brush) /* BRUSH TEXTURE SETTINGS */ default_mtex(&brush->mtex); + default_mtex(&brush->mask_mtex); brush->texture_sample_bias = 0; /* value to added to texture samples */ brush->texture_overlay_alpha = 33; @@ -152,6 +153,9 @@ Brush *BKE_brush_copy(Brush *brush) if (brush->mtex.tex) id_us_plus((ID *)brush->mtex.tex); + if (brush->mask_mtex.tex) + id_us_plus((ID *)brush->mask_mtex.tex); + if (brush->icon_imbuf) brushn->icon_imbuf = IMB_dupImBuf(brush->icon_imbuf); @@ -174,6 +178,9 @@ void BKE_brush_free(Brush *brush) if (brush->mtex.tex) brush->mtex.tex->id.us--; + if (brush->mask_mtex.tex) + brush->mask_mtex.tex->id.us--; + if (brush->icon_imbuf) IMB_freeImBuf(brush->icon_imbuf); @@ -185,6 +192,7 @@ void BKE_brush_free(Brush *brush) static void extern_local_brush(Brush *brush) { id_lib_extern((ID *)brush->mtex.tex); + id_lib_extern((ID *)brush->mask_mtex.tex); id_lib_extern((ID *)brush->clone.image); } @@ -514,7 +522,9 @@ float BKE_brush_sample_tex_3D(const Scene *scene, Brush *br, float radius = 1.0f; /* Quite warnings */ float co[3]; - if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) { + if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW || + mtex->brush_map_mode == MTEX_MAP_MODE_RANDOM) + { /* keep coordinates relative to mouse */ rotation += ups->brush_rotation; @@ -575,6 +585,60 @@ float BKE_brush_sample_tex_3D(const Scene *scene, Brush *br, return intensity; } +float BKE_brush_sample_masktex (const Scene *scene, Brush *br, + const float point[3], + const int thread, + struct ImagePool *pool) { + UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; + MTex *mtex = &br->mask_mtex; + + if (mtex && mtex->tex) { + float rotation = -mtex->rot; + float point_2d[2] = {point[0], point[1]}; + float x = 0.0f, y = 0.0f; /* Quite warnings */ + float radius = 1.0f; /* Quite warnings */ + float co[3]; + float rgba[4], intensity = 1.0; + + point_2d[0] -= ups->tex_mouse[0]; + point_2d[1] -= ups->tex_mouse[1]; + + /* use pressure adjusted size for fixed mode */ + radius = ups->pixel_radius; + + x = point_2d[0]; + y = point_2d[1]; + + x /= radius; + y /= radius; + + /* it is probably worth optimizing for those cases where + * the texture is not rotated by skipping the calls to + * atan2, sqrtf, sin, and cos. */ + if (rotation > 0.001f || rotation < -0.001f) { + const float angle = atan2f(y, x) + rotation; + const float flen = sqrtf(x * x + y * y); + + x = flen * cosf(angle); + y = flen * sinf(angle); + } + + x *= br->mask_mtex.size[0]; + y *= br->mask_mtex.size[1]; + + co[0] = x + br->mask_mtex.ofs[0]; + co[1] = y + br->mask_mtex.ofs[1]; + co[2] = 0.0f; + + externtex(mtex, co, &intensity, + rgba, rgba + 1, rgba + 2, rgba + 3, thread, pool); + + return intensity; + } + else { + return 1.0f; + } +} /* Brush Sampling for 2D brushes. when we unify the brush systems this will be necessarily a separate function */ float BKE_brush_sample_tex_2D(const Scene *scene, Brush *brush, const float xy[2], float rgba[4]) diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index 2517324242b..10b0e14d517 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -804,6 +804,10 @@ void BKE_texture_make_local(Tex *tex) if (br->id.lib) is_lib = TRUE; else is_local = TRUE; } + if (br->mask_mtex.tex == tex) { + if (br->id.lib) is_lib = TRUE; + else is_local = TRUE; + } br = br->id.next; } pa = bmain->particle.first; @@ -877,6 +881,13 @@ void BKE_texture_make_local(Tex *tex) tex->id.us--; } } + if (br->mask_mtex.tex == tex) { + if (br->id.lib == NULL) { + br->mask_mtex.tex = tex_new; + tex_new->id.us++; + tex->id.us--; + } + } br = br->id.next; } pa = bmain->particle.first; |