diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj index bfce5ff..1c52dfd 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj @@ -99,6 +99,7 @@ + @@ -150,6 +151,7 @@ + diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters index be03bfa..b73c477 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters @@ -126,6 +126,9 @@ Source Files\Renderer\Painting + + Source Files\Editor + @@ -266,6 +269,9 @@ Header Files\Renderer\Painting + + Header Files\Editor + diff --git a/ArchitectureColoredPainting/Shaders/painting.comp b/ArchitectureColoredPainting/Shaders/painting.comp index e3f7cdf..fba3020 100644 --- a/ArchitectureColoredPainting/Shaders/painting.comp +++ b/ArchitectureColoredPainting/Shaders/painting.comp @@ -251,8 +251,65 @@ int cubic_bezier_int_test(vec2 uv, vec2 p0, vec2 p1, vec2 p2, vec2 p3) return n_ints; } -bool cubic_bezier_sign_test(vec2 uv, vec2 p0, vec2 p1, vec2 p2, vec2 p3) +bvec3 cubic_bezier_sign_test(vec2 uv, vec2 p0, vec2 p1, vec2 p2, vec2 p3) { + // float cu = (-p0.y + 3. * p1.y - 3. * p2.y + p3.y); + // float qu = (3. * p0.y - 6. * p1.y + 3. * p2.y); + // float li = (-3. * p0.y + 3. * p1.y); + // float co = p0.y - uv.y; + + // vec3 roots = vec3(1e38); + // int n_roots; + + // int n_ints = 0; + // bvec3 result = bvec3(false); + + // if (uv.x < min(min(p0.x, p1.x), min(p2.x, p3.x))) + // { + // if (uv.y >= min(p0.y, p3.y) && uv.y <= max(p0.y, p3.y)) + // { + // n_ints = 1; + // result[1] = !result[1]; + // } + // } + // else + // { + + // if (abs(cu) < .0001) + // { + // n_roots = solve_quadric(vec2(co / qu, li / qu), roots.xy); + // } + // else + // { + // n_roots = solve_cubic(vec3(co / cu, li / cu, qu / cu), roots); + // } + + // for (int i = 0; i < n_roots; i++) + // { + // //if (roots[i] >= 0. && roots[i] <= 1.) + // { + // float x_pos = -p0.x + 3. * p1.x - 3. * p2.x + p3.x; + // x_pos = x_pos * roots[i] + 3. * p0.x - 6. * p1.x + 3. * p2.x; + // x_pos = x_pos * roots[i] + -3. * p0.x + 3. * p1.x; + // x_pos = x_pos * roots[i] + p0.x; + + // if (x_pos > uv.x) + // { + // if(roots[i] >= 0. && roots[i] <= 1.){ + // result[1] = !result[1]; + // } + // else if(roots[i] < 0.) + // { + // result[0]=!result[0]; + // } + // else + // result[2]=!result[2]; + // //n_ints++; + // } + // } + // } + // } + // return result; float cu = (-p0.y + 3. * p1.y - 3. * p2.y + p3.y); float qu = (3. * p0.y - 6. * p1.y + 3. * p2.y); float li = (-3. * p0.y + 3. * p1.y); @@ -261,24 +318,52 @@ bool cubic_bezier_sign_test(vec2 uv, vec2 p0, vec2 p1, vec2 p2, vec2 p3) vec3 roots = vec3(1e38); int n_roots = solve_cubic(vec3(co/cu,li/cu,qu/cu),roots); - int n_ints = 0; - + //int n_ints = 0; + bvec3 result = bvec3(false); for(int i=0;i<3;i++){ if(i < n_roots){ - //if(roots[i] >= 0. && roots[i] <= 1.){ + if(roots[i] >= 0. && roots[i] <= 1.){ float x_pos = -p0.x + 3. * p1.x - 3. * p2.x + p3.x; x_pos = x_pos * roots[i] + 3. * p0.x - 6. * p1.x + 3. * p2.x; x_pos = x_pos * roots[i] + -3. * p0.x + 3. * p1.x; x_pos = x_pos * roots[i] + p0.x; - if(x_pos < uv.x){ - n_ints++; + if(x_pos > uv.x){ + result[1] = !result[1]; } - //} + } + } + } + + vec2 tang1 = p0.xy - p1.xy; + vec2 tang2 = p2.xy - p3.xy; + + vec2 nor1 = vec2(tang1.y,-tang1.x); + vec2 nor2 = vec2(tang2.y,-tang2.x); + + if(p0.y < p1.y){ + if((uv.y<=p0.y) && (dot(uv-p0.xy,nor1)>0.)){ + result[0]=!result[0]; + } + } + else{ + if(!(uv.y<=p0.y) && !(dot(uv-p0.xy,nor1)>0.)){ + result[0]=!result[0]; + } + } + + if(p2.y0.){ + result[2]=!result[2]; + } + } + else{ + if((uv.y<=p3.y) && !(dot(uv-p3.xy,nor2)>0.)){ + result[2]=!result[2]; } } - return n_ints%2==0; + return result; // if(n_ints==0 || n_ints==2 || n_ints==4){ // return 1; // } @@ -840,11 +925,12 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metal float strokeWidth = elementData[styleIndex+1]; uint contourIndex = linesOffset + leftChild - 0x80000000; float d = 1e38; - uint signTmp=0; + bool signTmp=false; uint lineCountTmp=0; uint lastPIndex = -1; + bool lastSign = false; uint lineCount = elementIndexs[contourIndex]; - + uint reverseFlag = 0; for ( uint contourIterator = contourIndex + 1;contourIterator < contourIndex + 1 + lineCount; contourIterator++) { uint lineIndex = elementIndexs[contourIterator]; @@ -854,6 +940,7 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metal reverse = true; lineIndex -= 0x80000000; } + uint pLocation = linesOffset + 4 * lineIndex; uvec4 pxIndex = uvec4(pointsOffset)+2*uvec4(elementIndexs[pLocation], elementIndexs[pLocation+1], elementIndexs[pLocation+2], elementIndexs[pLocation+3]); uvec4 pyIndex = uvec4(1)+pxIndex; @@ -863,52 +950,122 @@ bool drawElement(uint elementIndex, vec2 localUV, out vec3 color, out vec2 metal elementData[pxIndex[2]],elementData[pyIndex[2]], elementData[pxIndex[3]], elementData[pyIndex[3]]); + bvec3 signTestResult = cubic_bezier_sign_test(localUV, p[0], p[1], p[2], p[3]); + if(lastPIndex!=pxIndex[0]) { + if(lastSign) + signTmp = !signTmp; float lineType = elementData[styleIndex+4]; if(d<=0.001) { hitElement = true; elementColor = vec4(0,0,0,1); } - else if(d<=strokeWidth && signTmp==lineCountTmp) + else if(d<=strokeWidth && (lineType==2 || signTmp==(lineType==1-reverseFlag))) { + d/=strokeWidth; hitElement = true; elementColor = vec4(1); + metallicRoughness = vec2(0.8); if(elementData[styleIndex+3]==0) { elementColor = vec4(elementData[styleIndex+7],elementData[styleIndex+8],elementData[styleIndex+9],1); metallicRoughness = vec2(elementData[styleIndex+10],elementData[styleIndex+11]); } + else if(elementData[styleIndex+3]==1) + { + elementColor = vec4(mix(vec3(0), vec3(1), d), 1); + metallicRoughness = vec2(0,0.8); + } + else if(elementData[styleIndex+3]==2) + { + float levels[] = {0.25,0.5,0.75}; + vec3 colors[] = {vec3(1,0,0), vec3(0,1,0), vec3(0,0,1), vec3(1,1,0)}; + int i = 0; + while(i<3) + { + if(d bvhBounds0 = { @@ -331,11 +331,11 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod 3, 0,2,3, //element1 //lines - 0,0,1,1, + 0,7,8,1, 1,2,3,4, 5,5,6,6, //contours - 3, 0+ 0x80000000 ,1,2 + 2, 0 ,1 }; std::vector elementData0 = { @@ -352,16 +352,16 @@ Drawable* Model::processMesh(aiMesh* mesh, const aiScene* scene, aiMatrix4x4 mod //element1 //points - -0.5,-0.5, -0.5,0.5, 0.2,0.5, 0.5,0.2, 0.5,-0.5, -0.8,-0.5, -0.8,0.5, + 0.5,-0.5, 0.5,0.5, -0.2,0.5, -0.5,0.2, -0.5,-0.5, -0.8,-0.5, -0.8,0.5, 0.5,-0.4, 0.5,0.4, //strokeStyle //stroke 1, //strokeWidth - 0.02, + 0.1, //strokeEndType 0, //圆角 //strokeFillType - 0, //单色 + 2, //单色 //线类型 1, //左侧 //线外描边宽度