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

Warp #30

Merged
merged 22 commits into from
Jan 28, 2025
Merged

Warp #30

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
9 changes: 9 additions & 0 deletions docs/src/app/warp/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Metadata } from 'next';

export const metadata: Metadata = {
title: 'Warp Shader | Paper',
};

export default function Layout({ children }: { children: React.ReactNode }) {
return <>{children}</>;
}
87 changes: 87 additions & 0 deletions docs/src/app/warp/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
'use client';

import { Warp, type WarpParams, warpPresets } from '@paper-design/shaders-react';
import { useControls, button, folder } from 'leva';
import { setParamsSafe, useResetLevaParams } from '@/helpers/use-reset-leva-params';
import { usePresetHighlight } from '@/helpers/use-preset-highlight';
import Link from 'next/link';
import { BackButton } from '@/components/back-button';
import { PatternShapes } from '@paper-design/shaders';

/**
* You can copy/paste this example to use Warp in your app
*/
const WarpExample = () => {
return (
<Warp
color1="#262626"
color2="#75c1f0"
color3="#ffffff"
scale={1}
rotation={0}
proportion={0.5}
softness={1}
distortion={0.25}
swirl={0.9}
swirlIterations={10}
shape={0}
shapeScale={0.5}
speed={0.3}
seed={0}
style={{ position: 'fixed', width: '100%', height: '100%' }}
/>
);
};

/**
* This example has controls added so you can play with settings in the example app
*/

const defaults = warpPresets[0].params;

const WarpWithControls = () => {
const [params, setParams] = useControls(() => {
const presets: WarpParams = Object.fromEntries(
warpPresets.map((preset) => [preset.name, button(() => setParamsSafe(params, setParams, preset.params))])
);

return {
Parameters: folder(
{
color1: { value: defaults.color1, order: 100 },
color2: { value: defaults.color2, order: 101 },
color3: { value: defaults.color3, order: 102 },
scale: { value: defaults.scale, min: 0, max: 2, order: 200 },
rotation: { value: defaults.rotation, min: 0, max: 2, order: 201 },
proportion: { value: defaults.proportion, min: 0, max: 1, order: 300 },
softness: { value: defaults.softness, min: 0, max: 1, order: 301 },
distortion: { value: defaults.distortion, min: 0, max: 1, order: 302 },
swirl: { value: defaults.swirl, min: 0, max: 1, order: 303 },
swirlIterations: { value: defaults.swirlIterations, min: 0, max: 20, order: 304 },
shape: { value: defaults.shape, options: PatternShapes, order: 305 },
shapeScale: { value: defaults.shapeScale, min: 0, max: 1, order: 306 },
speed: { value: defaults.speed, min: 0, max: 2, order: 400 },
},
{ order: 1 }
),
Presets: folder(presets, { order: 2 }),
};
});

// Reset to defaults on mount, so that Leva doesn't show values from other
// shaders when navigating (if two shaders have a color1 param for example)
useResetLevaParams(params, setParams, defaults);

usePresetHighlight(warpPresets, params);

return (
<>
<Link href="/">
<BackButton />
</Link>
<Warp {...params} style={{ position: 'fixed', width: '100%', height: '100%' }} />
</>
);
};

export default WarpWithControls;
10 changes: 9 additions & 1 deletion docs/src/home-shaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import {
Waves,
wavesPresets,
PerlinNoise,
perlinNoisePresets
perlinNoisePresets,
Warp,
warpPresets,
} from '@paper-design/shaders-react';
import { StaticImageData } from 'next/image';

Expand Down Expand Up @@ -114,4 +116,10 @@ export const homeShaders = [
ShaderComponent: Waves,
shaderConfig: wavesPresets[0].params,
},
{
name: 'warp',
url: '/warp',
ShaderComponent: Warp,
shaderConfig: warpPresets[0].params,
},
] satisfies HomeShaderConfig[];
2 changes: 1 addition & 1 deletion packages/shaders-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@paper-design/shaders-react",
"version": "0.0.17",
"version": "0.0.18",
"license": "MIT",
"type": "module",
"publishConfig": {
Expand Down
6 changes: 6 additions & 0 deletions packages/shaders-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,11 @@ export { type VoronoiProps } from './shaders/voronoi';
export { type VoronoiParams } from './shaders/voronoi';
export { type VoronoiUniforms } from '@paper-design/shaders';

// Warping distortion
export { Warp, warpPresets } from './shaders/warp';
export { type WarpProps } from './shaders/warp';
export { type WarpParams } from './shaders/warp';
export { type WarpUniforms, PatternShapes, type PatternShape } from '@paper-design/shaders';

// ----- Uniform conversion utils ----- //
export { getShaderColorFromString } from '@paper-design/shaders';
Loading