Replies: 3 comments 5 replies
-
One could write a custom shader to accomplish this. |
Beta Was this translation helpful? Give feedback.
-
Here's implementation in gdscript. Altough I earlier suggested doing this in shader, this works too:
Just slap this into Sprite3D and you're good to go (set However, if this would make into core, I think it would make sense to accomplish this via modifying standard shader to support rotated billboard mode. |
Beta Was this translation helpful? Give feedback.
-
I know this is an old discussion, but since I stumbled here looking for the same thing, here is what I came up with. /**
* Generate a transformation matrix.
* This code comes from the Terrain3D project.
*/
mat3 rotation_matrix(vec3 axis, float angle) {
float c = cos(angle);
float s = sin(angle);
float t = 1.0 - c;
vec3 n = normalize(axis);
float x = n.x;
float y = n.y;
float z = n.z;
return mat3(
vec3(t * x * x + c, t * x * y - z * s, t * x * z + y * s),
vec3(t * x * y + z * s, t * y * y + c, t * y * z - x * s),
vec3(t * x * z - y * s, t * y * z + x * s, t * z * z + c));
}
void vertex() {
// Billboard Mode: Enabled (default Godot shader)
MODELVIEW_MATRIX = VIEW_MATRIX * mat4(
MAIN_CAM_INV_VIEW_MATRIX[0],
MAIN_CAM_INV_VIEW_MATRIX[1],
MAIN_CAM_INV_VIEW_MATRIX[2],
pos_matrix);
// rotation along the Z axis
// This is the added part
vec3 orientation = vec3(0.0, 0.0, 1.0);
// angle is a value between 0.0 and 1.0
float angle = INSTANCE_CUSTOM.z;
mat3 rotation = rotation_matrix(orientation, angle * TAU);
MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(rotation);
// Billboard Keep Scale: Enabled
MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(
vec4(length(MODEL_MATRIX[0].xyz), 0.0, 0.0, 0.0),
vec4(.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));
MODELVIEW_NORMAL_MATRIX = mat3(MODELVIEW_MATRIX);
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the project you are working on: I'm working on a 2.5D game where the world is 3D but the characters are flat 2D sprites that always face forward.
Describe the problem or limitation you are having in your project: I would like to animate the rotation of one of my player sprites so that it looks like they are flipping upside-down.
As it turns out, Rotation Degrees X/Y/Z have no effect on Sprite3Ds while in Billboard mode.
This makes sense for 2 of the 3 axes (depending on which axis is billboarded) because those need to be fudged in order to make sure the sprite is always facing "forward", but the third axis still makes sense for rotation.
Describe how this feature / enhancement will help you overcome this problem or limitation: Intuitively, one expects to be able to rotate sprites that are facing the screen. Doing so via vector math is complicated, and baking the rotation into a sprite sheet is impractical. Adding this feature to Godot would cause the engine to behave more in line with user expectations.
Show a mock up screenshots/video or a flow diagram explaining how your proposal will work
Here's the billboarded sprite as it currently exists, with a slight offset to the camera angle that's effectively "ignored" by billboarding:

Rotating along the Z-axis has no effect:

Turning off billboarding gets the desired rotation, but now the sprite isn't directly facing the camera:

However it's still clearly possible to have the sprite both face the camera and be rotated along this axis. In this case that was faked by adding some Y-rotation:

Ideally I'd be able to end up with that last screenshot merely by setting the Z-rotation of a billboarded Sprite3D.
Describe implementation detail for your proposal (in code), if possible: I don't know enough about the back-end implementation but it ought to be pretty simple: take into account rotation values for whatever axis we're billboarded on, and apply them to the final rendering.
If this enhancement will not be used often, can it be worked around with a few lines of script? One would have to figure out the vector math necessary to perform billboarding relative to the current active camera and then apply it to every in-game object they wanted to rotate. That seems like a lot for a property that's already exposed in the editor (but ignored in billboard mode).
Is there a reason why this should be core and not an add-on in the asset library? It affects core functionality.
Beta Was this translation helpful? Give feedback.
All reactions