Tile face circle cutout

A simple circle cutout shader applied to the top face of a tile. 

 

This is a simplified version of a tile shader I made for my game, Cuboria. It was originally designed to be used for spawning objects on tiles that grow, and a circle of grass would expand around it as it grew. Go to this video for an example on how I expanded the shader for use in my game. And to see an example test scene of the spawn tile that uses it, watch this video

Shader code
shader_type spatial;

uniform vec4 cutout_color : source_color;
uniform vec4 base_color : source_color;

uniform float circle_size : hint_range(0.0, 1.0);

varying float is_up;
const vec3 up = vec3(0.0, 1.0, 0.0);

varying vec2 uv;

void vertex() {
	vec3 normal_dir = normalize(NORMAL);
	float scalar = dot(normal_dir, up);
	
	is_up = step(0.99, scalar);
	uv = UV*vec2(3.0, 2.0)*is_up + (1.0 - is_up)*UV;
}

void fragment() {	
	float dist = distance(uv, vec2(1.5, 1.5));
	float circle = (1.0 - step(circle_size/2.0, dist));
	
	vec4 mask = cutout_color*circle + base_color*(1.0 - circle);
	
	ALBEDO = is_up*mask.rgb + (1.0 - is_up)*base_color.rgb;
}
Live Preview
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

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments