Blob

A simple blob shader. You can tweak the speed, noise, color and amplitude. 

IMPORTANT! use small seamless noise textures for best results.

You should tweak some noise settings to get the result best fitting your needs.

Please leave some feedback, I would love to improve this! 

Thanks for your time!

Shader code
shader_type canvas_item;

//Noise texture only used if useSpriteTexture is set to false
uniform sampler2D noiseTexture;

//Wether to use shader param noise or texture as noise
uniform bool useSpriteTexture = false; 

//The speed of the movement
uniform float speed : hint_range(0.01,1.0) = 0.1; 

//How much it can differ from circle
uniform float amplitude : hint_range(0.01,1.0) = 0.2; 

float circle(vec2 center, float radius, vec2 p){
    return length(p - center) - radius;
}

void fragment(){
	vec4 noise;

	if (useSpriteTexture){
		noise = texture(TEXTURE, UV + speed * TIME) - 0.5;
	}
	else{
		noise = texture(noiseTexture, UV + speed * TIME) - 0.5;
	}
	
	float sdf = circle(vec2(0.5, 0.5), 0.4, UV) + amplitude * noise.r;

	if (sdf > 0.0){
		COLOR = vec4(1.0, 1.0, 1.0, 0.0);
	}
	else{
		COLOR = vec4(1.0, 1.0, 1.0, min(sdf*-200.0, 1.0));
	}
}
Tags
Abstract, Blob, Milk
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.
Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
NekotoArts
2 years ago

The second if statement fragments the GPU’s wavefront cycle. May not have much performance impact on this shader but its generally bad practice. Use the step() or smoothstep() functions instead:

shader_type canvas_item;


uniform sampler2D noiseTexture : hint_black;
uniform bool useSpriteTexture = false; 
uniform float speed : hint_range(0.01,1.0) = 0.1; 
uniform float amplitude : hint_range(0.01,1.0) = 0.2; 
uniform float aliasing = 0.01;


float circle(vec2 center, float radius, vec2 p){
	return length(p - center) - radius;
}


void fragment(){
	vec4 noise;
	if (useSpriteTexture){
		noise = texture(TEXTURE, UV + speed * TIME) - 0.5;
	} else {
		noise = texture(noiseTexture, UV + speed * TIME) - 0.5;
	}
	
	float sdf = circle(vec2(0.5, 0.5), 0.4, UV) + amplitude * noise.r;
	
	COLOR.rgb = vec3(1.0);
	COLOR.a = smoothstep(sdf, sdf + aliasing, 0.0);
}
Last edited 2 years ago by NekotoArts