Billboard shader help
Hi! I'm trying to implement a 3D billboard shader for sprites that preserves the sprite's original Z rotation and doesn't roll with the camera. I have a somewhat working solution, but the sprites start spinning at certain angles. Is it possible to eliminate this spinning? Thanks for any help! :)
shader_type spatial;
render_mode cull_back;
uniform sampler2D albedo_texture : source_color, filter_nearest;
uniform float transparency : hint_range(0.0, 1.0) = 0.0;
void vertex() {
vec3 forward = normalize(normalize((INV_VIEW_MATRIX * vec4(0.0, 0.0, 1.0, 0.0)).xyz));
vec3 right = normalize(cross(normalize(MODEL_MATRIX[1].xyz), forward));
MODELVIEW_MATRIX = VIEW_MATRIX * mat4(
vec4(right * length(MODEL_MATRIX[0]), 0.0),
vec4(cross(forward, right) * length(MODEL_MATRIX[1]), 0.0),
vec4(forward, 0.0),
MODEL_MATRIX[3]
);
NORMAL = forward;
}
void fragment() {
vec4 rgba = texture(albedo_texture, UV);
ALBEDO = rgba.rgb;
ALPHA = rgba.a * (1.0 - transparency);
}
Posted Jun 15, 2025, 3:20 PM UTC
20