From 492f0a12d75a57c8eed6112d55a9cb2533fed577 Mon Sep 17 00:00:00 2001 From: wuyize Date: Tue, 21 Mar 2023 22:30:19 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20Painting=E8=83=8C=E6=99=AF=E6=9D=90?= =?UTF-8?q?=E8=B4=A8=E4=BB=A5=E5=8F=8AzIndex=E6=94=B9=E4=B8=BA=E5=B0=8F?= =?UTF-8?q?=E7=9A=84=E5=9C=A8=E4=B8=8A=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 4_L0.json | 148 +++++++++++++++++- .../res/Shaders/painting.comp | 49 +++--- .../src/Editor/util/PaintingUtil.cpp | 5 +- .../src/Renderer/Model.cpp | 7 +- .../src/Renderer/Painting/Painting.cpp | 10 +- .../src/Renderer/Painting/Painting.h | 5 +- 6 files changed, 185 insertions(+), 39 deletions(-) diff --git a/4_L0.json b/4_L0.json index d5935e7..3b2d983 100644 --- a/4_L0.json +++ b/4_L0.json @@ -330,6 +330,146 @@ "y": 1 } } + }, + { + "element": 4, + "is-folder": false, + "name": "子图层-10", + "styles": [ + ], + "transform": { + "filpX": false, + "filpY": false, + "offset": { + "x": 610, + "y": -3 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 4, + "is-folder": false, + "name": "子图层-11", + "styles": [ + ], + "transform": { + "filpX": false, + "filpY": false, + "offset": { + "x": 614, + "y": 200 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 4, + "is-folder": false, + "name": "子图层-12", + "styles": [ + ], + "transform": { + "filpX": false, + "filpY": false, + "offset": { + "x": 617, + "y": 405 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 4, + "is-folder": false, + "name": "子图层-13", + "styles": [ + ], + "transform": { + "filpX": false, + "filpY": false, + "offset": { + "x": -3, + "y": -202 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 4, + "is-folder": false, + "name": "子图层-14", + "styles": [ + ], + "transform": { + "filpX": false, + "filpY": false, + "offset": { + "x": 200, + "y": -203 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 4, + "is-folder": false, + "name": "子图层-15", + "styles": [ + ], + "transform": { + "filpX": false, + "filpY": false, + "offset": { + "x": 402, + "y": -205 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } + }, + { + "element": 4, + "is-folder": false, + "name": "子图层-16", + "styles": [ + ], + "transform": { + "filpX": false, + "filpY": false, + "offset": { + "x": 606, + "y": -206 + }, + "rotation": 0, + "scale": { + "x": 1, + "y": 1 + } + } } ], "is-folder": true, @@ -339,13 +479,13 @@ "filpX": false, "filpY": false, "offset": { - "x": 195, - "y": 170 + "x": 116, + "y": 288 }, "rotation": 60, "scale": { - "x": 1, - "y": 1 + "x": 1.85202, + "y": 1.85202 } } }, diff --git a/ArchitectureColoredPainting/res/Shaders/painting.comp b/ArchitectureColoredPainting/res/Shaders/painting.comp index f933c92..d46c93d 100644 --- a/ArchitectureColoredPainting/res/Shaders/painting.comp +++ b/ArchitectureColoredPainting/res/Shaders/painting.comp @@ -6,7 +6,11 @@ layout(location = 0) uniform ivec2 pixelOffset; layout(std140, binding = 1) uniform ubo { - vec3 backgroundColor; + float backgroundRed; + float backgroundGreen; + float backgroundBlue; + float backgroundMetallic; + float backgroundRoughness; }; layout(rgba8, binding = 0) uniform image2D gBaseColor; @@ -1206,7 +1210,7 @@ bool strokeElement(vec2 localUV, uint contourIndex, uint linesOffset, uint point else { if (endType == 4 /*StrokeEndType::kClosed*/) - tangentBeginNext = tangentFirstBegin; + tangentBeginNext = tangentFirstBegin; else onVeryEnd = true; } @@ -1247,8 +1251,7 @@ bool strokeElement(vec2 localUV, uint contourIndex, uint linesOffset, uint point if (onBegin) hit = hit && shouldFillBeginCap(localUV, onVeryBegin, endType, p[0], tangentBegin, tangentEndLast); if (onEnd) - hit = hit && shouldFillEndCap(localUV, onVeryEnd, endType, p[3], tangentEnd, - tangentBeginNext); + hit = hit && shouldFillEndCap(localUV, onVeryEnd, endType, p[3], tangentEnd, tangentBeginNext); if (hit) { @@ -1371,8 +1374,11 @@ void main() vec3 debugBVH = vec3(0); // bool debugHit = false; // vec4 color = vec4(0.76, 0.33, 0.15, -1); - vec4 color = vec4(backgroundColor, -1); - vec2 metallicRoughness = vec2(0, 0.8); + vec4 color = vec4(backgroundRed, backgroundGreen, backgroundBlue, -1); + vec2 metallicRoughness = vec2(backgroundMetallic, backgroundRoughness); + int zIndex = 1<<15; + // vec4 color = vec4(0.72f, 0.66f, 0.55f, -1); + // vec2 metallicRoughness = vec2(0,0.5); stack.top = 0; uint index = 0, visitTime = 0; // uint bvhLength = paintingOffsets[paintingIndex-1].y; @@ -1392,23 +1398,24 @@ void main() if (leftChild >= bvhLength) { - uint transformIndex = leftChild - 0x80000000; - uint zIndex = bvhChildren[index].y >> 18; - uint elementIndex = bvhChildren[index].y - zIndex; - mat3x2 transform = elementTranform[transformIndex]; - vec2 localUV = - (mat3(vec3(transform[0], 0), vec3(transform[1], 0), vec3(transform[2], 1)) * vec3(uv, 1)).xy; - - vec3 elementColor; - vec2 elementMetallicRoughness; - if (drawElement(elementIndex, localUV, elementColor, elementMetallicRoughness, debugBVH)) + uint elementZIndex = bvhChildren[index].y >> 18; + if (elementZIndex <= zIndex) { - color = vec4(elementColor, zIndex); - metallicRoughness = elementMetallicRoughness; - } - // if(elementIndex == 1 && transformIndex==1) - // color = vec4(1,1,0,1); + uint transformIndex = leftChild - 0x80000000; + uint elementIndex = bvhChildren[index].y - elementZIndex; + mat3x2 transform = elementTranform[transformIndex]; + vec2 localUV = + (mat3(vec3(transform[0], 0), vec3(transform[1], 0), vec3(transform[2], 1)) * vec3(uv, 1)) + .xy; + vec3 elementColor; + vec2 elementMetallicRoughness; + if (drawElement(elementIndex, localUV, elementColor, elementMetallicRoughness, debugBVH)) + { + color = vec4(elementColor, elementZIndex); + metallicRoughness = elementMetallicRoughness; + } + } index = bvhLength; } else diff --git a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp index bcabd5d..b9f09c7 100644 --- a/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp +++ b/ArchitectureColoredPainting/src/Editor/util/PaintingUtil.cpp @@ -32,10 +32,9 @@ QJsonObject PaintingUtil::readJsonFile(QString jsonFilePath) { } Painting PaintingUtil::transfromToPainting(QString jsonFilePath) { - Painting painting; - glm::bvec2 flip(0, 0); QJsonObject jsonObj = readJsonFile(jsonFilePath); - qDebug() << jsonObj; + //qDebug() << jsonObj; + Painting painting(Renderer::Material(jsonObj.value("background-color").toVariant().value())); shared_ptr elementManager = make_shared(jsonObj, QFileInfo(jsonFilePath).absolutePath()); shared_ptr layerManager = make_shared(jsonObj, elementManager.get()); //qDebug() << elementManager->toJson(); diff --git a/ArchitectureColoredPainting/src/Renderer/Model.cpp b/ArchitectureColoredPainting/src/Renderer/Model.cpp index 433903a..ee5f5cc 100644 --- a/ArchitectureColoredPainting/src/Renderer/Model.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Model.cpp @@ -244,8 +244,7 @@ GLuint Renderer::Model::loadPainting(std::string path) return iter->second; Painting painting; - //path = "../test.json"; - if (auto file = QFileInfo(QString(path.c_str())); file.isFile()) + if (auto file = QFileInfo(directory.filePath(path.c_str())); file.isFile()) painting = PaintingUtil::transfromToPainting(file.filePath()); else { @@ -280,13 +279,13 @@ GLuint Renderer::Model::loadPainting(std::string path) std::make_shared(Element{ contours[2].first, style[0], contours[2].second}), }; - if (path == "0.json") + if (path == "0.json" && false) { //painting.addElement(*element[0], ElementTransform{ glm::vec2(-0.45,-0.45), glm::vec2(0.5,0.5) / 2.f, 0, glm::bvec2(false), 0 }); //painting.addElement(*element[1], ElementTransform{ glm::vec2(-0.45, 0.45), glm::vec2(0.5,0.5) / 2.f, 0, glm::bvec2(false), 0 }); //painting.addElement(*element[2], ElementTransform{ glm::vec2(0.50,-0.45), glm::vec2(0.6,0.7) / 2.f, 0, glm::bvec2(false), 0 }); } - else if (path == "1.json") + else if (path == "1.json" || true) { //painting.backgroundColor = QColor(196, 81, 35); float widths[] = { 0.22, 0.22 * 0.25 / 0.15, 0.22 * 0.25 / 0.15 }; diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp index 2fd6d73..6174b78 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp +++ b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.cpp @@ -9,7 +9,7 @@ using namespace Renderer; constexpr int kMaxLineCount = 20; -Painting::Painting(QColor backgroundColor) : backgroundColor(backgroundColor) +Painting::Painting(Material background) : background(background) { } @@ -86,7 +86,7 @@ void Painting::generateBuffers(QOpenGLFunctions_4_5_Core* glFunc) for (int index = 0; auto & i : elementTransformPool) i.second = index++; - + std::vector rootBvhTreeData; for (auto& i : elements) @@ -115,7 +115,7 @@ void Painting::generateBuffers(QOpenGLFunctions_4_5_Core* glFunc) elementData.insert(elementData.end(), encodedStyle.begin(), encodedStyle.end()); } - for (auto & i : elementTransformPool) + for (auto& i : elementTransformPool) elementTransform.emplace_back(i.first); for (auto& i : elementPool) @@ -142,8 +142,8 @@ void Painting::generateBuffers(QOpenGLFunctions_4_5_Core* glFunc) glFunc->glNamedBufferData(buffers[3], elementOffsets.size() * sizeof(elementOffsets[0]), elementOffsets.data(), GL_STATIC_READ); glFunc->glNamedBufferData(buffers[4], elementIndex.size() * sizeof(elementIndex[0]), elementIndex.data(), GL_STATIC_READ); glFunc->glNamedBufferData(buffers[5], elementData.size() * sizeof(elementData[0]), elementData.data(), GL_STATIC_READ); - glm::vec3 color(backgroundColor.redF(), backgroundColor.greenF(), backgroundColor.blueF()); - glFunc->glNamedBufferData(buffers[6], sizeof(glm::vec3), &color, GL_STATIC_READ); + GLfloat backgroundBuffer[] = { (GLfloat)background.color.redF(), (GLfloat)background.color.greenF(), (GLfloat)background.color.blueF(), background.metallicF(), background.roughnessF() }; + glFunc->glNamedBufferData(buffers[6], 5 * sizeof(GLfloat), backgroundBuffer, GL_STATIC_READ); } GLuint Renderer::Painting::getElementCount() diff --git a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h index cf18500..1dbde54 100644 --- a/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h +++ b/ArchitectureColoredPainting/src/Renderer/Painting/Painting.h @@ -54,9 +54,10 @@ namespace Renderer std::vector elementData; int paintingId = 0; std::array buffers; - QColor backgroundColor; + //QColor backgroundColor; + Material background; - Painting(QColor backgroundColor = Qt::white); + Painting(Material background = Material(Qt::white)); void addElement(const BaseElement& element, const ElementTransform& transform); void generateBuffers(QOpenGLFunctions_4_5_Core* glFunc); GLuint getElementCount();