I want to use 2d images and animations to represent characters emotions.
For this I want the images to always rendered in front of them, regardless of which angle you look at.
While billboard helps to keep the images facing towards the camera, it doesn't prevent it from clipping into the models.
Is there an easy way to do this?
How do I render objects always in front of other objects?
- Best Answerset by SuperDoomKing
SuperDoomKing You can try bilboarded 3d sprites with depth test disabled.
Maybe slap a Spatial node in the model and insert the effect as a 2D sprite like it's GUI or something on top of where the Spatial node is positioned on screen.
The effect would probably get weird with certain camera angles.
Just spitballing.
xyz
Thanks, that seems to work.
xyz You can try bilboarded 3d sprites with depth test disabled.
This is likely the simplest solution, but can also have it's downsides. Say there's a tree between the character and the camera, the billboard will now also be rendered over the tree appearing in front of it.
- Edited
The idea is this. A sphere is created around the character's head, which encompasses the entire head. A billboard shader is applied to this sphere, with an emotion.
- The emotion is always on top of the head.
- Trees (objects in the foreground) overlap the emotion.
shader_type spatial;
uniform sampler2D texture2D;
varying vec2 tex_position;
void vertex() {
mat4 emotion;
// GetBillboardMatrix:2
{
mat4 __mvm = VIEW_MATRIX * mat4(INV_VIEW_MATRIX[0], INV_VIEW_MATRIX[1], INV_VIEW_MATRIX[2], MODEL_MATRIX[3]);
__mvm = __mvm * mat4(vec4(length(MODEL_MATRIX[0].xyz), 0.0, 0.0, 0.0), vec4(0.0, length(MODEL_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, length(MODEL_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));
emotion = __mvm;
}
// Output:0
MODELVIEW_MATRIX = emotion;
}
void fragment() {
tex_position = VERTEX.xy * 3.0 - 0.05;
ALBEDO = texture(texture2D, tex_position).xyz;
ALPHA = 1.0 - texture(texture2D, tex_position).z;
}