@blakron/core 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/dist/blakron/display/DisplayObject.d.ts +1 -1
  2. package/dist/blakron/display/DisplayObject.d.ts.map +1 -1
  3. package/dist/blakron/display/DisplayObject.js +1 -1
  4. package/dist/blakron/display/DisplayObject.js.map +1 -1
  5. package/dist/blakron/player/Player.d.ts.map +1 -1
  6. package/dist/blakron/player/Player.js +1 -2
  7. package/dist/blakron/player/Player.js.map +1 -1
  8. package/dist/blakron/player/RenderPipe.d.ts +1 -1
  9. package/dist/blakron/player/RenderPipe.d.ts.map +1 -1
  10. package/dist/blakron/player/canvas/CanvasRenderer.d.ts +49 -0
  11. package/dist/blakron/player/canvas/CanvasRenderer.d.ts.map +1 -0
  12. package/dist/blakron/player/canvas/CanvasRenderer.js +792 -0
  13. package/dist/blakron/player/canvas/CanvasRenderer.js.map +1 -0
  14. package/dist/blakron/player/canvas/DisplayList.d.ts +32 -0
  15. package/dist/blakron/player/canvas/DisplayList.d.ts.map +1 -0
  16. package/dist/blakron/player/canvas/DisplayList.js +78 -0
  17. package/dist/blakron/player/canvas/DisplayList.js.map +1 -0
  18. package/dist/blakron/player/canvas/RenderBuffer.d.ts +35 -0
  19. package/dist/blakron/player/canvas/RenderBuffer.d.ts.map +1 -0
  20. package/dist/blakron/player/canvas/RenderBuffer.js +83 -0
  21. package/dist/blakron/player/canvas/RenderBuffer.js.map +1 -0
  22. package/dist/blakron/player/canvas/index.d.ts +4 -0
  23. package/dist/blakron/player/canvas/index.d.ts.map +1 -0
  24. package/dist/blakron/player/canvas/index.js +4 -0
  25. package/dist/blakron/player/canvas/index.js.map +1 -0
  26. package/dist/blakron/player/createPlayer.d.ts.map +1 -1
  27. package/dist/blakron/player/createPlayer.js +1 -2
  28. package/dist/blakron/player/createPlayer.js.map +1 -1
  29. package/dist/blakron/player/index.d.ts +2 -4
  30. package/dist/blakron/player/index.d.ts.map +1 -1
  31. package/dist/blakron/player/index.js +2 -4
  32. package/dist/blakron/player/index.js.map +1 -1
  33. package/dist/blakron/player/webgl/InstructionSet.d.ts +49 -0
  34. package/dist/blakron/player/webgl/InstructionSet.d.ts.map +1 -0
  35. package/dist/blakron/player/webgl/InstructionSet.js +45 -0
  36. package/dist/blakron/player/webgl/InstructionSet.js.map +1 -0
  37. package/dist/blakron/player/webgl/ShaderLib.d.ts +4 -16
  38. package/dist/blakron/player/webgl/ShaderLib.d.ts.map +1 -1
  39. package/dist/blakron/player/webgl/ShaderLib.js +5 -27
  40. package/dist/blakron/player/webgl/ShaderLib.js.map +1 -1
  41. package/dist/blakron/player/webgl/WebGLRenderContext.d.ts +6 -0
  42. package/dist/blakron/player/webgl/WebGLRenderContext.d.ts.map +1 -1
  43. package/dist/blakron/player/webgl/WebGLRenderContext.js +28 -10
  44. package/dist/blakron/player/webgl/WebGLRenderContext.js.map +1 -1
  45. package/dist/blakron/player/webgl/WebGLRenderer.d.ts.map +1 -1
  46. package/dist/blakron/player/webgl/WebGLRenderer.js +3 -8
  47. package/dist/blakron/player/webgl/WebGLRenderer.js.map +1 -1
  48. package/dist/blakron/player/webgl/index.d.ts +1 -1
  49. package/dist/blakron/player/webgl/index.d.ts.map +1 -1
  50. package/dist/blakron/player/webgl/index.js +1 -1
  51. package/dist/blakron/player/webgl/index.js.map +1 -1
  52. package/dist/blakron/player/webgl/pipes/BitmapPipe.d.ts +35 -0
  53. package/dist/blakron/player/webgl/pipes/BitmapPipe.d.ts.map +1 -0
  54. package/dist/blakron/player/webgl/pipes/BitmapPipe.js +130 -0
  55. package/dist/blakron/player/webgl/pipes/BitmapPipe.js.map +1 -0
  56. package/dist/blakron/player/webgl/pipes/FilterPipe.d.ts +68 -0
  57. package/dist/blakron/player/webgl/pipes/FilterPipe.d.ts.map +1 -0
  58. package/dist/blakron/player/webgl/pipes/FilterPipe.js +169 -0
  59. package/dist/blakron/player/webgl/pipes/FilterPipe.js.map +1 -0
  60. package/dist/blakron/player/webgl/pipes/GraphicsPipe.d.ts +36 -0
  61. package/dist/blakron/player/webgl/pipes/GraphicsPipe.d.ts.map +1 -0
  62. package/dist/blakron/player/webgl/pipes/GraphicsPipe.js +126 -0
  63. package/dist/blakron/player/webgl/pipes/GraphicsPipe.js.map +1 -0
  64. package/dist/blakron/player/webgl/pipes/MaskPipe.d.ts +58 -0
  65. package/dist/blakron/player/webgl/pipes/MaskPipe.d.ts.map +1 -0
  66. package/dist/blakron/player/webgl/pipes/MaskPipe.js +190 -0
  67. package/dist/blakron/player/webgl/pipes/MaskPipe.js.map +1 -0
  68. package/dist/blakron/player/webgl/pipes/MeshPipe.d.ts +22 -0
  69. package/dist/blakron/player/webgl/pipes/MeshPipe.d.ts.map +1 -0
  70. package/dist/blakron/player/webgl/pipes/MeshPipe.js +50 -0
  71. package/dist/blakron/player/webgl/pipes/MeshPipe.js.map +1 -0
  72. package/dist/blakron/player/webgl/pipes/TextPipe.d.ts +52 -0
  73. package/dist/blakron/player/webgl/pipes/TextPipe.d.ts.map +1 -0
  74. package/dist/blakron/player/webgl/pipes/TextPipe.js +163 -0
  75. package/dist/blakron/player/webgl/pipes/TextPipe.js.map +1 -0
  76. package/dist/blakron/player/webgl/pipes/index.d.ts +7 -0
  77. package/dist/blakron/player/webgl/pipes/index.d.ts.map +1 -0
  78. package/dist/blakron/player/webgl/pipes/index.js +7 -0
  79. package/dist/blakron/player/webgl/pipes/index.js.map +1 -0
  80. package/dist/blakron/player/webgl/shaders/ShaderLib.d.ts +22 -0
  81. package/dist/blakron/player/webgl/shaders/ShaderLib.d.ts.map +1 -0
  82. package/dist/blakron/player/webgl/shaders/ShaderLib.js +246 -0
  83. package/dist/blakron/player/webgl/shaders/ShaderLib.js.map +1 -0
  84. package/dist/blakron/player/webgl/shaders/ShaderLib2.d.ts +22 -0
  85. package/dist/blakron/player/webgl/shaders/ShaderLib2.d.ts.map +1 -0
  86. package/dist/blakron/player/webgl/shaders/ShaderLib2.js +261 -0
  87. package/dist/blakron/player/webgl/shaders/ShaderLib2.js.map +1 -0
  88. package/dist/blakron/player/webgl/shaders/index.d.ts +5 -0
  89. package/dist/blakron/player/webgl/shaders/index.d.ts.map +1 -0
  90. package/dist/blakron/player/webgl/shaders/index.js +5 -0
  91. package/dist/blakron/player/webgl/shaders/index.js.map +1 -0
  92. package/dist/blakron/player/webgl2/ShaderLib2.d.ts +22 -0
  93. package/dist/blakron/player/webgl2/ShaderLib2.d.ts.map +1 -0
  94. package/dist/blakron/player/webgl2/ShaderLib2.js +261 -0
  95. package/dist/blakron/player/webgl2/ShaderLib2.js.map +1 -0
  96. package/package.json +51 -52
@@ -0,0 +1,22 @@
1
+ /**
2
+ * GLSL ES 1.00 shaders — used with WebGL1 context.
3
+ * For WebGL2 (GLSL ES 3.00) shaders see ../webgl2/ShaderLib2.ts
4
+ */
5
+ export declare const ShaderLib: {
6
+ readonly default_vert: "\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec4 aColor;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4((aVertexPosition / projectionVector) + center, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n vColor = aColor;\n}";
7
+ readonly multi_vert: "\nattribute vec2 aVertexPosition;\nattribute vec2 aTextureCoord;\nattribute vec4 aColor;\nattribute float aTextureId;\nuniform vec2 projectionVector;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nvarying float vTextureId;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4((aVertexPosition / projectionVector) + center, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n vColor = aColor;\n vTextureId = aTextureId;\n}";
8
+ readonly multi_frag: "\nprecision lowp float;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nvarying float vTextureId;\nuniform sampler2D uSamplers[8];\nvoid main(void) {\n vec4 color;\n int id = int(vTextureId + 0.5);\n if (id == 0) color = texture2D(uSamplers[0], vTextureCoord);\n else if (id == 1) color = texture2D(uSamplers[1], vTextureCoord);\n else if (id == 2) color = texture2D(uSamplers[2], vTextureCoord);\n else if (id == 3) color = texture2D(uSamplers[3], vTextureCoord);\n else if (id == 4) color = texture2D(uSamplers[4], vTextureCoord);\n else if (id == 5) color = texture2D(uSamplers[5], vTextureCoord);\n else if (id == 6) color = texture2D(uSamplers[6], vTextureCoord);\n else color = texture2D(uSamplers[7], vTextureCoord);\n gl_FragColor = color * vColor;\n}";
9
+ readonly texture_frag: "\nprecision lowp float;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nuniform sampler2D uSampler;\nvoid main(void) {\n gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;\n}";
10
+ readonly primitive_frag: "\nprecision lowp float;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nvoid main(void) {\n gl_FragColor = vColor;\n}";
11
+ readonly blur_frag: "\nprecision mediump float;\nuniform vec2 blur;\nuniform sampler2D uSampler;\nvarying vec2 vTextureCoord;\nuniform vec2 uTextureSize;\nvoid main() {\n const int sampleRadius = 5;\n const int samples = sampleRadius * 2 + 1;\n vec2 blurUv = blur / uTextureSize;\n vec4 color = vec4(0.0, 0.0, 0.0, 0.0);\n vec2 uv = vec2(0.0, 0.0);\n blurUv /= float(sampleRadius);\n for (int i = -sampleRadius; i <= sampleRadius; i++) {\n uv.x = vTextureCoord.x + float(i) * blurUv.x;\n uv.y = vTextureCoord.y + float(i) * blurUv.y;\n color += texture2D(uSampler, uv);\n }\n color /= float(samples);\n gl_FragColor = color;\n}";
12
+ readonly blur_h_frag: "\nprecision mediump float;\nuniform float blurX;\nuniform sampler2D uSampler;\nvarying vec2 vTextureCoord;\nuniform vec2 uTextureSize;\nvoid main() {\n float step = 1.0 / uTextureSize.x;\n vec4 color = vec4(0.0);\n float total = 0.0;\n for (int i = -8; i <= 8; i++) {\n if (abs(float(i)) > blurX) continue;\n float weight = 1.0 - abs(float(i)) / (blurX + 1.0);\n color += texture2D(uSampler, vTextureCoord + vec2(float(i) * step, 0.0)) * weight;\n total += weight;\n }\n gl_FragColor = color / total;\n}";
13
+ readonly blur_v_frag: "\nprecision mediump float;\nuniform float blurY;\nuniform sampler2D uSampler;\nvarying vec2 vTextureCoord;\nuniform vec2 uTextureSize;\nvoid main() {\n float step = 1.0 / uTextureSize.y;\n vec4 color = vec4(0.0);\n float total = 0.0;\n for (int i = -8; i <= 8; i++) {\n if (abs(float(i)) > blurY) continue;\n float weight = 1.0 - abs(float(i)) / (blurY + 1.0);\n color += texture2D(uSampler, vTextureCoord + vec2(0.0, float(i) * step)) * weight;\n total += weight;\n }\n gl_FragColor = color / total;\n}";
14
+ readonly glow_frag: "\nprecision highp float;\nvarying vec2 vTextureCoord;\nuniform sampler2D uSampler;\nuniform float dist;\nuniform float angle;\nuniform vec4 color;\nuniform float alpha;\nuniform float blurX;\nuniform float blurY;\nuniform float strength;\nuniform float inner;\nuniform float knockout;\nuniform float hideObject;\nuniform vec2 uTextureSize;\nfloat random(vec2 scale) {\n return fract(sin(dot(gl_FragCoord.xy, scale)) * 43758.5453);\n}\nvoid main(void) {\n vec2 px = vec2(1.0 / uTextureSize.x, 1.0 / uTextureSize.y);\n const float linearSamplingTimes = 7.0;\n const float circleSamplingTimes = 12.0;\n vec4 ownColor = texture2D(uSampler, vTextureCoord);\n vec4 curColor;\n float totalAlpha = 0.0;\n float maxTotalAlpha = 0.0;\n float offsetX = dist * cos(angle) * px.x;\n float offsetY = dist * sin(angle) * px.y;\n const float PI = 3.14159265358979323846264;\n float offset = PI * 2.0 / circleSamplingTimes * random(vec2(12.9898, 78.233));\n float stepX = blurX * px.x / linearSamplingTimes;\n float stepY = blurY * px.y / linearSamplingTimes;\n for (float a = 0.0; a <= PI * 2.0; a += PI * 2.0 / circleSamplingTimes) {\n float cosAngle = cos(a + offset);\n float sinAngle = sin(a + offset);\n for (float i = 1.0; i <= linearSamplingTimes; i++) {\n float curDistanceX = i * stepX * cosAngle;\n float curDistanceY = i * stepY * sinAngle;\n if (vTextureCoord.x + curDistanceX - offsetX >= 0.0 && vTextureCoord.y + curDistanceY + offsetY <= 1.0) {\n curColor = texture2D(uSampler, vec2(vTextureCoord.x + curDistanceX - offsetX, vTextureCoord.y + curDistanceY + offsetY));\n totalAlpha += (linearSamplingTimes - i) * curColor.a;\n }\n maxTotalAlpha += (linearSamplingTimes - i);\n }\n }\n ownColor.a = max(ownColor.a, 0.0001);\n ownColor.rgb = ownColor.rgb / ownColor.a;\n float outerGlowAlpha = (totalAlpha / maxTotalAlpha) * strength * alpha * (1.0 - inner) * max(min(hideObject, knockout), 1.0 - ownColor.a);\n float innerGlowAlpha = ((maxTotalAlpha - totalAlpha) / maxTotalAlpha) * strength * alpha * inner * ownColor.a;\n ownColor.a = max(ownColor.a * knockout * (1.0 - hideObject), 0.0001);\n vec3 mix1 = mix(ownColor.rgb, color.rgb, innerGlowAlpha / (innerGlowAlpha + ownColor.a));\n vec3 mix2 = mix(mix1, color.rgb, outerGlowAlpha / (innerGlowAlpha + ownColor.a + outerGlowAlpha));\n float resultAlpha = min(ownColor.a + outerGlowAlpha + innerGlowAlpha, 1.0);\n gl_FragColor = vec4(mix2 * resultAlpha, resultAlpha);\n}";
15
+ readonly colorTransform_frag: "\nprecision mediump float;\nvarying vec2 vTextureCoord;\nvarying vec4 vColor;\nuniform mat4 matrix;\nuniform vec4 colorAdd;\nuniform sampler2D uSampler;\nvoid main(void) {\n vec4 texColor = texture2D(uSampler, vTextureCoord);\n if (texColor.a > 0.0) {\n texColor = vec4(texColor.rgb / texColor.a, texColor.a);\n }\n vec4 locColor = clamp(texColor * matrix + colorAdd, 0.0, 1.0);\n gl_FragColor = vColor * vec4(locColor.rgb * locColor.a, locColor.a);\n}";
16
+ };
17
+ export declare const BLUR_TIERS: readonly [4, 8, 16, 32];
18
+ export type BlurTier = (typeof BLUR_TIERS)[number];
19
+ export declare function getBlurTier(radius: number): BlurTier;
20
+ export declare function makeBlurHFrag(tier: BlurTier): string;
21
+ export declare function makeBlurVFrag(tier: BlurTier): string;
22
+ //# sourceMappingURL=ShaderLib.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShaderLib.d.ts","sourceRoot":"","sources":["../../../../../src/blakron/player/webgl/shaders/ShaderLib.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;CAwMZ,CAAC;AAIX,eAAO,MAAM,UAAU,yBAA0B,CAAC;AAClD,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnD,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAKpD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAmBpD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAmBpD"}
@@ -0,0 +1,246 @@
1
+ /**
2
+ * GLSL ES 1.00 shaders — used with WebGL1 context.
3
+ * For WebGL2 (GLSL ES 3.00) shaders see ../webgl2/ShaderLib2.ts
4
+ */
5
+ export const ShaderLib = {
6
+ default_vert: /* glsl */ `
7
+ attribute vec2 aVertexPosition;
8
+ attribute vec2 aTextureCoord;
9
+ attribute vec4 aColor;
10
+ uniform vec2 projectionVector;
11
+ varying vec2 vTextureCoord;
12
+ varying vec4 vColor;
13
+ const vec2 center = vec2(-1.0, 1.0);
14
+ void main(void) {
15
+ gl_Position = vec4((aVertexPosition / projectionVector) + center, 0.0, 1.0);
16
+ vTextureCoord = aTextureCoord;
17
+ vColor = aColor;
18
+ }`,
19
+ multi_vert: /* glsl */ `
20
+ attribute vec2 aVertexPosition;
21
+ attribute vec2 aTextureCoord;
22
+ attribute vec4 aColor;
23
+ attribute float aTextureId;
24
+ uniform vec2 projectionVector;
25
+ varying vec2 vTextureCoord;
26
+ varying vec4 vColor;
27
+ varying float vTextureId;
28
+ const vec2 center = vec2(-1.0, 1.0);
29
+ void main(void) {
30
+ gl_Position = vec4((aVertexPosition / projectionVector) + center, 0.0, 1.0);
31
+ vTextureCoord = aTextureCoord;
32
+ vColor = aColor;
33
+ vTextureId = aTextureId;
34
+ }`,
35
+ multi_frag: /* glsl */ `
36
+ precision lowp float;
37
+ varying vec2 vTextureCoord;
38
+ varying vec4 vColor;
39
+ varying float vTextureId;
40
+ uniform sampler2D uSamplers[8];
41
+ void main(void) {
42
+ vec4 color;
43
+ int id = int(vTextureId + 0.5);
44
+ if (id == 0) color = texture2D(uSamplers[0], vTextureCoord);
45
+ else if (id == 1) color = texture2D(uSamplers[1], vTextureCoord);
46
+ else if (id == 2) color = texture2D(uSamplers[2], vTextureCoord);
47
+ else if (id == 3) color = texture2D(uSamplers[3], vTextureCoord);
48
+ else if (id == 4) color = texture2D(uSamplers[4], vTextureCoord);
49
+ else if (id == 5) color = texture2D(uSamplers[5], vTextureCoord);
50
+ else if (id == 6) color = texture2D(uSamplers[6], vTextureCoord);
51
+ else color = texture2D(uSamplers[7], vTextureCoord);
52
+ gl_FragColor = color * vColor;
53
+ }`,
54
+ texture_frag: /* glsl */ `
55
+ precision lowp float;
56
+ varying vec2 vTextureCoord;
57
+ varying vec4 vColor;
58
+ uniform sampler2D uSampler;
59
+ void main(void) {
60
+ gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;
61
+ }`,
62
+ primitive_frag: /* glsl */ `
63
+ precision lowp float;
64
+ varying vec2 vTextureCoord;
65
+ varying vec4 vColor;
66
+ void main(void) {
67
+ gl_FragColor = vColor;
68
+ }`,
69
+ blur_frag: /* glsl */ `
70
+ precision mediump float;
71
+ uniform vec2 blur;
72
+ uniform sampler2D uSampler;
73
+ varying vec2 vTextureCoord;
74
+ uniform vec2 uTextureSize;
75
+ void main() {
76
+ const int sampleRadius = 5;
77
+ const int samples = sampleRadius * 2 + 1;
78
+ vec2 blurUv = blur / uTextureSize;
79
+ vec4 color = vec4(0.0, 0.0, 0.0, 0.0);
80
+ vec2 uv = vec2(0.0, 0.0);
81
+ blurUv /= float(sampleRadius);
82
+ for (int i = -sampleRadius; i <= sampleRadius; i++) {
83
+ uv.x = vTextureCoord.x + float(i) * blurUv.x;
84
+ uv.y = vTextureCoord.y + float(i) * blurUv.y;
85
+ color += texture2D(uSampler, uv);
86
+ }
87
+ color /= float(samples);
88
+ gl_FragColor = color;
89
+ }`,
90
+ blur_h_frag: /* glsl */ `
91
+ precision mediump float;
92
+ uniform float blurX;
93
+ uniform sampler2D uSampler;
94
+ varying vec2 vTextureCoord;
95
+ uniform vec2 uTextureSize;
96
+ void main() {
97
+ float step = 1.0 / uTextureSize.x;
98
+ vec4 color = vec4(0.0);
99
+ float total = 0.0;
100
+ for (int i = -8; i <= 8; i++) {
101
+ if (abs(float(i)) > blurX) continue;
102
+ float weight = 1.0 - abs(float(i)) / (blurX + 1.0);
103
+ color += texture2D(uSampler, vTextureCoord + vec2(float(i) * step, 0.0)) * weight;
104
+ total += weight;
105
+ }
106
+ gl_FragColor = color / total;
107
+ }`,
108
+ blur_v_frag: /* glsl */ `
109
+ precision mediump float;
110
+ uniform float blurY;
111
+ uniform sampler2D uSampler;
112
+ varying vec2 vTextureCoord;
113
+ uniform vec2 uTextureSize;
114
+ void main() {
115
+ float step = 1.0 / uTextureSize.y;
116
+ vec4 color = vec4(0.0);
117
+ float total = 0.0;
118
+ for (int i = -8; i <= 8; i++) {
119
+ if (abs(float(i)) > blurY) continue;
120
+ float weight = 1.0 - abs(float(i)) / (blurY + 1.0);
121
+ color += texture2D(uSampler, vTextureCoord + vec2(0.0, float(i) * step)) * weight;
122
+ total += weight;
123
+ }
124
+ gl_FragColor = color / total;
125
+ }`,
126
+ glow_frag: /* glsl */ `
127
+ precision highp float;
128
+ varying vec2 vTextureCoord;
129
+ uniform sampler2D uSampler;
130
+ uniform float dist;
131
+ uniform float angle;
132
+ uniform vec4 color;
133
+ uniform float alpha;
134
+ uniform float blurX;
135
+ uniform float blurY;
136
+ uniform float strength;
137
+ uniform float inner;
138
+ uniform float knockout;
139
+ uniform float hideObject;
140
+ uniform vec2 uTextureSize;
141
+ float random(vec2 scale) {
142
+ return fract(sin(dot(gl_FragCoord.xy, scale)) * 43758.5453);
143
+ }
144
+ void main(void) {
145
+ vec2 px = vec2(1.0 / uTextureSize.x, 1.0 / uTextureSize.y);
146
+ const float linearSamplingTimes = 7.0;
147
+ const float circleSamplingTimes = 12.0;
148
+ vec4 ownColor = texture2D(uSampler, vTextureCoord);
149
+ vec4 curColor;
150
+ float totalAlpha = 0.0;
151
+ float maxTotalAlpha = 0.0;
152
+ float offsetX = dist * cos(angle) * px.x;
153
+ float offsetY = dist * sin(angle) * px.y;
154
+ const float PI = 3.14159265358979323846264;
155
+ float offset = PI * 2.0 / circleSamplingTimes * random(vec2(12.9898, 78.233));
156
+ float stepX = blurX * px.x / linearSamplingTimes;
157
+ float stepY = blurY * px.y / linearSamplingTimes;
158
+ for (float a = 0.0; a <= PI * 2.0; a += PI * 2.0 / circleSamplingTimes) {
159
+ float cosAngle = cos(a + offset);
160
+ float sinAngle = sin(a + offset);
161
+ for (float i = 1.0; i <= linearSamplingTimes; i++) {
162
+ float curDistanceX = i * stepX * cosAngle;
163
+ float curDistanceY = i * stepY * sinAngle;
164
+ if (vTextureCoord.x + curDistanceX - offsetX >= 0.0 && vTextureCoord.y + curDistanceY + offsetY <= 1.0) {
165
+ curColor = texture2D(uSampler, vec2(vTextureCoord.x + curDistanceX - offsetX, vTextureCoord.y + curDistanceY + offsetY));
166
+ totalAlpha += (linearSamplingTimes - i) * curColor.a;
167
+ }
168
+ maxTotalAlpha += (linearSamplingTimes - i);
169
+ }
170
+ }
171
+ ownColor.a = max(ownColor.a, 0.0001);
172
+ ownColor.rgb = ownColor.rgb / ownColor.a;
173
+ float outerGlowAlpha = (totalAlpha / maxTotalAlpha) * strength * alpha * (1.0 - inner) * max(min(hideObject, knockout), 1.0 - ownColor.a);
174
+ float innerGlowAlpha = ((maxTotalAlpha - totalAlpha) / maxTotalAlpha) * strength * alpha * inner * ownColor.a;
175
+ ownColor.a = max(ownColor.a * knockout * (1.0 - hideObject), 0.0001);
176
+ vec3 mix1 = mix(ownColor.rgb, color.rgb, innerGlowAlpha / (innerGlowAlpha + ownColor.a));
177
+ vec3 mix2 = mix(mix1, color.rgb, outerGlowAlpha / (innerGlowAlpha + ownColor.a + outerGlowAlpha));
178
+ float resultAlpha = min(ownColor.a + outerGlowAlpha + innerGlowAlpha, 1.0);
179
+ gl_FragColor = vec4(mix2 * resultAlpha, resultAlpha);
180
+ }`,
181
+ colorTransform_frag: /* glsl */ `
182
+ precision mediump float;
183
+ varying vec2 vTextureCoord;
184
+ varying vec4 vColor;
185
+ uniform mat4 matrix;
186
+ uniform vec4 colorAdd;
187
+ uniform sampler2D uSampler;
188
+ void main(void) {
189
+ vec4 texColor = texture2D(uSampler, vTextureCoord);
190
+ if (texColor.a > 0.0) {
191
+ texColor = vec4(texColor.rgb / texColor.a, texColor.a);
192
+ }
193
+ vec4 locColor = clamp(texColor * matrix + colorAdd, 0.0, 1.0);
194
+ gl_FragColor = vColor * vec4(locColor.rgb * locColor.a, locColor.a);
195
+ }`,
196
+ };
197
+ // ── Dynamic blur shader generation (GLSL ES 1.00) ─────────────────────────────
198
+ export const BLUR_TIERS = [4, 8, 16, 32];
199
+ export function getBlurTier(radius) {
200
+ for (const tier of BLUR_TIERS) {
201
+ if (radius <= tier)
202
+ return tier;
203
+ }
204
+ return 32;
205
+ }
206
+ export function makeBlurHFrag(tier) {
207
+ return /* glsl */ `
208
+ precision mediump float;
209
+ uniform float blurX;
210
+ uniform sampler2D uSampler;
211
+ varying vec2 vTextureCoord;
212
+ uniform vec2 uTextureSize;
213
+ void main() {
214
+ float step = 1.0 / uTextureSize.x;
215
+ vec4 color = vec4(0.0);
216
+ float total = 0.0;
217
+ for (int i = -${tier}; i <= ${tier}; i++) {
218
+ if (abs(float(i)) > blurX) continue;
219
+ float weight = 1.0 - abs(float(i)) / (blurX + 1.0);
220
+ color += texture2D(uSampler, vTextureCoord + vec2(float(i) * step, 0.0)) * weight;
221
+ total += weight;
222
+ }
223
+ gl_FragColor = color / total;
224
+ }`;
225
+ }
226
+ export function makeBlurVFrag(tier) {
227
+ return /* glsl */ `
228
+ precision mediump float;
229
+ uniform float blurY;
230
+ uniform sampler2D uSampler;
231
+ varying vec2 vTextureCoord;
232
+ uniform vec2 uTextureSize;
233
+ void main() {
234
+ float step = 1.0 / uTextureSize.y;
235
+ vec4 color = vec4(0.0);
236
+ float total = 0.0;
237
+ for (int i = -${tier}; i <= ${tier}; i++) {
238
+ if (abs(float(i)) > blurY) continue;
239
+ float weight = 1.0 - abs(float(i)) / (blurY + 1.0);
240
+ color += texture2D(uSampler, vTextureCoord + vec2(0.0, float(i) * step)) * weight;
241
+ total += weight;
242
+ }
243
+ gl_FragColor = color / total;
244
+ }`;
245
+ }
246
+ //# sourceMappingURL=ShaderLib.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShaderLib.js","sourceRoot":"","sources":["../../../../../src/blakron/player/webgl/shaders/ShaderLib.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACxB,YAAY,EAAE,UAAU,CAAC;;;;;;;;;;;;EAYxB;IAED,UAAU,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;EAetB;IAED,UAAU,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;;;;EAkBtB;IAED,YAAY,EAAE,UAAU,CAAC;;;;;;;EAOxB;IAED,cAAc,EAAE,UAAU,CAAC;;;;;;EAM1B;IAED,SAAS,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;EAoBrB;IAED,WAAW,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;;;EAiBvB;IAED,WAAW,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;;;EAiBvB;IAED,SAAS,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsDrB;IAED,mBAAmB,EAAE,UAAU,CAAC;;;;;;;;;;;;;;EAc/B;CACQ,CAAC;AAEX,iFAAiF;AAEjF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAU,CAAC;AAGlD,MAAM,UAAU,WAAW,CAAC,MAAc;IACzC,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC/B,IAAI,MAAM,IAAI,IAAI;YAAE,OAAO,IAAI,CAAC;IACjC,CAAC;IACD,OAAO,EAAE,CAAC;AACX,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAc;IAC3C,OAAO,UAAU,CAAC;;;;;;;;;;oBAUC,IAAI,UAAU,IAAI;;;;;;;EAOpC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAc;IAC3C,OAAO,UAAU,CAAC;;;;;;;;;;oBAUC,IAAI,UAAU,IAAI;;;;;;;EAOpC,CAAC;AACH,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * GLSL ES 3.00 shaders — used with WebGL2 context.
3
+ * For WebGL1 (GLSL ES 1.00) shaders see ../webgl/ShaderLib.ts
4
+ */
5
+ export declare const ShaderLib2: {
6
+ readonly default_vert: "#version 300 es\nin vec2 aVertexPosition;\nin vec2 aTextureCoord;\nin vec4 aColor;\nuniform vec2 projectionVector;\nout vec2 vTextureCoord;\nout vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4((aVertexPosition / projectionVector) + center, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n vColor = aColor;\n}";
7
+ readonly multi_vert: "#version 300 es\nin vec2 aVertexPosition;\nin vec2 aTextureCoord;\nin vec4 aColor;\nin float aTextureId;\nuniform vec2 projectionVector;\nout vec2 vTextureCoord;\nout vec4 vColor;\nout float vTextureId;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4((aVertexPosition / projectionVector) + center, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n vColor = aColor;\n vTextureId = aTextureId;\n}";
8
+ readonly multi_frag: "#version 300 es\nprecision lowp float;\nin vec2 vTextureCoord;\nin vec4 vColor;\nin float vTextureId;\nuniform sampler2D uSamplers[8];\nout vec4 fragColor;\nvoid main(void) {\n vec4 color;\n int id = int(vTextureId + 0.5);\n if (id == 0) color = texture(uSamplers[0], vTextureCoord);\n else if (id == 1) color = texture(uSamplers[1], vTextureCoord);\n else if (id == 2) color = texture(uSamplers[2], vTextureCoord);\n else if (id == 3) color = texture(uSamplers[3], vTextureCoord);\n else if (id == 4) color = texture(uSamplers[4], vTextureCoord);\n else if (id == 5) color = texture(uSamplers[5], vTextureCoord);\n else if (id == 6) color = texture(uSamplers[6], vTextureCoord);\n else color = texture(uSamplers[7], vTextureCoord);\n fragColor = color * vColor;\n}";
9
+ readonly texture_frag: "#version 300 es\nprecision lowp float;\nin vec2 vTextureCoord;\nin vec4 vColor;\nuniform sampler2D uSampler;\nout vec4 fragColor;\nvoid main(void) {\n fragColor = texture(uSampler, vTextureCoord) * vColor;\n}";
10
+ readonly primitive_frag: "#version 300 es\nprecision lowp float;\nin vec2 vTextureCoord;\nin vec4 vColor;\nout vec4 fragColor;\nvoid main(void) {\n fragColor = vColor;\n}";
11
+ readonly blur_frag: "#version 300 es\nprecision mediump float;\nuniform vec2 blur;\nuniform sampler2D uSampler;\nin vec2 vTextureCoord;\nuniform vec2 uTextureSize;\nout vec4 fragColor;\nvoid main() {\n const int sampleRadius = 5;\n const int samples = sampleRadius * 2 + 1;\n vec2 blurUv = blur / uTextureSize;\n vec4 color = vec4(0.0, 0.0, 0.0, 0.0);\n vec2 uv = vec2(0.0, 0.0);\n blurUv /= float(sampleRadius);\n for (int i = -sampleRadius; i <= sampleRadius; i++) {\n uv.x = vTextureCoord.x + float(i) * blurUv.x;\n uv.y = vTextureCoord.y + float(i) * blurUv.y;\n color += texture(uSampler, uv);\n }\n color /= float(samples);\n fragColor = color;\n}";
12
+ readonly blur_h_frag: "#version 300 es\nprecision mediump float;\nuniform float blurX;\nuniform sampler2D uSampler;\nin vec2 vTextureCoord;\nuniform vec2 uTextureSize;\nout vec4 fragColor;\nvoid main() {\n float step = 1.0 / uTextureSize.x;\n vec4 color = vec4(0.0);\n float total = 0.0;\n for (int i = -8; i <= 8; i++) {\n if (abs(float(i)) > blurX) continue;\n float weight = 1.0 - abs(float(i)) / (blurX + 1.0);\n color += texture(uSampler, vTextureCoord + vec2(float(i) * step, 0.0)) * weight;\n total += weight;\n }\n fragColor = color / total;\n}";
13
+ readonly blur_v_frag: "#version 300 es\nprecision mediump float;\nuniform float blurY;\nuniform sampler2D uSampler;\nin vec2 vTextureCoord;\nuniform vec2 uTextureSize;\nout vec4 fragColor;\nvoid main() {\n float step = 1.0 / uTextureSize.y;\n vec4 color = vec4(0.0);\n float total = 0.0;\n for (int i = -8; i <= 8; i++) {\n if (abs(float(i)) > blurY) continue;\n float weight = 1.0 - abs(float(i)) / (blurY + 1.0);\n color += texture(uSampler, vTextureCoord + vec2(0.0, float(i) * step)) * weight;\n total += weight;\n }\n fragColor = color / total;\n}";
14
+ readonly glow_frag: "#version 300 es\nprecision highp float;\nin vec2 vTextureCoord;\nuniform sampler2D uSampler;\nuniform float dist;\nuniform float angle;\nuniform vec4 color;\nuniform float alpha;\nuniform float blurX;\nuniform float blurY;\nuniform float strength;\nuniform float inner;\nuniform float knockout;\nuniform float hideObject;\nuniform vec2 uTextureSize;\nout vec4 fragColor;\nfloat random(vec2 scale) {\n return fract(sin(dot(gl_FragCoord.xy, scale)) * 43758.5453);\n}\nvoid main(void) {\n vec2 px = vec2(1.0 / uTextureSize.x, 1.0 / uTextureSize.y);\n const float linearSamplingTimes = 7.0;\n const float circleSamplingTimes = 12.0;\n vec4 ownColor = texture(uSampler, vTextureCoord);\n vec4 curColor;\n float totalAlpha = 0.0;\n float maxTotalAlpha = 0.0;\n float offsetX = dist * cos(angle) * px.x;\n float offsetY = dist * sin(angle) * px.y;\n const float PI = 3.14159265358979323846264;\n float offset = PI * 2.0 / circleSamplingTimes * random(vec2(12.9898, 78.233));\n float stepX = blurX * px.x / linearSamplingTimes;\n float stepY = blurY * px.y / linearSamplingTimes;\n for (float a = 0.0; a <= PI * 2.0; a += PI * 2.0 / circleSamplingTimes) {\n float cosAngle = cos(a + offset);\n float sinAngle = sin(a + offset);\n for (float i = 1.0; i <= linearSamplingTimes; i++) {\n float curDistanceX = i * stepX * cosAngle;\n float curDistanceY = i * stepY * sinAngle;\n if (vTextureCoord.x + curDistanceX - offsetX >= 0.0 && vTextureCoord.y + curDistanceY + offsetY <= 1.0) {\n curColor = texture(uSampler, vec2(vTextureCoord.x + curDistanceX - offsetX, vTextureCoord.y + curDistanceY + offsetY));\n totalAlpha += (linearSamplingTimes - i) * curColor.a;\n }\n maxTotalAlpha += (linearSamplingTimes - i);\n }\n }\n ownColor.a = max(ownColor.a, 0.0001);\n ownColor.rgb = ownColor.rgb / ownColor.a;\n float outerGlowAlpha = (totalAlpha / maxTotalAlpha) * strength * alpha * (1.0 - inner) * max(min(hideObject, knockout), 1.0 - ownColor.a);\n float innerGlowAlpha = ((maxTotalAlpha - totalAlpha) / maxTotalAlpha) * strength * alpha * inner * ownColor.a;\n ownColor.a = max(ownColor.a * knockout * (1.0 - hideObject), 0.0001);\n vec3 mix1 = mix(ownColor.rgb, color.rgb, innerGlowAlpha / (innerGlowAlpha + ownColor.a));\n vec3 mix2 = mix(mix1, color.rgb, outerGlowAlpha / (innerGlowAlpha + ownColor.a + outerGlowAlpha));\n float resultAlpha = min(ownColor.a + outerGlowAlpha + innerGlowAlpha, 1.0);\n fragColor = vec4(mix2 * resultAlpha, resultAlpha);\n}";
15
+ readonly colorTransform_frag: "#version 300 es\nprecision mediump float;\nin vec2 vTextureCoord;\nin vec4 vColor;\nuniform mat4 matrix;\nuniform vec4 colorAdd;\nuniform sampler2D uSampler;\nout vec4 fragColor;\nvoid main(void) {\n vec4 texColor = texture(uSampler, vTextureCoord);\n if (texColor.a > 0.0) {\n texColor = vec4(texColor.rgb / texColor.a, texColor.a);\n }\n vec4 locColor = clamp(texColor * matrix + colorAdd, 0.0, 1.0);\n fragColor = vColor * vec4(locColor.rgb * locColor.a, locColor.a);\n}";
16
+ };
17
+ export declare const BLUR_TIERS2: readonly [4, 8, 16, 32];
18
+ export type BlurTier2 = (typeof BLUR_TIERS2)[number];
19
+ export declare function getBlurTier2(radius: number): BlurTier2;
20
+ export declare function makeBlurHFrag2(tier: BlurTier2): string;
21
+ export declare function makeBlurVFrag2(tier: BlurTier2): string;
22
+ //# sourceMappingURL=ShaderLib2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShaderLib2.d.ts","sourceRoot":"","sources":["../../../../../src/blakron/player/webgl/shaders/ShaderLib2.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;CAqNb,CAAC;AAIX,eAAO,MAAM,WAAW,yBAA0B,CAAC;AACnD,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAKtD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAoBtD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAoBtD"}
@@ -0,0 +1,261 @@
1
+ /**
2
+ * GLSL ES 3.00 shaders — used with WebGL2 context.
3
+ * For WebGL1 (GLSL ES 1.00) shaders see ../webgl/ShaderLib.ts
4
+ */
5
+ export const ShaderLib2 = {
6
+ default_vert: /* glsl */ `#version 300 es
7
+ in vec2 aVertexPosition;
8
+ in vec2 aTextureCoord;
9
+ in vec4 aColor;
10
+ uniform vec2 projectionVector;
11
+ out vec2 vTextureCoord;
12
+ out vec4 vColor;
13
+ const vec2 center = vec2(-1.0, 1.0);
14
+ void main(void) {
15
+ gl_Position = vec4((aVertexPosition / projectionVector) + center, 0.0, 1.0);
16
+ vTextureCoord = aTextureCoord;
17
+ vColor = aColor;
18
+ }`,
19
+ // Multi-texture vertex shader: carries textureId as a float attribute.
20
+ multi_vert: /* glsl */ `#version 300 es
21
+ in vec2 aVertexPosition;
22
+ in vec2 aTextureCoord;
23
+ in vec4 aColor;
24
+ in float aTextureId;
25
+ uniform vec2 projectionVector;
26
+ out vec2 vTextureCoord;
27
+ out vec4 vColor;
28
+ out float vTextureId;
29
+ const vec2 center = vec2(-1.0, 1.0);
30
+ void main(void) {
31
+ gl_Position = vec4((aVertexPosition / projectionVector) + center, 0.0, 1.0);
32
+ vTextureCoord = aTextureCoord;
33
+ vColor = aColor;
34
+ vTextureId = aTextureId;
35
+ }`,
36
+ // Multi-texture fragment shader.
37
+ // WebGL2 / GLSL ES 3.00 supports dynamic indexing into sampler arrays natively.
38
+ multi_frag: /* glsl */ `#version 300 es
39
+ precision lowp float;
40
+ in vec2 vTextureCoord;
41
+ in vec4 vColor;
42
+ in float vTextureId;
43
+ uniform sampler2D uSamplers[8];
44
+ out vec4 fragColor;
45
+ void main(void) {
46
+ vec4 color;
47
+ int id = int(vTextureId + 0.5);
48
+ if (id == 0) color = texture(uSamplers[0], vTextureCoord);
49
+ else if (id == 1) color = texture(uSamplers[1], vTextureCoord);
50
+ else if (id == 2) color = texture(uSamplers[2], vTextureCoord);
51
+ else if (id == 3) color = texture(uSamplers[3], vTextureCoord);
52
+ else if (id == 4) color = texture(uSamplers[4], vTextureCoord);
53
+ else if (id == 5) color = texture(uSamplers[5], vTextureCoord);
54
+ else if (id == 6) color = texture(uSamplers[6], vTextureCoord);
55
+ else color = texture(uSamplers[7], vTextureCoord);
56
+ fragColor = color * vColor;
57
+ }`,
58
+ texture_frag: /* glsl */ `#version 300 es
59
+ precision lowp float;
60
+ in vec2 vTextureCoord;
61
+ in vec4 vColor;
62
+ uniform sampler2D uSampler;
63
+ out vec4 fragColor;
64
+ void main(void) {
65
+ fragColor = texture(uSampler, vTextureCoord) * vColor;
66
+ }`,
67
+ primitive_frag: /* glsl */ `#version 300 es
68
+ precision lowp float;
69
+ in vec2 vTextureCoord;
70
+ in vec4 vColor;
71
+ out vec4 fragColor;
72
+ void main(void) {
73
+ fragColor = vColor;
74
+ }`,
75
+ blur_frag: /* glsl */ `#version 300 es
76
+ precision mediump float;
77
+ uniform vec2 blur;
78
+ uniform sampler2D uSampler;
79
+ in vec2 vTextureCoord;
80
+ uniform vec2 uTextureSize;
81
+ out vec4 fragColor;
82
+ void main() {
83
+ const int sampleRadius = 5;
84
+ const int samples = sampleRadius * 2 + 1;
85
+ vec2 blurUv = blur / uTextureSize;
86
+ vec4 color = vec4(0.0, 0.0, 0.0, 0.0);
87
+ vec2 uv = vec2(0.0, 0.0);
88
+ blurUv /= float(sampleRadius);
89
+ for (int i = -sampleRadius; i <= sampleRadius; i++) {
90
+ uv.x = vTextureCoord.x + float(i) * blurUv.x;
91
+ uv.y = vTextureCoord.y + float(i) * blurUv.y;
92
+ color += texture(uSampler, uv);
93
+ }
94
+ color /= float(samples);
95
+ fragColor = color;
96
+ }`,
97
+ // Horizontal blur pass for ping-pong two-pass Gaussian blur.
98
+ blur_h_frag: /* glsl */ `#version 300 es
99
+ precision mediump float;
100
+ uniform float blurX;
101
+ uniform sampler2D uSampler;
102
+ in vec2 vTextureCoord;
103
+ uniform vec2 uTextureSize;
104
+ out vec4 fragColor;
105
+ void main() {
106
+ float step = 1.0 / uTextureSize.x;
107
+ vec4 color = vec4(0.0);
108
+ float total = 0.0;
109
+ for (int i = -8; i <= 8; i++) {
110
+ if (abs(float(i)) > blurX) continue;
111
+ float weight = 1.0 - abs(float(i)) / (blurX + 1.0);
112
+ color += texture(uSampler, vTextureCoord + vec2(float(i) * step, 0.0)) * weight;
113
+ total += weight;
114
+ }
115
+ fragColor = color / total;
116
+ }`,
117
+ // Vertical blur pass for ping-pong two-pass Gaussian blur.
118
+ blur_v_frag: /* glsl */ `#version 300 es
119
+ precision mediump float;
120
+ uniform float blurY;
121
+ uniform sampler2D uSampler;
122
+ in vec2 vTextureCoord;
123
+ uniform vec2 uTextureSize;
124
+ out vec4 fragColor;
125
+ void main() {
126
+ float step = 1.0 / uTextureSize.y;
127
+ vec4 color = vec4(0.0);
128
+ float total = 0.0;
129
+ for (int i = -8; i <= 8; i++) {
130
+ if (abs(float(i)) > blurY) continue;
131
+ float weight = 1.0 - abs(float(i)) / (blurY + 1.0);
132
+ color += texture(uSampler, vTextureCoord + vec2(0.0, float(i) * step)) * weight;
133
+ total += weight;
134
+ }
135
+ fragColor = color / total;
136
+ }`,
137
+ glow_frag: /* glsl */ `#version 300 es
138
+ precision highp float;
139
+ in vec2 vTextureCoord;
140
+ uniform sampler2D uSampler;
141
+ uniform float dist;
142
+ uniform float angle;
143
+ uniform vec4 color;
144
+ uniform float alpha;
145
+ uniform float blurX;
146
+ uniform float blurY;
147
+ uniform float strength;
148
+ uniform float inner;
149
+ uniform float knockout;
150
+ uniform float hideObject;
151
+ uniform vec2 uTextureSize;
152
+ out vec4 fragColor;
153
+ float random(vec2 scale) {
154
+ return fract(sin(dot(gl_FragCoord.xy, scale)) * 43758.5453);
155
+ }
156
+ void main(void) {
157
+ vec2 px = vec2(1.0 / uTextureSize.x, 1.0 / uTextureSize.y);
158
+ const float linearSamplingTimes = 7.0;
159
+ const float circleSamplingTimes = 12.0;
160
+ vec4 ownColor = texture(uSampler, vTextureCoord);
161
+ vec4 curColor;
162
+ float totalAlpha = 0.0;
163
+ float maxTotalAlpha = 0.0;
164
+ float offsetX = dist * cos(angle) * px.x;
165
+ float offsetY = dist * sin(angle) * px.y;
166
+ const float PI = 3.14159265358979323846264;
167
+ float offset = PI * 2.0 / circleSamplingTimes * random(vec2(12.9898, 78.233));
168
+ float stepX = blurX * px.x / linearSamplingTimes;
169
+ float stepY = blurY * px.y / linearSamplingTimes;
170
+ for (float a = 0.0; a <= PI * 2.0; a += PI * 2.0 / circleSamplingTimes) {
171
+ float cosAngle = cos(a + offset);
172
+ float sinAngle = sin(a + offset);
173
+ for (float i = 1.0; i <= linearSamplingTimes; i++) {
174
+ float curDistanceX = i * stepX * cosAngle;
175
+ float curDistanceY = i * stepY * sinAngle;
176
+ if (vTextureCoord.x + curDistanceX - offsetX >= 0.0 && vTextureCoord.y + curDistanceY + offsetY <= 1.0) {
177
+ curColor = texture(uSampler, vec2(vTextureCoord.x + curDistanceX - offsetX, vTextureCoord.y + curDistanceY + offsetY));
178
+ totalAlpha += (linearSamplingTimes - i) * curColor.a;
179
+ }
180
+ maxTotalAlpha += (linearSamplingTimes - i);
181
+ }
182
+ }
183
+ ownColor.a = max(ownColor.a, 0.0001);
184
+ ownColor.rgb = ownColor.rgb / ownColor.a;
185
+ float outerGlowAlpha = (totalAlpha / maxTotalAlpha) * strength * alpha * (1.0 - inner) * max(min(hideObject, knockout), 1.0 - ownColor.a);
186
+ float innerGlowAlpha = ((maxTotalAlpha - totalAlpha) / maxTotalAlpha) * strength * alpha * inner * ownColor.a;
187
+ ownColor.a = max(ownColor.a * knockout * (1.0 - hideObject), 0.0001);
188
+ vec3 mix1 = mix(ownColor.rgb, color.rgb, innerGlowAlpha / (innerGlowAlpha + ownColor.a));
189
+ vec3 mix2 = mix(mix1, color.rgb, outerGlowAlpha / (innerGlowAlpha + ownColor.a + outerGlowAlpha));
190
+ float resultAlpha = min(ownColor.a + outerGlowAlpha + innerGlowAlpha, 1.0);
191
+ fragColor = vec4(mix2 * resultAlpha, resultAlpha);
192
+ }`,
193
+ colorTransform_frag: /* glsl */ `#version 300 es
194
+ precision mediump float;
195
+ in vec2 vTextureCoord;
196
+ in vec4 vColor;
197
+ uniform mat4 matrix;
198
+ uniform vec4 colorAdd;
199
+ uniform sampler2D uSampler;
200
+ out vec4 fragColor;
201
+ void main(void) {
202
+ vec4 texColor = texture(uSampler, vTextureCoord);
203
+ if (texColor.a > 0.0) {
204
+ texColor = vec4(texColor.rgb / texColor.a, texColor.a);
205
+ }
206
+ vec4 locColor = clamp(texColor * matrix + colorAdd, 0.0, 1.0);
207
+ fragColor = vColor * vec4(locColor.rgb * locColor.a, locColor.a);
208
+ }`,
209
+ };
210
+ // ── Dynamic blur shader generation (GLSL ES 3.00) ─────────────────────────────
211
+ export const BLUR_TIERS2 = [4, 8, 16, 32];
212
+ export function getBlurTier2(radius) {
213
+ for (const tier of BLUR_TIERS2) {
214
+ if (radius <= tier)
215
+ return tier;
216
+ }
217
+ return 32;
218
+ }
219
+ export function makeBlurHFrag2(tier) {
220
+ return /* glsl */ `#version 300 es
221
+ precision mediump float;
222
+ uniform float blurX;
223
+ uniform sampler2D uSampler;
224
+ in vec2 vTextureCoord;
225
+ uniform vec2 uTextureSize;
226
+ out vec4 fragColor;
227
+ void main() {
228
+ float step = 1.0 / uTextureSize.x;
229
+ vec4 color = vec4(0.0);
230
+ float total = 0.0;
231
+ for (int i = -${tier}; i <= ${tier}; i++) {
232
+ if (abs(float(i)) > blurX) continue;
233
+ float weight = 1.0 - abs(float(i)) / (blurX + 1.0);
234
+ color += texture(uSampler, vTextureCoord + vec2(float(i) * step, 0.0)) * weight;
235
+ total += weight;
236
+ }
237
+ fragColor = color / total;
238
+ }`;
239
+ }
240
+ export function makeBlurVFrag2(tier) {
241
+ return /* glsl */ `#version 300 es
242
+ precision mediump float;
243
+ uniform float blurY;
244
+ uniform sampler2D uSampler;
245
+ in vec2 vTextureCoord;
246
+ uniform vec2 uTextureSize;
247
+ out vec4 fragColor;
248
+ void main() {
249
+ float step = 1.0 / uTextureSize.y;
250
+ vec4 color = vec4(0.0);
251
+ float total = 0.0;
252
+ for (int i = -${tier}; i <= ${tier}; i++) {
253
+ if (abs(float(i)) > blurY) continue;
254
+ float weight = 1.0 - abs(float(i)) / (blurY + 1.0);
255
+ color += texture(uSampler, vTextureCoord + vec2(0.0, float(i) * step)) * weight;
256
+ total += weight;
257
+ }
258
+ fragColor = color / total;
259
+ }`;
260
+ }
261
+ //# sourceMappingURL=ShaderLib2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShaderLib2.js","sourceRoot":"","sources":["../../../../../src/blakron/player/webgl/shaders/ShaderLib2.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;IACzB,YAAY,EAAE,UAAU,CAAC;;;;;;;;;;;;EAYxB;IAED,uEAAuE;IACvE,UAAU,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;EAetB;IAED,iCAAiC;IACjC,gFAAgF;IAChF,UAAU,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;;;;;EAmBtB;IAED,YAAY,EAAE,UAAU,CAAC;;;;;;;;EAQxB;IAED,cAAc,EAAE,UAAU,CAAC;;;;;;;EAO1B;IAED,SAAS,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;EAqBrB;IAED,6DAA6D;IAC7D,WAAW,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;;;;EAkBvB;IAED,2DAA2D;IAC3D,WAAW,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;;;;EAkBvB;IAED,SAAS,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuDrB;IAED,mBAAmB,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;EAe/B;CACQ,CAAC;AAEX,iFAAiF;AAEjF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAU,CAAC;AAGnD,MAAM,UAAU,YAAY,CAAC,MAAc;IAC1C,KAAK,MAAM,IAAI,IAAI,WAAW,EAAE,CAAC;QAChC,IAAI,MAAM,IAAI,IAAI;YAAE,OAAO,IAAI,CAAC;IACjC,CAAC;IACD,OAAO,EAAE,CAAC;AACX,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAe;IAC7C,OAAO,UAAU,CAAC;;;;;;;;;;;oBAWC,IAAI,UAAU,IAAI;;;;;;;EAOpC,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAe;IAC7C,OAAO,UAAU,CAAC;;;;;;;;;;;oBAWC,IAAI,UAAU,IAAI;;;;;;;EAOpC,CAAC;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { ShaderLib, BLUR_TIERS, getBlurTier, makeBlurHFrag, makeBlurVFrag } from './ShaderLib.js';
2
+ export type { BlurTier } from './ShaderLib.js';
3
+ export { ShaderLib2, BLUR_TIERS2, getBlurTier2, makeBlurHFrag2, makeBlurVFrag2 } from './ShaderLib2.js';
4
+ export type { BlurTier2 } from './ShaderLib2.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/blakron/player/webgl/shaders/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAClG,YAAY,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG/C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACxG,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,5 @@
1
+ // GLSL ES 1.00 — WebGL1
2
+ export { ShaderLib, BLUR_TIERS, getBlurTier, makeBlurHFrag, makeBlurVFrag } from './ShaderLib.js';
3
+ // GLSL ES 3.00 — WebGL2
4
+ export { ShaderLib2, BLUR_TIERS2, getBlurTier2, makeBlurHFrag2, makeBlurVFrag2 } from './ShaderLib2.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/blakron/player/webgl/shaders/index.ts"],"names":[],"mappings":"AAAA,wBAAwB;AACxB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGlG,wBAAwB;AACxB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * GLSL ES 3.00 shaders — used with WebGL2 context.
3
+ * For WebGL1 (GLSL ES 1.00) shaders see ../webgl/ShaderLib.ts
4
+ */
5
+ export declare const ShaderLib2: {
6
+ readonly default_vert: "#version 300 es\nin vec2 aVertexPosition;\nin vec2 aTextureCoord;\nin vec4 aColor;\nuniform vec2 projectionVector;\nout vec2 vTextureCoord;\nout vec4 vColor;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4((aVertexPosition / projectionVector) + center, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n vColor = aColor;\n}";
7
+ readonly multi_vert: "#version 300 es\nin vec2 aVertexPosition;\nin vec2 aTextureCoord;\nin vec4 aColor;\nin float aTextureId;\nuniform vec2 projectionVector;\nout vec2 vTextureCoord;\nout vec4 vColor;\nout float vTextureId;\nconst vec2 center = vec2(-1.0, 1.0);\nvoid main(void) {\n gl_Position = vec4((aVertexPosition / projectionVector) + center, 0.0, 1.0);\n vTextureCoord = aTextureCoord;\n vColor = aColor;\n vTextureId = aTextureId;\n}";
8
+ readonly multi_frag: "#version 300 es\nprecision lowp float;\nin vec2 vTextureCoord;\nin vec4 vColor;\nin float vTextureId;\nuniform sampler2D uSamplers[8];\nout vec4 fragColor;\nvoid main(void) {\n vec4 color;\n int id = int(vTextureId + 0.5);\n if (id == 0) color = texture(uSamplers[0], vTextureCoord);\n else if (id == 1) color = texture(uSamplers[1], vTextureCoord);\n else if (id == 2) color = texture(uSamplers[2], vTextureCoord);\n else if (id == 3) color = texture(uSamplers[3], vTextureCoord);\n else if (id == 4) color = texture(uSamplers[4], vTextureCoord);\n else if (id == 5) color = texture(uSamplers[5], vTextureCoord);\n else if (id == 6) color = texture(uSamplers[6], vTextureCoord);\n else color = texture(uSamplers[7], vTextureCoord);\n fragColor = color * vColor;\n}";
9
+ readonly texture_frag: "#version 300 es\nprecision lowp float;\nin vec2 vTextureCoord;\nin vec4 vColor;\nuniform sampler2D uSampler;\nout vec4 fragColor;\nvoid main(void) {\n fragColor = texture(uSampler, vTextureCoord) * vColor;\n}";
10
+ readonly primitive_frag: "#version 300 es\nprecision lowp float;\nin vec2 vTextureCoord;\nin vec4 vColor;\nout vec4 fragColor;\nvoid main(void) {\n fragColor = vColor;\n}";
11
+ readonly blur_frag: "#version 300 es\nprecision mediump float;\nuniform vec2 blur;\nuniform sampler2D uSampler;\nin vec2 vTextureCoord;\nuniform vec2 uTextureSize;\nout vec4 fragColor;\nvoid main() {\n const int sampleRadius = 5;\n const int samples = sampleRadius * 2 + 1;\n vec2 blurUv = blur / uTextureSize;\n vec4 color = vec4(0.0, 0.0, 0.0, 0.0);\n vec2 uv = vec2(0.0, 0.0);\n blurUv /= float(sampleRadius);\n for (int i = -sampleRadius; i <= sampleRadius; i++) {\n uv.x = vTextureCoord.x + float(i) * blurUv.x;\n uv.y = vTextureCoord.y + float(i) * blurUv.y;\n color += texture(uSampler, uv);\n }\n color /= float(samples);\n fragColor = color;\n}";
12
+ readonly blur_h_frag: "#version 300 es\nprecision mediump float;\nuniform float blurX;\nuniform sampler2D uSampler;\nin vec2 vTextureCoord;\nuniform vec2 uTextureSize;\nout vec4 fragColor;\nvoid main() {\n float step = 1.0 / uTextureSize.x;\n vec4 color = vec4(0.0);\n float total = 0.0;\n for (int i = -8; i <= 8; i++) {\n if (abs(float(i)) > blurX) continue;\n float weight = 1.0 - abs(float(i)) / (blurX + 1.0);\n color += texture(uSampler, vTextureCoord + vec2(float(i) * step, 0.0)) * weight;\n total += weight;\n }\n fragColor = color / total;\n}";
13
+ readonly blur_v_frag: "#version 300 es\nprecision mediump float;\nuniform float blurY;\nuniform sampler2D uSampler;\nin vec2 vTextureCoord;\nuniform vec2 uTextureSize;\nout vec4 fragColor;\nvoid main() {\n float step = 1.0 / uTextureSize.y;\n vec4 color = vec4(0.0);\n float total = 0.0;\n for (int i = -8; i <= 8; i++) {\n if (abs(float(i)) > blurY) continue;\n float weight = 1.0 - abs(float(i)) / (blurY + 1.0);\n color += texture(uSampler, vTextureCoord + vec2(0.0, float(i) * step)) * weight;\n total += weight;\n }\n fragColor = color / total;\n}";
14
+ readonly glow_frag: "#version 300 es\nprecision highp float;\nin vec2 vTextureCoord;\nuniform sampler2D uSampler;\nuniform float dist;\nuniform float angle;\nuniform vec4 color;\nuniform float alpha;\nuniform float blurX;\nuniform float blurY;\nuniform float strength;\nuniform float inner;\nuniform float knockout;\nuniform float hideObject;\nuniform vec2 uTextureSize;\nout vec4 fragColor;\nfloat random(vec2 scale) {\n return fract(sin(dot(gl_FragCoord.xy, scale)) * 43758.5453);\n}\nvoid main(void) {\n vec2 px = vec2(1.0 / uTextureSize.x, 1.0 / uTextureSize.y);\n const float linearSamplingTimes = 7.0;\n const float circleSamplingTimes = 12.0;\n vec4 ownColor = texture(uSampler, vTextureCoord);\n vec4 curColor;\n float totalAlpha = 0.0;\n float maxTotalAlpha = 0.0;\n float offsetX = dist * cos(angle) * px.x;\n float offsetY = dist * sin(angle) * px.y;\n const float PI = 3.14159265358979323846264;\n float offset = PI * 2.0 / circleSamplingTimes * random(vec2(12.9898, 78.233));\n float stepX = blurX * px.x / linearSamplingTimes;\n float stepY = blurY * px.y / linearSamplingTimes;\n for (float a = 0.0; a <= PI * 2.0; a += PI * 2.0 / circleSamplingTimes) {\n float cosAngle = cos(a + offset);\n float sinAngle = sin(a + offset);\n for (float i = 1.0; i <= linearSamplingTimes; i++) {\n float curDistanceX = i * stepX * cosAngle;\n float curDistanceY = i * stepY * sinAngle;\n if (vTextureCoord.x + curDistanceX - offsetX >= 0.0 && vTextureCoord.y + curDistanceY + offsetY <= 1.0) {\n curColor = texture(uSampler, vec2(vTextureCoord.x + curDistanceX - offsetX, vTextureCoord.y + curDistanceY + offsetY));\n totalAlpha += (linearSamplingTimes - i) * curColor.a;\n }\n maxTotalAlpha += (linearSamplingTimes - i);\n }\n }\n ownColor.a = max(ownColor.a, 0.0001);\n ownColor.rgb = ownColor.rgb / ownColor.a;\n float outerGlowAlpha = (totalAlpha / maxTotalAlpha) * strength * alpha * (1.0 - inner) * max(min(hideObject, knockout), 1.0 - ownColor.a);\n float innerGlowAlpha = ((maxTotalAlpha - totalAlpha) / maxTotalAlpha) * strength * alpha * inner * ownColor.a;\n ownColor.a = max(ownColor.a * knockout * (1.0 - hideObject), 0.0001);\n vec3 mix1 = mix(ownColor.rgb, color.rgb, innerGlowAlpha / (innerGlowAlpha + ownColor.a));\n vec3 mix2 = mix(mix1, color.rgb, outerGlowAlpha / (innerGlowAlpha + ownColor.a + outerGlowAlpha));\n float resultAlpha = min(ownColor.a + outerGlowAlpha + innerGlowAlpha, 1.0);\n fragColor = vec4(mix2 * resultAlpha, resultAlpha);\n}";
15
+ readonly colorTransform_frag: "#version 300 es\nprecision mediump float;\nin vec2 vTextureCoord;\nin vec4 vColor;\nuniform mat4 matrix;\nuniform vec4 colorAdd;\nuniform sampler2D uSampler;\nout vec4 fragColor;\nvoid main(void) {\n vec4 texColor = texture(uSampler, vTextureCoord);\n if (texColor.a > 0.0) {\n texColor = vec4(texColor.rgb / texColor.a, texColor.a);\n }\n vec4 locColor = clamp(texColor * matrix + colorAdd, 0.0, 1.0);\n fragColor = vColor * vec4(locColor.rgb * locColor.a, locColor.a);\n}";
16
+ };
17
+ export declare const BLUR_TIERS2: readonly [4, 8, 16, 32];
18
+ export type BlurTier2 = (typeof BLUR_TIERS2)[number];
19
+ export declare function getBlurTier2(radius: number): BlurTier2;
20
+ export declare function makeBlurHFrag2(tier: BlurTier2): string;
21
+ export declare function makeBlurVFrag2(tier: BlurTier2): string;
22
+ //# sourceMappingURL=ShaderLib2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ShaderLib2.d.ts","sourceRoot":"","sources":["../../../../src/blakron/player/webgl2/ShaderLib2.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;CAqNb,CAAC;AAIX,eAAO,MAAM,WAAW,yBAA0B,CAAC;AACnD,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC;AAErD,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAKtD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAoBtD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAoBtD"}