Medical Cross

This shader creates a medical cross (which you may have seen on pharmacies in the CIS countries).

You can adjust the size of the circles, the color, the number of circles, and the size of the cross’s edges. You can also enable transparency for the entire background (leaving only the circles in the shape of a cross) by using – `full_transparent_background`. Alternatively, you can make the background transparent only outside the cross by using – `transparent_background`.

It’s important to note that `full_transparent_background` has a higher transparency priority.

Shader code
shader_type spatial;


uniform float width_hrestic : hint_range(0.001, 0.15, 0.001) = 0.03;
uniform vec3 color_hrestic : source_color = vec3(0.264, 1.222, 0.571);

uniform float reduction_coefficient : hint_range(0.5, 1.0, 0.01) = 0.75;
uniform float count_pixel : hint_range(1.0, 100.0, 1.0) = 25.0;

uniform bool full_transparent_background = false;
uniform bool transparent_background = false;

const float COUNT_PIXEL_HRESTIC = 100.0;


float generate_alpha(float original_alpha, float limit_x, float limit_y) {
	float alpha_full_background = full_transparent_background ? original_alpha : 1.0;
	
	float alpha_background = transparent_background ? 0.0 : 1.0;
	if (limit_x < width_hrestic || limit_y < width_hrestic) {
		alpha_background = 1.0;
	}
	
	return alpha_background * alpha_full_background;
}

float generate_circle_map(vec2 uv) {
	float pixel_x = floor(uv.x * count_pixel) / count_pixel;
	float pixel_y = floor(uv.y * count_pixel) / count_pixel;
	vec2 pixel_coord = vec2(pixel_x, pixel_y);
	
	vec2 pixel_size = vec2(1.0 / count_pixel);
	vec2 pixel_center = pixel_coord + pixel_size * 0.5;
	float distance_to_center_pixel = 1.0 - distance(vec2(uv.x, uv.y), pixel_center) * count_pixel;
	return smoothstep(reduction_coefficient, reduction_coefficient, distance_to_center_pixel);
}

vec3 painting_hrestik(float limit_x, float limit_y) {
	vec3 hrestic_texture = vec3(0.0);
	
	if (limit_x < width_hrestic || limit_y < width_hrestic) {
		hrestic_texture = color_hrestic;
	}
	
	return hrestic_texture;
}

void fragment() {
	const vec2 CENTRED_UV = UV - 0.5;
	const vec2 PIXILATE_UV = floor(CENTRED_UV * COUNT_PIXEL_HRESTIC) / COUNT_PIXEL_HRESTIC;

	float width_x = PIXILATE_UV.x * PIXILATE_UV.x;
	float width_y = PIXILATE_UV.y * PIXILATE_UV.y;
	
	// Hrestik painting
	vec3 hrestic_texture = painting_hrestik(width_x, width_y);
	
	// Generate circle map
	float circle_map = generate_circle_map(UV);
	
	// Alpha background/full generate
	float original_alpha_pixel = hrestic_texture.g * circle_map;
	float pixel_alpha = generate_alpha(original_alpha_pixel, width_x, width_y);
	
	// Paste data
	vec3 hrestic_with_circle = hrestic_texture * circle_map;
	ALBEDO = hrestic_with_circle;
	ALPHA = pixel_alpha;
}
Live Preview
Tags
cross
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.
guest

0 Comments
Oldest
Newest Most Voted