Grayscale

Converts a texture to grayscale

Uniforms:
weighted: determines whether or not to use the normal average or weighted average for calculating the shade of gray (The weighted average is more accurate to human perception of colors)

Shader code
shader_type canvas_item;

// --- Uniforms --- //
uniform bool weighted = true;	// Determines whether to use normal or weighted averages

void fragment() {
	COLOR.rgb = mix(vec3((COLOR.r + COLOR.g + COLOR.b) / 3.0),  vec3(0.299 * COLOR.r + 0.587 * COLOR.g + 0.114 * COLOR.b), float(weighted));
}
Tags
gray, grayscale
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from KingToot

Erase

Radar Blip

Invert Color

Related shaders

Loading effect (color over grayscale)

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments