Discuss Scratch

Crow_Boy08
Scratcher
1000+ posts

why does infinity color return grayscale?

set [color v] effect to (join [] [infinity])
medians
Scratcher
1000+ posts

why does infinity color return grayscale?

..You guys have fun..

Also probably just to return grayscale since they wanted a workaround for it. That's probably my only guess LOL
Crow_Boy08
Scratcher
1000+ posts

why does infinity color return grayscale?


.

Last edited by Crow_Boy08 (Jan. 8, 2023 04:19:18)

medians
Scratcher
1000+ posts

why does infinity color return grayscale?

Crow_Boy08 wrote:

medians wrote:

..You guys have fun..
Also probably just to return grayscale since they wanted a workaround for it. That's probably my only guess LOL
your pain is epilepsy
Yea and not being able to memorate the raccoon potato..

AHHH
Yeah, higher values don’t even turn it black/grey, yet 1/0 does LOL.
ScratchCreatesIt
Scratcher
7 posts

why does infinity color return grayscale?

Here's my guess, since the number is too high, Scratch isn't able to perfectly divide by 100 (that's the scale) and so it turns black and white.

Let me know if you know the answer!
-Valtren-
Scratcher
1000+ posts

why does infinity color return grayscale?

it's an error last I checked.
jlnilocalsip
New Scratcher
100+ posts

why does infinity color return grayscale?

Jesus everloving Christ, this bug needs to be fixed immediately for the good and wellbeing of all Scratchers.
-Valtren-
Scratcher
1000+ posts

why does infinity color return grayscale?

jlnilocalsip wrote:

Jesus everloving Christ, this bug needs to be fixed immediately for the good and wellbeing of all Scratchers.
then how are we supposed to get greyscale? also it's not as if this harms anyone
hi875230163394
Scratcher
1000+ posts

why does infinity color return grayscale?

medians wrote:

Yeah, higher values don’t even turn it black/grey, yet 1/0 does LOL.
1/0 returns infinity, it also does this in JS

the question is, was this intentional, and did it exist before 3.0 started using JS
Maximouse
Scratcher
1000+ posts

why does infinity color return grayscale?

hi875230163394 wrote:

medians wrote:

Yeah, higher values don’t even turn it black/grey, yet 1/0 does LOL.
1/0 returns infinity, it also does this in JS

the question is, was this intentional, and did it exist before 3.0 started using JS
Scratch 2.0 was written in ActionScript, a JS dialect, so infinity worked the same way. It didn't break the color effect though, so I think the 3.0 behavior is a bug.
Lionwarriorspets
Scratcher
1000+ posts

why does infinity color return grayscale?

don't work.
-HatsuMiku-
Scratcher
30 posts

why does infinity color return grayscale?

-Valtren- wrote:

jlnilocalsip wrote:

Jesus everloving Christ, this bug needs to be fixed immediately for the good and wellbeing of all Scratchers.
then how are we supposed to get greyscale? also it's not as if this harms anyone
If anything, it actually benefits them.
awesome-llama
Scratcher
1000+ posts

why does infinity color return grayscale?

I can guess by looking at the code…
I haven't gone to the length of running it or debugging it, I am only reading it and guessing what the functions are doing with certain data.

One of the places that the effect blocks are implemented is in the sprite fragment shader.
https://github.com/LLK/scratch-render/blob/develop/src/shaders/sprite.frag

Here's the line responsible for changing hue and also setting the RGB colour afterwards. (hsv is a 3D vector here and the x component would be hue, u_color is the value from the colour effect)
hsv.x = mod(hsv.x + u_color, 1.0);
if (hsv.x < 0.0) hsv.x += 1.0;
gl_FragColor.rgb = convertHSV2RGB(hsv);

I assume what's happening is the modulo operator is not able to handle Infinity and so it returns something that ends up affecting the HSV to RGB conversion afterwards in an unexpected way.

Also here's the conversion code:
vec3 convertHue2RGB(float hue)
{
	float r = abs(hue * 6.0 - 3.0) - 1.0;
	float g = 2.0 - abs(hue * 6.0 - 2.0);
	float b = 2.0 - abs(hue * 6.0 - 4.0);
	return clamp(vec3(r, g, b), 0.0, 1.0);
}
vec3 convertHSV2RGB(vec3 hsv)
{
	vec3 rgb = convertHue2RGB(hsv.x);
	float c = hsv.z * hsv.y;
	return rgb * c + hsv.z - c;
}

medians
Scratcher
1000+ posts

why does infinity color return grayscale?

hi875230163394 wrote:

medians wrote:

Yeah, higher values don’t even turn it black/grey, yet 1/0 does LOL.
1/0 returns infinity, it also does this in JS

the question is, was this intentional, and did it exist before 3.0 started using JS
Yea I don’t think so.

jlnilocalsip wrote:

Jesus everloving Christ, this bug needs to be fixed immediately for the good and wellbeing of all Scratchers.
Oh it’s the greyscale dude
_Icicle-Cube_
Scratcher
500+ posts

why does infinity color return grayscale?

Lionwarriorspets wrote:

don't work.
try doing this:
set [color v] effect to ((1) / (0))
as far as I know, that code makes it greayscale.
Vadik1
Scratcher
500+ posts

why does infinity color return grayscale?

-Valtren- wrote:

then how are we supposed to get greyscale? also it's not as if this harms anyone
People shouldn't use this way of getting greyscale, as it is very unreliable. The results of setting color to infinity differ depending on device and the browser.
I tested it on 3 devices and got different results:
Desktop computer running Chromium 107 (greyscale):

Android phone (with Mali-G71 GPU) made in 2019 running Chrome 108 (like greyscale, except it's shades of red):

Android tablet (with Mali-400 MP GPU) made in 2013 running Chrome 81 (slight red tint):


A reliable and better looking way to get greyscale is to have costume, with this same costume overlayed on top with color=100 and ghost=50.

Last edited by Vadik1 (Jan. 13, 2023 15:44:20)

_Icicle-Cube_
Scratcher
500+ posts

why does infinity color return grayscale?

Vadik1 wrote:

-Valtren- wrote:

then how are we supposed to get greyscale? also it's not as if this harms anyone
People shouldn't use this way of getting greyscale, as it is very unreliable. The results of setting color to infinity differ depending on device and the browser.
-snip-

A reliable and better looking way to get greyscale is to have costume, with this same costume overlayed on top with color=100 and ghost=50.
I did it the way you said, and it came out as blue, not greay.
doesn't work, doing
change [color v] effect by ((1)/(0))
works though.
Vadik1
Scratcher
500+ posts

why does infinity color return grayscale?

_Icicle-Cube_ wrote:

Vadik1 wrote:


A reliable and better looking way to get greyscale is to have costume, with this same costume overlayed on top with color=100 and ghost=50.
I did it the way you said, and it came out as blue, not greay.
doesn't work
I meant something like:
blablablahello
Scratcher
1000+ posts

why does infinity color return grayscale?

I feel like this probably has to do with how the colors are calculated, at infinity, the algorithm probably just thinks “hey, how bout no color at all”
Vadik1
Scratcher
500+ posts

why does infinity color return grayscale?

awesome-llama wrote:

I assume what's happening is the modulo operator is not able to handle Infinity and so it returns something that ends up affecting the HSV to RGB conversion afterwards in an unexpected way.
It returns NaN.
Any mathematical operation with NaN also results in NaN.
When given NaN, “clamp(value, minimum, maximum)” always returns it's minimum value.

It can be verified, by running the following glsl code on https://www.shadertoy.com/new
(pause and then reset animation to time 0, so that iTime is also 0)
void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // Clamp turns NaN into it's minimum value
    float col = clamp(mod(1.0/iTime, 1.0), -1.0, 1.0)+1.5; // col = -1.0+1.5 = 0.5
    fragColor = vec4(vec3(col),1.0); // vec(0.5, 0.5, 0.5, 1.0)  is grey
}
void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // Without clamp, NaN leaks and turns everything into NaN
    float col = mod(1.0/iTime, 1.0)+1.5; // col = NaN+1.5 = NaN, not 1.5
    fragColor = vec4(vec3(col),1.0); // vec(NaN, NaN, NaN, 1.0)  is black
}
void mainImage( out vec4 fragColor, in vec2 fragCoord ) { // If it was 1.5
    float col = 0.0+1.5; // col = 1.5
    fragColor = vec4(vec3(col),1.0); // vec(1.5, 1.5, 1.5, 1.0)  is white
}

So, in scratch:
mod(hue + Infinity, 1.0) returns NaN
if(hsv.x < 0) doesn't trigger
convertHSV2RGB is called with hsv in which x=NaN
convertHue2RGB is called with hue=NaN
Inside of it, as the result of calculations: r=NaN, g=NaN, b=NaN
Clamping vector of those values to range between 0 and 1 returns vector of 3 zeroes, which is black.
Brightness and saturation are added on top of black, which results in greyscale.

Powered by DjangoBB