Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

feat(canvas): add wavy denoising strength track

joshistoasteb232eb14475
diff --git a/invokeai/frontend/webv2/src/workbench/components/ui/Slider.tsx b/invokeai/frontend/webv2/src/workbench/components/ui/Slider.tsx
index 97de382b88..43cfc0a036 100644
--- a/invokeai/frontend/webv2/src/workbench/components/ui/Slider.tsx
+++ b/invokeai/frontend/webv2/src/workbench/components/ui/Slider.tsx
@@ -12,6 +12,8 @@ export interface SliderProps extends Omit<ChakraSlider.RootProps, 'children'> {
marks?: SliderMark[];
/** Show the formatted value above each thumb while the slider is hovered or a thumb is dragged. */
withThumbTooltip?: boolean;
+ /** Optional visual rendered behind the track and thumbs. */
+ trackDecoration?: ReactNode;
}
// Marks stay mounted so the slider keeps a stable height, but only fade in
@@ -70,6 +72,7 @@ const SliderThumb = ({ index, isTooltipOpen, label }: { index: number; isTooltip
export const Slider = ({
formatValue = formatValueDefault,
marks,
+ trackDecoration,
withThumbTooltip = true,
...rootProps
}: SliderProps) => {
@@ -159,6 +162,7 @@ export const Slider = ({
thumbCollisionBehavior="push"
>
<ChakraSlider.Control>
+ {trackDecoration}
<ChakraSlider.Track>
<ChakraSlider.Range />
</ChakraSlider.Track>
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/DenoisingStrengthWave.test.ts b/invokeai/frontend/webv2/src/workbench/widgets/layers/DenoisingStrengthWave.test.ts
new file mode 100644
index 0000000000..5b96aa53ae
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/DenoisingStrengthWave.test.ts
@@ -0,0 +1,22 @@
+import { describe, expect, it } from 'vitest';
+
+import { getDenoisingStrengthWavePath } from './DenoisingStrengthWave';
+
+describe('getDenoisingStrengthWavePath', () => {
+ it('renders zero strength as a straight centered line', () => {
+ expect(getDenoisingStrengthWavePath(0, 100, 12, 10)).toBe('M0,6 L100,6');
+ });
+
+ it('increases wave amplitude with denoising strength', () => {
+ const low = getDenoisingStrengthWavePath(0.25, 100, 12, 10);
+ const high = getDenoisingStrengthWavePath(1, 100, 12, 10);
+
+ expect(low).toContain('Q5,4.75 10,6');
+ expect(high).toContain('Q5,1 10,6');
+ });
+
+ it('clamps strength before calculating amplitude', () => {
+ expect(getDenoisingStrengthWavePath(-1, 100, 12, 10)).toBe(getDenoisingStrengthWavePath(0, 100, 12, 10));
+ expect(getDenoisingStrengthWavePath(2, 100, 12, 10)).toBe(getDenoisingStrengthWavePath(1, 100, 12, 10));
+ });
+});
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/DenoisingStrengthWave.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/DenoisingStrengthWave.tsx
new file mode 100644
index 0000000000..df17cb92cf
--- /dev/null
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/DenoisingStrengthWave.tsx
@@ -0,0 +1,63 @@
+const clamp01 = (value: number): number => Math.min(1, Math.max(0, value));
+
+export const getDenoisingStrengthWavePath = (
+ strength: number,
+ width: number,
+ height: number,
+ segments: number
+): string => {
+ const centerY = height / 2;
+ const amplitude = clamp01(strength) * Math.max(0, centerY - 1);
+ if (amplitude === 0) {
+ return `M0,${centerY} L${width},${centerY}`;
+ }
+
+ const segmentWidth = width / segments;
+ let path = `M0,${centerY}`;
+ for (let index = 1; index <= segments; index += 1) {
+ const x = index * segmentWidth;
+ const controlX = x - segmentWidth / 2;
+ const controlY = centerY + (index % 2 === 0 ? amplitude : -amplitude);
+ path += ` Q${controlX},${controlY} ${x},${centerY}`;
+ }
+ return path;
+};
+
+const WAVE_WIDTH = 100;
+const WAVE_HEIGHT = 12;
+const WAVE_SEGMENTS = 10;
+
+/** A value-reactive replacement for the denoising slider's straight track. */
+export const DenoisingStrengthWave = ({ value }: { value: number }) => {
+ const clampedValue = clamp01(value);
+ const path = getDenoisingStrengthWavePath(clampedValue, WAVE_WIDTH, WAVE_HEIGHT, WAVE_SEGMENTS);
+
+ return (
+ <svg
+ aria-hidden
+ height={WAVE_HEIGHT}
+ preserveAspectRatio="none"
+ style={{ left: 0, pointerEvents: 'none', position: 'absolute', top: '50%', transform: 'translateY(-50%)' }}
+ viewBox={`0 0 ${WAVE_WIDTH} ${WAVE_HEIGHT}`}
+ width="100%"
+ >
+ <path
+ d={path}
+ fill="none"
+ opacity="0.55"
+ stroke="var(--chakra-colors-fg-muted)"
+ strokeWidth="1.25"
+ vectorEffect="non-scaling-stroke"
+ />
+ <path
+ d={path}
+ fill="none"
+ pathLength={100}
+ stroke="var(--chakra-colors-accent-solid)"
+ strokeDasharray={`${clampedValue * 100} 100`}
+ strokeWidth="1.75"
+ vectorEffect="non-scaling-stroke"
+ />
+ </svg>
+ );
+};
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersPanelHeader.tsx b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersPanelHeader.tsx
index ca3f58c251..62959c4897 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersPanelHeader.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/layers/LayersPanelHeader.tsx
@@ -21,9 +21,13 @@ import { useActiveProjectSelector, useWorkbenchDispatch } from '@workbench/Workb
import { useCallback, useMemo, useRef } from 'react';
import { useTranslation } from 'react-i18next';
+import { DenoisingStrengthWave } from './DenoisingStrengthWave';
import { applyStructural } from './layerOps';
const STRENGTH_DEBOUNCE_MS = 250;
+const DENOISING_STRENGTH_SLIDER_CSS = {
+ '& [data-part="range"], & [data-part="track"]': { background: 'transparent' },
+} as const;
const formatStrengthPercent = (value: number): string => `${Math.round(value * 100)}%`;
const clamp01 = (value: number): number => Math.min(1, Math.max(0, value));
@@ -286,6 +290,7 @@ const DenoisingStrengthControl = () => {
const strengthAriaLabel = useMemo(() => [t('widgets.layers.denoisingStrength')], [t]);
const strengthSliderValue = useMemo(() => [draftStrength], [draftStrength]);
const strengthNumberValue = useMemo(() => draftStrength.toFixed(2), [draftStrength]);
+ const strengthTrackDecoration = useMemo(() => <DenoisingStrengthWave value={draftStrength} />, [draftStrength]);
const onSliderChange = useCallback(
({ value }: SliderValueChangeDetails) => {
@@ -311,6 +316,7 @@ const DenoisingStrengthControl = () => {
<Stack direction="row" gap="2">
<Slider
aria-label={strengthAriaLabel}
+ css={DENOISING_STRENGTH_SLIDER_CSS}
flex="1"
formatValue={formatStrengthPercent}
max={MAX_CANVAS_DENOISING_STRENGTH}
@@ -318,6 +324,7 @@ const DenoisingStrengthControl = () => {
minW="0"
size="sm"
step={0.01}
+ trackDecoration={strengthTrackDecoration}
value={strengthSliderValue}
withThumbTooltip
onValueChange={onSliderChange}