diff --git a/src/effects/turbulence.js b/src/effects/turbulence.js index 8d9789c..a79660b 100644 --- a/src/effects/turbulence.js +++ b/src/effects/turbulence.js @@ -9,6 +9,7 @@ * @param {number} [params.octaves=1] initial number of octaves to use for turbulence noise generation. * @param {boolean} [params.isFractal=false] initial number of octaves to use for turbulence noise generation. * @param {number} [params.time=0] initial time for controlling initial noise value. + * @param {string} [params.input] how to define `turbulenceSeed`. Defaults to `turbulence.FRAGCOORD_XY_TIME`. * @returns {turbulenceEffect} * * @example turbulence({noise: kampos.noise.simplex, output: turbulence.COLOR, octaves: 4, isFractal: true}) @@ -20,6 +21,7 @@ function turbulence({ octaves = 1, isFractal = false, time = 0.0, + input = INPUT_TYPES.FRAGCOORD_XY_TIME, }) { const { x: fx, y: fy } = frequency || { x: 0.0, y: 0.0 }; @@ -82,10 +84,10 @@ float turbulence (vec3 seed, vec2 frequency, int numOctaves, bool isFractal) { return clamp(sum, 0.0, 1.0); }`, source: ` - vec3 turbulenceSeed = vec3(gl_FragCoord.xy, u_time * 0.0001); + ${input || ''} float turbulenceValue = turbulence(turbulenceSeed, u_turbulenceFrequency, u_turbulenceOctaves, u_isFractal);`, main: ` - ${output || ''}` + ${output || ''}`, }, get frequency() { const [x, y] = this.uniforms[0].data; @@ -143,7 +145,21 @@ const OUTPUT_TYPES = { ALPHA: 'alpha = turbulenceValue;', }; +const INPUT_TYPES = { + FRAGCOORD_XY_TIME: + 'vec3 turbulenceSeed = vec3(gl_FragCoord.xy, u_time * 0.0001)', + FRAGCOORD_XYZ: 'vec3 turbulenceSeed = vec3(gl_FragCoord.xyz)', + FRAGCOORD_XY_MOUSE_TIME: + 'vec3 turbulenceSeed = vec3(gl_FragCoord.x + u_mouse.x * u_resolution.x * -1.0, gl_FragCoord.y + u_mouse.y * u_resolution.y, u_time * 0.0001);', + FRAGCOORD_XY_MOUSE_Z: + 'vec3 turbulenceSeed = vec3(gl_FragCoord.x + u_mouse.x * u_resolution.x * -1.0, gl_FragCoord.y + u_mouse.y * u_resolution.y);', +}; + turbulence.COLOR = OUTPUT_TYPES.COLOR; turbulence.ALPHA = OUTPUT_TYPES.ALPHA; +turbulence.FRAGCOORD_XY_TIME = INPUT_TYPES.FRAGCOORD_XY_TIME; +turbulence.FRAGCOORD_XYZ = INPUT_TYPES.FRAGCOORD_XYZ; +turbulence.FRAGCOORD_XY_MOUSE_TIME = INPUT_TYPES.FRAGCOORD_XY_MOUSE_TIME; +turbulence.FRAGCOORD_XY_MOUSE_Z = INPUT_TYPES.FRAGCOORD_XY_MOUSE_Z; export default turbulence;