From c6a4d798880e992100118ec83544b13f4941e055 Mon Sep 17 00:00:00 2001 From: wuyize Date: Wed, 15 Mar 2023 00:09:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E4=BA=86StrokeEndType?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../res/Shaders/element.comp | 31 +++++-------------- .../Renderer/Painting/MaterialStyleStroke.h | 2 +- UnitTest/ElementRendererTest.cpp | 4 +-- 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/ArchitectureColoredPainting/res/Shaders/element.comp b/ArchitectureColoredPainting/res/Shaders/element.comp index eb169f8..66910e7 100644 --- a/ArchitectureColoredPainting/res/Shaders/element.comp +++ b/ArchitectureColoredPainting/res/Shaders/element.comp @@ -998,9 +998,9 @@ bool shouldFillBeginCap(vec2 localUV, bool onVeryBegin, int endType, vec2 p0, ve vec2 normal; if (onVeryBegin) { - if (endType == 0) + if (endType%2 == 0) return true; - else if (endType == 1) + else if (endType%2 == 1) normal = normalize(mat2(0, 1, -1, 0) * (-tangentBegin)); } else @@ -1017,9 +1017,9 @@ bool shouldFillEndCap(vec2 localUV, bool onVeryEnd, int endType, vec2 p3, vec2 t vec2 normal; if (onVeryEnd) { - if (endType == 0) + if ((endType/2)%2 == 0) return true; - else if (endType == 1) + else if ((endType/2)%2 == 1) normal = normalize(mat2(0, 1, -1, 0) * tangentEnd); } else @@ -1103,10 +1103,7 @@ void main() if (isinf(pTemp.x)) { // TODO: ¼ì²âÊÇ·ñ·â±Õ²¢´¦Àí - if (hitElement && distance(localUV, p3Last) <= strokeWidth) - { - // hitElement = shouldFillEndCap(localUV, true, endType, p3Last, tangentEndLast); - } + pBegin = path[++pathIndex]; p3Last = pBegin; @@ -1134,6 +1131,8 @@ void main() tangentBeginNext = normalize(pNext[0] - pNext[2]); } } + else + onVeryEnd = true; float d = cubic_bezier_dis(localUV, p[0], p[1], p[2], p[3], true); if (d <= strokeWidth) @@ -1184,18 +1183,6 @@ void main() vec2 metallicRoughness; drawLine(minDistance / strokeWidth, styleIndex, elementColor, metallicRoughness); } - // else if (lastHitIndex == pathIndex - 3) - // { - // hitElement = lastHitElement; - // lastHitElement = false; - // // if(lastHitElement ==false) - // //{ - // // hitElement = true; - // // elementColor = vec4(1, 1, 0, 1); - // //} - - // minDistance = 1e38; - // } } tangentEndLast = tangentEnd; } @@ -1203,10 +1190,6 @@ void main() p2Last = p[2]; onVeryBegin = false; } - if (hitElement && distance(localUV, p3Last) <= strokeWidth) - { - // hitElement = shouldFillEndCap(localUV, true, endType, p3Last, tangentEndLast); - } nextStyleIndex(styleIndex); } diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.h b/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.h index 95f5957..29fd55b 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.h +++ b/ArchitectureColoredPainting/src/Renderer/Painting/MaterialStyleStroke.h @@ -43,7 +43,7 @@ namespace Renderer }; enum class StrokeType { kBothSides = 2, kLeftSide = 1, kRightSide = 0 }; - enum class StrokeEndType { kRound = 0, kFlat = 1 }; + enum class StrokeEndType { kRound = 0b00, kFlat = 0b11, kRoundFlat = 0b10, kFlatRound = 0b01 }; class MaterialStyleStroke : public MaterialStyle { diff --git a/UnitTest/ElementRendererTest.cpp b/UnitTest/ElementRendererTest.cpp index 2efebee..7a0c035 100644 --- a/UnitTest/ElementRendererTest.cpp +++ b/UnitTest/ElementRendererTest.cpp @@ -111,7 +111,7 @@ namespace UnitTest w.show(); a.exec(); } - TEST_METHOD(TestRightSideFlat) + TEST_METHOD(TestRightSideFlatRound) { QApplication a(argc, argv); class StyleStrokeRadialGradient : public Renderer::ElementStyle @@ -124,7 +124,7 @@ namespace UnitTest {1.00, Material{QColor(58,64,151)}} }; return { BaseStyle(std::make_shared(), - std::make_shared(200, StrokeType::kRightSide, StrokeEndType::kFlat, + std::make_shared(160, StrokeType::kRightSide, StrokeEndType::kFlatRound, std::make_shared(materialMap, false))) }; } } style;