Fix T75161: Random UV doesn´t work with fats drawing
Also fixed T75162
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
#include "MEM_guardedalloc.h"
|
#include "MEM_guardedalloc.h"
|
||||||
|
|
||||||
#include "BLI_blenlib.h"
|
#include "BLI_blenlib.h"
|
||||||
|
#include "BLI_hash.h"
|
||||||
#include "BLI_math.h"
|
#include "BLI_math.h"
|
||||||
#include "BLI_math_geom.h"
|
#include "BLI_math_geom.h"
|
||||||
#include "BLI_rand.h"
|
#include "BLI_rand.h"
|
||||||
@@ -486,6 +487,7 @@ static void gp_stroke_convertcoords(tGPsdata *p, const float mval[2], float out[
|
|||||||
/* Apply jitter to stroke point. */
|
/* Apply jitter to stroke point. */
|
||||||
static void gp_brush_jitter(bGPdata *gpd, tGPspoint *pt, const float amplitude)
|
static void gp_brush_jitter(bGPdata *gpd, tGPspoint *pt, const float amplitude)
|
||||||
{
|
{
|
||||||
|
const float axis[2] = {0.0f, 1.0f};
|
||||||
/* Jitter is applied perpendicular to the mouse movement vector (2D space). */
|
/* Jitter is applied perpendicular to the mouse movement vector (2D space). */
|
||||||
float mvec[2];
|
float mvec[2];
|
||||||
/* Mouse movement in ints -> floats. */
|
/* Mouse movement in ints -> floats. */
|
||||||
@@ -493,16 +495,15 @@ static void gp_brush_jitter(bGPdata *gpd, tGPspoint *pt, const float amplitude)
|
|||||||
tGPspoint *pt_prev = pt - 1;
|
tGPspoint *pt_prev = pt - 1;
|
||||||
sub_v2_v2v2(mvec, &pt->x, &pt_prev->x);
|
sub_v2_v2v2(mvec, &pt->x, &pt_prev->x);
|
||||||
normalize_v2(mvec);
|
normalize_v2(mvec);
|
||||||
|
/* Rotate mvec by 90 degrees... */
|
||||||
|
float angle = angle_v2v2(mvec, axis);
|
||||||
|
/* Reduce noise in the direction of the stroke. */
|
||||||
|
mvec[0] *= cos(angle);
|
||||||
|
mvec[1] *= sin(angle);
|
||||||
|
|
||||||
|
/* Scale by displacement amount, and apply. */
|
||||||
|
madd_v2_v2fl(&pt->x, mvec, amplitude * 10.0f);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
mvec[0] = 0.0f;
|
|
||||||
mvec[1] = 0.0f;
|
|
||||||
}
|
|
||||||
/* Rotate mvec by 90 degrees... */
|
|
||||||
SWAP(float, mvec[0], mvec[1]);
|
|
||||||
mvec[0] -= mvec[0];
|
|
||||||
/* Scale by displacement amount, and apply. */
|
|
||||||
madd_v2_v2fl(&pt->x, mvec, amplitude);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* apply pressure change depending of the angle of the stroke to simulate a pen with shape */
|
/* apply pressure change depending of the angle of the stroke to simulate a pen with shape */
|
||||||
@@ -788,8 +789,10 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure
|
|||||||
}
|
}
|
||||||
/* apply randomness to uv texture rotation */
|
/* apply randomness to uv texture rotation */
|
||||||
if (brush_settings->uv_random > 0.0f) {
|
if (brush_settings->uv_random > 0.0f) {
|
||||||
float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f;
|
float rand = BLI_hash_int_01(BLI_hash_int_2d((int)pt->x, gpd->runtime.sbuffer_used)) *
|
||||||
pt->uv_rot += rand * M_PI * brush_settings->uv_random;
|
2.0f -
|
||||||
|
1.0f;
|
||||||
|
pt->uv_rot += rand * M_PI_2 * brush_settings->uv_random;
|
||||||
CLAMP(pt->uv_rot, -M_PI_2, M_PI_2);
|
CLAMP(pt->uv_rot, -M_PI_2, M_PI_2);
|
||||||
}
|
}
|
||||||
/* apply randomness to color strength */
|
/* apply randomness to color strength */
|
||||||
@@ -3141,7 +3144,7 @@ static void gpencil_add_arc_points(tGPsdata *p, float mval[2], int segments)
|
|||||||
if (gpd->runtime.sbuffer_used < 3) {
|
if (gpd->runtime.sbuffer_used < 3) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
BrushGpencilSettings *brush_settings = p->brush->gpencil_settings;
|
||||||
int idx_prev = gpd->runtime.sbuffer_used;
|
int idx_prev = gpd->runtime.sbuffer_used;
|
||||||
|
|
||||||
/* Add space for new arc points. */
|
/* Add space for new arc points. */
|
||||||
@@ -3206,6 +3209,27 @@ static void gpencil_add_arc_points(tGPsdata *p, float mval[2], int segments)
|
|||||||
pt->pressure = pt_prev->pressure;
|
pt->pressure = pt_prev->pressure;
|
||||||
pt->strength = pt_prev->strength;
|
pt->strength = pt_prev->strength;
|
||||||
|
|
||||||
|
/* Apply randomness to pressure. */
|
||||||
|
if (brush_settings->draw_random_press > 0.0f) {
|
||||||
|
float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f;
|
||||||
|
pt->pressure *= 1.0 + rand * 2.0 * brush_settings->draw_random_press;
|
||||||
|
CLAMP(pt->pressure, GPENCIL_STRENGTH_MIN, 1.0f);
|
||||||
|
}
|
||||||
|
/* Apply randomness to color strength. */
|
||||||
|
if (brush_settings->draw_random_strength) {
|
||||||
|
float rand = BLI_rng_get_float(p->rng) * 2.0f - 1.0f;
|
||||||
|
pt->strength *= 1.0 + rand * brush_settings->draw_random_strength;
|
||||||
|
CLAMP(pt->strength, GPENCIL_STRENGTH_MIN, 1.0f);
|
||||||
|
}
|
||||||
|
/* Apply randomness to uv texture rotation. */
|
||||||
|
if (brush_settings->uv_random > 0.0f) {
|
||||||
|
float rand = BLI_hash_int_01(BLI_hash_int_2d((int)pt->x, gpd->runtime.sbuffer_used + i)) *
|
||||||
|
2.0f -
|
||||||
|
1.0f;
|
||||||
|
pt->uv_rot += rand * M_PI_2 * brush_settings->uv_random;
|
||||||
|
CLAMP(pt->uv_rot, -M_PI_2, M_PI_2);
|
||||||
|
}
|
||||||
|
|
||||||
a += step;
|
a += step;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user