From 4ef208909762eae844da0488f2f113d007687a80 Mon Sep 17 00:00:00 2001 From: Miika Hamalainen Date: Fri, 11 Nov 2011 10:46:26 +0000 Subject: Dynamic Paint: * Renamed "Sharp" proximity falloff to "Constant". * Added a new "Negate Volume" option for "Volume + Proximity" brush. * Possible fix for random particle clipping errors. --- source/blender/blenkernel/intern/dynamicpaint.c | 75 ++++++++++++++--------- source/blender/makesdna/DNA_dynamicpaint_types.h | 3 +- source/blender/makesrna/intern/rna_dynamicpaint.c | 7 ++- 3 files changed, 54 insertions(+), 31 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 354aa57e200..df7cd85e6a1 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -3175,13 +3175,20 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, { float ray_start[3], ray_dir[3]; - float colorband[4] = {0.0f}; - float sample_factor; + float sample_factor = 0.0f; float sampleStrength = 0.0f; BVHTreeRayHit hit; BVHTreeNearest nearest; short hit_found = 0; + /* volume sample */ + float volume_factor = 0.0f; + /* proximity sample */ + float proximity_factor = 0.0f; + float prox_colorband[4] = {0.0f}; + int inner_proximity = (brush->flags & MOD_DPAINT_INVERSE_PROX && + brush->collision == MOD_DPAINT_COL_VOLDIST); + /* hit data */ float hitCoord[3]; int hitFace = -1; @@ -3236,7 +3243,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, if(hit.index != -1) { /* Add factor on supersample filter */ - sampleStrength += sample_factor; + volume_factor = 1.0f; hit_found = HIT_VOLUME; /* Mark hit info */ @@ -3256,8 +3263,6 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, float hitCo[3]; short hQuad; int face; - int inner_proximity = (brush->flags & MOD_DPAINT_INVERSE_PROX && - brush->collision == MOD_DPAINT_COL_VOLDIST); /* if inverse prox and no hit found, skip this sample */ if (inner_proximity && !hit_found) continue; @@ -3299,25 +3304,12 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, /* If a hit was found, calculate required values */ if (proxDist >= 0.0f && proxDist <= brush->paint_distance) { - float dist_rate = proxDist / brush->paint_distance; - float prox_influence = 0.0f; - - /* in case of inverse prox also undo volume effect */ - if (inner_proximity) { - sampleStrength -= sample_factor; - dist_rate = 1.0f - dist_rate; - } - - /* if using proximity color ramp use it's alpha */ - if (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP && do_colorband(brush->paint_ramp, dist_rate, colorband)) - prox_influence = colorband[3]; - else if (brush->proximity_falloff == MOD_DPAINT_PRFALL_SMOOTH) { - prox_influence = (1.0f - dist_rate) * sample_factor; - } - else prox_influence = inner_proximity ? 0.0f : 1.0f; + proximity_factor = proxDist / brush->paint_distance; + CLAMP(proximity_factor, 0.0f, 1.0f); + if (!inner_proximity) + proximity_factor = 1.0f - proximity_factor; hit_found = HIT_PROXIMITY; - sampleStrength += prox_influence*sample_factor; /* if no volume hit, use prox point face info */ if (hitFace == -1) { @@ -3328,7 +3320,32 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, } } - if (!hit_found) continue; + /* mix final sample strength depending on brush settings */ + if (hit_found) { + /* if "negate volume" enabled, negate all factors within volume*/ + if (brush->collision == MOD_DPAINT_COL_VOLDIST && brush->flags & MOD_DPAINT_NEGATE_VOLUME) { + volume_factor = 1.0f - volume_factor; + if (inner_proximity) + proximity_factor = 1.0f - proximity_factor; + } + + /* apply final sample depending on final hit type */ + if (hit_found == HIT_VOLUME) { + sampleStrength = volume_factor; + } + else if (hit_found == HIT_PROXIMITY) { + /* apply falloff curve to the proximity_factor */ + if (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP && do_colorband(brush->paint_ramp, (1.0f-proximity_factor), prox_colorband)) + proximity_factor = prox_colorband[3]; + else if (brush->proximity_falloff == MOD_DPAINT_PRFALL_CONSTANT) + proximity_factor = (!inner_proximity || brush->flags & MOD_DPAINT_NEGATE_VOLUME) ? 1.0f : 0.0f; + /* apply sample */ + sampleStrength = proximity_factor; + } + + sampleStrength *= sample_factor; + } + else continue; /* velocity brush, only do on main sample */ if (brush->flags & MOD_DPAINT_USES_VELOCITY && ss==0 && brushVelocity) { @@ -3395,9 +3412,9 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface, /* Sample proximity colorband if required */ if ((hit_found == HIT_PROXIMITY) && (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP)) { if (!(brush->flags & MOD_DPAINT_RAMP_ALPHA)) { - sampleColor[0] = colorband[0]; - sampleColor[1] = colorband[1]; - sampleColor[2] = colorband[2]; + sampleColor[0] = prox_colorband[0]; + sampleColor[1] = prox_colorband[1]; + sampleColor[2] = prox_colorband[2]; } } @@ -3478,7 +3495,7 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, float range = solidradius + smooth; float particle_timestep = 0.04f * part->timetweak; - Bounds3D part_bb; + Bounds3D part_bb = {0}; if (psys->totpart < 1) return 1; @@ -4482,7 +4499,7 @@ static int dynamicPaint_surfaceHasMoved(DynamicPaintSurface *surface, Object *ob return ret; } -static int surface_needsVelocityData(DynamicPaintSurface *surface, Scene *scene, Object *UNUSED(ob)) +static int surface_needsVelocityData(DynamicPaintSurface *surface, Scene *scene) { if (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP) return 1; @@ -4509,7 +4526,7 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, Scene *sc PaintBakeData *bData = sData->bData; DerivedMesh *dm = surface->canvas->dm; int index, new_bdata = 0; - int do_velocity_data = surface_needsVelocityData(surface, scene, ob); + int do_velocity_data = surface_needsVelocityData(surface, scene); int do_accel_data = surface_needsAccelerationData(surface); int canvasNumOfVerts = dm->getNumVerts(dm); diff --git a/source/blender/makesdna/DNA_dynamicpaint_types.h b/source/blender/makesdna/DNA_dynamicpaint_types.h index 04d50c78652..22a0462985c 100644 --- a/source/blender/makesdna/DNA_dynamicpaint_types.h +++ b/source/blender/makesdna/DNA_dynamicpaint_types.h @@ -144,6 +144,7 @@ typedef struct DynamicPaintCanvasSettings { #define MOD_DPAINT_RAMP_ALPHA (1<<4) /* only read falloff ramp alpha */ #define MOD_DPAINT_PROX_PROJECT (1<<5) /* do proximity check only in defined dir */ #define MOD_DPAINT_INVERSE_PROX (1<<6) /* inverse proximity painting */ +#define MOD_DPAINT_NEGATE_VOLUME (1<<7) /* negates volume influence on "volume + prox" mode */ #define MOD_DPAINT_DO_SMUDGE (1<<8) /* brush smudges existing paint */ #define MOD_DPAINT_VELOCITY_ALPHA (1<<9) /* multiply brush influence by velocity */ @@ -160,7 +161,7 @@ typedef struct DynamicPaintCanvasSettings { #define MOD_DPAINT_COL_POINT 4 /* use distance to object center point */ /* proximity_falloff */ -#define MOD_DPAINT_PRFALL_SHARP 0 /* no-falloff */ +#define MOD_DPAINT_PRFALL_CONSTANT 0 /* no-falloff */ #define MOD_DPAINT_PRFALL_SMOOTH 1 /* smooth, linear falloff */ #define MOD_DPAINT_PRFALL_RAMP 2 /* use color ramp */ diff --git a/source/blender/makesrna/intern/rna_dynamicpaint.c b/source/blender/makesrna/intern/rna_dynamicpaint.c index 754ed82e010..00a73afb789 100644 --- a/source/blender/makesrna/intern/rna_dynamicpaint.c +++ b/source/blender/makesrna/intern/rna_dynamicpaint.c @@ -695,7 +695,7 @@ static void rna_def_dynamic_paint_brush_settings(BlenderRNA *brna) static EnumPropertyItem prop_dynamicpaint_prox_falloff[] = { {MOD_DPAINT_PRFALL_SMOOTH, "SMOOTH", ICON_SPHERECURVE, "Smooth", ""}, - {MOD_DPAINT_PRFALL_SHARP, "SHARP", ICON_SHARPCURVE, "Sharp", ""}, + {MOD_DPAINT_PRFALL_CONSTANT, "CONSTANT", ICON_NOCURVE, "Constant", ""}, {MOD_DPAINT_PRFALL_RAMP, "RAMP", ICON_COLOR, "Color Ramp", ""}, {0, NULL, 0, NULL, NULL}}; @@ -847,6 +847,11 @@ static void rna_def_dynamic_paint_brush_settings(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_DPAINT_INVERSE_PROX); RNA_def_property_ui_text(prop, "Inner Proximity", "Proximity falloff is applied inside the volume"); RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_DynamicPaint_redoModifier"); + + prop= RNA_def_property(srna, "negate_volume", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_DPAINT_NEGATE_VOLUME); + RNA_def_property_ui_text(prop, "Negate Volume", "Negate influence inside the volume"); + RNA_def_property_update(prop, NC_OBJECT|ND_MODIFIER, "rna_DynamicPaint_redoModifier"); /* -- cgit v1.2.3