@paper-design/shaders 0.0.29 → 0.0.31

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 (68) hide show
  1. package/README.md +7 -4
  2. package/dist/index.d.ts +25 -23
  3. package/dist/index.js +44 -23
  4. package/dist/index.js.map +2 -2
  5. package/dist/shader-mount.d.ts +5 -1
  6. package/dist/shader-mount.js +15 -2
  7. package/dist/shader-mount.js.map +2 -2
  8. package/dist/shader-sizing.d.ts +1 -1
  9. package/dist/shader-sizing.js +2 -5
  10. package/dist/shader-sizing.js.map +2 -2
  11. package/dist/shaders/color-panels.d.ts +48 -0
  12. package/dist/shaders/color-panels.js +213 -0
  13. package/dist/shaders/color-panels.js.map +7 -0
  14. package/dist/shaders/dithering.d.ts +29 -15
  15. package/dist/shaders/dithering.js +85 -61
  16. package/dist/shaders/dithering.js.map +2 -2
  17. package/dist/shaders/dot-grid.d.ts +1 -1
  18. package/dist/shaders/dot-grid.js +20 -13
  19. package/dist/shaders/dot-grid.js.map +2 -2
  20. package/dist/shaders/dot-orbit.d.ts +6 -3
  21. package/dist/shaders/dot-orbit.js +15 -11
  22. package/dist/shaders/dot-orbit.js.map +2 -2
  23. package/dist/shaders/god-rays.d.ts +9 -6
  24. package/dist/shaders/god-rays.js +15 -16
  25. package/dist/shaders/god-rays.js.map +2 -2
  26. package/dist/shaders/grain-gradient.d.ts +17 -5
  27. package/dist/shaders/grain-gradient.js +61 -37
  28. package/dist/shaders/grain-gradient.js.map +2 -2
  29. package/dist/shaders/liquid-metal.d.ts +27 -12
  30. package/dist/shaders/liquid-metal.js +64 -67
  31. package/dist/shaders/liquid-metal.js.map +2 -2
  32. package/dist/shaders/mesh-gradient.d.ts +3 -3
  33. package/dist/shaders/mesh-gradient.js +7 -7
  34. package/dist/shaders/mesh-gradient.js.map +1 -1
  35. package/dist/shaders/metaballs.d.ts +6 -3
  36. package/dist/shaders/metaballs.js +12 -11
  37. package/dist/shaders/metaballs.js.map +2 -2
  38. package/dist/shaders/neuro-noise.d.ts +12 -6
  39. package/dist/shaders/neuro-noise.js +27 -12
  40. package/dist/shaders/neuro-noise.js.map +2 -2
  41. package/dist/shaders/perlin-noise.d.ts +10 -10
  42. package/dist/shaders/perlin-noise.js +30 -22
  43. package/dist/shaders/perlin-noise.js.map +2 -2
  44. package/dist/shaders/pulsing-border.d.ts +3 -3
  45. package/dist/shaders/pulsing-border.js +25 -25
  46. package/dist/shaders/pulsing-border.js.map +1 -1
  47. package/dist/shaders/simplex-noise.d.ts +3 -3
  48. package/dist/shaders/simplex-noise.js +13 -13
  49. package/dist/shaders/simplex-noise.js.map +1 -1
  50. package/dist/shaders/smoke-ring.d.ts +3 -3
  51. package/dist/shaders/smoke-ring.js +7 -7
  52. package/dist/shaders/smoke-ring.js.map +1 -1
  53. package/dist/shaders/spiral.d.ts +8 -8
  54. package/dist/shaders/spiral.js +16 -8
  55. package/dist/shaders/spiral.js.map +2 -2
  56. package/dist/shaders/swirl.d.ts +5 -3
  57. package/dist/shaders/swirl.js +30 -19
  58. package/dist/shaders/swirl.js.map +2 -2
  59. package/dist/shaders/voronoi.d.ts +8 -8
  60. package/dist/shaders/voronoi.js +12 -12
  61. package/dist/shaders/voronoi.js.map +1 -1
  62. package/dist/shaders/warp.d.ts +3 -3
  63. package/dist/shaders/warp.js +32 -28
  64. package/dist/shaders/warp.js.map +2 -2
  65. package/dist/shaders/waves.d.ts +7 -7
  66. package/dist/shaders/waves.js +17 -9
  67. package/dist/shaders/waves.js.map +2 -2
  68. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/shader-sizing.ts"],
4
- "sourcesContent": ["/*\n ===================================================================\n The space coordinates passed from the vertex shader.\n\n `sizingVariablesDeclaration` must be included in every fragment\n shader\u2014unless we want to apply sizing to the coordinates directly\n in the fragment shader.\n\n So far, the only exception is when we need to apply pixelization\n before sizing (e.g., to make dithering pixels independent of sizing).\n*/\nexport const sizingVariablesDeclaration = `\nin vec2 v_objectUV;\nin vec2 v_responsiveUV;\nin vec2 v_responsiveBoxGivenSize;\nin vec2 v_patternUV;`;\n\n/*\n ===================================================================\n Additional variables used only for drawing a sizing overlay.\n*/\nexport const sizingDebugVariablesDeclaration = `\nin vec2 v_objectBoxSize;\nin vec2 v_objectHelperBox;\nin vec2 v_responsiveBoxSize;\nin vec2 v_responsiveHelperBox;\nin vec2 v_patternBoxSize;\nin vec2 v_patternHelperBox;`;\n\n/*\n ===================================================================\n In most cases, sizing UNIFORMS are used only in the vertex shader.\n But there are cases where we need to pass them to the fragment shader\n as well:\n - dithering pixelization where all the sizing happens in fragment\n - drawing the sizing helpers\n*/\nexport const sizingUniformsDeclaration = `\nuniform float u_originX;\nuniform float u_originY;\nuniform float u_worldWidth;\nuniform float u_worldHeight;\nuniform float u_fit;\n\nuniform float u_scale;\nuniform float u_rotation;\nuniform float u_offsetX;\nuniform float u_offsetY;`;\n\n/*\n ===================================================================\n In most cases, sizing TRANSFORMS are applied in the vertex shader.\n For exceptions (e.g., dithering pixelization), the operations below\n need to be included in the fragment shader instead.\n\n Currently, only `objectUV` and `patternUV` are supported.\n The transforms are identical to those in the vertex shader,\n except for the `USE_PIXELIZATION` part.\n*/\nexport const sizingUV = `\n\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n #ifdef USE_PIXELIZATION\n float pxSize = u_pxSize * u_pixelRatio;\n vec2 pxSizeUv = gl_FragCoord.xy;\n pxSizeUv -= .5 * u_resolution;\n pxSizeUv /= pxSize;\n vec2 roundedUv = floor(pxSizeUv) * pxSize / u_resolution.xy; \n roundedUv += .5;\n if (u_pxRounded == true) {\n uv = roundedUv;\n } \n #endif\n uv -= .5;\n\n \n // ===================================================\n // sizing params shared between objects and patterns\n \n vec2 boxOrigin = vec2(.5 - u_originX, u_originY - .5);\n vec2 givenBoxSize = vec2(u_worldWidth, u_worldHeight);\n givenBoxSize = max(givenBoxSize, vec2(1.)) * u_pixelRatio;\n vec2 maxBoxSize = vec2(max(u_resolution.x, givenBoxSize.x), max(u_resolution.y, givenBoxSize.y));\n float r = u_rotation * 3.14159265358979323846 / 180.;\n mat2 graphicRotation = mat2(cos(r), sin(r), -sin(r), cos(r));\n vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);\n\n \n // ===================================================\n // Sizing api for objects (graphics with fixed ratio)\n\n #ifdef USE_OBJECT_SIZING\n float fixedRatio = 1.;\n vec2 fixedRatioBoxGivenSize = vec2(\n (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,\n (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y\n );\n vec2 objectBoxSize = vec2(0.);\n // fit = none\n objectBoxSize.x = fixedRatio * min(fixedRatioBoxGivenSize.x / fixedRatio, fixedRatioBoxGivenSize.y);\n if (u_fit == 1.) { // fit = contain\n objectBoxSize.x = fixedRatio * min(maxBoxSize.x / fixedRatio, maxBoxSize.y);\n } else if (u_fit == 2.) { // fit = cover\n objectBoxSize.x = fixedRatio * max(maxBoxSize.x / fixedRatio, maxBoxSize.y);\n }\n objectBoxSize.y = objectBoxSize.x / fixedRatio;\n vec2 objectWorldScale = u_resolution.xy / objectBoxSize;\n \n #ifdef ADD_HELPERS\n vec2 objectHelperBox = gl_FragCoord.xy / u_resolution.xy;\n objectHelperBox -= .5;\n objectHelperBox *= objectWorldScale;\n objectHelperBox += boxOrigin * (objectWorldScale - 1.); \n #endif\n \n vec2 objectUV = uv;\n objectUV *= objectWorldScale;\n objectUV += boxOrigin * (objectWorldScale - 1.);\n objectUV += vec2(-u_offsetX, u_offsetY);\n objectUV /= u_scale;\n objectUV = graphicRotation * objectUV;\n #endif\n \n // ===================================================\n \n // ===================================================\n // Sizing api for patterns (graphics respecting u_worldWidth / u_worldHeight ratio)\n \n #ifdef USE_PATTERN_SIZING\n float patternBoxRatio = givenBoxSize.x / givenBoxSize.y;\n vec2 patternBoxGivenSize = vec2(\n (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,\n (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y\n );\n vec2 patternBoxSize = vec2(0.);\n // fit = none\n patternBoxSize.x = patternBoxRatio * min(patternBoxGivenSize.x / patternBoxRatio, patternBoxGivenSize.y);\n float patternWorldNoFitBoxWidth = patternBoxSize.x;\n if (u_fit == 1.) { // fit = contain\n patternBoxSize.x = patternBoxRatio * min(maxBoxSize.x / patternBoxRatio, maxBoxSize.y);\n } else if (u_fit == 2.) { // fit = cover\n patternBoxSize.x = patternBoxRatio * max(maxBoxSize.x / patternBoxRatio, maxBoxSize.y);\n }\n patternBoxSize.y = patternBoxSize.x / patternBoxRatio;\n vec2 patternWorldScale = u_resolution.xy / patternBoxSize;\n \n #ifdef ADD_HELPERS \n vec2 patternHelperBox = gl_FragCoord.xy / u_resolution.xy;\n patternHelperBox -= .5;\n patternHelperBox *= patternWorldScale;\n patternHelperBox += boxOrigin * (patternWorldScale - 1.); \n #endif\n \n vec2 patternUV = uv;\n patternUV += vec2(-u_offsetX, u_offsetY) / patternWorldScale;\n patternUV += boxOrigin;\n patternUV -= boxOrigin / patternWorldScale;\n patternUV *= u_resolution.xy;\n patternUV /= u_pixelRatio;\n if (u_fit > 0.) {\n patternUV *= (patternWorldNoFitBoxWidth / patternBoxSize.x);\n }\n patternUV /= u_scale;\n patternUV = graphicRotation * patternUV;\n patternUV += boxOrigin / patternWorldScale;\n patternUV -= boxOrigin;\n patternUV += .5;\n #endif\n`;\n\n/*\n ===================================================================\n Helpers used to draw the sizing (box, box origin and graphic origin)\n over the shader. Can be used with both vertex sizing and vector sizing\n\n helperBox and boxSize should be defined before inserting the code\n*/\nexport const drawSizingHelpers = `\n vec2 worldBoxDist = abs(helperBox);\n float boxStroke = (step(max(worldBoxDist.x, worldBoxDist.y), .5) - step(max(worldBoxDist.x, worldBoxDist.y), .495));\n color.rgb = mix(color.rgb, vec3(1., 0., 0.), boxStroke);\n opacity += boxStroke;\n\n vec2 boxOriginCopy = vec2(.5 - u_originX, u_originY - .5);\n vec2 boxOriginDist = helperBox + boxOriginCopy;\n boxOriginDist.x *= (boxSize.x / boxSize.y);\n float boxOriginPoint = 1. - smoothstep(0., .05, length(boxOriginDist));\n \n vec2 graphicOriginPointDist = helperBox + vec2(-u_offsetX, u_offsetY);\n graphicOriginPointDist.x *= (boxSize.x / boxSize.y);\n float graphicOriginPoint = 1. - smoothstep(0., .05, length(graphicOriginPointDist));\n \n color.rgb = mix(color.rgb, vec3(0., 1., 0.), boxOriginPoint);\n opacity += boxOriginPoint;\n color.rgb = mix(color.rgb, vec3(0., 0., 1.), graphicOriginPoint);\n opacity += graphicOriginPoint;\n`;\n\nexport interface ShaderSizingUniforms {\n u_fit: (typeof ShaderFitOptions)[ShaderFit];\n u_scale: number;\n u_rotation: number;\n u_originX: number;\n u_originY: number;\n u_offsetX: number;\n u_offsetY: number;\n u_worldWidth: number;\n u_worldHeight: number;\n}\n\nexport interface ShaderSizingParams {\n fit?: 'none' | 'contain' | 'cover';\n scale?: number;\n rotation?: number;\n originX?: number;\n originY?: number;\n offsetX?: number;\n offsetY?: number;\n worldWidth?: number;\n worldHeight?: number;\n}\n\nexport const defaultObjectSizing: Required<ShaderSizingParams> = {\n fit: 'contain',\n scale: 1,\n rotation: 0,\n offsetX: 0,\n offsetY: 0,\n originX: 0.5,\n originY: 0.5,\n worldWidth: 0,\n worldHeight: 0,\n};\n\nexport const defaultPatternSizing: Required<ShaderSizingParams> = {\n fit: 'none',\n scale: 1,\n rotation: 0,\n offsetX: 0,\n offsetY: 0,\n originX: 0.5,\n originY: 0.5,\n worldWidth: 0,\n worldHeight: 0,\n};\n\nexport const ShaderFitOptions = {\n none: 0,\n contain: 1,\n cover: 2,\n} as const;\n\nexport type ShaderFit = keyof typeof ShaderFitOptions;\n"],
5
- "mappings": ";;;;;AAWO,MAAM,6BAA6B;AAAA;AAAA;AAAA;AAAA;AAUnC,MAAM,kCAAkC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBxC,MAAM,4BAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBlC,MAAM,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsHjB,MAAM,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6C1B,MAAM,sBAAoD;AAAA,EAC/D,KAAK;AAAA,EACL,OAAO;AAAA,EACP,UAAU;AAAA,EACV,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,aAAa;AACf;AAEO,MAAM,uBAAqD;AAAA,EAChE,KAAK;AAAA,EACL,OAAO;AAAA,EACP,UAAU;AAAA,EACV,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,aAAa;AACf;AAEO,MAAM,mBAAmB;AAAA,EAC9B,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AACT;",
4
+ "sourcesContent": ["/*\n ===================================================================\n The space coordinates passed from the vertex shader.\n\n `sizingVariablesDeclaration` must be included in every fragment\n shader\u2014unless we want to apply sizing to the coordinates directly\n in the fragment shader.\n\n So far, the only exception is when we need to apply pixelization\n before sizing (e.g., to make dithering pixels independent of sizing).\n*/\nexport const sizingVariablesDeclaration = `\nin vec2 v_objectUV;\nin vec2 v_responsiveUV;\nin vec2 v_responsiveBoxGivenSize;\nin vec2 v_patternUV;`;\n\n/*\n ===================================================================\n Additional variables used only for drawing a sizing overlay.\n*/\nexport const sizingDebugVariablesDeclaration = `\nin vec2 v_objectBoxSize;\nin vec2 v_objectHelperBox;\nin vec2 v_responsiveBoxSize;\nin vec2 v_responsiveHelperBox;\nin vec2 v_patternBoxSize;\nin vec2 v_patternHelperBox;`;\n\n/*\n ===================================================================\n In most cases, sizing UNIFORMS are used only in the vertex shader.\n But there are cases where we need to pass them to the fragment shader\n as well:\n - dithering pixelization where all the sizing happens in fragment\n - drawing the sizing helpers\n*/\nexport const sizingUniformsDeclaration = `\nuniform float u_originX;\nuniform float u_originY;\nuniform float u_worldWidth;\nuniform float u_worldHeight;\nuniform float u_fit;\n\nuniform float u_scale;\nuniform float u_rotation;\nuniform float u_offsetX;\nuniform float u_offsetY;`;\n\n/*\n ===================================================================\n In most cases, sizing TRANSFORMS are applied in the vertex shader.\n For exceptions (e.g., dithering pixelization), the operations below\n need to be included in the fragment shader instead.\n\n Currently, only `objectUV` and `patternUV` are supported.\n The transforms are identical to those in the vertex shader,\n except for the `USE_PIXELIZATION` part.\n*/\nexport const sizingUV = `\n\n vec2 uv = gl_FragCoord.xy / u_resolution.xy;\n #ifdef USE_PIXELIZATION\n float pxSize = u_pxSize * u_pixelRatio;\n vec2 pxSizeUv = gl_FragCoord.xy;\n pxSizeUv -= .5 * u_resolution;\n pxSizeUv /= pxSize;\n uv = floor(pxSizeUv) * pxSize / u_resolution.xy; \n uv += .5;\n #endif\n uv -= .5;\n\n \n // ===================================================\n // sizing params shared between objects and patterns\n \n vec2 boxOrigin = vec2(.5 - u_originX, u_originY - .5);\n vec2 givenBoxSize = vec2(u_worldWidth, u_worldHeight);\n givenBoxSize = max(givenBoxSize, vec2(1.)) * u_pixelRatio;\n vec2 maxBoxSize = vec2(max(u_resolution.x, givenBoxSize.x), max(u_resolution.y, givenBoxSize.y));\n float r = u_rotation * 3.14159265358979323846 / 180.;\n mat2 graphicRotation = mat2(cos(r), sin(r), -sin(r), cos(r));\n vec2 graphicOffset = vec2(-u_offsetX, u_offsetY);\n\n \n // ===================================================\n // Sizing api for objects (graphics with fixed ratio)\n\n #ifdef USE_OBJECT_SIZING\n float fixedRatio = 1.;\n vec2 fixedRatioBoxGivenSize = vec2(\n (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,\n (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y\n );\n vec2 objectBoxSize = vec2(0.);\n // fit = none\n objectBoxSize.x = fixedRatio * min(fixedRatioBoxGivenSize.x / fixedRatio, fixedRatioBoxGivenSize.y);\n if (u_fit == 1.) { // fit = contain\n objectBoxSize.x = fixedRatio * min(maxBoxSize.x / fixedRatio, maxBoxSize.y);\n } else if (u_fit == 2.) { // fit = cover\n objectBoxSize.x = fixedRatio * max(maxBoxSize.x / fixedRatio, maxBoxSize.y);\n }\n objectBoxSize.y = objectBoxSize.x / fixedRatio;\n vec2 objectWorldScale = u_resolution.xy / objectBoxSize;\n \n #ifdef ADD_HELPERS\n vec2 objectHelperBox = gl_FragCoord.xy / u_resolution.xy;\n objectHelperBox -= .5;\n objectHelperBox *= objectWorldScale;\n objectHelperBox += boxOrigin * (objectWorldScale - 1.); \n #endif\n \n vec2 objectUV = uv;\n objectUV *= objectWorldScale;\n objectUV += boxOrigin * (objectWorldScale - 1.);\n objectUV += vec2(-u_offsetX, u_offsetY);\n objectUV /= u_scale;\n objectUV = graphicRotation * objectUV;\n #endif\n \n // ===================================================\n \n // ===================================================\n // Sizing api for patterns (graphics respecting u_worldWidth / u_worldHeight ratio)\n \n #ifdef USE_PATTERN_SIZING\n float patternBoxRatio = givenBoxSize.x / givenBoxSize.y;\n vec2 patternBoxGivenSize = vec2(\n (u_worldWidth == 0.) ? u_resolution.x : givenBoxSize.x,\n (u_worldHeight == 0.) ? u_resolution.y : givenBoxSize.y\n );\n vec2 patternBoxSize = vec2(0.);\n // fit = none\n patternBoxSize.x = patternBoxRatio * min(patternBoxGivenSize.x / patternBoxRatio, patternBoxGivenSize.y);\n float patternWorldNoFitBoxWidth = patternBoxSize.x;\n if (u_fit == 1.) { // fit = contain\n patternBoxSize.x = patternBoxRatio * min(maxBoxSize.x / patternBoxRatio, maxBoxSize.y);\n } else if (u_fit == 2.) { // fit = cover\n patternBoxSize.x = patternBoxRatio * max(maxBoxSize.x / patternBoxRatio, maxBoxSize.y);\n }\n patternBoxSize.y = patternBoxSize.x / patternBoxRatio;\n vec2 patternWorldScale = u_resolution.xy / patternBoxSize;\n \n #ifdef ADD_HELPERS \n vec2 patternHelperBox = gl_FragCoord.xy / u_resolution.xy;\n patternHelperBox -= .5;\n patternHelperBox *= patternWorldScale;\n patternHelperBox += boxOrigin * (patternWorldScale - 1.); \n #endif\n \n vec2 patternUV = uv;\n patternUV += vec2(-u_offsetX, u_offsetY) / patternWorldScale;\n patternUV += boxOrigin;\n patternUV -= boxOrigin / patternWorldScale;\n patternUV *= u_resolution.xy;\n patternUV /= u_pixelRatio;\n if (u_fit > 0.) {\n patternUV *= (patternWorldNoFitBoxWidth / patternBoxSize.x);\n }\n patternUV /= u_scale;\n patternUV = graphicRotation * patternUV;\n patternUV += boxOrigin / patternWorldScale;\n patternUV -= boxOrigin;\n patternUV += .5;\n #endif\n`;\n\n/*\n ===================================================================\n Helpers used to draw the sizing (box, box origin and graphic origin)\n over the shader. Can be used with both vertex sizing and vector sizing\n\n helperBox and boxSize should be defined before inserting the code\n*/\nexport const drawSizingHelpers = `\n vec2 worldBoxDist = abs(helperBox);\n float boxStroke = (step(max(worldBoxDist.x, worldBoxDist.y), .5) - step(max(worldBoxDist.x, worldBoxDist.y), .495));\n color.rgb = mix(color.rgb, vec3(1., 0., 0.), boxStroke);\n opacity += boxStroke;\n\n vec2 boxOriginCopy = vec2(.5 - u_originX, u_originY - .5);\n vec2 boxOriginDist = helperBox + boxOriginCopy;\n boxOriginDist.x *= (boxSize.x / boxSize.y);\n float boxOriginPoint = 1. - smoothstep(0., .05, length(boxOriginDist));\n \n vec2 graphicOriginPointDist = helperBox + vec2(-u_offsetX, u_offsetY);\n graphicOriginPointDist.x *= (boxSize.x / boxSize.y);\n float graphicOriginPoint = 1. - smoothstep(0., .05, length(graphicOriginPointDist));\n \n color.rgb = mix(color.rgb, vec3(0., 1., 0.), boxOriginPoint);\n opacity += boxOriginPoint;\n color.rgb = mix(color.rgb, vec3(0., 0., 1.), graphicOriginPoint);\n opacity += graphicOriginPoint;\n`;\n\nexport interface ShaderSizingUniforms {\n u_fit: (typeof ShaderFitOptions)[ShaderFit];\n u_scale: number;\n u_rotation: number;\n u_originX: number;\n u_originY: number;\n u_offsetX: number;\n u_offsetY: number;\n u_worldWidth: number;\n u_worldHeight: number;\n}\n\nexport interface ShaderSizingParams {\n fit?: 'none' | 'contain' | 'cover';\n scale?: number;\n rotation?: number;\n originX?: number;\n originY?: number;\n offsetX?: number;\n offsetY?: number;\n worldWidth?: number;\n worldHeight?: number;\n}\n\nexport const defaultObjectSizing: Required<ShaderSizingParams> = {\n fit: 'contain',\n scale: 1,\n rotation: 0,\n offsetX: 0,\n offsetY: 0,\n originX: 0.5,\n originY: 0.5,\n worldWidth: 0,\n worldHeight: 0,\n};\n\nexport const defaultPatternSizing: Required<ShaderSizingParams> = {\n fit: 'none',\n scale: 1,\n rotation: 0,\n offsetX: 0,\n offsetY: 0,\n originX: 0.5,\n originY: 0.5,\n worldWidth: 0,\n worldHeight: 0,\n};\n\nexport const ShaderFitOptions = {\n none: 0,\n contain: 1,\n cover: 2,\n} as const;\n\nexport type ShaderFit = keyof typeof ShaderFitOptions;\n"],
5
+ "mappings": ";;;;;AAWO,MAAM,6BAA6B;AAAA;AAAA;AAAA;AAAA;AAUnC,MAAM,kCAAkC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBxC,MAAM,4BAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBlC,MAAM,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmHjB,MAAM,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6C1B,MAAM,sBAAoD;AAAA,EAC/D,KAAK;AAAA,EACL,OAAO;AAAA,EACP,UAAU;AAAA,EACV,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,aAAa;AACf;AAEO,MAAM,uBAAqD;AAAA,EAChE,KAAK;AAAA,EACL,OAAO;AAAA,EACP,UAAU;AAAA,EACV,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,aAAa;AACf;AAEO,MAAM,mBAAmB;AAAA,EAC9B,MAAM;AAAA,EACN,SAAS;AAAA,EACT,OAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,48 @@
1
+ import type { vec4 } from '../types.js';
2
+ import type { ShaderMotionParams } from '../shader-mount.js';
3
+ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';
4
+ export declare const colorPanelsMeta: {
5
+ readonly maxColorCount: 7;
6
+ };
7
+ /**
8
+ * Animated, pseudo-3D color panels with dynamic layering and directional blur
9
+ * by Ksenia Kondrashova
10
+ *
11
+ * Uniforms include:
12
+ * - u_colors (vec4[]): Input RGBA colors for panels
13
+ * - u_colorsCount (float): Number of active colors (`u_colors` length)
14
+ * - u_density (float): Panels to show
15
+ * - u_colorBack (vec4): Background color to blend behind panels
16
+ * - u_angle (float): Panel skew angle to morph rect to triangle panels
17
+ * - u_length (float): Length of panels (relative to total height)
18
+ * - u_blur (float): Horizontal blur amount along panel edges
19
+ * - u_fadePosition (float): Controls transparency toward the center of panels
20
+ * - u_colorShuffler (float): Affects how panel colors cycle
21
+ * - u_singleColor (float): Controls blending of adjacent colors per panel
22
+ */
23
+ export declare const colorPanelsFragmentShader: string;
24
+ export interface ColorPanelsUniforms extends ShaderSizingUniforms {
25
+ u_colors: vec4[];
26
+ u_colorsCount: number;
27
+ u_colorBack: [number, number, number, number];
28
+ u_angle1: number;
29
+ u_angle2: number;
30
+ u_length: number;
31
+ u_blur: number;
32
+ u_fadeIn: number;
33
+ u_fadeOut: number;
34
+ u_density: number;
35
+ u_gradient: number;
36
+ }
37
+ export interface ColorPanelsParams extends ShaderSizingParams, ShaderMotionParams {
38
+ colors?: string[];
39
+ colorBack?: string;
40
+ angle1?: number;
41
+ angle2?: number;
42
+ length?: number;
43
+ blur?: number;
44
+ fadeIn?: number;
45
+ fadeOut?: number;
46
+ density?: number;
47
+ gradient?: number;
48
+ }
@@ -0,0 +1,213 @@
1
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
+ * Paper Shaders *
3
+ * https://github.com/paper-design/shaders *
4
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * */
5
+
6
+ import { sizingVariablesDeclaration } from "../shader-sizing.js";
7
+ import { declarePI, colorBandingFix } from "../shader-utils.js";
8
+ const colorPanelsMeta = {
9
+ maxColorCount: 7
10
+ };
11
+ const colorPanelsFragmentShader = `#version 300 es
12
+ precision lowp float;
13
+
14
+ uniform vec2 u_resolution;
15
+
16
+ uniform float u_time;
17
+ uniform float u_scale;
18
+
19
+ uniform vec4 u_colors[${colorPanelsMeta.maxColorCount}];
20
+ uniform float u_colorsCount;
21
+ uniform vec4 u_colorBack;
22
+ uniform float u_angle1;
23
+ uniform float u_angle2;
24
+ uniform float u_length;
25
+ uniform float u_blur;
26
+ uniform float u_fadeIn;
27
+ uniform float u_fadeOut;
28
+ uniform float u_density;
29
+ uniform float u_gradient;
30
+
31
+ ${sizingVariablesDeclaration}
32
+
33
+ out vec4 fragColor;
34
+
35
+ ${declarePI}
36
+
37
+ vec2 getPanel(float angle, vec2 uv, float invLength) {
38
+ float sinA = sin(angle);
39
+ float cosA = cos(angle);
40
+
41
+ float denom = sinA - uv.y * cosA;
42
+ if (abs(denom) < 1e-5) return vec2(0.);
43
+
44
+ float z = uv.y / denom;
45
+ float zLimit = 0.5;
46
+
47
+ if (z < 0. || z > zLimit) return vec2(0.);
48
+
49
+ float zRatio = z / zLimit;
50
+ float panelMap = 1.0 - zRatio;
51
+ float x = uv.x * (cosA * z + 1.) * invLength;
52
+
53
+ float zOffset = zRatio - .5;
54
+ float left = -.5 + zOffset * u_angle1;
55
+ float right = .5 - zOffset * u_angle2;
56
+
57
+ float blurFactor = (1. - panelMap) * clamp((abs(angle / TWO_PI - .5) - .01) / (-.01), 0., 1.);;
58
+ float blurX = .15 * blurFactor + panelMap * u_blur;
59
+
60
+ float leftEdge1 = left - .5 * blurX;
61
+ float leftEdge2 = left + blurX;
62
+ float rightEdge1 = right - blurX;
63
+ float rightEdge2 = right + .5 * blurX;
64
+
65
+ float panel = smoothstep(leftEdge1, leftEdge2, x) * (1.0 - smoothstep(rightEdge1, rightEdge2, x));
66
+
67
+ return vec2(panel, clamp(panelMap, 0., 1.));
68
+ }
69
+
70
+ vec4 blendColor(vec4 colorA, float panelMask, float panelMap) {
71
+ float fade = smoothstep(-.2 * (1. - u_fadeOut), u_fadeOut, panelMap)
72
+ * (1. - smoothstep(1. - u_fadeIn, 1., panelMap));
73
+
74
+ vec3 blendedRGB = mix(vec3(0.), colorA.rgb, fade);
75
+ float blendedAlpha = mix(0., colorA.a, fade);
76
+
77
+ return vec4(blendedRGB, blendedAlpha) * panelMask;
78
+ }
79
+
80
+ void main() {
81
+ vec2 uv = v_objectUV;
82
+ uv *= 1.25;
83
+
84
+ float t = .05 * u_time;
85
+ t = fract(t);
86
+ bool reverseTime = (t < 0.5);
87
+
88
+ vec3 color = vec3(0.);
89
+ float opacity = 0.;
90
+
91
+ int colorsCount = int(u_colorsCount);
92
+
93
+ vec4 premultipliedColors[${colorPanelsMeta.maxColorCount}];
94
+ for (int i = 0; i < ${colorPanelsMeta.maxColorCount}; i++) {
95
+ if (i >= colorsCount) break;
96
+ vec4 c = u_colors[i];
97
+ c.rgb *= c.a;
98
+ premultipliedColors[i] = c;
99
+ }
100
+
101
+ float invLength = 1.5 / (u_length + 0.001);
102
+
103
+ float totalColorWeight = 0.;
104
+ int panelsNumber = 12;
105
+
106
+ float densityNormalizer = 1.;
107
+ if (colorsCount == 4) {
108
+ panelsNumber = 16;
109
+ densityNormalizer = 1.34;
110
+ } else if (colorsCount == 5) {
111
+ panelsNumber = 20;
112
+ densityNormalizer = 1.67;
113
+ } else if (colorsCount == 7) {
114
+ panelsNumber = 14;
115
+ densityNormalizer = 1.17;
116
+ }
117
+
118
+ float fPanelsNumber = float(panelsNumber);
119
+
120
+ float totalPanelsShape = 0.;
121
+ float panelGrad = 1. - clamp(u_gradient, 0., 1.);
122
+
123
+ for (int set = 0; set < 2; set++) {
124
+ bool isForward = (set == 0 && !reverseTime) || (set == 1 && reverseTime);
125
+ if (!isForward) continue;
126
+
127
+ for (int i = 0; i <= 20; i++) {
128
+ if (i >= panelsNumber) break;
129
+
130
+ int idx = panelsNumber - 1 - i;
131
+
132
+ float offset = float(idx) / fPanelsNumber;
133
+ if (set == 1) {
134
+ offset += .5;
135
+ }
136
+
137
+ float densityFract = densityNormalizer * fract(t + offset);
138
+ float angleNorm = densityFract / u_density;
139
+ if (densityFract >= .5 || angleNorm >= .3) continue;
140
+
141
+ float smoothDensity = clamp((.5 - densityFract) / .1, 0., 1.) * clamp(densityFract / .01, 0., 1.);
142
+ float smoothAngle = clamp((.3 - angleNorm) / .05, 0., 1.);
143
+ if (smoothDensity * smoothAngle < .001) continue;
144
+
145
+ vec2 panel = getPanel(angleNorm * TWO_PI + PI, uv, invLength);
146
+ float panelMask = panel[0] * smoothDensity * smoothAngle;
147
+ if (panelMask <= .001) continue;
148
+ float panelMap = panel[1];
149
+
150
+ int colorIdx = idx % colorsCount;
151
+ int nextColorIdx = (idx + 1) % colorsCount;
152
+
153
+ vec4 colorA = premultipliedColors[colorIdx];
154
+ vec4 colorB = premultipliedColors[nextColorIdx];
155
+
156
+ colorA = mix(colorA, colorB, max(0., smoothstep(.0, .45, panelMap) - panelGrad));
157
+ vec4 blended = blendColor(colorA, panelMask, panelMap);
158
+ color = blended.rgb + color * (1. - blended.a);
159
+ opacity = blended.a + opacity * (1. - blended.a);
160
+ }
161
+
162
+
163
+ for (int i = 0; i <= 20; i++) {
164
+ if (i >= panelsNumber) break;
165
+
166
+ int idx = panelsNumber - 1 - i;
167
+
168
+ float offset = float(idx) / fPanelsNumber;
169
+ if (set == 0) {
170
+ offset += .5;
171
+ }
172
+
173
+ float densityFract = densityNormalizer * fract(-t + offset);
174
+ float angleNorm = -densityFract / u_density;
175
+ if (densityFract >= .5 || angleNorm < -.3) continue;
176
+
177
+ float smoothDensity = clamp((.5 - densityFract) / .1, 0., 1.) * clamp(densityFract / .01, 0., 1.);
178
+ float smoothAngle = clamp((angleNorm + .3) / .05, 0., 1.);
179
+ if (smoothDensity * smoothAngle < .001) continue;
180
+
181
+ vec2 panel = getPanel(angleNorm * TWO_PI + PI, uv, invLength);
182
+ float panelMask = panel[0] * smoothDensity * smoothAngle;
183
+ if (panelMask <= .001) continue;
184
+ float panelMap = panel[1];
185
+
186
+ int colorIdx = (colorsCount - (idx % colorsCount)) % colorsCount;
187
+ if (colorIdx < 0) colorIdx += colorsCount;
188
+ int nextColorIdx = (colorIdx + 1) % colorsCount;
189
+
190
+ vec4 colorA = premultipliedColors[colorIdx];
191
+ vec4 colorB = premultipliedColors[nextColorIdx];
192
+
193
+ colorA = mix(colorA, colorB, max(0., smoothstep(.0, .45, panelMap) - panelGrad));
194
+ vec4 blended = blendColor(colorA, panelMask, panelMap);
195
+ color = blended.rgb + color * (1. - blended.a);
196
+ opacity = blended.a + opacity * (1. - blended.a);
197
+ }
198
+ }
199
+
200
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
201
+ color = color + bgColor * (1.0 - opacity);
202
+ opacity = opacity + u_colorBack.a * (1.0 - opacity);
203
+
204
+ ${colorBandingFix}
205
+
206
+ fragColor = vec4(color, opacity);
207
+ }
208
+ `;
209
+ export {
210
+ colorPanelsFragmentShader,
211
+ colorPanelsMeta
212
+ };
213
+ //# sourceMappingURL=color-panels.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/shaders/color-panels.ts"],
4
+ "sourcesContent": ["import type { vec4 } from '../types.js';\nimport type { ShaderMotionParams } from '../shader-mount.js';\nimport { sizingVariablesDeclaration, type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI, colorBandingFix } from '../shader-utils.js';\n\nexport const colorPanelsMeta = {\n maxColorCount: 7,\n} as const;\n\n/**\n * Animated, pseudo-3D color panels with dynamic layering and directional blur\n * by Ksenia Kondrashova\n *\n * Uniforms include:\n * - u_colors (vec4[]): Input RGBA colors for panels\n * - u_colorsCount (float): Number of active colors (`u_colors` length)\n * - u_density (float): Panels to show\n * - u_colorBack (vec4): Background color to blend behind panels\n * - u_angle (float): Panel skew angle to morph rect to triangle panels\n * - u_length (float): Length of panels (relative to total height)\n * - u_blur (float): Horizontal blur amount along panel edges\n * - u_fadePosition (float): Controls transparency toward the center of panels\n * - u_colorShuffler (float): Affects how panel colors cycle\n * - u_singleColor (float): Controls blending of adjacent colors per panel\n */\n\nexport const colorPanelsFragmentShader: string = `#version 300 es\nprecision lowp float;\n\nuniform vec2 u_resolution;\n\nuniform float u_time;\nuniform float u_scale;\n\nuniform vec4 u_colors[${colorPanelsMeta.maxColorCount}];\nuniform float u_colorsCount;\nuniform vec4 u_colorBack;\nuniform float u_angle1;\nuniform float u_angle2;\nuniform float u_length;\nuniform float u_blur;\nuniform float u_fadeIn;\nuniform float u_fadeOut;\nuniform float u_density;\nuniform float u_gradient;\n\n${sizingVariablesDeclaration}\n\nout vec4 fragColor;\n\n${declarePI}\n\nvec2 getPanel(float angle, vec2 uv, float invLength) {\n float sinA = sin(angle);\n float cosA = cos(angle);\n\n float denom = sinA - uv.y * cosA;\n if (abs(denom) < 1e-5) return vec2(0.);\n\n float z = uv.y / denom;\n float zLimit = 0.5;\n\n if (z < 0. || z > zLimit) return vec2(0.);\n\n float zRatio = z / zLimit;\n float panelMap = 1.0 - zRatio;\n float x = uv.x * (cosA * z + 1.) * invLength;\n\n float zOffset = zRatio - .5;\n float left = -.5 + zOffset * u_angle1;\n float right = .5 - zOffset * u_angle2;\n\n float blurFactor = (1. - panelMap) * clamp((abs(angle / TWO_PI - .5) - .01) / (-.01), 0., 1.);;\n float blurX = .15 * blurFactor + panelMap * u_blur;\n\n float leftEdge1 = left - .5 * blurX;\n float leftEdge2 = left + blurX;\n float rightEdge1 = right - blurX;\n float rightEdge2 = right + .5 * blurX;\n\n float panel = smoothstep(leftEdge1, leftEdge2, x) * (1.0 - smoothstep(rightEdge1, rightEdge2, x));\n\n return vec2(panel, clamp(panelMap, 0., 1.));\n}\n\nvec4 blendColor(vec4 colorA, float panelMask, float panelMap) {\n float fade = smoothstep(-.2 * (1. - u_fadeOut), u_fadeOut, panelMap)\n * (1. - smoothstep(1. - u_fadeIn, 1., panelMap));\n\n vec3 blendedRGB = mix(vec3(0.), colorA.rgb, fade);\n float blendedAlpha = mix(0., colorA.a, fade);\n\n return vec4(blendedRGB, blendedAlpha) * panelMask;\n}\n\nvoid main() {\n vec2 uv = v_objectUV;\n uv *= 1.25;\n\n float t = .05 * u_time;\n t = fract(t);\n bool reverseTime = (t < 0.5);\n\n vec3 color = vec3(0.);\n float opacity = 0.;\n\n int colorsCount = int(u_colorsCount);\n\n vec4 premultipliedColors[${colorPanelsMeta.maxColorCount}];\n for (int i = 0; i < ${colorPanelsMeta.maxColorCount}; i++) {\n if (i >= colorsCount) break;\n vec4 c = u_colors[i];\n c.rgb *= c.a;\n premultipliedColors[i] = c;\n }\n\n float invLength = 1.5 / (u_length + 0.001);\n\n float totalColorWeight = 0.;\n int panelsNumber = 12;\n\n float densityNormalizer = 1.;\n if (colorsCount == 4) {\n panelsNumber = 16;\n densityNormalizer = 1.34;\n } else if (colorsCount == 5) {\n panelsNumber = 20;\n densityNormalizer = 1.67;\n } else if (colorsCount == 7) {\n panelsNumber = 14;\n densityNormalizer = 1.17;\n }\n\n float fPanelsNumber = float(panelsNumber);\n\n float totalPanelsShape = 0.;\n float panelGrad = 1. - clamp(u_gradient, 0., 1.);\n\n for (int set = 0; set < 2; set++) {\n bool isForward = (set == 0 && !reverseTime) || (set == 1 && reverseTime);\n if (!isForward) continue;\n\n for (int i = 0; i <= 20; i++) {\n if (i >= panelsNumber) break;\n\n int idx = panelsNumber - 1 - i;\n\n float offset = float(idx) / fPanelsNumber;\n if (set == 1) {\n offset += .5;\n }\n\n float densityFract = densityNormalizer * fract(t + offset);\n float angleNorm = densityFract / u_density;\n if (densityFract >= .5 || angleNorm >= .3) continue;\n\n float smoothDensity = clamp((.5 - densityFract) / .1, 0., 1.) * clamp(densityFract / .01, 0., 1.);\n float smoothAngle = clamp((.3 - angleNorm) / .05, 0., 1.);\n if (smoothDensity * smoothAngle < .001) continue;\n\n vec2 panel = getPanel(angleNorm * TWO_PI + PI, uv, invLength);\n float panelMask = panel[0] * smoothDensity * smoothAngle;\n if (panelMask <= .001) continue;\n float panelMap = panel[1];\n\n int colorIdx = idx % colorsCount;\n int nextColorIdx = (idx + 1) % colorsCount;\n\n vec4 colorA = premultipliedColors[colorIdx];\n vec4 colorB = premultipliedColors[nextColorIdx];\n\n colorA = mix(colorA, colorB, max(0., smoothstep(.0, .45, panelMap) - panelGrad));\n vec4 blended = blendColor(colorA, panelMask, panelMap);\n color = blended.rgb + color * (1. - blended.a);\n opacity = blended.a + opacity * (1. - blended.a);\n }\n\n\n for (int i = 0; i <= 20; i++) {\n if (i >= panelsNumber) break;\n\n int idx = panelsNumber - 1 - i;\n\n float offset = float(idx) / fPanelsNumber;\n if (set == 0) {\n offset += .5;\n }\n\n float densityFract = densityNormalizer * fract(-t + offset);\n float angleNorm = -densityFract / u_density;\n if (densityFract >= .5 || angleNorm < -.3) continue;\n\n float smoothDensity = clamp((.5 - densityFract) / .1, 0., 1.) * clamp(densityFract / .01, 0., 1.);\n float smoothAngle = clamp((angleNorm + .3) / .05, 0., 1.);\n if (smoothDensity * smoothAngle < .001) continue;\n\n vec2 panel = getPanel(angleNorm * TWO_PI + PI, uv, invLength);\n float panelMask = panel[0] * smoothDensity * smoothAngle;\n if (panelMask <= .001) continue;\n float panelMap = panel[1];\n\n int colorIdx = (colorsCount - (idx % colorsCount)) % colorsCount;\n if (colorIdx < 0) colorIdx += colorsCount;\n int nextColorIdx = (colorIdx + 1) % colorsCount;\n\n vec4 colorA = premultipliedColors[colorIdx];\n vec4 colorB = premultipliedColors[nextColorIdx];\n\n colorA = mix(colorA, colorB, max(0., smoothstep(.0, .45, panelMap) - panelGrad));\n vec4 blended = blendColor(colorA, panelMask, panelMap);\n color = blended.rgb + color * (1. - blended.a);\n opacity = blended.a + opacity * (1. - blended.a);\n }\n }\n\n vec3 bgColor = u_colorBack.rgb * u_colorBack.a;\n color = color + bgColor * (1.0 - opacity);\n opacity = opacity + u_colorBack.a * (1.0 - opacity);\n\n ${colorBandingFix}\n\n fragColor = vec4(color, opacity);\n}\n`;\n\nexport interface ColorPanelsUniforms extends ShaderSizingUniforms {\n u_colors: vec4[];\n u_colorsCount: number;\n u_colorBack: [number, number, number, number];\n u_angle1: number;\n u_angle2: number;\n u_length: number;\n u_blur: number;\n u_fadeIn: number;\n u_fadeOut: number;\n u_density: number;\n u_gradient: number;\n}\n\nexport interface ColorPanelsParams extends ShaderSizingParams, ShaderMotionParams {\n colors?: string[];\n colorBack?: string;\n angle1?: number;\n angle2?: number;\n length?: number;\n blur?: number;\n fadeIn?: number;\n fadeOut?: number;\n density?: number;\n gradient?: number;\n}\n"],
5
+ "mappings": ";;;;;AAEA,SAAS,kCAAsF;AAC/F,SAAS,WAAW,uBAAuB;AAEpC,MAAM,kBAAkB;AAAA,EAC7B,eAAe;AACjB;AAmBO,MAAM,4BAAoC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAQzB,gBAAgB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYnD,0BAA0B;AAAA;AAAA;AAAA;AAAA,EAI1B,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6BA0DkB,gBAAgB,aAAa;AAAA,wBAClC,gBAAgB,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IA8GjD,eAAe;AAAA;AAAA;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -1,13 +1,13 @@
1
- import type { ShaderMotionParams } from '../shader-mount';
2
- import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing';
1
+ import type { ShaderMotionParams } from '../shader-mount.js';
2
+ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';
3
3
  /**
4
4
  * Dithering Fragment Shader by Ksenia Kondrashova
5
5
  * Applies dithering (4 dithering types available) over the
6
6
  * abstract shapes animation (7 animated shapes available)
7
7
  *
8
8
  * Uniforms include:
9
- * - u_color1: background color, RGBA
10
- * - u_color2: pixels color, RGBA
9
+ * - u_colorBack: background color, RGBA
10
+ * - u_colorFront: pixels color, RGBA
11
11
  *
12
12
  * - u_shape (float, used as int, 1 to 7):
13
13
  * --- shape = 1: Simplex noise pattern
@@ -25,23 +25,37 @@ import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-si
25
25
  * --- type = 4: 8x8 Bayer matrix
26
26
  *
27
27
  * - pxSize (float), relative to canvas resolution
28
- * - u_pxRounded (bool)
29
28
  *
30
29
  */
31
30
  export declare const ditheringFragmentShader: string;
32
31
  export interface DitheringUniforms extends ShaderSizingUniforms {
33
- u_color1: [number, number, number, number];
34
- u_color2: [number, number, number, number];
35
- u_shape: number;
36
- u_type: number;
32
+ u_colorBack: [number, number, number, number];
33
+ u_colorFront: [number, number, number, number];
34
+ u_shape: (typeof DitheringShapes)[DitheringShape];
35
+ u_type: (typeof DitheringTypes)[DitheringType];
37
36
  u_pxSize: number;
38
- u_pxRounded: boolean;
39
37
  }
40
38
  export interface DitheringParams extends ShaderSizingParams, ShaderMotionParams {
41
- color1?: string;
42
- color2?: string;
43
- shape?: number;
44
- type?: number;
39
+ colorBack?: string;
40
+ colorFront?: string;
41
+ shape?: DitheringShape;
42
+ type?: DitheringType;
45
43
  pxSize?: number;
46
- pxRounded?: boolean;
47
44
  }
45
+ export declare const DitheringShapes: {
46
+ readonly simplex: 1;
47
+ readonly warp: 2;
48
+ readonly dots: 3;
49
+ readonly wave: 4;
50
+ readonly ripple: 5;
51
+ readonly swirl: 6;
52
+ readonly sphere: 7;
53
+ };
54
+ export type DitheringShape = keyof typeof DitheringShapes;
55
+ export declare const DitheringTypes: {
56
+ readonly random: 1;
57
+ readonly '2x2': 2;
58
+ readonly '4x4': 3;
59
+ readonly '8x8': 4;
60
+ };
61
+ export type DitheringType = keyof typeof DitheringTypes;
@@ -7,10 +7,10 @@ import {
7
7
  sizingUniformsDeclaration,
8
8
  sizingUV,
9
9
  drawSizingHelpers
10
- } from "../shader-sizing";
11
- import { declareSimplexNoise, declarePI, declareRandom } from "../shader-utils";
10
+ } from "../shader-sizing.js";
11
+ import { declareSimplexNoise, declarePI, declareRandom } from "../shader-utils.js";
12
12
  const ditheringFragmentShader = `#version 300 es
13
- precision highp float;
13
+ precision mediump float;
14
14
 
15
15
  uniform float u_time;
16
16
  uniform vec2 u_resolution;
@@ -18,12 +18,11 @@ uniform float u_pixelRatio;
18
18
 
19
19
  ${sizingUniformsDeclaration}
20
20
 
21
- uniform vec4 u_color1;
22
- uniform vec4 u_color2;
21
+ uniform vec4 u_colorBack;
22
+ uniform vec4 u_colorFront;
23
23
  uniform float u_shape;
24
24
  uniform float u_type;
25
25
  uniform float u_pxSize;
26
- uniform bool u_pxRounded;
27
26
 
28
27
  out vec4 fragColor;
29
28
 
@@ -40,9 +39,9 @@ float getSimplexNoise(vec2 uv, float t) {
40
39
 
41
40
  const int bayer2x2[4] = int[4](0, 2, 3, 1);
42
41
  const int bayer4x4[16] = int[16](
43
- 0, 8, 2, 10,
44
- 12, 4, 14, 6,
45
- 3, 11, 1, 9,
42
+ 0, 8, 2, 10,
43
+ 12, 4, 14, 6,
44
+ 3, 11, 1, 9,
46
45
  15, 7, 13, 5
47
46
  );
48
47
 
@@ -72,111 +71,119 @@ float getBayerValue(vec2 uv, int size) {
72
71
  }
73
72
 
74
73
 
75
- void main() {
76
- float t = .5 * u_time;
74
+ void main() {
75
+ float t = .5 * u_time;
77
76
 
78
77
  #define USE_PATTERN_SIZING
79
78
  #define USE_OBJECT_SIZING
80
79
  #define USE_PIXELIZATION
81
80
  // #define ADD_HELPERS
82
-
81
+
83
82
  ${sizingUV}
84
-
83
+
85
84
  vec2 dithering_uv = pxSizeUv;
86
- vec2 ditheringNoise_uv = roundedUv;
85
+ vec2 ditheringNoise_uv = uv;
87
86
  vec2 shape_uv = objectUV;
88
87
  if (u_shape < 3.5) {
89
88
  shape_uv = patternUV;
90
89
  }
91
90
 
92
- float shape = 0.;
91
+ float shape = 0.;
93
92
  if (u_shape < 1.5) {
94
93
  // Simplex noise
95
94
  shape_uv *= .001;
96
95
 
97
96
  shape = 0.5 + 0.5 * getSimplexNoise(shape_uv, t);
98
97
  shape = smoothstep(0.3, 0.9, shape);
99
-
100
- } else if (u_shape < 2.5) {
98
+
99
+ } else if (u_shape < 2.5) {
101
100
  // Warp
102
101
  shape_uv *= .003;
103
102
 
104
- for (float i = 1.0; i < 6.0; i++) {
105
- shape_uv.x += 0.6 / i * cos(i * 2.5 * shape_uv.y + t);
106
- shape_uv.y += 0.6 / i * cos(i * 1.5 * shape_uv.x + t);
107
- }
108
-
109
- shape = .15 / abs(sin(t - shape_uv.y - shape_uv.x));
103
+ for (float i = 1.0; i < 6.0; i++) {
104
+ shape_uv.x += 0.6 / i * cos(i * 2.5 * shape_uv.y + t);
105
+ shape_uv.y += 0.6 / i * cos(i * 1.5 * shape_uv.x + t);
106
+ }
107
+
108
+ shape = .15 / abs(sin(t - shape_uv.y - shape_uv.x));
110
109
  shape = smoothstep(0.02, 1., shape);
111
-
112
- } else if (u_shape < 3.5) {
113
- // Dots
110
+
111
+ } else if (u_shape < 3.5) {
112
+ // Dots
114
113
  shape_uv *= .05;
115
114
 
116
115
  float stripeIdx = floor(2. * shape_uv.x / TWO_PI);
117
116
  float rand = fract(sin(stripeIdx * 12.9898) * 43758.5453);
118
117
 
119
118
  float speed = sign(rand - .5) * ceil(2. + rand);
120
- shape = sin(shape_uv.x) * cos(shape_uv.y + speed * t);
119
+ shape = sin(shape_uv.x) * cos(shape_uv.y + speed * t);
121
120
  shape = pow(shape, 6.);
122
121
 
123
- } else if (u_shape < 4.5) {
122
+ } else if (u_shape < 4.5) {
124
123
  // Sine wave
125
124
  shape_uv *= 4.;
126
125
 
127
126
  float wave = cos(.5 * shape_uv.x - 2. * t) * sin(1.5 * shape_uv.x + t) * (.75 + .25 * cos(3. * t));
128
127
  shape = 1. - smoothstep(-1., 1., shape_uv.y + wave);
129
-
130
- } else if (u_shape < 5.5) {
128
+
129
+ } else if (u_shape < 5.5) {
131
130
  // Ripple
132
131
 
133
132
  float dist = length(shape_uv);
134
133
  float waves = sin(pow(dist, 1.7) * 7. - 3. * t) * .5 + .5;
135
134
  shape = waves;
136
-
137
- } else if (u_shape < 6.5) {
138
- // Swirl
135
+
136
+ } else if (u_shape < 6.5) {
137
+ // Swirl
139
138
 
140
139
  float l = length(shape_uv);
141
140
  float angle = 6. * atan(shape_uv.y, shape_uv.x) + 4. * t;
142
141
  float twist = 1.2;
143
- float offset = pow(l, -twist) + angle / TWO_PI;
142
+ float offset = pow(l, -twist) + angle / TWO_PI;
144
143
  float mid = smoothstep(0., 1., pow(l, twist));
145
144
  shape = mix(0., fract(offset), mid);
146
-
145
+
147
146
  } else {
148
147
  // Sphere
149
148
  shape_uv *= 2.;
150
-
149
+
151
150
  vec3 pos = vec3(shape_uv, sqrt(1. - pow(length(shape_uv), 2.)));
152
151
  vec3 lightPos = normalize(vec3(cos(1.5 * t), .8, sin(1.25 * t)));
153
152
  shape = .5 + .5 * dot(lightPos, pos);
154
- }
155
-
156
-
157
- int type = int(floor(u_type));
158
- float dithering = 0.0;
159
-
160
- switch (type) {
153
+ }
154
+
155
+
156
+ int type = int(floor(u_type));
157
+ float dithering = 0.0;
158
+
159
+ switch (type) {
161
160
  case 1: {
162
- dithering = step(random(ditheringNoise_uv), shape);
163
- } break;
164
- case 2:
165
- dithering = getBayerValue(dithering_uv, 2);
166
- break;
167
- case 3:
168
- dithering = getBayerValue(dithering_uv, 4);
169
- break;
170
- default:
171
- dithering = getBayerValue(dithering_uv, 8);
172
- break;
173
- }
174
-
175
- dithering -= .5;
176
- float res = step(.5, shape + dithering);
177
-
178
- vec3 color = mix(u_color1.rgb, u_color2.rgb, res);
179
- float opacity = mix(u_color1.a, u_color2.a, res);
161
+ dithering = step(random(ditheringNoise_uv), shape);
162
+ } break;
163
+ case 2:
164
+ dithering = getBayerValue(dithering_uv, 2);
165
+ break;
166
+ case 3:
167
+ dithering = getBayerValue(dithering_uv, 4);
168
+ break;
169
+ default:
170
+ dithering = getBayerValue(dithering_uv, 8);
171
+ break;
172
+ }
173
+
174
+ dithering -= .5;
175
+ float res = step(.5, shape + dithering);
176
+
177
+ vec3 fgColor = u_colorFront.rgb * u_colorFront.a;
178
+ float fgOpacity = u_colorFront.a;
179
+ vec3 bgColor = u_colorBack.rgb * u_colorBack.a;
180
+ float bgOpacity = u_colorBack.a;
181
+
182
+ vec3 color = fgColor * res;
183
+ float opacity = fgOpacity * res;
184
+
185
+ color += bgColor * (1. - opacity);
186
+ opacity += bgOpacity * (1. - opacity);
180
187
 
181
188
  #ifdef ADD_HELPERS
182
189
  vec2 helperBox = objectHelperBox;
@@ -191,7 +198,24 @@ void main() {
191
198
  fragColor = vec4(color, opacity);
192
199
  }
193
200
  `;
201
+ const DitheringShapes = {
202
+ simplex: 1,
203
+ warp: 2,
204
+ dots: 3,
205
+ wave: 4,
206
+ ripple: 5,
207
+ swirl: 6,
208
+ sphere: 7
209
+ };
210
+ const DitheringTypes = {
211
+ "random": 1,
212
+ "2x2": 2,
213
+ "4x4": 3,
214
+ "8x8": 4
215
+ };
194
216
  export {
217
+ DitheringShapes,
218
+ DitheringTypes,
195
219
  ditheringFragmentShader
196
220
  };
197
221
  //# sourceMappingURL=dithering.js.map