3D Pulsing transparency

A simple shader to make a mesh’s transparency pulse. Useful for powerups!

Shader code
shader_type spatial;
render_mode blend_mix;

uniform sampler2D TEXTURE; // Declare the texture uniform
uniform float Frequency = 1.0;
uniform float MaxOpacity : hint_range(0, 1) = 1.0;
uniform float MinimumOpacity : hint_range(.5, 1) = 0.0;

void fragment() {
    vec4 tex_color = texture(TEXTURE, UV); 

    float base_alpha = tex_color.a; // Use the texture's alpha channel.
    float time_based_factor = sin(Frequency * TIME);

    // Ensure opacity stays within the defined range
    float opacity_range = (1.0 - time_based_factor) * MinimumOpacity;
    float final_opacity = fma(time_based_factor, MaxOpacity, opacity_range);

    ALBEDO = tex_color.rgb; // Use texture color for the mesh
    ALPHA = base_alpha * final_opacity; // Adjust opacity dynamically
}
Tags
3d, heart, opacity, pulsing, Transparent
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.

Related shaders

Simple World Triplanar Grid (Allows Transparency)

Decal Shader for 4.3 compatibility renderer + transparency support & no repeat

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments