UV light (2D and 3D)

This is an example of a “UV light” shader, useful for secret messages.

Remember to:
* put the UV light source in a separate layer
* put secret objects in the same layer (`light_cull_mask`)
* remove normal light sources from that layer (`light_cull_mask`)

Shader code
// 2D objects, e.g. text on a wall, where the shape is defined by a texture
shader_type spatial;

uniform sampler2D tex;
uniform vec4 color: hint_color = vec4(0, 1, 1, 1);
uniform float energy: hint_range(0, 16) = 1;

void fragment() {
	EMISSION = color.rgb * energy;
	ALPHA = 0.0;
}

void light() {
	vec4 pixel = textureLod(tex, UV, 1.0);
	DIFFUSE_LIGHT = vec3(0.0);
	ALPHA = length(ATTENUATION) * pixel.a;
}

// 3D objects, e.g. a ghost, where the shape is defined by geometry
shader_type spatial;

uniform vec4 color: hint_color = vec4(0, 1, 1, 1);
uniform float energy: hint_range(0, 16) = 1;

void fragment() {
	EMISSION = color.rgb * energy;
	ALPHA = 0.0;
}

void light() {
	DIFFUSE_LIGHT = vec3(0.0);
	SPECULAR_LIGHT = vec3(0.0);
	ALPHA = length(ATTENUATION);
}
Tags
light, uv
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 miskatonicstudio

Aurora Borealis

Hexagon pattern

Frosted glass

Related shaders

UCBC’s Stylized Light with Light Masking

Modulate Before Light

Notes on the light function

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments