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-01-21 01:32:14 +0400
committerAntony Riakiotakis <kalast@gmail.com>2013-01-21 01:32:14 +0400
commite6f82619899af71b823e58812b231599d4dd46e2 (patch)
tree02410f8a066eed56cb5806f351b0e661358884ec /source/blender/blenkernel/intern/brush.c
parent952c83cb621b97789ca5436390f28309c38ab0ff (diff)
3D mapping for projective texture painting (only for draw brush). Useful
to draw with procedural textures on surface of object. 2D painting will still paint as if tiled. When we unify the paint systems, the texture sampling functions will need to be changed. Sculpt uses a slightly different system that passes both screen and 3d coordinates to the sampling function. This commit however is not too disrupting for that however so it can go in now.
Diffstat (limited to 'source/blender/blenkernel/intern/brush.c')
-rw-r--r--source/blender/blenkernel/intern/brush.c55
1 files changed, 47 insertions, 8 deletions
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index e8275471b09..bb4f073a3d7 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -471,8 +471,46 @@ int BKE_brush_clone_image_delete(Brush *brush)
return 0;
}
-/* Brush Sampling */
-void BKE_brush_sample_tex(const Scene *scene, Brush *brush, const float xy[2], float rgba[4], const int thread)
+/* Brush Sampling for 3d brushes. Currently used for texture painting only, but should be generalized */
+void BKE_brush_sample_tex(const Scene *scene, Brush *brush, const float sampleco[3], float rgba[4], const int thread)
+{
+ MTex *mtex = &brush->mtex;
+
+ if (mtex && mtex->tex) {
+ float co[3], tin, tr, tg, tb, ta;
+ int hasrgb;
+ const int radius = BKE_brush_size_get(scene, brush);
+
+ if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_3D) {
+ copy_v3_v3(co, sampleco);
+ } else {
+ co[0] = sampleco[0] / radius;
+ co[1] = sampleco[1] / radius;
+ co[2] = 0.0f;
+ }
+
+ hasrgb = externtex(mtex, co, &tin, &tr, &tg, &tb, &ta, thread);
+
+ if (hasrgb) {
+ rgba[0] = tr;
+ rgba[1] = tg;
+ rgba[2] = tb;
+ rgba[3] = ta;
+ }
+ else {
+ rgba[0] = tin;
+ rgba[1] = tin;
+ rgba[2] = tin;
+ rgba[3] = 1.0f;
+ }
+ }
+ else {
+ rgba[0] = rgba[1] = rgba[2] = rgba[3] = 1.0f;
+ }
+}
+
+/* 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)
{
MTex *mtex = &brush->mtex;
@@ -505,7 +543,8 @@ void BKE_brush_sample_tex(const Scene *scene, Brush *brush, const float xy[2], f
}
}
-/* TODO, use define for 'texfall' arg */
+/* TODO, use define for 'texfall' arg
+ * NOTE: only used for 2d brushes currently! */
void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texfall, int bufsize, ImBuf **outbuf, int use_color_correction)
{
ImBuf *ibuf;
@@ -544,10 +583,10 @@ void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texf
dstf[3] = alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
}
else if (texfall == 1) {
- BKE_brush_sample_tex(scene, brush, xy, dstf, 0);
+ BKE_brush_sample_tex_2D(scene, brush, xy, dstf, 0);
}
else {
- BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
+ BKE_brush_sample_tex_2D(scene, brush, xy, rgba, 0);
mul_v3_v3v3(dstf, rgba, brush_rgb);
dstf[3] = rgba[3] * alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
}
@@ -574,11 +613,11 @@ void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texf
dst[3] = FTOCHAR(alpha_f);
}
else if (texfall == 1) {
- BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
+ BKE_brush_sample_tex_2D(scene, brush, xy, rgba, 0);
rgba_float_to_uchar(dst, rgba);
}
else if (texfall == 2) {
- BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
+ BKE_brush_sample_tex_2D(scene, brush, xy, rgba, 0);
mul_v3_v3(rgba, brush->rgb);
alpha_f = rgba[3] * alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
@@ -587,7 +626,7 @@ void BKE_brush_imbuf_new(const Scene *scene, Brush *brush, short flt, short texf
dst[3] = FTOCHAR(alpha_f);
}
else {
- BKE_brush_sample_tex(scene, brush, xy, rgba, 0);
+ BKE_brush_sample_tex_2D(scene, brush, xy, rgba, 0);
alpha_f = rgba[3] * alpha * BKE_brush_curve_strength_clamp(brush, len_v2(xy), radius);
dst[0] = crgb[0];