Merge pull request #68863 from clayjohn/RD-2D-skeleton

Fix drawing of 2D skeletons in the RD renderer.
This commit is contained in:
Rémi Verschelde 2022-11-19 10:25:31 +01:00 committed by GitHub
commit 895428c805
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 15 additions and 111 deletions

View File

@ -153,48 +153,6 @@ void main() {
uv += 1e-5;
}
#ifdef USE_ATTRIBUTES
#if 0
if (bool(draw_data[draw_data_instance].flags & FLAGS_USE_SKELETON) && bone_weights != vec4(0.0)) { //must be a valid bone
//skeleton transform
ivec4 bone_indicesi = ivec4(bone_indices);
uvec2 tex_ofs = bone_indicesi.x * 2;
mat2x4 m;
m = mat2x4(
texelFetch(skeleton_buffer, tex_ofs + 0),
texelFetch(skeleton_buffer, tex_ofs + 1)) *
bone_weights.x;
tex_ofs = bone_indicesi.y * 2;
m += mat2x4(
texelFetch(skeleton_buffer, tex_ofs + 0),
texelFetch(skeleton_buffer, tex_ofs + 1)) *
bone_weights.y;
tex_ofs = bone_indicesi.z * 2;
m += mat2x4(
texelFetch(skeleton_buffer, tex_ofs + 0),
texelFetch(skeleton_buffer, tex_ofs + 1)) *
bone_weights.z;
tex_ofs = bone_indicesi.w * 2;
m += mat2x4(
texelFetch(skeleton_buffer, tex_ofs + 0),
texelFetch(skeleton_buffer, tex_ofs + 1)) *
bone_weights.w;
mat4 bone_matrix = skeleton_data.skeleton_transform * transpose(mat4(m[0], m[1], vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0))) * skeleton_data.skeleton_transform_inverse;
//outvec = bone_matrix * outvec;
}
#endif
#endif
vertex = (canvas_transform * vec4(vertex, 0.0, 1.0)).xy;
vertex_interp = vertex;

View File

@ -114,7 +114,7 @@ void Polygon2D::_notification(int p_what) {
ObjectID new_skeleton_id;
if (skeleton_node) {
if (skeleton_node && !invert && bone_weights.size()) {
RS::get_singleton()->canvas_item_attach_skeleton(get_canvas_item(), skeleton_node->get_skeleton());
new_skeleton_id = skeleton_node->get_instance_id();
} else {

View File

@ -32,7 +32,7 @@
#include "servers/rendering/rendering_server_globals.h"
const Rect2 &RendererCanvasRender::Item::get_rect() const {
if (custom_rect || (!rect_dirty && !update_when_visible)) {
if (custom_rect || (!rect_dirty && !update_when_visible && skeleton == RID())) {
return rect;
}
@ -80,7 +80,7 @@ const Rect2 &RendererCanvasRender::Item::get_rect() const {
} break;
case Item::Command::TYPE_MESH: {
const Item::CommandMesh *mesh = static_cast<const Item::CommandMesh *>(c);
AABB aabb = RSG::mesh_storage->mesh_get_aabb(mesh->mesh, RID());
AABB aabb = RSG::mesh_storage->mesh_get_aabb(mesh->mesh, skeleton);
r = Rect2(aabb.position.x, aabb.position.y, aabb.size.x, aabb.size.y);

View File

@ -2681,16 +2681,6 @@ RendererCanvasRenderRD::RendererCanvasRenderRD() {
primitive_arrays.index_array[3] = shader.quad_index_array = RD::get_singleton()->index_array_create(shader.quad_index_buffer, 0, 6);
}
{ //default skeleton buffer
shader.default_skeleton_uniform_buffer = RD::get_singleton()->uniform_buffer_create(sizeof(SkeletonUniform));
SkeletonUniform su;
_update_transform_2d_to_mat4(Transform2D(), su.skeleton_inverse);
_update_transform_2d_to_mat4(Transform2D(), su.skeleton_transform);
RD::get_singleton()->buffer_update(shader.default_skeleton_uniform_buffer, 0, sizeof(SkeletonUniform), &su);
shader.default_skeleton_texture_buffer = RD::get_singleton()->texture_buffer_create(32, RD::DATA_FORMAT_R32G32B32A32_SFLOAT);
}
{
//default shadow texture to keep uniform set happy
RD::TextureFormat tf;
@ -2834,8 +2824,6 @@ RendererCanvasRenderRD::~RendererCanvasRenderRD() {
memdelete_arr(state.light_uniforms);
RD::get_singleton()->free(state.lights_uniform_buffer);
RD::get_singleton()->free(shader.default_skeleton_uniform_buffer);
RD::get_singleton()->free(shader.default_skeleton_texture_buffer);
}
//shadow rendering

View File

@ -144,10 +144,6 @@ class RendererCanvasRenderRD : public RendererCanvasRender {
RID quad_index_array;
PipelineVariants pipeline_variants;
// default_skeleton uniform set
RID default_skeleton_uniform_buffer;
RID default_skeleton_texture_buffer;
ShaderCompiler compiler;
} shader;
@ -409,11 +405,6 @@ class RendererCanvasRenderRD : public RendererCanvasRender {
uint32_t lights[4];
};
struct SkeletonUniform {
float skeleton_transform[16];
float skeleton_inverse[16];
};
Item *items[MAX_RENDER_ITEMS];
bool using_directional_lights = false;

View File

@ -191,48 +191,6 @@ void main() {
uv += 1e-5;
}
#ifdef USE_ATTRIBUTES
#if 0
if (bool(draw_data.flags & FLAGS_USE_SKELETON) && bone_weights != vec4(0.0)) { //must be a valid bone
//skeleton transform
ivec4 bone_indicesi = ivec4(bone_indices);
uvec2 tex_ofs = bone_indicesi.x * 2;
mat2x4 m;
m = mat2x4(
texelFetch(skeleton_buffer, tex_ofs + 0),
texelFetch(skeleton_buffer, tex_ofs + 1)) *
bone_weights.x;
tex_ofs = bone_indicesi.y * 2;
m += mat2x4(
texelFetch(skeleton_buffer, tex_ofs + 0),
texelFetch(skeleton_buffer, tex_ofs + 1)) *
bone_weights.y;
tex_ofs = bone_indicesi.z * 2;
m += mat2x4(
texelFetch(skeleton_buffer, tex_ofs + 0),
texelFetch(skeleton_buffer, tex_ofs + 1)) *
bone_weights.z;
tex_ofs = bone_indicesi.w * 2;
m += mat2x4(
texelFetch(skeleton_buffer, tex_ofs + 0),
texelFetch(skeleton_buffer, tex_ofs + 1)) *
bone_weights.w;
mat4 bone_matrix = skeleton_data.skeleton_transform * transpose(mat4(m[0], m[1], vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0))) * skeleton_data.skeleton_transform_inverse;
//outvec = bone_matrix * outvec;
}
#endif
#endif
vertex = (canvas_data.canvas_transform * vec4(vertex, 0.0, 1.0)).xy;
vertex_interp = vertex;

View File

@ -143,8 +143,8 @@ void main() {
uint skin_offset = params.skin_stride * index;
uvec2 bones = uvec2(src_bone_weights.data[skin_offset + 0], src_bone_weights.data[skin_offset + 1]);
uvec2 bones_01 = uvec2(bones.x & 0xFFFF, bones.x >> 16) * 3; //pre-add xform offset
uvec2 bones_23 = uvec2(bones.y & 0xFFFF, bones.y >> 16) * 3;
uvec2 bones_01 = uvec2(bones.x & 0xFFFF, bones.x >> 16) * 2; //pre-add xform offset
uvec2 bones_23 = uvec2(bones.y & 0xFFFF, bones.y >> 16) * 2;
skin_offset += params.skin_weight_offset;
@ -161,6 +161,13 @@ void main() {
//reverse order because its transposed
vertex = (vec4(vertex, 0.0, 1.0) * m).xy;
}
uint dst_offset = index * params.vertex_stride;
uvec2 uvertex = floatBitsToUint(vertex);
dst_vertices.data[dst_offset + 0] = uvertex.x;
dst_vertices.data[dst_offset + 1] = uvertex.y;
#else
vec3 vertex;
vec3 normal;

View File

@ -616,7 +616,7 @@ AABB MeshStorage::mesh_get_aabb(RID p_mesh, RID p_skeleton) {
Skeleton *skeleton = skeleton_owner.get_or_null(p_skeleton);
if (!skeleton || skeleton->size == 0) {
if (!skeleton || skeleton->size == 0 || mesh->skeleton_aabb_version == skeleton->version) {
return mesh->aabb;
}
@ -708,6 +708,7 @@ AABB MeshStorage::mesh_get_aabb(RID p_mesh, RID p_skeleton) {
}
}
mesh->skeleton_aabb_version = skeleton->version;
return aabb;
}

View File

@ -144,6 +144,7 @@ private:
AABB aabb;
AABB custom_aabb;
uint64_t skeleton_aabb_version = 0;
Vector<RID> material_cache;