Fixes
This commit is contained in:
parent
f300dbd394
commit
646564fc73
4 changed files with 108 additions and 45 deletions
|
|
@ -12,6 +12,14 @@ struct Settings {
|
|||
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(2) var trailMap: 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 {
|
||||
let traceColor =
|
||||
traceStrengths.r * settings.colorA
|
||||
+ 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 traceColor = colorFromChannelStrengths(traceStrengths);
|
||||
return vec4(mix(background, clamp(traceColor, vec3(0), vec3(1)), traceStrength), 1);
|
||||
}
|
||||
|
||||
let strengths = max(traceStrengths, sourceStrengths);
|
||||
let traceColor =
|
||||
strengths.r * settings.colorA
|
||||
+ 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 traceColor = colorFromChannelStrengths(strengths);
|
||||
let brushColor = colorFromChannelStrengths(sourceStrengths);
|
||||
let brushVisibility = clamp(
|
||||
brushStrength * (
|
||||
settings.brushColorBase +
|
||||
|
|
@ -68,7 +64,7 @@ fn renderColor(traces: vec4<f32>, sources: vec4<f32>, background: vec3<f32>) ->
|
|||
0,
|
||||
1
|
||||
);
|
||||
let color = max(normalizedTraceColor, normalizedBrushColor);
|
||||
let color = mix(traceColor, brushColor, brushVisibility);
|
||||
|
||||
let strength = max(maxComponent(strengths), brushVisibility);
|
||||
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);
|
||||
}
|
||||
|
||||
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> {
|
||||
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> {
|
||||
let brightestChannel = maxComponent(color);
|
||||
return color / max(settings.traceNormalizationFloor, brightestChannel);
|
||||
|
|
|
|||
Loading…
Reference in a new issue