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

Changes in turbulence #57

Merged
merged 6 commits into from
Dec 16, 2024
Merged
Changes from 3 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
15 changes: 12 additions & 3 deletions src/effects/turbulence.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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 @@ -81,11 +82,11 @@ 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);
source: `
ydaniv marked this conversation as resolved.
Show resolved Hide resolved
${INPUT_TYPES[input] || input || ''}
float turbulenceValue = turbulence(turbulenceSeed, u_turbulenceFrequency, u_turbulenceOctaves, u_isFractal);`,
main: `
${output || ''}`
${output || ''}`,
},
get frequency() {
const [x, y] = this.uniforms[0].data;
Expand Down Expand Up @@ -143,6 +144,14 @@ 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_MOUSE_RESOLUTION:
Copy link
Collaborator

@ydaniv ydaniv Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FRAGCOORD_XY_MOUSE_Z
FRAGCOORD_XY_MOUSE_TIME

'vec3 turbulenceSeed = vec2(gl_FragCoord.x + u_mouse.x * u_resolution.x * -1.0, gl_FragCoord.y + u_mouse.y * u_resolution.y, u_time * 0.0001);',
};

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And expose as below

turbulence.COLOR = OUTPUT_TYPES.COLOR;
turbulence.ALPHA = OUTPUT_TYPES.ALPHA;

Expand Down
Loading