Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntony Riakiotakis <kalast@gmail.com>2013-03-13 07:46:22 +0400
committerAntony Riakiotakis <kalast@gmail.com>2013-03-13 07:46:22 +0400
commitacd3bef34e6a6b30df694f931dc0c622ca083f59 (patch)
tree5ed6c71a9d92b3e8a21c44ee69ee59eb39566fff /source/blender/blenkernel
parent153b63e0fde21730cd54f16a501c18c793256ae2 (diff)
Texture sampling function refactoring:
ALERT! POSSIBLE BREAKING COMMIT, ESPECIALLY FOR SCULPT! Separate the sculpt sampling function so that it can be reused from other paint systems. This includes updating of the relevant coordinates for anchored and rake style brushes, which are now being updated as part of the stroke system. I left only code for area-style brush texture mapping in sculpt code, since it requires a few data structures not present on other paint systems. This commit makes it almost as easy to support rake on other systems as exposing the python UI for it. Also it makes it totally possible to have texture painting capabilities in vertex paint too :) These commits will follow very soon. Also, even if I did my best to keep the code from breaking, (even fixed a leftover bug from coordinate changes) this is a big change. Please test!
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_brush.h4
-rw-r--r--source/blender/blenkernel/BKE_paint.h3
-rw-r--r--source/blender/blenkernel/intern/brush.c96
-rw-r--r--source/blender/blenkernel/intern/paint.c20
4 files changed, 119 insertions, 4 deletions
diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h
index 3c65cb03c68..2247495ce9e 100644
--- a/source/blender/blenkernel/BKE_brush.h
+++ b/source/blender/blenkernel/BKE_brush.h
@@ -70,7 +70,9 @@ float BKE_brush_curve_strength(struct Brush *br, float p, const float len); /* u
/* sampling */
void BKE_brush_sample_tex(const struct Scene *scene, struct Brush *brush, const float sampleco[3], float rgba[4], const int thread, struct ImagePool *pool);
-void BKE_brush_sample_tex_2D(const struct Scene *scene, struct Brush *brush, const float xy[2], float rgba[4], const int thread);
+float BKE_brush_sample_tex_3D(const Scene *scene, struct Brush *br,const float point[3],
+ float rgba[3], struct ImagePool *pool);
+float BKE_brush_sample_tex_2D(const struct Scene *scene, struct Brush *brush, const float xy[2], float rgba[4], 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/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 6e9dfdb5cba..35941d0a05a 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -48,6 +48,7 @@ struct PBVH;
struct Scene;
struct StrokeCache;
struct ImagePool;
+struct UnifiedPaintSettings;
extern const char PAINT_CURSOR_SCULPT[3];
extern const char PAINT_CURSOR_VERTEX_PAINT[3];
@@ -90,7 +91,7 @@ int paint_is_bmesh_face_hidden(struct BMFace *f);
/* paint masks */
float paint_grid_paint_mask(const struct GridPaintMask *gpm, unsigned level,
unsigned x, unsigned y);
-
+void paint_calculate_rake_rotation(struct UnifiedPaintSettings *ups, const float mouse_pos[2]);
/* Session data (mode-specific) */
typedef struct SculptSession {
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index ab821ec37a1..4ec20d5fe04 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -513,8 +513,98 @@ void BKE_brush_sample_tex(const Scene *scene, Brush *brush, const float sampleco
}
}
+
+/* Return a multiplier for brush strength on a particular vertex. */
+float BKE_brush_sample_tex_3D(const Scene *scene, Brush *br,
+ const float point[3],
+ float rgba[3],
+ struct ImagePool *pool)
+{
+ UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
+ MTex *mtex = &br->mtex;
+ float intensity = 1.0;
+ bool hasrgb = false;
+
+ if (!mtex->tex) {
+ intensity = 1;
+ }
+ else if (mtex->brush_map_mode == MTEX_MAP_MODE_3D) {
+ /* Get strength by feeding the vertex
+ * location directly into a texture */
+ hasrgb = externtex(mtex, point, &intensity,
+ rgba, rgba + 1, rgba + 2, rgba + 3, 0, pool);
+ }
+ else {
+ 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[2];
+
+ if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) {
+ /* keep coordinates relative to mouse */
+
+ rotation += ups->brush_rotation;
+
+ 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];
+ }
+ else if (mtex->brush_map_mode == MTEX_MAP_MODE_TILED) {
+ /* leave the coordinates relative to the screen */
+
+ /* use unadjusted size for tiled mode */
+ radius = BKE_brush_size_get(scene, br);
+
+ 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->mtex.size[0];
+ y *= br->mtex.size[1];
+
+ co[0] = x + br->mtex.ofs[0];
+ co[1] = y + br->mtex.ofs[1];
+ co[2] = 0.0f;
+
+ hasrgb = externtex(mtex, co, &intensity,
+ rgba, rgba + 1, rgba + 2, rgba + 3, 0, pool);
+ }
+
+ intensity += br->texture_sample_bias;
+
+ if (!hasrgb) {
+ rgba[0] = intensity;
+ rgba[1] = intensity;
+ rgba[2] = intensity;
+ rgba[3] = 1.0f;
+ }
+
+ return intensity;
+}
+
+
/* Brush Sampling for 2D brushes. when we unify the brush systems this will be necessarily a separate function */
-void BKE_brush_sample_tex_2D(const Scene *scene, Brush *brush, const float xy[2], float rgba[4], const int thread)
+float BKE_brush_sample_tex_2D(const Scene *scene, Brush *brush, const float xy[2], float rgba[4], struct ImagePool *pool)
{
MTex *mtex = &brush->mtex;
@@ -527,7 +617,7 @@ void BKE_brush_sample_tex_2D(const Scene *scene, Brush *brush, const float xy[2]
co[1] = xy[1] / radius;
co[2] = 0.0f;
- hasrgb = externtex(mtex, co, &tin, &tr, &tg, &tb, &ta, thread, NULL);
+ hasrgb = externtex(mtex, co, &tin, &tr, &tg, &tb, &ta, 0, pool);
if (hasrgb) {
rgba[0] = tr;
@@ -541,9 +631,11 @@ void BKE_brush_sample_tex_2D(const Scene *scene, Brush *brush, const float xy[2]
rgba[2] = tin;
rgba[3] = 1.0f;
}
+ return tin;
}
else {
rgba[0] = rgba[1] = rgba[2] = rgba[3] = 1.0f;
+ return 1.0;
}
}
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index a001a13d000..cc647a90c8f 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -40,6 +40,7 @@
#include "BLI_bitmap.h"
#include "BLI_utildefines.h"
+#include "BLI_math_vector.h"
#include "BKE_brush.h"
#include "BKE_context.h"
@@ -300,3 +301,22 @@ float paint_grid_paint_mask(const GridPaintMask *gpm, unsigned level,
return gpm->data[(y * factor) * gridsize + (x * factor)];
}
+
+/* threshhold to move before updating the brush rotation */
+#define RAKE_THRESHHOLD 20
+
+void paint_calculate_rake_rotation(UnifiedPaintSettings *ups, const float mouse_pos[2])
+{
+ const float u = 0.5f;
+ const float r = RAKE_THRESHHOLD;
+
+ float dpos[2];
+ sub_v2_v2v2(dpos, ups->last_rake, mouse_pos);
+
+ if (len_squared_v2(dpos) >= r * r) {
+ ups->brush_rotation = atan2(dpos[0], dpos[1]);
+
+ interp_v2_v2v2(ups->last_rake, ups->last_rake,
+ mouse_pos, u);
+ }
+}