text: import _extends from '@babel/runtime/helpers/esm/extends';
  import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/esm/objectWithoutPropertiesLoose';
  import { forwardRef, useState, createElement } from 'react';
  import { MeshPhysicalMaterial } from 'three';
  import { useFrame } from 'react-three-fiber';
  import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
  import distort from '../helpers/glsl/distort.vert.glsl.js';
  
  class DistortMaterialImpl extends MeshPhysicalMaterial {
    constructor(parameters = {}) {
      super(parameters);
  
      _defineProperty(this, "_time", void 0);
  
      _defineProperty(this, "_distort", void 0);
  
      _defineProperty(this, "_radius", void 0);
  
      this.setValues(parameters);
      this._time = {
        value: 0
      };
      this._distort = {
        value: 0.4
      };
      this._radius = {
        value: 1
      };
    }
  
    onBeforeCompile(shader) {
      shader.uniforms.time = this._time;
      shader.uniforms.radius = this._radius;
      shader.uniforms.distort = this._distort;
      shader.vertexShader = "\n      uniform float time;\n      uniform float radius;\n      uniform float distort;\n      " + distort + "\n      " + shader.vertexShader + "\n    ";
      shader.vertexShader = shader.vertexShader.replace('#include <begin_vertex>', "\n        float updateTime = time / 50.0;\n        float noise = snoise(vec3(position / 2.0 + updateTime * 5.0));\n        vec3 transformed = vec3(position * (noise * pow(distort, 2.0) + radius));\n        ");
    }
  
    get time() {
      return this._time.value;
    }
  
    set time(v) {
      this._time.value = v;
    }
  
    get distort() {
      return this._distort.value;
    }
  
    set distort(v) {
      this._distort.value = v;
    }
  
    get radius() {
      return this._radius.value;
    }
  
    set radius(v) {
      this._radius.value = v;
    }
  
  }
  
  const MeshDistortMaterial = /*#__PURE__*/forwardRef((_ref, ref) => {
    let {
      speed = 1
    } = _ref,
        props = _objectWithoutPropertiesLoose(_ref, ["speed"]);
  
    const [material] = useState(() => new DistortMaterialImpl());
    useFrame(state => material && (material.time = state.clock.getElapsedTime() * speed));
    return /*#__PURE__*/createElement("primitive", _extends({
      dispose: undefined,
      object: material,
      ref: ref,
      attach: "material"
    }, props));
  });
  
  export { MeshDistortMaterial };
  