@firecms/neat 0.1.4 → 0.2.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/NeatGradient.ts"],"sourcesContent":["import * as THREE from \"three\";\n\nconst PLANE_WIDTH = 50;\nconst PLANE_HEIGHT = 80;\n\nconst WIREFRAME = true;\nconst COLORS_COUNT = 5;\n\nconst clock = new THREE.Clock();\n\ntype SceneState = {\n renderer: THREE.WebGLRenderer,\n camera: THREE.OrthographicCamera,\n scene: THREE.Scene,\n meshes: THREE.Mesh[],\n}\n\nexport type NeatConfig = {\n speed?: number;\n horizontalPressure?: number;\n verticalPressure?: number;\n waveFrequencyX?: number;\n waveFrequencyY?: number;\n waveAmplitude?: number;\n highlights?: number;\n shadows?: number;\n colorSaturation?: number;\n colorBrightness?: number;\n colors: NeatColor[];\n colorBlending?: number;\n wireframe?: boolean;\n backgroundColor?: string;\n backgroundAlpha?: number;\n};\n\nexport type NeatColor = {\n color: string;\n enabled: boolean;\n /**\n * Value from 0 to 1\n */\n influence?: number;\n}\n\nexport type NeatController = {\n destroy: () => void;\n}\n\nexport class NeatGradient implements NeatController {\n\n private _speed: number = -1;\n\n private _horizontalPressure: number = -1;\n private _verticalPressure: number = -1;\n\n private _waveFrequencyX: number = -1;\n private _waveFrequencyY: number = -1;\n private _waveAmplitude: number = -1;\n\n private _shadows: number = -1;\n private _highlights: number = -1;\n private _saturation: number = -1;\n private _brightness: number = -1;\n\n private _colorBlending: number = -1;\n\n private _colors: NeatColor[] = [];\n private _wireframe: boolean = false;\n\n private _backgroundColor: string = \"#FFFFFF\";\n private _backgroundAlpha: number = 1.0;\n\n private requestRef: number = -1;\n private sizeObserver: ResizeObserver;\n private readonly sceneState: SceneState;\n\n constructor(config: NeatConfig & { ref: HTMLCanvasElement, resolution?: number }) {\n\n const {\n ref,\n speed = 4,\n horizontalPressure = 3,\n verticalPressure = 3,\n waveFrequencyX = 5,\n waveFrequencyY = 5,\n waveAmplitude = 3,\n colors,\n highlights = 4,\n shadows = 4,\n colorSaturation = 0,\n colorBrightness = 1,\n colorBlending = 5,\n wireframe = false,\n backgroundColor = \"#FFFFFF\",\n backgroundAlpha = 1.0,\n resolution = 1\n } = config;\n\n const width = ref.width,\n height = ref.height;\n\n this.destroy = this.destroy.bind(this);\n this._initScene = this._initScene.bind(this);\n this._buildMaterial = this._buildMaterial.bind(this);\n\n this.speed = speed;\n this.horizontalPressure = horizontalPressure;\n this.verticalPressure = verticalPressure;\n this.waveFrequencyX = waveFrequencyX;\n this.waveFrequencyY = waveFrequencyY;\n this.waveAmplitude = waveAmplitude;\n this.colorBlending = colorBlending;\n this.colors = colors;\n this.shadows = shadows;\n this.highlights = highlights;\n this.colorSaturation = colorSaturation;\n this.colorBrightness = colorBrightness;\n this.wireframe = wireframe;\n this.backgroundColor = backgroundColor;\n this.backgroundAlpha = backgroundAlpha;\n\n this.sceneState = this._initScene(ref, width, height, resolution);\n\n const { renderer, camera, scene, meshes } = this.sceneState;\n\n let tick = 0;\n const render = () => {\n\n if (Math.floor(tick * 10) % 5 === 0) {\n addNeatLink(ref);\n }\n\n renderer.setClearColor(this._backgroundColor, this._backgroundAlpha);\n meshes.forEach((mesh) => {\n\n const colors = [\n ...this._colors.map(color => ({\n is_active: color.enabled,\n color: new THREE.Color(color.color),\n influence: color.influence\n })),\n ...Array.from({ length: COLORS_COUNT - this._colors.length }).map(() => ({\n is_active: false,\n color: new THREE.Color(0x000000)\n }))\n ];\n\n tick += clock.getDelta() * this._speed;\n // @ts-ignore\n mesh.material.uniforms.u_time.value = tick;\n // @ts-ignore\n mesh.material.uniforms.u_resolution = { value: new THREE.Vector2(width, height) };\n // @ts-ignore\n mesh.material.uniforms.u_color_pressure = { value: new THREE.Vector2(this._horizontalPressure, this._verticalPressure) };\n // @ts-ignore\n mesh.material.uniforms.u_wave_frequency_x = { value: this._waveFrequencyX };\n // @ts-ignore\n mesh.material.uniforms.u_wave_frequency_y = { value: this._waveFrequencyY };\n // @ts-ignore\n mesh.material.uniforms.u_wave_amplitude = { value: this._waveAmplitude };\n // @ts-ignore\n mesh.material.uniforms.u_plane_width = { value: PLANE_WIDTH };\n // @ts-ignore\n mesh.material.uniforms.u_plane_height = { value: PLANE_HEIGHT };\n // @ts-ignore\n mesh.material.uniforms.u_color_blending = { value: this._colorBlending };\n // @ts-ignore\n mesh.material.uniforms.u_colors = { value: colors };\n // @ts-ignore\n mesh.material.uniforms.u_colors_count = { value: COLORS_COUNT };\n // @ts-ignore\n mesh.material.uniforms.u_shadows = { value: this._shadows };\n // @ts-ignore\n mesh.material.uniforms.u_highlights = { value: this._highlights };\n // @ts-ignore\n mesh.material.uniforms.u_saturation = { value: this._saturation };\n // @ts-ignore\n mesh.material.uniforms.u_brightness = { value: this._brightness };\n // @ts-ignore\n mesh.material.wireframe = this._wireframe;\n });\n\n renderer.render(scene, camera);\n this.requestRef = requestAnimationFrame(render);\n };\n\n const setSize = () => {\n const canvas = renderer.domElement;\n const width = canvas.clientWidth;\n const height = canvas.clientHeight;\n\n this.sceneState.renderer.setSize(width, height, false);\n updateCamera(this.sceneState.camera, width, height);\n };\n\n this.sizeObserver = new ResizeObserver(entries => {\n setSize();\n });\n\n this.sizeObserver.observe(ref);\n\n\n render();\n }\n\n destroy() {\n if (this) {\n cancelAnimationFrame(this.requestRef);\n this.sizeObserver.disconnect();\n }\n }\n\n set speed(speed: number) {\n this._speed = speed / 20;\n }\n\n set horizontalPressure(horizontalPressure: number) {\n this._horizontalPressure = horizontalPressure / 4;\n }\n\n set verticalPressure(verticalPressure: number) {\n this._verticalPressure = verticalPressure / 4;\n }\n\n set waveFrequencyX(waveFrequencyX: number) {\n this._waveFrequencyX = waveFrequencyX * 0.04;\n }\n\n set waveFrequencyY(waveFrequencyY: number) {\n this._waveFrequencyY = waveFrequencyY * 0.04;\n }\n\n set waveAmplitude(waveAmplitude: number) {\n this._waveAmplitude = waveAmplitude * .75;\n }\n\n set colors(colors: NeatColor[]) {\n this._colors = colors;\n }\n\n set highlights(highlights: number) {\n this._highlights = highlights / 100;\n }\n\n set shadows(shadows: number) {\n this._shadows = shadows / 100;\n }\n\n set colorSaturation(colorSaturation: number) {\n this._saturation = colorSaturation / 10;\n }\n\n set colorBrightness(colorBrightness: number) {\n console.log(\"colorBrightness\", colorBrightness)\n this._brightness = colorBrightness;\n }\n\n set colorBlending(colorBlending: number) {\n this._colorBlending = colorBlending / 10;\n }\n\n set wireframe(wireframe: boolean) {\n this._wireframe = wireframe;\n }\n\n set backgroundColor(backgroundColor: string) {\n this._backgroundColor = backgroundColor;\n }\n\n set backgroundAlpha(backgroundAlpha: number) {\n this._backgroundAlpha = backgroundAlpha;\n }\n\n _initScene(ref: HTMLCanvasElement, width: number, height: number, resolution: number): SceneState {\n\n const renderer = new THREE.WebGLRenderer({\n // antialias: true,\n alpha: true,\n canvas: ref\n });\n\n renderer.setClearColor(0xFF0000, .5);\n renderer.setSize(width, height, false);\n\n const meshes: THREE.Mesh[] = [];\n\n const scene = new THREE.Scene();\n\n const material = this._buildMaterial(width, height);\n\n const geo = new THREE.PlaneGeometry(PLANE_WIDTH, PLANE_HEIGHT, 240 * resolution, 240 * resolution);\n const plane = new THREE.Mesh(geo, material);\n plane.rotation.x = -Math.PI / 3.5;\n plane.position.z = -1;\n meshes.push(plane);\n scene.add(plane);\n\n const camera = new THREE.OrthographicCamera(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);\n // camera.zoom = 1;\n updateCamera(camera, width, height);\n\n return {\n renderer,\n camera,\n scene,\n meshes\n };\n }\n\n _buildMaterial(width: number, height: number) {\n\n const colors = [\n ...this._colors.map(color => ({\n is_active: color.enabled,\n color: new THREE.Color(color.color),\n influence: color.influence\n })),\n ...Array.from({ length: COLORS_COUNT - this._colors.length }).map(() => ({\n is_active: false,\n color: new THREE.Color(0x000000)\n }))\n ];\n\n const uniforms = {\n u_time: { value: 0 },\n u_color_pressure: { value: new THREE.Vector2(this._horizontalPressure, this._verticalPressure) },\n u_wave_frequency_x: { value: this._waveFrequencyX },\n u_wave_frequency_y: { value: this._waveFrequencyY },\n u_wave_amplitude: { value: this._waveAmplitude },\n u_resolution: { value: new THREE.Vector2(width, height) },\n u_colors: { value: colors },\n u_colors_count: { value: this._colors.length },\n u_plane_width: { value: PLANE_WIDTH },\n u_plane_height: { value: PLANE_HEIGHT },\n u_shadows: { value: this._shadows },\n u_highlights: { value: this._highlights },\n };\n\n const material = new THREE.ShaderMaterial({\n uniforms: uniforms,\n vertexShader: buildUniforms() + buildNoise() + buildColorFunctions() + buildVertexShader(),\n fragmentShader: buildUniforms() + buildColorFunctions() + buildFragmentShader()\n });\n\n material.wireframe = WIREFRAME;\n return material;\n }\n\n\n}\n\nfunction updateCamera(camera: THREE.OrthographicCamera, width: number, height: number) {\n\n const viewPortAreaRatio = 1000000;\n const areaViewPort = width * height;\n const targetPlaneArea =\n areaViewPort / viewPortAreaRatio *\n PLANE_WIDTH * PLANE_HEIGHT / 1.5;\n\n const ratio = width / height;\n\n const targetWidth = Math.sqrt(targetPlaneArea * ratio);\n const targetHeight = targetPlaneArea / targetWidth;\n\n const left = -PLANE_WIDTH / 2;\n const right = Math.min((left + targetWidth) / 1.5, PLANE_WIDTH / 2);\n\n const top = PLANE_HEIGHT / 4;\n const bottom = Math.max((top - targetHeight) / 2, -PLANE_HEIGHT / 4);\n\n const near = -100;\n const far = 1000;\n camera.left = left;\n camera.right = right;\n camera.top = top;\n camera.bottom = bottom;\n camera.near = near;\n camera.far = far;\n camera.updateProjectionMatrix();\n}\n\n\nfunction buildVertexShader() {\n return `\n\nvoid main() {\n\n vUv = uv;\n\n v_displacement_amount = cnoise( vec3(\n u_wave_frequency_x * position.x + u_time,\n u_wave_frequency_y * position.y + u_time,\n u_time\n ));\n \n vec3 color;\n\n // float t = mod(u_base_color, 100.0);\n color = u_colors[0].color;\n \n vec2 noise_cord = vUv * u_color_pressure;\n \n const float minNoise = .0;\n const float maxNoise = .9;\n \n for (int i = 1; i < u_colors_count; i++) {\n \n if(u_colors[i].is_active == 1.0){\n float noiseFlow = (1. + float(i)) / 30.;\n float noiseSpeed = (1. + float(i)) * 0.11;\n float noiseSeed = 13. + float(i) * 7.;\n \n float noise = snoise(\n vec3(\n noise_cord.x * u_color_pressure.x + u_time * noiseFlow * 2.,\n noise_cord.y * u_color_pressure.y,\n u_time * noiseSpeed\n ) + noiseSeed\n );\n \n noise = clamp(minNoise, maxNoise + float(i) * 0.02, noise);\n vec3 nextColor = u_colors[i].color;\n color = mix(color, nextColor, smoothstep(0.0, u_color_blending, noise));\n }\n \n }\n \n v_color = color;\n \n vec3 newPosition = position + normal * v_displacement_amount * u_wave_amplitude;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( newPosition, 1.0 );\n \n v_new_position = gl_Position;\n}\n`;\n}\n\nfunction buildFragmentShader() {\n return `\n\nvoid main(){\n vec3 color = v_color;\n \n color.rgb += pow(v_displacement_amount, 1.0) * u_highlights;\n color.rgb -= pow(1.0 - v_displacement_amount, 2.0) * u_shadows;\n color = saturation(color, 1.0 + u_saturation);\n color = color * u_brightness;\n \n gl_FragColor = vec4(color,1.0);\n}\n`;\n}\n\nconst buildUniforms = () => `\nprecision highp float;\n\nstruct Color {\n float is_active;\n vec3 color;\n float value;\n};\n\nuniform float u_time;\n\nuniform float u_wave_amplitude;\nuniform float u_wave_frequency_x;\nuniform float u_wave_frequency_y;\n\nuniform vec2 u_color_pressure;\n\nuniform float u_plane_width;\nuniform float u_plane_height;\n\nuniform float u_shadows;\nuniform float u_highlights;\nuniform float u_saturation;\nuniform float u_brightness;\n\nuniform float u_color_blending;\n\nuniform int u_colors_count;\nuniform Color u_colors[5];\nuniform vec2 u_resolution;\n\nvarying vec2 vUv;\nvarying vec4 v_new_position;\nvarying vec3 v_color;\nvarying float v_displacement_amount;\n\n `;\n\nconst buildNoise = () => `\n\nvec3 mod289(vec3 x)\n{\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\n\nvec4 mod289(vec4 x)\n{\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\n\nvec4 permute(vec4 x)\n{\n return mod289(((x*34.0)+1.0)*x);\n}\n\nvec4 taylorInvSqrt(vec4 r)\n{\n return 1.79284291400159 - 0.85373472095314 * r;\n}\n\nvec3 fade(vec3 t) {\n return t*t*t*(t*(t*6.0-15.0)+10.0);\n}\n\nfloat snoise(vec3 v)\n{\n const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;\n const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n\n// First corner\n vec3 i = floor(v + dot(v, C.yyy) );\n vec3 x0 = v - i + dot(i, C.xxx) ;\n\n// Other corners\n vec3 g = step(x0.yzx, x0.xyz);\n vec3 l = 1.0 - g;\n vec3 i1 = min( g.xyz, l.zxy );\n vec3 i2 = max( g.xyz, l.zxy );\n\n // x0 = x0 - 0.0 + 0.0 * C.xxx;\n // x1 = x0 - i1 + 1.0 * C.xxx;\n // x2 = x0 - i2 + 2.0 * C.xxx;\n // x3 = x0 - 1.0 + 3.0 * C.xxx;\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y\n vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y\n\n// Permutations\n i = mod289(i);\n vec4 p = permute( permute( permute(\n i.z + vec4(0.0, i1.z, i2.z, 1.0 ))\n + i.y + vec4(0.0, i1.y, i2.y, 1.0 ))\n + i.x + vec4(0.0, i1.x, i2.x, 1.0 ));\n\n// Gradients: 7x7 points over a square, mapped onto an octahedron.\n// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)\n float n_ = 0.142857142857; // 1.0/7.0\n vec3 ns = n_ * D.wyz - D.xzx;\n\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)\n\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)\n\n vec4 x = x_ *ns.x + ns.yyyy;\n vec4 y = y_ *ns.x + ns.yyyy;\n vec4 h = 1.0 - abs(x) - abs(y);\n\n vec4 b0 = vec4( x.xy, y.xy );\n vec4 b1 = vec4( x.zw, y.zw );\n\n //vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;\n //vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;\n vec4 s0 = floor(b0)*2.0 + 1.0;\n vec4 s1 = floor(b1)*2.0 + 1.0;\n vec4 sh = -step(h, vec4(0.0));\n\n vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;\n vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;\n\n vec3 p0 = vec3(a0.xy,h.x);\n vec3 p1 = vec3(a0.zw,h.y);\n vec3 p2 = vec3(a1.xy,h.z);\n vec3 p3 = vec3(a1.zw,h.w);\n\n//Normalise gradients\n vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n\n// Mix final noise value\n vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);\n m = m * m;\n return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1),\n dot(p2,x2), dot(p3,x3) ) );\n}\n\n// Classic Perlin noise\nfloat cnoise(vec3 P)\n{\n vec3 Pi0 = floor(P); // Integer part for indexing\n vec3 Pi1 = Pi0 + vec3(1.0); // Integer part + 1\n Pi0 = mod289(Pi0);\n Pi1 = mod289(Pi1);\n vec3 Pf0 = fract(P); // Fractional part for interpolation\n vec3 Pf1 = Pf0 - vec3(1.0); // Fractional part - 1.0\n vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);\n vec4 iy = vec4(Pi0.yy, Pi1.yy);\n vec4 iz0 = Pi0.zzzz;\n vec4 iz1 = Pi1.zzzz;\n\n vec4 ixy = permute(permute(ix) + iy);\n vec4 ixy0 = permute(ixy + iz0);\n vec4 ixy1 = permute(ixy + iz1);\n\n vec4 gx0 = ixy0 * (1.0 / 7.0);\n vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5;\n gx0 = fract(gx0);\n vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0);\n vec4 sz0 = step(gz0, vec4(0.0));\n gx0 -= sz0 * (step(0.0, gx0) - 0.5);\n gy0 -= sz0 * (step(0.0, gy0) - 0.5);\n\n vec4 gx1 = ixy1 * (1.0 / 7.0);\n vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5;\n gx1 = fract(gx1);\n vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1);\n vec4 sz1 = step(gz1, vec4(0.0));\n gx1 -= sz1 * (step(0.0, gx1) - 0.5);\n gy1 -= sz1 * (step(0.0, gy1) - 0.5);\n\n vec3 g000 = vec3(gx0.x,gy0.x,gz0.x);\n vec3 g100 = vec3(gx0.y,gy0.y,gz0.y);\n vec3 g010 = vec3(gx0.z,gy0.z,gz0.z);\n vec3 g110 = vec3(gx0.w,gy0.w,gz0.w);\n vec3 g001 = vec3(gx1.x,gy1.x,gz1.x);\n vec3 g101 = vec3(gx1.y,gy1.y,gz1.y);\n vec3 g011 = vec3(gx1.z,gy1.z,gz1.z);\n vec3 g111 = vec3(gx1.w,gy1.w,gz1.w);\n\n vec4 norm0 = taylorInvSqrt(vec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));\n g000 *= norm0.x;\n g010 *= norm0.y;\n g100 *= norm0.z;\n g110 *= norm0.w;\n vec4 norm1 = taylorInvSqrt(vec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));\n g001 *= norm1.x;\n g011 *= norm1.y;\n g101 *= norm1.z;\n g111 *= norm1.w;\n\n float n000 = dot(g000, Pf0);\n float n100 = dot(g100, vec3(Pf1.x, Pf0.yz));\n float n010 = dot(g010, vec3(Pf0.x, Pf1.y, Pf0.z));\n float n110 = dot(g110, vec3(Pf1.xy, Pf0.z));\n float n001 = dot(g001, vec3(Pf0.xy, Pf1.z));\n float n101 = dot(g101, vec3(Pf1.x, Pf0.y, Pf1.z));\n float n011 = dot(g011, vec3(Pf0.x, Pf1.yz));\n float n111 = dot(g111, Pf1);\n\n vec3 fade_xyz = fade(Pf0);\n vec4 n_z = mix(vec4(n000, n100, n010, n110), vec4(n001, n101, n011, n111), fade_xyz.z);\n vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y);\n float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);\n return 2.2 * n_xyz;\n}\n\n// YUV to RGB matrix\nmat3 yuv2rgb = mat3(1.0, 0.0, 1.13983,\n 1.0, -0.39465, -0.58060,\n 1.0, 2.03211, 0.0);\n\n// RGB to YUV matrix\nmat3 rgb2yuv = mat3(0.2126, 0.7152, 0.0722,\n -0.09991, -0.33609, 0.43600,\n 0.615, -0.5586, -0.05639);\n\n `;\n\nconst buildColorFunctions = () => `\n\nvec3 saturation(vec3 rgb, float adjustment) {\n const vec3 W = vec3(0.2125, 0.7154, 0.0721);\n vec3 intensity = vec3(dot(rgb, W));\n return mix(intensity, rgb, adjustment);\n}\n\nfloat saturation(vec3 rgb)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(rgb.bg, K.wz), vec4(rgb.gb, K.xy), step(rgb.b, rgb.g));\n vec4 q = mix(vec4(p.xyw, rgb.r), vec4(rgb.r, p.yzx), step(p.x, rgb.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return abs(6.0 * d + e);\n}\n\n// get saturation of a color in values between 0 and 1\nfloat getSaturation(vec3 color) {\n float max = max(color.r, max(color.g, color.b));\n float min = min(color.r, min(color.g, color.b));\n return (max - min) / max;\n}\n \nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n`;\n\n\nconst setLinkStyles = (link: HTMLAnchorElement) => {\n link.id = \"neat-link\";\n link.href = \"https://neat.firecms.co\";\n link.target = \"_blank\";\n link.style.position = \"absolute\";\n link.style.display = \"block\";\n link.style.opacity = \"1\";\n link.style.bottom = \"0\";\n link.style.right = \"0\";\n link.style.padding = \"10px\";\n link.style.color = \"#dcdcdc\";\n link.style.fontFamily = \"sans-serif\";\n link.style.fontSize = \"16px\";\n link.style.fontWeight = \"bold\";\n link.style.textDecoration = \"none\";\n link.style.zIndex = \"100\";\n link.innerHTML = \"NEAT\";\n}\n\nconst addNeatLink = (ref: HTMLCanvasElement) => {\n const existingLinks = ref.parentElement?.getElementsByTagName(\"a\");\n if (existingLinks) {\n for (let i = 0; i < existingLinks.length; i++) {\n if (existingLinks[i].id === \"neat-link\") {\n setLinkStyles(existingLinks[i]);\n return;\n }\n }\n }\n const link = document.createElement(\"a\");\n setLinkStyles(link);\n ref.parentElement?.appendChild(link);\n}\n"],"names":["PLANE_WIDTH","PLANE_HEIGHT","WIREFRAME","COLORS_COUNT","clock","THREE","NeatGradient","config","ref","speed","horizontalPressure","verticalPressure","waveFrequencyX","waveFrequencyY","waveAmplitude","colors","highlights","shadows","colorSaturation","colorBrightness","colorBlending","wireframe","backgroundColor","backgroundAlpha","resolution","width","height","renderer","camera","scene","meshes","tick","render","addNeatLink","mesh","color","setSize","canvas","updateCamera","entries","material","geo","plane","uniforms","buildUniforms","buildNoise","buildColorFunctions","buildVertexShader","buildFragmentShader","targetPlaneArea","ratio","targetWidth","targetHeight","left","right","top","bottom","near","far","setLinkStyles","link","existingLinks"],"mappings":"wjBAEMA,EAAc,GACdC,EAAe,GAEfC,EAAY,GACZC,EAAe,EAEfC,EAAQ,IAAIC,EAAM,MAwCjB,MAAMC,CAAuC,CAExC,OAAiB,GAEjB,oBAA8B,GAC9B,kBAA4B,GAE5B,gBAA0B,GAC1B,gBAA0B,GAC1B,eAAyB,GAEzB,SAAmB,GACnB,YAAsB,GACtB,YAAsB,GACtB,YAAsB,GAEtB,eAAyB,GAEzB,QAAuB,CAAA,EACvB,WAAsB,GAEtB,iBAA2B,UAC3B,iBAA2B,EAE3B,WAAqB,GACrB,aACS,WAEjB,YAAYC,EAAsE,CAExE,KAAA,CACF,IAAAC,EACA,MAAAC,EAAQ,EACR,mBAAAC,EAAqB,EACrB,iBAAAC,EAAmB,EACnB,eAAAC,EAAiB,EACjB,eAAAC,EAAiB,EACjB,cAAAC,EAAgB,EAChB,OAAAC,EACA,WAAAC,EAAa,EACb,QAAAC,EAAU,EACV,gBAAAC,EAAkB,EAClB,gBAAAC,EAAkB,EAClB,cAAAC,EAAgB,EAChB,UAAAC,EAAY,GACZ,gBAAAC,EAAkB,UAClB,gBAAAC,EAAkB,EAClB,WAAAC,EAAa,CACb,EAAAjB,EAEEkB,EAAQjB,EAAI,MACdkB,EAASlB,EAAI,OAEjB,KAAK,QAAU,KAAK,QAAQ,KAAK,IAAI,EACrC,KAAK,WAAa,KAAK,WAAW,KAAK,IAAI,EAC3C,KAAK,eAAiB,KAAK,eAAe,KAAK,IAAI,EAEnD,KAAK,MAAQC,EACb,KAAK,mBAAqBC,EAC1B,KAAK,iBAAmBC,EACxB,KAAK,eAAiBC,EACtB,KAAK,eAAiBC,EACtB,KAAK,cAAgBC,EACrB,KAAK,cAAgBM,EACr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AAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA8C5Ba,EAAiBC,GAA4B,CAC/CA,EAAK,GAAK,YACVA,EAAK,KAAO,0BACZA,EAAK,OAAS,SACdA,EAAK,MAAM,SAAW,WACtBA,EAAK,MAAM,QAAU,QACrBA,EAAK,MAAM,QAAU,IACrBA,EAAK,MAAM,OAAS,IACpBA,EAAK,MAAM,MAAQ,IACnBA,EAAK,MAAM,QAAU,OACrBA,EAAK,MAAM,MAAQ,UACnBA,EAAK,MAAM,WAAa,aACxBA,EAAK,MAAM,SAAW,OACtBA,EAAK,MAAM,WAAa,OACxBA,EAAK,MAAM,eAAiB,OAC5BA,EAAK,MAAM,OAAS,MACpBA,EAAK,UAAY,MACrB,EAEM3B,EAAezB,GAA2B,CAC5C,MAAMqD,EAAgBrD,EAAI,eAAe,qBAAqB,GAAG,EACjE,GAAIqD,GACA,QAAS,EAAI,EAAG,EAAIA,EAAc,OAAQ,IAClC,GAAAA,EAAc,GAAG,KAAO,YAAa,CACrCF,EAAcE,EAAc,EAAE,EAC9B,MACJ,EAGF,MAAAD,EAAO,SAAS,cAAc,GAAG,EACvCD,EAAcC,CAAI,EACdpD,EAAA,eAAe,YAAYoD,CAAI,CACvC"}
1
+ {"version":3,"file":"index.umd.js","sources":["../src/NeatGradient.ts"],"sourcesContent":["import * as THREE from \"three\";\n\nconst PLANE_WIDTH = 50;\nconst PLANE_HEIGHT = 80;\n\nconst WIREFRAME = true;\nconst COLORS_COUNT = 5;\n\nconst clock = new THREE.Clock();\n\ntype SceneState = {\n renderer: THREE.WebGLRenderer,\n camera: THREE.Camera,\n scene: THREE.Scene,\n meshes: THREE.Mesh[],\n resolution: number\n}\n\nexport type NeatConfig = {\n resolution?: number;\n speed?: number;\n horizontalPressure?: number;\n verticalPressure?: number;\n waveFrequencyX?: number;\n waveFrequencyY?: number;\n waveAmplitude?: number;\n highlights?: number;\n shadows?: number;\n colorSaturation?: number;\n colorBrightness?: number;\n colors: NeatColor[];\n colorBlending?: number;\n wireframe?: boolean;\n backgroundColor?: string;\n backgroundAlpha?: number;\n};\n\nexport type NeatColor = {\n color: string;\n enabled: boolean;\n /**\n * Value from 0 to 1\n */\n influence?: number;\n}\n\nexport type NeatController = {\n destroy: () => void;\n}\n\nexport class NeatGradient implements NeatController {\n\n private _ref: HTMLCanvasElement;\n\n private _speed: number = -1;\n\n private _horizontalPressure: number = -1;\n private _verticalPressure: number = -1;\n\n private _waveFrequencyX: number = -1;\n private _waveFrequencyY: number = -1;\n private _waveAmplitude: number = -1;\n\n private _shadows: number = -1;\n private _highlights: number = -1;\n private _saturation: number = -1;\n private _brightness: number = -1;\n\n private _colorBlending: number = -1;\n\n private _colors: NeatColor[] = [];\n private _wireframe: boolean = false;\n\n private _backgroundColor: string = \"#FFFFFF\";\n private _backgroundAlpha: number = 1.0;\n\n private requestRef: number = -1;\n private sizeObserver: ResizeObserver;\n private sceneState: SceneState;\n\n constructor(config: NeatConfig & { ref: HTMLCanvasElement, resolution?: number }) {\n\n const {\n ref,\n speed = 4,\n horizontalPressure = 3,\n verticalPressure = 3,\n waveFrequencyX = 5,\n waveFrequencyY = 5,\n waveAmplitude = 3,\n colors,\n highlights = 4,\n shadows = 4,\n colorSaturation = 0,\n colorBrightness = 1,\n colorBlending = 5,\n wireframe = false,\n backgroundColor = \"#FFFFFF\",\n backgroundAlpha = 1.0,\n resolution = 1\n } = config;\n\n\n this._ref = ref;\n\n this.destroy = this.destroy.bind(this);\n this._initScene = this._initScene.bind(this);\n this._buildMaterial = this._buildMaterial.bind(this);\n\n this.speed = speed;\n this.horizontalPressure = horizontalPressure;\n this.verticalPressure = verticalPressure;\n this.waveFrequencyX = waveFrequencyX;\n this.waveFrequencyY = waveFrequencyY;\n this.waveAmplitude = waveAmplitude;\n this.colorBlending = colorBlending;\n this.colors = colors;\n this.shadows = shadows;\n this.highlights = highlights;\n this.colorSaturation = colorSaturation;\n this.colorBrightness = colorBrightness;\n this.wireframe = wireframe;\n this.backgroundColor = backgroundColor;\n this.backgroundAlpha = backgroundAlpha;\n\n this.sceneState = this._initScene(resolution);\n\n\n let tick = 0;\n const render = () => {\n\n const { renderer, camera, scene, meshes } = this.sceneState;\n if (Math.floor(tick * 10) % 5 === 0) {\n addNeatLink(ref);\n }\n\n renderer.setClearColor(this._backgroundColor, this._backgroundAlpha);\n meshes.forEach((mesh) => {\n\n const width = this._ref.width,\n height = this._ref.height;\n\n const colors = [\n ...this._colors.map(color => ({\n is_active: color.enabled,\n color: new THREE.Color(color.color),\n influence: color.influence\n })),\n ...Array.from({ length: COLORS_COUNT - this._colors.length }).map(() => ({\n is_active: false,\n color: new THREE.Color(0x000000)\n }))\n ];\n\n tick += clock.getDelta() * this._speed;\n // @ts-ignore\n mesh.material.uniforms.u_time.value = tick;\n // @ts-ignore\n mesh.material.uniforms.u_resolution = { value: new THREE.Vector2(width, height) };\n // @ts-ignore\n mesh.material.uniforms.u_color_pressure = { value: new THREE.Vector2(this._horizontalPressure, this._verticalPressure) };\n // @ts-ignore\n mesh.material.uniforms.u_wave_frequency_x = { value: this._waveFrequencyX };\n // @ts-ignore\n mesh.material.uniforms.u_wave_frequency_y = { value: this._waveFrequencyY };\n // @ts-ignore\n mesh.material.uniforms.u_wave_amplitude = { value: this._waveAmplitude };\n // @ts-ignore\n mesh.material.uniforms.u_plane_width = { value: PLANE_WIDTH };\n // @ts-ignore\n mesh.material.uniforms.u_plane_height = { value: PLANE_HEIGHT };\n // @ts-ignore\n mesh.material.uniforms.u_color_blending = { value: this._colorBlending };\n // @ts-ignore\n mesh.material.uniforms.u_colors = { value: colors };\n // @ts-ignore\n mesh.material.uniforms.u_colors_count = { value: COLORS_COUNT };\n // @ts-ignore\n mesh.material.uniforms.u_shadows = { value: this._shadows };\n // @ts-ignore\n mesh.material.uniforms.u_highlights = { value: this._highlights };\n // @ts-ignore\n mesh.material.uniforms.u_saturation = { value: this._saturation };\n // @ts-ignore\n mesh.material.uniforms.u_brightness = { value: this._brightness };\n // @ts-ignore\n mesh.material.wireframe = this._wireframe;\n });\n\n renderer.render(scene, camera);\n this.requestRef = requestAnimationFrame(render);\n };\n\n const setSize = () => {\n\n const { renderer } = this.sceneState;\n const canvas = renderer.domElement;\n const width = canvas.clientWidth;\n const height = canvas.clientHeight;\n\n this.sceneState.renderer.setSize(width, height, false);\n updateCamera(this.sceneState.camera, width, height);\n };\n\n this.sizeObserver = new ResizeObserver(entries => {\n setSize();\n });\n\n this.sizeObserver.observe(ref);\n\n\n render();\n }\n\n destroy() {\n if (this) {\n cancelAnimationFrame(this.requestRef);\n this.sizeObserver.disconnect();\n }\n }\n\n set speed(speed: number) {\n this._speed = speed / 20;\n }\n\n set horizontalPressure(horizontalPressure: number) {\n this._horizontalPressure = horizontalPressure / 4;\n }\n\n set verticalPressure(verticalPressure: number) {\n this._verticalPressure = verticalPressure / 4;\n }\n\n set waveFrequencyX(waveFrequencyX: number) {\n this._waveFrequencyX = waveFrequencyX * 0.04;\n }\n\n set waveFrequencyY(waveFrequencyY: number) {\n this._waveFrequencyY = waveFrequencyY * 0.04;\n }\n\n set waveAmplitude(waveAmplitude: number) {\n this._waveAmplitude = waveAmplitude * .75;\n }\n\n set colors(colors: NeatColor[]) {\n this._colors = colors;\n }\n\n set highlights(highlights: number) {\n this._highlights = highlights / 100;\n }\n\n set shadows(shadows: number) {\n this._shadows = shadows / 100;\n }\n\n set colorSaturation(colorSaturation: number) {\n this._saturation = colorSaturation / 10;\n }\n\n set colorBrightness(colorBrightness: number) {\n this._brightness = colorBrightness;\n }\n\n set colorBlending(colorBlending: number) {\n this._colorBlending = colorBlending / 10;\n }\n\n set wireframe(wireframe: boolean) {\n this._wireframe = wireframe;\n }\n\n set resolution(resolution: number) {\n this.sceneState = this._initScene(resolution);\n }\n\n set backgroundColor(backgroundColor: string) {\n this._backgroundColor = backgroundColor;\n }\n\n set backgroundAlpha(backgroundAlpha: number) {\n this._backgroundAlpha = backgroundAlpha;\n }\n\n _initScene(resolution: number): SceneState {\n\n const width = this._ref.width,\n height = this._ref.height;\n\n const renderer = new THREE.WebGLRenderer({\n // antialias: true,\n alpha: true,\n canvas: this._ref\n });\n\n renderer.setClearColor(0xFF0000, .5);\n renderer.setSize(width, height, false);\n\n const meshes: THREE.Mesh[] = [];\n\n const scene = new THREE.Scene();\n\n const material = this._buildMaterial(width, height);\n\n const geo = new THREE.PlaneGeometry(PLANE_WIDTH, PLANE_HEIGHT, 240 * resolution, 240 * resolution);\n const plane = new THREE.Mesh(geo, material);\n plane.rotation.x = -Math.PI / 3.5;\n plane.position.z = -1;\n meshes.push(plane);\n scene.add(plane);\n\n const camera = new THREE.OrthographicCamera(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);\n // const camera = new THREE.PerspectiveCamera( 1000, window.innerWidth / window.innerHeight, 1, 1000000 );\n camera.position.z = 5;\n updateCamera(camera, width, height);\n\n return {\n renderer,\n camera,\n scene,\n meshes,\n resolution\n };\n }\n\n _buildMaterial(width: number, height: number) {\n\n const colors = [\n ...this._colors.map(color => ({\n is_active: color.enabled,\n color: new THREE.Color(color.color),\n influence: color.influence\n })),\n ...Array.from({ length: COLORS_COUNT - this._colors.length }).map(() => ({\n is_active: false,\n color: new THREE.Color(0x000000)\n }))\n ];\n\n const uniforms = {\n u_time: { value: 0 },\n u_color_pressure: { value: new THREE.Vector2(this._horizontalPressure, this._verticalPressure) },\n u_wave_frequency_x: { value: this._waveFrequencyX },\n u_wave_frequency_y: { value: this._waveFrequencyY },\n u_wave_amplitude: { value: this._waveAmplitude },\n u_resolution: { value: new THREE.Vector2(width, height) },\n u_colors: { value: colors },\n u_colors_count: { value: this._colors.length },\n u_plane_width: { value: PLANE_WIDTH },\n u_plane_height: { value: PLANE_HEIGHT },\n u_shadows: { value: this._shadows },\n u_highlights: { value: this._highlights },\n };\n\n const material = new THREE.ShaderMaterial({\n uniforms: uniforms,\n vertexShader: buildUniforms() + buildNoise() + buildColorFunctions() + buildVertexShader(),\n fragmentShader: buildUniforms() + buildColorFunctions() + buildFragmentShader()\n });\n\n material.wireframe = WIREFRAME;\n return material;\n }\n\n\n}\n\nfunction updateCamera(camera: THREE.Camera, width: number, height: number) {\n\n const viewPortAreaRatio = 1000000;\n const areaViewPort = width * height;\n const targetPlaneArea =\n areaViewPort / viewPortAreaRatio *\n PLANE_WIDTH * PLANE_HEIGHT / 1.5;\n\n const ratio = width / height;\n\n const targetWidth = Math.sqrt(targetPlaneArea * ratio);\n const targetHeight = targetPlaneArea / targetWidth;\n\n const left = -PLANE_WIDTH / 2;\n const right = Math.min((left + targetWidth) / 1.5, PLANE_WIDTH / 2);\n\n const top = PLANE_HEIGHT / 4;\n const bottom = Math.max((top - targetHeight) / 2, -PLANE_HEIGHT / 4);\n\n const near = -100;\n const far = 1000;\n if (camera instanceof THREE.OrthographicCamera) {\n camera.left = left;\n camera.right = right;\n camera.top = top;\n camera.bottom = bottom;\n camera.near = near;\n camera.far = far;\n camera.updateProjectionMatrix();\n } else if (camera instanceof THREE.PerspectiveCamera) {\n camera.aspect = width / height;\n camera.updateProjectionMatrix();\n }\n\n}\n\n\nfunction buildVertexShader() {\n return `\n\nvoid main() {\n\n vUv = uv;\n\n v_displacement_amount = cnoise( vec3(\n u_wave_frequency_x * position.x + u_time,\n u_wave_frequency_y * position.y + u_time,\n u_time\n ));\n \n vec3 color;\n\n // float t = mod(u_base_color, 100.0);\n color = u_colors[0].color;\n \n vec2 noise_cord = vUv * u_color_pressure;\n \n const float minNoise = .0;\n const float maxNoise = .9;\n \n for (int i = 1; i < u_colors_count; i++) {\n \n if(u_colors[i].is_active == 1.0){\n float noiseFlow = (1. + float(i)) / 30.;\n float noiseSpeed = (1. + float(i)) * 0.11;\n float noiseSeed = 13. + float(i) * 7.;\n \n float noise = snoise(\n vec3(\n noise_cord.x * u_color_pressure.x + u_time * noiseFlow * 2.,\n noise_cord.y * u_color_pressure.y,\n u_time * noiseSpeed\n ) + noiseSeed\n );\n \n noise = clamp(minNoise, maxNoise + float(i) * 0.02, noise);\n vec3 nextColor = u_colors[i].color;\n \n // vec3 colorOklab = oklab2rgb(color);\n // vec3 nextColorOklab = oklab2rgb(nextColor);\n // vec3 mixColor = mix(colorOklab, nextColorOklab, smoothstep(0.0, u_color_blending, noise));\n //\n // color = rgb2oklab(mixColor);\n \n color = mix(color, nextColor, smoothstep(0.0, u_color_blending, noise));\n }\n \n }\n \n v_color = color;\n \n vec3 newPosition = position + normal * v_displacement_amount * u_wave_amplitude;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( newPosition, 1.0 );\n \n v_new_position = gl_Position;\n}\n`;\n}\n\nfunction buildFragmentShader() {\n return `\n\nvoid main(){\n vec3 color = v_color;\n \n color.rgb += pow(v_displacement_amount, 1.0) * u_highlights;\n color.rgb -= pow(1.0 - v_displacement_amount, 2.0) * u_shadows;\n color = saturation(color, 1.0 + u_saturation);\n color = color * u_brightness;\n \n gl_FragColor = vec4(color,1.0);\n}\n`;\n}\n\nconst buildUniforms = () => `\nprecision highp float;\n\nstruct Color {\n float is_active;\n vec3 color;\n float value;\n};\n\nuniform float u_time;\n\nuniform float u_wave_amplitude;\nuniform float u_wave_frequency_x;\nuniform float u_wave_frequency_y;\n\nuniform vec2 u_color_pressure;\n\nuniform float u_plane_width;\nuniform float u_plane_height;\n\nuniform float u_shadows;\nuniform float u_highlights;\nuniform float u_saturation;\nuniform float u_brightness;\n\nuniform float u_color_blending;\n\nuniform int u_colors_count;\nuniform Color u_colors[5];\nuniform vec2 u_resolution;\n\nvarying vec2 vUv;\nvarying vec4 v_new_position;\nvarying vec3 v_color;\nvarying float v_displacement_amount;\n\n `;\n\nconst buildNoise = () => `\n\nvec3 mod289(vec3 x)\n{\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\n\nvec4 mod289(vec4 x)\n{\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\n\nvec4 permute(vec4 x)\n{\n return mod289(((x*34.0)+1.0)*x);\n}\n\nvec4 taylorInvSqrt(vec4 r)\n{\n return 1.79284291400159 - 0.85373472095314 * r;\n}\n\nvec3 fade(vec3 t) {\n return t*t*t*(t*(t*6.0-15.0)+10.0);\n}\n\nfloat snoise(vec3 v)\n{\n const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;\n const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n\n// First corner\n vec3 i = floor(v + dot(v, C.yyy) );\n vec3 x0 = v - i + dot(i, C.xxx) ;\n\n// Other corners\n vec3 g = step(x0.yzx, x0.xyz);\n vec3 l = 1.0 - g;\n vec3 i1 = min( g.xyz, l.zxy );\n vec3 i2 = max( g.xyz, l.zxy );\n\n // x0 = x0 - 0.0 + 0.0 * C.xxx;\n // x1 = x0 - i1 + 1.0 * C.xxx;\n // x2 = x0 - i2 + 2.0 * C.xxx;\n // x3 = x0 - 1.0 + 3.0 * C.xxx;\n vec3 x1 = x0 - i1 + C.xxx;\n vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y\n vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y\n\n// Permutations\n i = mod289(i);\n vec4 p = permute( permute( permute(\n i.z + vec4(0.0, i1.z, i2.z, 1.0 ))\n + i.y + vec4(0.0, i1.y, i2.y, 1.0 ))\n + i.x + vec4(0.0, i1.x, i2.x, 1.0 ));\n\n// Gradients: 7x7 points over a square, mapped onto an octahedron.\n// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)\n float n_ = 0.142857142857; // 1.0/7.0\n vec3 ns = n_ * D.wyz - D.xzx;\n\n vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)\n\n vec4 x_ = floor(j * ns.z);\n vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)\n\n vec4 x = x_ *ns.x + ns.yyyy;\n vec4 y = y_ *ns.x + ns.yyyy;\n vec4 h = 1.0 - abs(x) - abs(y);\n\n vec4 b0 = vec4( x.xy, y.xy );\n vec4 b1 = vec4( x.zw, y.zw );\n\n //vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;\n //vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;\n vec4 s0 = floor(b0)*2.0 + 1.0;\n vec4 s1 = floor(b1)*2.0 + 1.0;\n vec4 sh = -step(h, vec4(0.0));\n\n vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;\n vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;\n\n vec3 p0 = vec3(a0.xy,h.x);\n vec3 p1 = vec3(a0.zw,h.y);\n vec3 p2 = vec3(a1.xy,h.z);\n vec3 p3 = vec3(a1.zw,h.w);\n\n//Normalise gradients\n vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));\n p0 *= norm.x;\n p1 *= norm.y;\n p2 *= norm.z;\n p3 *= norm.w;\n\n// Mix final noise value\n vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);\n m = m * m;\n return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1),\n dot(p2,x2), dot(p3,x3) ) );\n}\n\n// Classic Perlin noise\nfloat cnoise(vec3 P)\n{\n vec3 Pi0 = floor(P); // Integer part for indexing\n vec3 Pi1 = Pi0 + vec3(1.0); // Integer part + 1\n Pi0 = mod289(Pi0);\n Pi1 = mod289(Pi1);\n vec3 Pf0 = fract(P); // Fractional part for interpolation\n vec3 Pf1 = Pf0 - vec3(1.0); // Fractional part - 1.0\n vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);\n vec4 iy = vec4(Pi0.yy, Pi1.yy);\n vec4 iz0 = Pi0.zzzz;\n vec4 iz1 = Pi1.zzzz;\n\n vec4 ixy = permute(permute(ix) + iy);\n vec4 ixy0 = permute(ixy + iz0);\n vec4 ixy1 = permute(ixy + iz1);\n\n vec4 gx0 = ixy0 * (1.0 / 7.0);\n vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5;\n gx0 = fract(gx0);\n vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0);\n vec4 sz0 = step(gz0, vec4(0.0));\n gx0 -= sz0 * (step(0.0, gx0) - 0.5);\n gy0 -= sz0 * (step(0.0, gy0) - 0.5);\n\n vec4 gx1 = ixy1 * (1.0 / 7.0);\n vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5;\n gx1 = fract(gx1);\n vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1);\n vec4 sz1 = step(gz1, vec4(0.0));\n gx1 -= sz1 * (step(0.0, gx1) - 0.5);\n gy1 -= sz1 * (step(0.0, gy1) - 0.5);\n\n vec3 g000 = vec3(gx0.x,gy0.x,gz0.x);\n vec3 g100 = vec3(gx0.y,gy0.y,gz0.y);\n vec3 g010 = vec3(gx0.z,gy0.z,gz0.z);\n vec3 g110 = vec3(gx0.w,gy0.w,gz0.w);\n vec3 g001 = vec3(gx1.x,gy1.x,gz1.x);\n vec3 g101 = vec3(gx1.y,gy1.y,gz1.y);\n vec3 g011 = vec3(gx1.z,gy1.z,gz1.z);\n vec3 g111 = vec3(gx1.w,gy1.w,gz1.w);\n\n vec4 norm0 = taylorInvSqrt(vec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));\n g000 *= norm0.x;\n g010 *= norm0.y;\n g100 *= norm0.z;\n g110 *= norm0.w;\n vec4 norm1 = taylorInvSqrt(vec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));\n g001 *= norm1.x;\n g011 *= norm1.y;\n g101 *= norm1.z;\n g111 *= norm1.w;\n\n float n000 = dot(g000, Pf0);\n float n100 = dot(g100, vec3(Pf1.x, Pf0.yz));\n float n010 = dot(g010, vec3(Pf0.x, Pf1.y, Pf0.z));\n float n110 = dot(g110, vec3(Pf1.xy, Pf0.z));\n float n001 = dot(g001, vec3(Pf0.xy, Pf1.z));\n float n101 = dot(g101, vec3(Pf1.x, Pf0.y, Pf1.z));\n float n011 = dot(g011, vec3(Pf0.x, Pf1.yz));\n float n111 = dot(g111, Pf1);\n\n vec3 fade_xyz = fade(Pf0);\n vec4 n_z = mix(vec4(n000, n100, n010, n110), vec4(n001, n101, n011, n111), fade_xyz.z);\n vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y);\n float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);\n return 2.2 * n_xyz;\n}\n\n// YUV to RGB matrix\nmat3 yuv2rgb = mat3(1.0, 0.0, 1.13983,\n 1.0, -0.39465, -0.58060,\n 1.0, 2.03211, 0.0);\n\n// RGB to YUV matrix\nmat3 rgb2yuv = mat3(0.2126, 0.7152, 0.0722,\n -0.09991, -0.33609, 0.43600,\n 0.615, -0.5586, -0.05639);\n \nvec3 oklab2rgb(vec3 linear)\n{\n const mat3 im1 = mat3(0.4121656120, 0.2118591070, 0.0883097947,\n 0.5362752080, 0.6807189584, 0.2818474174,\n 0.0514575653, 0.1074065790, 0.6302613616);\n \n const mat3 im2 = mat3(+0.2104542553, +1.9779984951, +0.0259040371,\n +0.7936177850, -2.4285922050, +0.7827717662,\n -0.0040720468, +0.4505937099, -0.8086757660);\n \n vec3 lms = im1 * linear;\n \n return im2 * (sign(lms) * pow(abs(lms), vec3(1.0/3.0)));\n}\n\nvec3 rgb2oklab(vec3 oklab)\n{\n const mat3 m1 = mat3(+1.000000000, +1.000000000, +1.000000000,\n +0.396337777, -0.105561346, -0.089484178,\n +0.215803757, -0.063854173, -1.291485548);\n \n const mat3 m2 = mat3(+4.076724529, -1.268143773, -0.004111989,\n -3.307216883, +2.609332323, -0.703476310,\n +0.230759054, -0.341134429, +1.706862569);\n vec3 lms = m1 * oklab;\n \n return m2 * (lms * lms * lms);\n}\n\n `;\n\nconst buildColorFunctions = () => `\n\nvec3 saturation(vec3 rgb, float adjustment) {\n const vec3 W = vec3(0.2125, 0.7154, 0.0721);\n vec3 intensity = vec3(dot(rgb, W));\n return mix(intensity, rgb, adjustment);\n}\n\nfloat saturation(vec3 rgb)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(rgb.bg, K.wz), vec4(rgb.gb, K.xy), step(rgb.b, rgb.g));\n vec4 q = mix(vec4(p.xyw, rgb.r), vec4(rgb.r, p.yzx), step(p.x, rgb.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return abs(6.0 * d + e);\n}\n\n// get saturation of a color in values between 0 and 1\nfloat getSaturation(vec3 color) {\n float max = max(color.r, max(color.g, color.b));\n float min = min(color.r, min(color.g, color.b));\n return (max - min) / max;\n}\n \nvec3 rgb2hsv(vec3 c)\n{\n vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n\n float d = q.x - min(q.w, q.y);\n float e = 1.0e-10;\n return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n}\n\nvec3 hsv2rgb(vec3 c)\n{\n vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n}\n`;\n\n\nconst setLinkStyles = (link: HTMLAnchorElement) => {\n link.id = \"neat-link\";\n link.href = \"https://neat.firecms.co\";\n link.target = \"_blank\";\n link.style.position = \"absolute\";\n link.style.display = \"block\";\n link.style.opacity = \"1\";\n link.style.bottom = \"0\";\n link.style.right = \"0\";\n link.style.padding = \"10px\";\n link.style.color = \"#dcdcdc\";\n link.style.opacity = \"0.8\";\n link.style.fontFamily = \"sans-serif\";\n link.style.fontSize = \"16px\";\n link.style.fontWeight = \"bold\";\n link.style.textDecoration = \"none\";\n link.style.zIndex = \"100\";\n link.innerHTML = \"NEAT\";\n}\n\nconst addNeatLink = (ref: HTMLCanvasElement) => {\n const existingLinks = ref.parentElement?.getElementsByTagName(\"a\");\n if (existingLinks) {\n for (let i = 0; i < existingLinks.length; i++) {\n if (existingLinks[i].id === \"neat-link\") {\n setLinkStyles(existingLinks[i]);\n return;\n }\n }\n }\n const link = document.createElement(\"a\");\n setLinkStyles(link);\n ref.parentElement?.appendChild(link);\n}\n"],"names":["PLANE_WIDTH","PLANE_HEIGHT","WIREFRAME","COLORS_COUNT","clock","THREE","NeatGradient","config","ref","speed","horizontalPressure","verticalPressure","waveFrequencyX","waveFrequencyY","waveAmplitude","colors","highlights","shadows","colorSaturation","colorBrightness","colorBlending","wireframe","backgroundColor","backgroundAlpha","resolution","tick","render","renderer","camera","scene","meshes","addNeatLink","mesh","width","height","color","setSize","canvas","updateCamera","entries","material","geo","plane","uniforms","buildUniforms","buildNoise","buildColorFunctions","buildVertexShader","buildFragmentShader","targetPlaneArea","ratio","targetWidth","targetHeight","left","right","top","bottom","near","far","setLinkStyles","link","existingLinks"],"mappings":"wjBAEMA,EAAc,GACdC,EAAe,GAEfC,EAAY,GACZC,EAAe,EAEfC,EAAQ,IAAIC,EAAM,MA0CjB,MAAMC,CAAuC,CAExC,KAEA,OAAiB,GAEjB,oBAA8B,GAC9B,kBAA4B,GAE5B,gBAA0B,GAC1B,gBAA0B,GAC1B,eAAyB,GAEzB,SAAmB,GACnB,YAAsB,GACtB,YAAsB,GACtB,YAAsB,GAEtB,eAAyB,GAEzB,QAAuB,CAAA,EACvB,WAAsB,GAEtB,iBAA2B,UAC3B,iBAA2B,EAE3B,WAAqB,GACrB,aACA,WAER,YAAYC,EAAsE,CAExE,KAAA,CACF,IAAAC,EACA,MAAAC,EAAQ,EACR,mBAAAC,EAAqB,EACrB,iBAAAC,EAAmB,EACnB,eAAAC,EAAiB,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4B,CAC/CA,EAAK,GAAK,YACVA,EAAK,KAAO,0BACZA,EAAK,OAAS,SACdA,EAAK,MAAM,SAAW,WACtBA,EAAK,MAAM,QAAU,QACrBA,EAAK,MAAM,QAAU,IACrBA,EAAK,MAAM,OAAS,IACpBA,EAAK,MAAM,MAAQ,IACnBA,EAAK,MAAM,QAAU,OACrBA,EAAK,MAAM,MAAQ,UACnBA,EAAK,MAAM,QAAU,MACrBA,EAAK,MAAM,WAAa,aACxBA,EAAK,MAAM,SAAW,OACtBA,EAAK,MAAM,WAAa,OACxBA,EAAK,MAAM,eAAiB,OAC5BA,EAAK,MAAM,OAAS,MACpBA,EAAK,UAAY,MACrB,EAEM7B,EAAevB,GAA2B,CAC5C,MAAMqD,EAAgBrD,EAAI,eAAe,qBAAqB,GAAG,EACjE,GAAIqD,GACA,QAAS,EAAI,EAAG,EAAIA,EAAc,OAAQ,IAClC,GAAAA,EAAc,GAAG,KAAO,YAAa,CACrCF,EAAcE,EAAc,EAAE,EAC9B,MACJ,EAGF,MAAAD,EAAO,SAAS,cAAc,GAAG,EACvCD,EAAcC,CAAI,EACdpD,EAAA,eAAe,YAAYoD,CAAI,CACvC"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@firecms/neat",
3
3
  "description": "Beautiful 3D gradients for your website",
4
4
  "access": "public",
5
- "version": "0.1.4",
5
+ "version": "0.2.0",
6
6
  "main": "./dist/index.umd.js",
7
7
  "module": "./dist/index.es.js",
8
8
  "types": "dist/index.d.ts",
@@ -15,9 +15,9 @@
15
15
  "three": "^0.144.0"
16
16
  },
17
17
  "devDependencies": {
18
+ "three": "^0.144.0",
18
19
  "typescript": "^4.8.4",
19
- "vite": "^3.1.4",
20
- "three": "^0.144.0"
20
+ "vite": "^3.1.4"
21
21
  },
22
22
  "scripts": {
23
23
  "start": "vite",
@@ -10,12 +10,14 @@ const clock = new THREE.Clock();
10
10
 
11
11
  type SceneState = {
12
12
  renderer: THREE.WebGLRenderer,
13
- camera: THREE.OrthographicCamera,
13
+ camera: THREE.Camera,
14
14
  scene: THREE.Scene,
15
15
  meshes: THREE.Mesh[],
16
+ resolution: number
16
17
  }
17
18
 
18
19
  export type NeatConfig = {
20
+ resolution?: number;
19
21
  speed?: number;
20
22
  horizontalPressure?: number;
21
23
  verticalPressure?: number;
@@ -48,6 +50,8 @@ export type NeatController = {
48
50
 
49
51
  export class NeatGradient implements NeatController {
50
52
 
53
+ private _ref: HTMLCanvasElement;
54
+
51
55
  private _speed: number = -1;
52
56
 
53
57
  private _horizontalPressure: number = -1;
@@ -72,7 +76,7 @@ export class NeatGradient implements NeatController {
72
76
 
73
77
  private requestRef: number = -1;
74
78
  private sizeObserver: ResizeObserver;
75
- private readonly sceneState: SceneState;
79
+ private sceneState: SceneState;
76
80
 
77
81
  constructor(config: NeatConfig & { ref: HTMLCanvasElement, resolution?: number }) {
78
82
 
@@ -96,8 +100,8 @@ export class NeatGradient implements NeatController {
96
100
  resolution = 1
97
101
  } = config;
98
102
 
99
- const width = ref.width,
100
- height = ref.height;
103
+
104
+ this._ref = ref;
101
105
 
102
106
  this.destroy = this.destroy.bind(this);
103
107
  this._initScene = this._initScene.bind(this);
@@ -119,13 +123,13 @@ export class NeatGradient implements NeatController {
119
123
  this.backgroundColor = backgroundColor;
120
124
  this.backgroundAlpha = backgroundAlpha;
121
125
 
122
- this.sceneState = this._initScene(ref, width, height, resolution);
126
+ this.sceneState = this._initScene(resolution);
123
127
 
124
- const { renderer, camera, scene, meshes } = this.sceneState;
125
128
 
126
129
  let tick = 0;
127
130
  const render = () => {
128
131
 
132
+ const { renderer, camera, scene, meshes } = this.sceneState;
129
133
  if (Math.floor(tick * 10) % 5 === 0) {
130
134
  addNeatLink(ref);
131
135
  }
@@ -133,6 +137,9 @@ export class NeatGradient implements NeatController {
133
137
  renderer.setClearColor(this._backgroundColor, this._backgroundAlpha);
134
138
  meshes.forEach((mesh) => {
135
139
 
140
+ const width = this._ref.width,
141
+ height = this._ref.height;
142
+
136
143
  const colors = [
137
144
  ...this._colors.map(color => ({
138
145
  is_active: color.enabled,
@@ -185,6 +192,8 @@ export class NeatGradient implements NeatController {
185
192
  };
186
193
 
187
194
  const setSize = () => {
195
+
196
+ const { renderer } = this.sceneState;
188
197
  const canvas = renderer.domElement;
189
198
  const width = canvas.clientWidth;
190
199
  const height = canvas.clientHeight;
@@ -251,7 +260,6 @@ export class NeatGradient implements NeatController {
251
260
  }
252
261
 
253
262
  set colorBrightness(colorBrightness: number) {
254
- console.log("colorBrightness", colorBrightness)
255
263
  this._brightness = colorBrightness;
256
264
  }
257
265
 
@@ -263,6 +271,10 @@ export class NeatGradient implements NeatController {
263
271
  this._wireframe = wireframe;
264
272
  }
265
273
 
274
+ set resolution(resolution: number) {
275
+ this.sceneState = this._initScene(resolution);
276
+ }
277
+
266
278
  set backgroundColor(backgroundColor: string) {
267
279
  this._backgroundColor = backgroundColor;
268
280
  }
@@ -271,12 +283,15 @@ export class NeatGradient implements NeatController {
271
283
  this._backgroundAlpha = backgroundAlpha;
272
284
  }
273
285
 
274
- _initScene(ref: HTMLCanvasElement, width: number, height: number, resolution: number): SceneState {
286
+ _initScene(resolution: number): SceneState {
287
+
288
+ const width = this._ref.width,
289
+ height = this._ref.height;
275
290
 
276
291
  const renderer = new THREE.WebGLRenderer({
277
292
  // antialias: true,
278
293
  alpha: true,
279
- canvas: ref
294
+ canvas: this._ref
280
295
  });
281
296
 
282
297
  renderer.setClearColor(0xFF0000, .5);
@@ -296,14 +311,16 @@ export class NeatGradient implements NeatController {
296
311
  scene.add(plane);
297
312
 
298
313
  const camera = new THREE.OrthographicCamera(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
299
- // camera.zoom = 1;
314
+ // const camera = new THREE.PerspectiveCamera( 1000, window.innerWidth / window.innerHeight, 1, 1000000 );
315
+ camera.position.z = 5;
300
316
  updateCamera(camera, width, height);
301
317
 
302
318
  return {
303
319
  renderer,
304
320
  camera,
305
321
  scene,
306
- meshes
322
+ meshes,
323
+ resolution
307
324
  };
308
325
  }
309
326
 
@@ -349,7 +366,7 @@ export class NeatGradient implements NeatController {
349
366
 
350
367
  }
351
368
 
352
- function updateCamera(camera: THREE.OrthographicCamera, width: number, height: number) {
369
+ function updateCamera(camera: THREE.Camera, width: number, height: number) {
353
370
 
354
371
  const viewPortAreaRatio = 1000000;
355
372
  const areaViewPort = width * height;
@@ -370,13 +387,19 @@ function updateCamera(camera: THREE.OrthographicCamera, width: number, height: n
370
387
 
371
388
  const near = -100;
372
389
  const far = 1000;
373
- camera.left = left;
374
- camera.right = right;
375
- camera.top = top;
376
- camera.bottom = bottom;
377
- camera.near = near;
378
- camera.far = far;
379
- camera.updateProjectionMatrix();
390
+ if (camera instanceof THREE.OrthographicCamera) {
391
+ camera.left = left;
392
+ camera.right = right;
393
+ camera.top = top;
394
+ camera.bottom = bottom;
395
+ camera.near = near;
396
+ camera.far = far;
397
+ camera.updateProjectionMatrix();
398
+ } else if (camera instanceof THREE.PerspectiveCamera) {
399
+ camera.aspect = width / height;
400
+ camera.updateProjectionMatrix();
401
+ }
402
+
380
403
  }
381
404
 
382
405
 
@@ -420,6 +443,13 @@ void main() {
420
443
 
421
444
  noise = clamp(minNoise, maxNoise + float(i) * 0.02, noise);
422
445
  vec3 nextColor = u_colors[i].color;
446
+
447
+ // vec3 colorOklab = oklab2rgb(color);
448
+ // vec3 nextColorOklab = oklab2rgb(nextColor);
449
+ // vec3 mixColor = mix(colorOklab, nextColorOklab, smoothstep(0.0, u_color_blending, noise));
450
+ //
451
+ // color = rgb2oklab(mixColor);
452
+
423
453
  color = mix(color, nextColor, smoothstep(0.0, u_color_blending, noise));
424
454
  }
425
455
 
@@ -669,6 +699,35 @@ mat3 yuv2rgb = mat3(1.0, 0.0, 1.13983,
669
699
  mat3 rgb2yuv = mat3(0.2126, 0.7152, 0.0722,
670
700
  -0.09991, -0.33609, 0.43600,
671
701
  0.615, -0.5586, -0.05639);
702
+
703
+ vec3 oklab2rgb(vec3 linear)
704
+ {
705
+ const mat3 im1 = mat3(0.4121656120, 0.2118591070, 0.0883097947,
706
+ 0.5362752080, 0.6807189584, 0.2818474174,
707
+ 0.0514575653, 0.1074065790, 0.6302613616);
708
+
709
+ const mat3 im2 = mat3(+0.2104542553, +1.9779984951, +0.0259040371,
710
+ +0.7936177850, -2.4285922050, +0.7827717662,
711
+ -0.0040720468, +0.4505937099, -0.8086757660);
712
+
713
+ vec3 lms = im1 * linear;
714
+
715
+ return im2 * (sign(lms) * pow(abs(lms), vec3(1.0/3.0)));
716
+ }
717
+
718
+ vec3 rgb2oklab(vec3 oklab)
719
+ {
720
+ const mat3 m1 = mat3(+1.000000000, +1.000000000, +1.000000000,
721
+ +0.396337777, -0.105561346, -0.089484178,
722
+ +0.215803757, -0.063854173, -1.291485548);
723
+
724
+ const mat3 m2 = mat3(+4.076724529, -1.268143773, -0.004111989,
725
+ -3.307216883, +2.609332323, -0.703476310,
726
+ +0.230759054, -0.341134429, +1.706862569);
727
+ vec3 lms = m1 * oklab;
728
+
729
+ return m2 * (lms * lms * lms);
730
+ }
672
731
 
673
732
  `;
674
733
 
@@ -729,6 +788,7 @@ const setLinkStyles = (link: HTMLAnchorElement) => {
729
788
  link.style.right = "0";
730
789
  link.style.padding = "10px";
731
790
  link.style.color = "#dcdcdc";
791
+ link.style.opacity = "0.8";
732
792
  link.style.fontFamily = "sans-serif";
733
793
  link.style.fontSize = "16px";
734
794
  link.style.fontWeight = "bold";