Analytical Die / Dice Texture

No textures! Only boolean math goodness!

I challenge you to do this in less lines (of reasonable length of course)

Shader code
shader_type canvas_item;

uniform int value: hint_range(1, 6, 1) = 1;

void fragment() {
	vec2 uv = UV * 3.0;
	float d = distance(ceil(uv) - 0.5, uv) - 0.45;
	float m = smoothstep(fwidth(d), 0.0, d);
	int c = abs(int(floor(uv.y) * 3.0 + floor(uv.x)) - 4);
	
	m *= float(c != 3);
	m *= float(c != 2 || value >= 2);
	m *= float(c != 4 || value >= 4);
	m *= float(c != 1 || value >= 6);
	m *= float(c != 0 || value % 2 == 1);
	
	COLOR.rgb = vec3(1.0 - m);
}
Live Preview
Tags
2d, analytical, canvas_item, dice, die, game, texture
The shader code and all code snippets in this post are under MIT license and can be used freely. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from Snowlith

Filtered 2D Checkerboard Grid

Related shaders

Tiled texture plus offset texture overlay

Texture population using Texture

Stylized Cloud as texture

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments