Fix colour calculations if spectrum is entirely one value

If the range of the colour spectrum is 0, i.e. there is only one value for the current colour spectrum, then this would previously give a division by 0 in the shader, causing the final colour to become black. This is unexpected and makes the layer view hard to read. Instead, we'll now use the middle of the range then.
This was likely a problem for a long time but only really became visible due to the colour spectrum now showing only the range of values for the visible structures. Previously it was a problem e.g. for layer thickness if all layers had the same thickness (i.e. initial layer height == layer height).
This commit is contained in:
Ghostkeeper 2021-04-03 17:29:33 +02:00
parent 6209a08121
commit 71b217c624
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -44,7 +44,15 @@ vertex41core =
vec4 feedrateGradientColor(float abs_value, float min_value, float max_value) vec4 feedrateGradientColor(float abs_value, float min_value, float max_value)
{ {
float value = (abs_value - min_value)/(max_value - min_value); float value;
if(abs(max_value - min_value) < 0.0001) //Max and min are equal (barring floating point rounding errors).
{
value = 0.5; //Pick a colour in exactly the middle of the range.
}
else
{
value = (abs_value - min_value) / (max_value - min_value);
}
float red = value; float red = value;
float green = 1-abs(1-4*value); float green = 1-abs(1-4*value);
if (value > 0.375) if (value > 0.375)
@ -57,7 +65,15 @@ vertex41core =
vec4 layerThicknessGradientColor(float abs_value, float min_value, float max_value) vec4 layerThicknessGradientColor(float abs_value, float min_value, float max_value)
{ {
float value = (abs_value - min_value)/(max_value - min_value); float value;
if(abs(max_value - min_value) < 0.0001) //Max and min are equal (barring floating point rounding errors).
{
value = 0.5; //Pick a colour in exactly the middle of the range.
}
else
{
value = (abs_value - min_value) / (max_value - min_value);
}
float red = min(max(4*value-2, 0), 1); float red = min(max(4*value-2, 0), 1);
float green = min(1.5*value, 0.75); float green = min(1.5*value, 0.75);
if (value > 0.75) if (value > 0.75)
@ -70,7 +86,15 @@ vertex41core =
vec4 lineWidthGradientColor(float abs_value, float min_value, float max_value) vec4 lineWidthGradientColor(float abs_value, float min_value, float max_value)
{ {
float value = (abs_value - min_value) / (max_value - min_value); float value;
if(abs(max_value - min_value) < 0.0001) //Max and min are equal (barring floating point rounding errors).
{
value = 0.5; //Pick a colour in exactly the middle of the range.
}
else
{
value = (abs_value - min_value) / (max_value - min_value);
}
float red = value; float red = value;
float green = 1 - abs(1 - 4 * value); float green = 1 - abs(1 - 4 * value);
if(value > 0.375) if(value > 0.375)