pretty still wrong

This commit is contained in:
Orion Reed 2024-12-14 14:26:09 -05:00
parent 2ffe6360a4
commit 50c2bd52b8
1 changed files with 27 additions and 18 deletions

View File

@ -593,32 +593,41 @@ vec3 hsv2rgb(vec3 c) {
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
} }
// Smooth minimum function
float smoothMin(float a, float b, float k) {
float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0);
return mix(b, a, h) - k * h * (1.0 - h);
}
void main() { void main() {
vec4 texelEven = texture(u_textureEven, v_texCoord); vec4 texelEven = texture(u_textureEven, v_texCoord);
vec4 texelOdd = texture(u_textureOdd, v_texCoord); vec4 texelOdd = texture(u_textureOdd, v_texCoord);
// Extract shape IDs and distances // Extract shape IDs and distances
float shapeIDEven = texelEven.z; float shapeIDEven = texelEven.z;
float distanceEven = texelEven.a; float distanceEven = texelEven.a;
float shapeIDOdd = texelOdd.z; float shapeIDOdd = texelOdd.z;
float distanceOdd = texelOdd.a; float distanceOdd = texelOdd.a;
// Compute colors for even and odd distance fields // Use smooth minimum to merge distances
float hueEven = fract(shapeIDEven * 0.61803398875); // Golden ratio conjugate float k = 0.05; // Smoothing factor, adjust as needed
vec3 colorEven = hsv2rgb(vec3(hueEven, 0.5, 0.95)); float mergedDistance = smoothMin(distanceEven, distanceOdd, k);
float hueOdd = fract(shapeIDOdd * 0.61803398875); // Determine the contributing shape ID based on which distance is closer
vec3 colorOdd = hsv2rgb(vec3(hueOdd, 0.5, 0.95)); float h = clamp(0.5 + 0.5 * (distanceOdd - distanceEven) / k, 0.0, 1.0);
float mergedShapeID = mix(shapeIDOdd, shapeIDEven, h);
// Apply 'soft merge' function (e.g., weighted average based on distance) // Compute color based on the merged shape ID
float weightEven = exp(-distanceEven * 10.0); float hue = fract(mergedShapeID * 0.61803398875); // Golden ratio conjugate
float weightOdd = exp(-distanceOdd * 10.0); vec3 color = hsv2rgb(vec3(hue, 0.5, 0.95));
float totalWeight = weightEven + weightOdd;
vec3 mergedColor = (colorEven * weightEven + colorOdd * weightOdd) / totalWeight; // Optionally, you can adjust the brightness based on the merged distance
// For example, fade out colors further from the shapes
float brightness = exp(-mergedDistance * 10.0);
color *= brightness;
outColor = vec4(mergedColor, 1.0); outColor = vec4(color, 1.0);
}`; }`;
/** /**