mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
Update asciiart.glsl
This commit is contained in:
@ -53,32 +53,31 @@ void main()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
The next lines are a bit harder, hf :-)
|
||||
// The next lines are a bit harder, hf :-)
|
||||
|
||||
The idea is to find the perfect char with the perfect background color and the perfect font color.
|
||||
As this is an equation with three unknowns, we can't just try all chars and color combinations.
|
||||
// The idea is to find the perfect char with the perfect background color and the perfect font color.
|
||||
// As this is an equation with three unknowns, we can't just try all chars and color combinations.
|
||||
|
||||
As criterion how "perfect" the selection is, we compare the "mean squared error" of the resulted colors of all chars.
|
||||
So, now the big issue: how to calculate the MSE without knowing the two colors ...
|
||||
// As criterion how "perfect" the selection is, we compare the "mean squared error" of the resulted colors of all chars.
|
||||
// So, now the big issue: how to calculate the MSE without knowing the two colors ...
|
||||
|
||||
In the next steps, "a" is the font color, "b" is the background color, "f" is the font value at this pixel, "t" is the texture value
|
||||
// In the next steps, "a" is the font color, "b" is the background color, "f" is the font value at this pixel, "t" is the texture value
|
||||
|
||||
So the square error of one pixel is:
|
||||
e = ( t - a⋅f - b⋅(1-f) ) ^ 2
|
||||
// So the square error of one pixel is:
|
||||
// e = ( t - a⋅f - b⋅(1-f) ) ^ 2
|
||||
|
||||
In longer:
|
||||
e = a^2⋅f^2 - 2⋅a⋅b⋅f^2 + 2⋅a⋅b⋅f - 2⋅a⋅f⋅t + b^2⋅f^2 - 2⋅b^2⋅f + b^2 + 2⋅b⋅f⋅t - 2⋅b⋅t + t^2
|
||||
// In longer:
|
||||
// e = a^2⋅f^2 - 2⋅a⋅b⋅f^2 + 2⋅a⋅b⋅f - 2⋅a⋅f⋅t + b^2⋅f^2 - 2⋅b^2⋅f + b^2 + 2⋅b⋅f⋅t - 2⋅b⋅t + t^2
|
||||
|
||||
The sum of all errors is: (as shortcut, ff,f,ft,t,tt are now the sums like declared above, sum(1) is the count of pixels)
|
||||
sum(e) = a^2⋅ff - 2⋅a^2⋅ff + 2⋅a⋅b⋅f - 2⋅a⋅ft + b^2⋅ff - 2⋅b^2⋅f + b^2⋅sum(1) + 2⋅b⋅ft - 2⋅b⋅t + tt
|
||||
// The sum of all errors is: (as shortcut, ff,f,ft,t,tt are now the sums like declared above, sum(1) is the count of pixels)
|
||||
// sum(e) = a^2⋅ff - 2⋅a^2⋅ff + 2⋅a⋅b⋅f - 2⋅a⋅ft + b^2⋅ff - 2⋅b^2⋅f + b^2⋅sum(1) + 2⋅b⋅ft - 2⋅b⋅t + tt
|
||||
|
||||
To find the minimum, we have to derive this by "a" and "b":
|
||||
d/da sum(e) = 2⋅a⋅ff + 2⋅b⋅f - 2⋅b⋅ff - 2⋅ft
|
||||
d/db sum(e) = 2⋅a⋅f - 2⋅a⋅ff - 4⋅b⋅f + 2⋅b⋅ff + 2⋅b⋅sum(1) + 2⋅ft - 2⋅t
|
||||
// To find the minimum, we have to derive this by "a" and "b":
|
||||
// d/da sum(e) = 2⋅a⋅ff + 2⋅b⋅f - 2⋅b⋅ff - 2⋅ft
|
||||
// d/db sum(e) = 2⋅a⋅f - 2⋅a⋅ff - 4⋅b⋅f + 2⋅b⋅ff + 2⋅b⋅sum(1) + 2⋅ft - 2⋅t
|
||||
|
||||
// So, both equations must be zero at minimum and there is only one solution.
|
||||
|
||||
So, both equations must be zero at minimum and there is only one solution.
|
||||
*/
|
||||
vec4 a = (f*ft - ff*t + f*t - ft*float(char_pixels)) / (f*f - ff*float(char_pixels));
|
||||
vec4 b = (f*ft - ff*t) / (f*f - ff*float(char_pixels));
|
||||
|
||||
|
Reference in New Issue
Block a user