Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump turbulence updates #58

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
### 0.14.1 (2024-12-15)
### 0.14.3 (2024-12-16)

_New:_

- Added ability to use `u_mouse` as input to `turbulence` effect.

### 0.14.2 (2024-12-15)

_Fixed:_

Expand Down
1 change: 0 additions & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
nav {
position: fixed;
width: 256px;
min-height: 100vh;
z-index: 20;
top: 0;
}
Expand Down
25 changes: 23 additions & 2 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,7 @@ float noise (vec3 seed) {
* @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})
Expand All @@ -1917,6 +1918,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 };

Expand Down Expand Up @@ -1979,8 +1981,9 @@ 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);
float turbulenceValue = turbulence(turbulenceSeed, u_turbulenceFrequency, u_turbulenceOctaves, u_isFractal);
${input || ''}
float turbulenceValue = turbulence(turbulenceSeed, u_turbulenceFrequency, u_turbulenceOctaves, u_isFractal);`,
main: `
${output || ''}`,
},
get frequency() {
Expand Down Expand Up @@ -2039,8 +2042,22 @@ 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.xy + u_mouse * u_resolution * vec2(-1.0, 1.0), u_time * 0.0001);',
FRAGCOORD_XY_MOUSE_Z:
'vec3 turbulenceSeed = vec3(gl_FragCoord.xy + u_mouse * u_resolution * vec2(-1.0, 1.0), gl_FragCoord.z);',
};

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;

/**
* @function fadeTransition
Expand Down Expand Up @@ -3490,6 +3507,10 @@ class Kampos {
this.dimensions = { width: media.naturalWidth, height: media.naturalHeight };
}

if (source && !this.data.source) {
this.data.source = source;
}

if (typeof shouldUpdate === 'boolean') {
this.data.source.shouldUpdate = shouldUpdate;
}
Expand Down
17 changes: 15 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset='utf-8'>
<title>kampos 0.14.0 | Documentation</title>
<title>kampos 0.14.2 | Documentation</title>
<meta name='description' content='Tiny and fast effects compositor on WebGL'>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<link href='assets/bass.css' rel='stylesheet'>
Expand All @@ -15,7 +15,7 @@
<div id='split-left' class='overflow-auto fs0 height-viewport-100'>
<div class='py1 px2'>
<h3 class='mb0 no-anchor'>kampos</h3>
<div class='mb1'><code>0.14.0</code></div>
<div class='mb1'><code>0.14.2</code></div>
<input
placeholder='Filter'
id='filter-input'
Expand Down Expand Up @@ -3595,6 +3595,19 @@ <h3 class='fl m0' id='effects'>



<tr>
<td class='break-word'><span class='code bold'>params.input</span> <code class='quiet'><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>?</code>
</td>
<td class='break-word'><span>how to define
<code>turbulenceSeed</code>
. Defaults to
<code>turbulence.FRAGCOORD_XY_TIME</code>
.
</span></td>
</tr>



</tbody>
</table>

Expand Down
25 changes: 23 additions & 2 deletions index.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -1910,6 +1910,7 @@ float noise (vec3 seed) {
* @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})
Expand All @@ -1921,6 +1922,7 @@ float noise (vec3 seed) {
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 };

Expand Down Expand Up @@ -1983,8 +1985,9 @@ 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);
float turbulenceValue = turbulence(turbulenceSeed, u_turbulenceFrequency, u_turbulenceOctaves, u_isFractal);
${input || ''}
float turbulenceValue = turbulence(turbulenceSeed, u_turbulenceFrequency, u_turbulenceOctaves, u_isFractal);`,
main: `
${output || ''}`,
},
get frequency() {
Expand Down Expand Up @@ -2043,8 +2046,22 @@ float turbulence (vec3 seed, vec2 frequency, int numOctaves, bool isFractal) {
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.xy + u_mouse * u_resolution * vec2(-1.0, 1.0), u_time * 0.0001);',
FRAGCOORD_XY_MOUSE_Z:
'vec3 turbulenceSeed = vec3(gl_FragCoord.xy + u_mouse * u_resolution * vec2(-1.0, 1.0), gl_FragCoord.z);',
};

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;

/**
* @function fadeTransition
Expand Down Expand Up @@ -3494,6 +3511,10 @@ void main() {
this.dimensions = { width: media.naturalWidth, height: media.naturalHeight };
}

if (source && !this.data.source) {
this.data.source = source;
}

if (typeof shouldUpdate === 'boolean') {
this.data.source.shouldUpdate = shouldUpdate;
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kampos",
"version": "0.14.2",
"version": "0.14.3",
"description": "Tiny and fast effects compositor on WebGL",
"registry": "https://registry.npmjs.org/",
"main": "dist/index.cjs",
Expand Down
8 changes: 4 additions & 4 deletions src/effects/turbulence.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ const OUTPUT_TYPES = {

const INPUT_TYPES = {
FRAGCOORD_XY_TIME:
'vec3 turbulenceSeed = vec3(gl_FragCoord.xy, u_time * 0.0001)',
FRAGCOORD_XYZ: 'vec3 turbulenceSeed = vec3(gl_FragCoord.xyz)',
'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);',
'vec3 turbulenceSeed = vec3(gl_FragCoord.xy + u_mouse * u_resolution * vec2(-1.0, 1.0), 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);',
'vec3 turbulenceSeed = vec3(gl_FragCoord.xy + u_mouse * u_resolution * vec2(-1.0, 1.0), gl_FragCoord.z);',
};

turbulence.COLOR = OUTPUT_TYPES.COLOR;
Expand Down
4 changes: 4 additions & 0 deletions src/kampos.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ export class Kampos {
this.dimensions = { width: media.naturalWidth, height: media.naturalHeight };
}

if (source && !this.data.source) {
this.data.source = source;
}

if (typeof shouldUpdate === 'boolean') {
this.data.source.shouldUpdate = shouldUpdate;
}
Expand Down
Loading