1 line
24 KiB
Plaintext
1 line
24 KiB
Plaintext
|
|
{"version":3,"file":"SmoothShader.mjs","sources":["../src/SmoothShader.ts"],"sourcesContent":["import { Program, Shader } from '@pixi/core';\r\nimport { IGraphicsBatchSettings } from './core/BatchDrawCall';\r\n\r\nconst smoothVert = `#version 100\r\nprecision highp float;\r\nconst float FILL = 1.0;\r\nconst float BEVEL = 4.0;\r\nconst float MITER = 8.0;\r\nconst float ROUND = 12.0;\r\nconst float JOINT_CAP_BUTT = 16.0;\r\nconst float JOINT_CAP_SQUARE = 18.0;\r\nconst float JOINT_CAP_ROUND = 20.0;\r\n\r\nconst float FILL_EXPAND = 24.0;\r\n\r\nconst float CAP_BUTT = 1.0;\r\nconst float CAP_SQUARE = 2.0;\r\nconst float CAP_ROUND = 3.0;\r\nconst float CAP_BUTT2 = 4.0;\r\n\r\nconst float MITER_LIMIT = 10.0;\r\n\r\n// === geom ===\r\nattribute vec2 aPrev;\r\nattribute vec2 aPoint1;\r\nattribute vec2 aPoint2;\r\nattribute vec2 aNext;\r\nattribute float aVertexJoint;\r\nattribute float aTravel;\r\n\r\nuniform mat3 projectionMatrix;\r\nuniform mat3 translationMatrix;\r\nuniform vec4 tint;\r\n\r\nvarying vec4 vLine1;\r\nvarying vec4 vLine2;\r\nvarying vec4 vArc;\r\nvarying float vType;\r\n\r\nuniform float resolution;\r\nuniform float expand;\r\n\r\n// === style ===\r\nattribute float aStyleId;\r\nattribute vec4 aColor;\r\n\r\nvarying float vTextureId;\r\nvarying vec4 vColor;\r\nvarying vec2 vTextureCoord;\r\nvarying vec2 vTravel;\r\n\r\nuniform vec2 styleLine[%MAX_STYLES%];\r\nuniform vec3 styleMatrix[2 * %MAX_STYLES%];\r\nuniform float styleTextureId[%MAX_STYLES%];\r\nuniform vec2 samplerSize[%MAX_TEXTURES%];\r\n\r\nvec2 doBisect(vec2 norm, float len, vec2 norm2, float len2,\r\n float dy, float inner) {\r\n vec2 bisect = (norm + norm2) / 2.0;\r\n bisect /= dot(norm, bisect);\r\n vec2 shift = dy * bisect;\r\n if (inner > 0.5) {\r\n if (len < len2) {\r\n if (abs(dy * (bisect.x * norm.y - bisect.y * norm.x)) > len) {\r\n return dy * norm;\r\n }\r\n } else {\r\n if (abs(dy * (bisect.x * norm2.y - bisect.y * norm2.x)) > len2) {\r\n return dy * norm;\r\n }\r\n }\r\n }\r\n return dy * bisect;\r\n}\r\n\r\nvoid main(void){\r\n vec2 pointA = (translationMatrix * vec3(aPoint1, 1.0)).xy;\r\n vec2 pointB = (translationMatrix * vec3(aPoint2, 1.0)).xy;\r\n\r\n vec2 xBasis = pointB - pointA;\r\n float len = length(xBasis);\r\n vec2 forward = xBasis / len;\r\n vec2 norm = vec2(forward.y, -forward.x);\r\n\r\n float type = floor(aVertexJoint / 16.0);\r\n float vertexNum = aVertexJoint - type * 16.0;\r\n float dx = 0.0, dy = 1.0;\r\n\r\n float capType = floor(type / 32.0);\r\n type -= capType * 32.0;\r\n\r\n int styleId = int(aStyleId + 0.5);\r\n float lineWidth = styleLine[styleId].x;\r\n vTextureId = floor(styleTextureId[styleId] / 4.0);\r\n float scaleMode = styleTextureId[styleId] - vTextureId * 4.0;\r\n float avgScale = 1.0;\r\n if (scaleMode > 2.5) {\r\n avgScale = length(translationMatrix * vec3(1.0, 0.0, 0.0));\r\n } else if (scaleMode > 1.5) {\r\n avgScale = length(translationMatrix * vec3(0.0, 1.0, 0.0));\r\n } else if (scaleMode > 0.5) {\r\n vec2 avgDiag = (translationMatrix * vec3(1.0, 1.0, 0.0)).xy;\r\n avgScale = sqrt(dot(avgDiag, avgDiag) * 0.5);\r\n }\r\n lineWidth *= 0.5 * avgScale;\r\n float lineAlignment = 2.0 * styleLine[styleId].y - 1.0;\r\n vTextureCoord = vec2(0.0);\r\n\r\n vec2 pos;\r\n\r\n if (capType == CAP_ROUND) {\r\n vertexNum += 4.0;\r\n type = JOINT_CAP_ROUND;\r\n capType = 0.0;\r\n lineAlignment = -lineAlignment;\r\n }\r\n\r\n vLine1 = vec4(0.0, 10.0, 1.0, 0.0);\r\n vLine2 = vec4(0.0, 10.0, 1.0, 0.0);\r\n vArc = vec4(0.0);\r\n if (type == FILL) {\r\n pos = pointA;\r\n vType = 0.0;\r\n vLine2 = vec4(-2.0, -2.0, -2.0, 0.0);\r\n vec2 vTexturePixel;\r\n vTexturePixel.x = dot(vec3(aPoint1, 1.0), styleMatrix[styleId * 2]);\r\n vTexturePixel.y = dot(vec3(aPoint1, 1.0), styleMatrix[styleId * 2 + 1]);\r\n vTextureCoord
|