This commit is contained in:
Andras Schmelczer 2026-05-22 08:03:13 +01:00
parent f300dbd394
commit 646564fc73
4 changed files with 108 additions and 45 deletions

View file

@ -3,7 +3,7 @@ import { describe, expect, it } from 'vitest';
import { vibePresets } from './vibe-presets'; import { vibePresets } from './vibe-presets';
const FINAL_VIBE_NAMES = [ const FINAL_VIBE_NAMES = [
'Aurora Mycelium', 'Aurora Mycelium Copy',
'Velvet Observatory', 'Velvet Observatory',
'Lichen Signal', 'Lichen Signal',
'Tidepool Lantern', 'Tidepool Lantern',
@ -31,10 +31,7 @@ describe('vibePresets', () => {
) )
.map((preset) => preset.name); .map((preset) => preset.name);
expect(blendedNames).toEqual([ expect(blendedNames).toEqual(['Tidepool Lantern']);
'Aurora Mycelium',
'Tidepool Lantern',
]);
expect(softParticleNames).toEqual(['Chrome Pollen']); expect(softParticleNames).toEqual(['Chrome Pollen']);
}); });

View file

@ -20,13 +20,13 @@ type ColorReactionSettings = Pick<
const colorReactions = { const colorReactions = {
auroraMycelium: { auroraMycelium: {
color1ToColor1: 1, color1ToColor1: 1,
color1ToColor2: 1, color1ToColor2: 0,
color1ToColor3: 0, color1ToColor3: 0,
color2ToColor1: 0, color2ToColor1: -1,
color2ToColor2: 1, color2ToColor2: 1,
color2ToColor3: 1, color2ToColor3: 0,
color3ToColor1: 1, color3ToColor1: -1,
color3ToColor2: 0, color3ToColor2: -1,
color3ToColor3: 1, color3ToColor3: 1,
}, },
velvetObservatory: { velvetObservatory: {
@ -137,38 +137,38 @@ export const defaultVibeId = VibeId.AuroraMycelium;
export const vibePresets: Array<VibePreset> = [ export const vibePresets: Array<VibePreset> = [
{ {
id: VibeId.AuroraMycelium, id: VibeId.AuroraMycelium,
name: 'Aurora Mycelium', name: 'Aurora Mycelium Copy',
colors: [ colors: [
[78, 255, 176], [221, 255, 78],
[154, 99, 255], [154, 99, 255],
[169, 238, 255], [255, 31, 199],
], ],
backgroundColor: [6, 13, 22], backgroundColor: [6, 13, 22],
settings: { settings: {
...colorReactions.auroraMycelium, ...colorReactions.auroraMycelium,
backgroundGrainStrength: 0.014, backgroundGrainStrength: 0.003,
brushSize: 21, brushSize: 8.75,
clarity: 0.52, clarity: 0.379,
decayRateTrails: 988, decayRateTrails: 940,
forwardRotationScale: 0.28, forwardRotationScale: 0,
individualTrailWeight: 0.082, individualTrailWeight: 0.121,
moveSpeed: 54, moveSpeed: 270,
sensorOffsetAngle: 36, sensorOffsetAngle: 36,
sensorOffsetDistance: 76, sensorOffsetDistance: 51,
spawnPerPixel: 0.14, spawnPerPixel: 0.13999999999999999,
strokeAngleJitterRadians: 1.45, strokeAngleJitterRadians: 0.44999999999999996,
turnSpeed: 34, turnSpeed: 22,
turnWhenLost: 0.75, turnWhenLost: 6.071532165918825e-17,
}, },
audio: { audio: {
...defaultGardenAudioVibeSettings, ...defaultGardenAudioVibeSettings,
idleIntensity: 0.12, idleIntensity: 0.12,
bpm: 60, bpm: 60,
rampUpIntensity: 0.7, rampUpIntensity: 0.7000000000000001,
rampUpTime: 0.14, rampUpTime: 0.14,
noteLength: 0.86, noteLength: 0.86,
notePitchOffset: -2, notePitchOffset: -2,
brightness: 0.84, brightness: 0.8400000000000001,
scale: musicScales.lydian, scale: musicScales.lydian,
progression: musicProgressions.aurora, progression: musicProgressions.aurora,
}, },

View file

@ -12,6 +12,14 @@ struct Settings {
brushColorStrengthMultiplier: f32, brushColorStrengthMultiplier: f32,
}; };
const COMMON_CHANNEL_REDUCTION: f32 = 0.75;
const OVERLAP_SATURATION_BOOST: f32 = 1.35;
const LOW_SATURATION_RESCUE_AMOUNT: f32 = 0.65;
const LOW_SATURATION_RESCUE_MIN: f32 = 0.08;
const LOW_SATURATION_RESCUE_MAX: f32 = 0.22;
const COLOR_WEIGHT_EPSILON: f32 = 0.0001;
const LUMA_WEIGHTS: vec3<f32> = vec3<f32>(0.2126, 0.7152, 0.0722);
@group(1) @binding(0) var<uniform> settings: Settings; @group(1) @binding(0) var<uniform> settings: Settings;
@group(1) @binding(2) var trailMap: texture_2d<f32>; @group(1) @binding(2) var trailMap: texture_2d<f32>;
@group(1) @binding(3) var sourceMap: texture_2d<f32>; @group(1) @binding(3) var sourceMap: texture_2d<f32>;
@ -41,25 +49,13 @@ fn renderColor(traces: vec4<f32>, sources: vec4<f32>, background: vec3<f32>) ->
} }
if brushStrength <= 0.0 { if brushStrength <= 0.0 {
let traceColor = let traceColor = colorFromChannelStrengths(traceStrengths);
traceStrengths.r * settings.colorA return vec4(mix(background, clamp(traceColor, vec3(0), vec3(1)), traceStrength), 1);
+ traceStrengths.g * settings.colorB
+ traceStrengths.b * settings.colorC;
let normalizedTraceColor = normalizeColorIntensity(traceColor);
return vec4(mix(background, clamp(normalizedTraceColor, vec3(0), vec3(1)), traceStrength), 1);
} }
let strengths = max(traceStrengths, sourceStrengths); let strengths = max(traceStrengths, sourceStrengths);
let traceColor = let traceColor = colorFromChannelStrengths(strengths);
strengths.r * settings.colorA let brushColor = colorFromChannelStrengths(sourceStrengths);
+ strengths.g * settings.colorB
+ strengths.b * settings.colorC;
let normalizedTraceColor = normalizeColorIntensity(traceColor);
let brushColor =
sourceStrengths.r * settings.colorA
+ sourceStrengths.g * settings.colorB
+ sourceStrengths.b * settings.colorC;
let normalizedBrushColor = normalizeColorIntensity(brushColor);
let brushVisibility = clamp( let brushVisibility = clamp(
brushStrength * ( brushStrength * (
settings.brushColorBase + settings.brushColorBase +
@ -68,7 +64,7 @@ fn renderColor(traces: vec4<f32>, sources: vec4<f32>, background: vec3<f32>) ->
0, 0,
1 1
); );
let color = max(normalizedTraceColor, normalizedBrushColor); let color = mix(traceColor, brushColor, brushVisibility);
let strength = max(maxComponent(strengths), brushVisibility); let strength = max(maxComponent(strengths), brushVisibility);
return vec4(mix(background, clamp(color, vec3(0), vec3(1)), strength), 1); return vec4(mix(background, clamp(color, vec3(0), vec3(1)), strength), 1);
@ -78,10 +74,80 @@ fn maxComponent(v: vec3<f32>) -> f32 {
return max(max(v.r, v.g), v.b); return max(max(v.r, v.g), v.b);
} }
fn minComponent(v: vec3<f32>) -> f32 {
return min(min(v.r, v.g), v.b);
}
fn componentSum(v: vec3<f32>) -> f32 {
return v.r + v.g + v.b;
}
fn clarity(strength: vec3<f32>) -> vec3<f32> { fn clarity(strength: vec3<f32>) -> vec3<f32> {
return pow(clamp(strength, vec3(0), vec3(1)), vec3(settings.clarity)); return pow(clamp(strength, vec3(0), vec3(1)), vec3(settings.clarity));
} }
fn colorFromChannelStrengths(strengths: vec3<f32>) -> vec3<f32> {
if maxComponent(strengths) <= 0.0 {
return vec3<f32>(0.0);
}
let weights = colorWeights(strengths);
let color =
weights.r * settings.colorA
+ weights.g * settings.colorB
+ weights.b * settings.colorC;
return preserveOverlapVibrancy(normalizeColorIntensity(color), strengths);
}
fn colorWeights(strengths: vec3<f32>) -> vec3<f32> {
let commonStrength = minComponent(strengths);
var weightBase = max(
strengths - vec3<f32>(commonStrength * COMMON_CHANNEL_REDUCTION),
vec3<f32>(0.0)
);
if componentSum(weightBase) <= COLOR_WEIGHT_EPSILON {
weightBase = strengths;
}
let sharpenedWeights = weightBase * weightBase;
return sharpenedWeights / max(COLOR_WEIGHT_EPSILON, componentSum(sharpenedWeights));
}
fn preserveOverlapVibrancy(color: vec3<f32>, strengths: vec3<f32>) -> vec3<f32> {
let strongest = maxComponent(strengths);
let overlapAmount = clamp(
(componentSum(strengths) - strongest) / max(COLOR_WEIGHT_EPSILON, strongest),
0.0,
1.0
);
let luminance = dot(color, LUMA_WEIGHTS);
var vibrantColor = clamp(
vec3<f32>(luminance) +
(color - vec3<f32>(luminance)) *
mix(1.0, OVERLAP_SATURATION_BOOST, overlapAmount),
vec3<f32>(0.0),
vec3<f32>(1.0)
);
let saturation = maxComponent(vibrantColor) - minComponent(vibrantColor);
let rescueAmount =
overlapAmount *
(1.0 - smoothstep(LOW_SATURATION_RESCUE_MIN, LOW_SATURATION_RESCUE_MAX, saturation)) *
LOW_SATURATION_RESCUE_AMOUNT;
return mix(vibrantColor, dominantColor(strengths), rescueAmount);
}
fn dominantColor(strengths: vec3<f32>) -> vec3<f32> {
if strengths.r >= strengths.g && strengths.r >= strengths.b {
return normalizeColorIntensity(settings.colorA);
}
if strengths.g >= strengths.b {
return normalizeColorIntensity(settings.colorB);
}
return normalizeColorIntensity(settings.colorC);
}
fn normalizeColorIntensity(color: vec3<f32>) -> vec3<f32> { fn normalizeColorIntensity(color: vec3<f32>) -> vec3<f32> {
let brightestChannel = maxComponent(color); let brightestChannel = maxComponent(color);
return color / max(settings.traceNormalizationFloor, brightestChannel); return color / max(settings.traceNormalizationFloor, brightestChannel);

View file

@ -8,7 +8,7 @@ describe('vibe URI handling', () => {
expect(getVibeIdFromUri('https://example.test/?vibe=aurora-mycelium')).toBe( expect(getVibeIdFromUri('https://example.test/?vibe=aurora-mycelium')).toBe(
VibeId.AuroraMycelium VibeId.AuroraMycelium
); );
expect(getVibeIdFromUri('https://example.test/?vibe=Aurora%20Mycelium')).toBe( expect(getVibeIdFromUri('https://example.test/?vibe=Aurora%20Mycelium%20Copy')).toBe(
VibeId.AuroraMycelium VibeId.AuroraMycelium
); );
expect(getVibeIdFromUri('https://example.test/?vibe=velvet%20observatory')).toBe( expect(getVibeIdFromUri('https://example.test/?vibe=velvet%20observatory')).toBe(