Luminance Mask Transition

A general purpose transition shader which uses greyscale masks to obscure/reveal the canvas behind a color rect over a scene.

Parameters:

  • luminance_cutoff – The cutoff point to apply the mask based on its sampled luminance. Sweep this value to transition.
  • invert – Inverts the behavior of luminance_cutoff.
  • mask_texture – A greyscale texture defining the mask. Transitions will ocurr from light to dark or dark to light depending on invert and luminance_cutoff.
  • display_texture – The texture to display over masked areas. Try a solid color like black or a loading image.
Shader code
shader_type canvas_item;

uniform float luminance_cutoff: hint_range(0.0, 1.0) = 0.0;
uniform bool invert = false;
uniform sampler2D mask_texture;
uniform sampler2D display_texture;

void fragment() {
	vec4 sample_color = texture(mask_texture, UV);
	float luminance = dot(sample_color.rgb, vec3(0.2126, 0.7152, 0.0722));
	bool filter = luminance > luminance_cutoff;
	if (invert) {
		filter = !filter;
	}
	
	if (filter) {
		COLOR = texture(display_texture, UV);
	} else {
		COLOR = vec4(1.0, 1.0, 1.0, 0.0) * texture(display_texture, UV);
	}
}
Live Preview
Tags
animated, luminance, mask, transition
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 null_builds

Related shaders

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments