brush scale for non-square brushes

This commit is contained in:
2019-02-24 21:00:53 +01:00
parent 399bc3d433
commit bfaff312f8
9 changed files with 52 additions and 22 deletions

View File

@@ -64,13 +64,10 @@ void main()
mediump float patt = texture(tex_pattern, uv * (1.0 / pattern_scale) * rscale + pattern_offset).r;
if (pattern_invert)
patt = 1.0 - patt;
//patt = patt * pattern_alpha + (1.0 - pattern_alpha);
if (pattern_bright != 0.5)
patt = brightness1(patt, 1.0 - pattern_bright);
if (pattern_contr != 0.5)
patt = contrast1(patt, pattern_contr);
//mediump float pa = (1.0 - patt) * pow(pattern_depth, 0.25) + (stroke.a * pattern_depth * 10.0);
//mediump float pa = pow((1.0 - patt), max(1.0, (1.0 - pattern_depth) * 10.0)) * pow(pattern_depth, 0.25) + (stroke.a * pattern_depth * 5.0);
stroke.a = blend_stroke(stroke.a, patt, pattern_depth, patt_blend_mode);
}

View File

@@ -120,12 +120,13 @@ std::vector<std::shared_ptr<Brush>> ABR::compute_brushes(const std::string& path
b->m_tip_flow = .90f;
b->m_tip_opacity = 1.f;
b->m_tip_wet = p->value<UnitFloat>("Wtdg");
b->m_tip_noise = p->value<Boolean>("Nose") ? 1.f : 0.f;
b->m_tip_aspect = (1.f - samp->value<UnitFloat>("Rndn") * 0.01) * 0.5f + 0.5f;
b->m_tip_size = samp->value<UnitFloat>("Dmtr");
b->m_tip_spacing = samp->value<UnitFloat>("Spcn") * 0.01f;
b->m_tip_angle = samp->value<UnitFloat>("Angl") / 360.f + 0.5f; // [-180, 180] -> [0, 1]
b->m_tip_wet = p->value<UnitFloat>("Wtdg");
b->m_tip_noise = samp->value<UnitFloat>("Nose");
b->m_tip_angle = samp->value<UnitFloat>("Angl") / 360.f; // [-180, 180] -> [0, 1]
b->m_tip_flipx = samp->value<Boolean>("flipX");
b->m_tip_flipy = samp->value<Boolean>("flipY");
@@ -137,7 +138,10 @@ std::vector<std::shared_ptr<Brush>> ABR::compute_brushes(const std::string& path
b->m_brush_thumb_path = path + "/brushes/thumbs/" + tip_uid + ".png";
const auto& samp_img = m_samples[tip_uid];
b->m_tip_width = (float)samp_img->width / (float)samp_img->height;
if (samp_img->height > samp_img->width)
b->m_tip_scale = { (float)samp_img->width / (float)samp_img->height, 1.f };
else
b->m_tip_scale = { 1.f, (float)samp_img->height / (float)samp_img->width };
}
else if (samp->class_id == "computedBrush")
{
@@ -162,6 +166,8 @@ std::vector<std::shared_ptr<Brush>> ABR::compute_brushes(const std::string& path
{
b->m_jitter_scale = jitter_size->value<UnitFloat>("jitter") * 0.01f;
// TODO: p->value<UnitFloat>("minimumDiameter") * 0.001f; // minimum size
if (jitter_size->value<Integer>("bVTy") == 2)
b->m_tip_size_pressure;
}
auto jitter_angle = p->get<Descriptor>("angleDynamics");
@@ -189,6 +195,30 @@ std::vector<std::shared_ptr<Brush>> ABR::compute_brushes(const std::string& path
b->m_tip_randflipy = p->value<Boolean>("flipY");
}
// Transfer settings
if (p->value<Boolean>("usePaintDynamics"))
{
// TODO: implement this when opacity is per-sample
//auto jitter_opacity = p->get<Descriptor>("opVr");
//if (jitter_opacity)
//{
// b->m_jitter_opacity = jitter_opacity->value<UnitFloat>("jitter") * 0.01f;
// // TODO: jitter_opacity->value<UnitFloat>("Mnm ") * 0.01f; // minimum size
// if (jitter_opacity->value<Integer>("bVTy") == 2)
// b->m_tip_opacity_pressure;
//}
auto jitter_flow = p->get<Descriptor>("prVr");
if (jitter_flow)
{
b->m_jitter_flow = jitter_flow->value<UnitFloat>("jitter") * 0.01f;
// TODO: m_jitter_flow->value<UnitFloat>("Mnm ") * 0.01f; // minimum size
if (jitter_flow->value<Integer>("bVTy") == 2)
b->m_tip_flow_pressure = true;
}
}
std::vector<std::string> modes = {
"normal", // normal (not in Photoshop)
"Mltp", // multiply
@@ -246,7 +276,7 @@ std::vector<std::shared_ptr<Brush>> ABR::compute_brushes(const std::string& path
b->m_dual_opacity = 1.f;
//b->m_tip_aspect = (1.f - samp->value<UnitFloat>("Rndn") * 0.01) * 0.5f + 0.5f;
b->m_dual_size = samp->value<UnitFloat>("Dmtr");
b->m_dual_size = samp->value<UnitFloat>("Dmtr") / b->m_tip_size;
b->m_dual_spacing = samp->value<UnitFloat>("Spcn") * 0.01f;
//b->m_tip_angle = samp->value<UnitFloat>("Angl") / 360.f + 0.5f; // [-180, 180] -> [0, 1]
//b->m_tip_wet = p->value<UnitFloat>("Wtdg");
@@ -408,7 +438,7 @@ std::shared_ptr<ABR::Descriptor> ABR::parse_objc()
if (!property)
return nullptr;
if (ret->props.find(key) != ret->props.end())
LOG("DUPLICATE prop %d\n", key.c_str());
LOG("DUPLICATE prop %s\n", key.c_str());
ret->props[key] = property;
}
return ret;

View File

@@ -141,9 +141,9 @@ StrokeSample Stroke::randomize_sample(const glm::vec3& pos, float pressure, floa
float randflipy = m_brush->m_tip_randflipy ? rnd_bneg() : 1.f;
StrokeSample s;
s.scale.x = m_brush->m_tip_width * randflipx * (m_brush->m_tip_flipx ? -1.f : 1.f) *
s.scale.x = m_brush->m_tip_scale.x * randflipx * (m_brush->m_tip_flipx ? -1.f : 1.f) *
(m_brush->m_tip_aspect <= 0.5 ? m_brush->m_tip_aspect * 2.f : 1.f);
s.scale.y = randflipy * (m_brush->m_tip_flipy ? -1.f : 1.f) *
s.scale.y = m_brush->m_tip_scale.y * randflipy * (m_brush->m_tip_flipy ? -1.f : 1.f) *
(m_brush->m_tip_aspect > 0.5 ? 1.f - (m_brush->m_tip_aspect - .5f) * 2.f : 1.f);
s.origin = pos;
s.angle = -curve_angle + (m_brush->m_tip_angle + rnd_neg() * m_brush->m_jitter_angle) * (float)(M_PI * 2.0);
@@ -188,6 +188,8 @@ std::vector<StrokeSample> Stroke::compute_samples()
m_dir_angle = -glm::orientedAngle(v, m_dir_ref);
if (m_brush->m_tip_angle_delay > 0 && (glm::abs(m_dir_angle) > glm::pi<float>() / 2.f || !m_dir_valid))
{
//if (glm::abs(m_dir_angle) > glm::radians(110.f))
// LOG("BIG ANGLE");
auto old_dir = m_dir_ref;
m_dir_ref = v;
m_dir_ref_angle = -glm::orientedAngle(m_dir_ref, { 1, 0 });
@@ -256,7 +258,7 @@ void Stroke::add_point(glm::vec3 pos, float pressure)
if (m_brush->m_tip_size_pressure)
{
float aspect_width = glm::min(1.f, m_brush->m_tip_aspect * 2.f);
float raw_size = aspect_width * m_brush->m_tip_width * m_brush->m_tip_size;
float raw_size = aspect_width * glm::min(m_brush->m_tip_scale.x, m_brush->m_tip_scale.y) * m_brush->m_tip_size;
float size = glm::clamp(raw_size / glm::tan(glm::radians(m_camera.fov * 0.5f)), 1.f, m_max_size);
if (raw_size < 2.f)
@@ -301,7 +303,7 @@ void Stroke::start(const std::shared_ptr<Brush>& brush)
m_brush = brush;
float aspect_width = glm::min(1.f, m_brush->m_tip_aspect * 2.f);
float raw_size = aspect_width * m_brush->m_tip_width * m_brush->m_tip_size;
float raw_size = aspect_width * glm::min(m_brush->m_tip_scale.x, m_brush->m_tip_scale.y) * m_brush->m_tip_size;
float size = glm::clamp(raw_size / glm::tan(glm::radians(m_camera.fov * 0.5f)), 1.f, m_max_size);
if (raw_size < 2.f)

View File

@@ -22,14 +22,14 @@ public:
std::string m_pattern_path;
std::string m_pattern_thumb_path;
glm::vec4 m_tip_color{0, 0, 0, 1};
float m_tip_width = 1.f;
glm::vec4 m_tip_color = { 0, 0, 0, 1 };
glm::vec2 m_tip_scale = { 1.f, 1.f };
float m_tip_size = 50;
float m_tip_spacing = .25;
float m_tip_flow = 1.f;
float m_tip_opacity = 1.f;
float m_tip_angle = 0;
float m_tip_angle_delay = 0;
float m_tip_angle_delay = 0.01;
float m_tip_mix = 0;
float m_tip_wet = 0;
float m_tip_noise = 0;
@@ -55,7 +55,7 @@ public:
bool m_dual_enabled = false;
int m_dual_blend_mode = 1;
bool m_dual_randflip = false;
float m_dual_size = 100;
float m_dual_size = .75;
float m_dual_spacing = .25;
float m_dual_scatter = 0;
bool m_dual_scatter_axis = false;

View File

@@ -913,7 +913,7 @@ void Canvas::stroke_start(glm::vec3 point, float pressure)
dual_brush->m_blend_mode = m_current_brush->m_dual_blend_mode;
dual_brush->m_tip_randflipx = m_current_brush->m_dual_randflip;
dual_brush->m_tip_randflipy = m_current_brush->m_dual_randflip;
dual_brush->m_tip_size = m_current_brush->m_dual_size;
dual_brush->m_tip_size = m_current_brush->m_dual_size * m_current_brush->m_tip_size;
dual_brush->m_tip_spacing = m_current_brush->m_dual_spacing;
dual_brush->m_jitter_spread = m_current_brush->m_dual_scatter;
dual_brush->m_jitter_angle = m_current_brush->m_dual_rotate;

View File

@@ -213,7 +213,7 @@ void CanvasModePen::on_Draw(const glm::mat4& ortho, const glm::mat4& proj, const
ShaderManager::u_int(kShaderUniform::Tex, 0);
float tip_scale_fix = 1.f / glm::tan(glm::radians(Canvas::I->m_cam_fov * 0.5f));
float tip_angle = brush->m_tip_angle * (float)(M_PI * 2.0);
glm::vec2 tip_scale = glm::vec2(brush->m_tip_width, 1.f) *
glm::vec2 tip_scale = brush->m_tip_scale *
glm::vec2(brush->m_tip_size * tip_scale_fix) *
glm::vec2(brush->m_tip_flipx ? -1 : 1, brush->m_tip_flipy ? -1.f : 1.f) *
glm::vec2((brush->m_tip_aspect <= 0.5 ? brush->m_tip_aspect * 2.f : 1.f),

View File

@@ -642,7 +642,8 @@ int main(int argc, char** argv)
{
static wchar_t title_fps[512];
swprintf_s(title_fps, L"%s - %d fps", window_title, frames);
SetWindowText(hWnd, title_fps);
if (running)
SetWindowText(hWnd, title_fps);
one_sec = 0;
frames = 0;
}

View File

@@ -536,7 +536,7 @@ void NodePanelStroke::init_controls()
m_curves[m_tip_size] = curve_size5k_pix;
m_curves[m_tip_spacing] = curve_size1k_perc;
m_curves[m_tip_flow] = curve_quad;
m_curves[m_dual_size] = curve_size5k_pix;
m_curves[m_dual_size] = curve_size1k_perc;
m_curves[m_dual_spacing] = curve_size1k_perc;
m_curves[m_dual_flow] = curve_quad;
m_curves[m_pattern_scale] = curve_size1k_perc;

View File

@@ -259,7 +259,7 @@ void NodeStrokePreview::draw_stroke()
dual_brush->m_blend_mode = b->m_dual_blend_mode;
dual_brush->m_tip_randflipx = b->m_dual_randflip;
dual_brush->m_tip_randflipy = b->m_dual_randflip;
dual_brush->m_tip_size = b->m_dual_size;
dual_brush->m_tip_size = b->m_dual_size * b->m_tip_size;
dual_brush->m_tip_spacing = b->m_dual_spacing;
dual_brush->m_jitter_spread = b->m_dual_scatter;
dual_brush->m_jitter_angle = b->m_dual_rotate;