Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 6051576

Browse files
authored
[Impeller Scene] Compute joint transforms and apply them to skinned meshes (#38628)
1 parent cdd3bf2 commit 6051576

File tree

25 files changed

+429
-67
lines changed

25 files changed

+429
-67
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,8 @@ ORIGIN: ../../../flutter/impeller/scene/scene_encoder.h + ../../../flutter/LICEN
16471647
ORIGIN: ../../../flutter/impeller/scene/shaders/skinned.vert + ../../../flutter/LICENSE
16481648
ORIGIN: ../../../flutter/impeller/scene/shaders/unlit.frag + ../../../flutter/LICENSE
16491649
ORIGIN: ../../../flutter/impeller/scene/shaders/unskinned.vert + ../../../flutter/LICENSE
1650+
ORIGIN: ../../../flutter/impeller/scene/skin.cc + ../../../flutter/LICENSE
1651+
ORIGIN: ../../../flutter/impeller/scene/skin.h + ../../../flutter/LICENSE
16501652
ORIGIN: ../../../flutter/impeller/tessellator/c/tessellator.cc + ../../../flutter/LICENSE
16511653
ORIGIN: ../../../flutter/impeller/tessellator/c/tessellator.h + ../../../flutter/LICENSE
16521654
ORIGIN: ../../../flutter/impeller/tessellator/dart/lib/tessellator.dart + ../../../flutter/LICENSE
@@ -4116,6 +4118,8 @@ FILE: ../../../flutter/impeller/scene/scene_encoder.h
41164118
FILE: ../../../flutter/impeller/scene/shaders/skinned.vert
41174119
FILE: ../../../flutter/impeller/scene/shaders/unlit.frag
41184120
FILE: ../../../flutter/impeller/scene/shaders/unskinned.vert
4121+
FILE: ../../../flutter/impeller/scene/skin.cc
4122+
FILE: ../../../flutter/impeller/scene/skin.h
41194123
FILE: ../../../flutter/impeller/tessellator/c/tessellator.cc
41204124
FILE: ../../../flutter/impeller/tessellator/c/tessellator.h
41214125
FILE: ../../../flutter/impeller/tessellator/dart/lib/tessellator.dart
-132 Bytes
Binary file not shown.

impeller/renderer/backend/gles/texture_gles.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ struct TexImage2DData {
107107
external_format = GL_RGBA;
108108
type = GL_UNSIGNED_BYTE;
109109
break;
110+
case PixelFormat::kR32G32B32A32Float:
111+
internal_format = GL_RGBA;
112+
external_format = GL_RGBA;
113+
type = GL_FLOAT;
114+
break;
115+
case PixelFormat::kR16G16B16A16Float:
116+
internal_format = GL_RGBA;
117+
external_format = GL_RGBA;
118+
type = GL_HALF_FLOAT;
119+
break;
110120
case PixelFormat::kUnknown:
111121
case PixelFormat::kS8UInt:
112122
case PixelFormat::kD32FloatS8UInt:
@@ -136,6 +146,20 @@ struct TexImage2DData {
136146
data = std::move(mapping);
137147
break;
138148
}
149+
case PixelFormat::kR32G32B32A32Float: {
150+
internal_format = GL_RGBA;
151+
external_format = GL_RGBA;
152+
type = GL_FLOAT;
153+
data = std::move(mapping);
154+
break;
155+
}
156+
case PixelFormat::kR16G16B16A16Float: {
157+
internal_format = GL_RGBA;
158+
external_format = GL_RGBA;
159+
type = GL_HALF_FLOAT;
160+
data = std::move(mapping);
161+
break;
162+
}
139163
case PixelFormat::kR8G8B8A8UNormIntSRGB:
140164
case PixelFormat::kB8G8R8A8UNormInt:
141165
case PixelFormat::kB8G8R8A8UNormIntSRGB:
@@ -274,6 +298,10 @@ static std::optional<GLenum> ToRenderBufferFormat(PixelFormat format) {
274298
case PixelFormat::kB8G8R8A8UNormInt:
275299
case PixelFormat::kR8G8B8A8UNormInt:
276300
return GL_RGBA4;
301+
case PixelFormat::kR32G32B32A32Float:
302+
return GL_RGBA32F;
303+
case PixelFormat::kR16G16B16A16Float:
304+
return GL_RGBA16F;
277305
case PixelFormat::kS8UInt:
278306
return GL_STENCIL_INDEX8;
279307
case PixelFormat::kD32FloatS8UInt:

impeller/renderer/backend/metal/formats_mtl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ constexpr PixelFormat FromMTLPixelFormat(MTLPixelFormat format) {
2929
return PixelFormat::kR8G8B8A8UNormInt;
3030
case MTLPixelFormatRGBA8Unorm_sRGB:
3131
return PixelFormat::kR8G8B8A8UNormIntSRGB;
32+
case MTLPixelFormatRGBA32Float:
33+
return PixelFormat::kR32G32B32A32Float;
34+
case MTLPixelFormatRGBA16Float:
35+
return PixelFormat::kR16G16B16A16Float;
3236
case MTLPixelFormatStencil8:
3337
return PixelFormat::kS8UInt;
3438
case MTLPixelFormatDepth32Float_Stencil8:
@@ -57,6 +61,10 @@ constexpr MTLPixelFormat ToMTLPixelFormat(PixelFormat format) {
5761
return MTLPixelFormatRGBA8Unorm;
5862
case PixelFormat::kR8G8B8A8UNormIntSRGB:
5963
return MTLPixelFormatRGBA8Unorm_sRGB;
64+
case PixelFormat::kR32G32B32A32Float:
65+
return MTLPixelFormatRGBA32Float;
66+
case PixelFormat::kR16G16B16A16Float:
67+
return MTLPixelFormatRGBA16Float;
6068
case PixelFormat::kS8UInt:
6169
return MTLPixelFormatStencil8;
6270
case PixelFormat::kD32FloatS8UInt:

impeller/renderer/backend/vulkan/formats_vk.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ constexpr vk::Format ToVKImageFormat(PixelFormat format) {
148148
return vk::Format::eB8G8R8A8Unorm;
149149
case PixelFormat::kB8G8R8A8UNormIntSRGB:
150150
return vk::Format::eB8G8R8A8Srgb;
151+
case PixelFormat::kR32G32B32A32Float:
152+
return vk::Format::eR32G32B32A32Sfloat;
153+
case PixelFormat::kR16G16B16A16Float:
154+
return vk::Format::eR16G16B16A16Sfloat;
151155
case PixelFormat::kS8UInt:
152156
return vk::Format::eS8Uint;
153157
case PixelFormat::kD32FloatS8UInt:
@@ -178,6 +182,12 @@ constexpr PixelFormat ToPixelFormat(vk::Format format) {
178182
case vk::Format::eB8G8R8A8Srgb:
179183
return PixelFormat::kB8G8R8A8UNormIntSRGB;
180184

185+
case vk::Format::eR32G32B32A32Sfloat:
186+
return PixelFormat::kR32G32B32A32Float;
187+
188+
case vk::Format::eR16G16B16A16Sfloat:
189+
return PixelFormat::kR16G16B16A16Float;
190+
181191
case vk::Format::eS8Uint:
182192
return PixelFormat::kS8UInt;
183193

impeller/renderer/formats.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ enum class PixelFormat {
8787
kR8G8B8A8UNormIntSRGB,
8888
kB8G8R8A8UNormInt,
8989
kB8G8R8A8UNormIntSRGB,
90+
kR32G32B32A32Float,
91+
kR16G16B16A16Float,
9092

9193
// Depth and stencil formats.
9294
kS8UInt,
@@ -290,6 +292,10 @@ constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format) {
290292
return 4u;
291293
case PixelFormat::kD32FloatS8UInt:
292294
return 5u;
295+
case PixelFormat::kR16G16B16A16Float:
296+
return 8u;
297+
case PixelFormat::kR32G32B32A32Float:
298+
return 16u;
293299
}
294300
return 0u;
295301
}

impeller/scene/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ impeller_component("scene") {
3131
"scene_context.h",
3232
"scene_encoder.cc",
3333
"scene_encoder.h",
34+
"skin.cc",
35+
"skin.h",
3436
]
3537

3638
public_deps = [

impeller/scene/animation/animation_player.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void AnimationPlayer::Update() {
5454

5555
void AnimationPlayer::Reset() {
5656
for (auto& [node, transform] : default_target_transforms_) {
57-
node->SetLocalTransform(transform);
57+
node->SetLocalTransform(Matrix());
5858
}
5959
}
6060

impeller/scene/animation/property_resolver.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ void TranslationTimelineResolver::Apply(Node& target,
8989
if (key.lerp < 1) {
9090
value = values_[key.index - 1].Lerp(value, key.lerp);
9191
}
92-
target.SetLocalTransform(Matrix::MakeTranslation(value * weight) *
93-
target.GetLocalTransform());
92+
target.SetLocalTransform(target.GetLocalTransform() *
93+
Matrix::MakeTranslation(value * weight));
9494
}
9595

9696
RotationTimelineResolver::RotationTimelineResolver() = default;
@@ -108,8 +108,8 @@ void RotationTimelineResolver::Apply(Node& target,
108108
if (key.lerp < 1) {
109109
value = values_[key.index - 1].Slerp(value, key.lerp);
110110
}
111-
target.SetLocalTransform(Matrix::MakeRotation(value * weight) *
112-
target.GetLocalTransform());
111+
target.SetLocalTransform(target.GetLocalTransform() *
112+
Matrix::MakeRotation(value * weight));
113113
}
114114

115115
ScaleTimelineResolver::ScaleTimelineResolver() = default;
@@ -125,8 +125,8 @@ void ScaleTimelineResolver::Apply(Node& target, SecondsF time, Scalar weight) {
125125
if (key.lerp < 1) {
126126
value = values_[key.index - 1].Lerp(value, key.lerp);
127127
}
128-
target.SetLocalTransform(Matrix::MakeScale(value * weight) *
129-
target.GetLocalTransform());
128+
target.SetLocalTransform(target.GetLocalTransform() *
129+
Matrix::MakeScale(value * weight));
130130
}
131131

132132
} // namespace scene

impeller/scene/geometry.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "impeller/geometry/vector.h"
1313
#include "impeller/renderer/device_buffer_descriptor.h"
1414
#include "impeller/renderer/formats.h"
15+
#include "impeller/renderer/sampler_descriptor.h"
16+
#include "impeller/renderer/sampler_library.h"
1517
#include "impeller/renderer/vertex_buffer.h"
1618
#include "impeller/renderer/vertex_buffer_builder.h"
1719
#include "impeller/scene/importer/scene_flatbuffers.h"
@@ -117,6 +119,8 @@ std::shared_ptr<Geometry> Geometry::MakeFromFlatbuffer(
117119
return MakeVertexBuffer(std::move(vertex_buffer), is_skinned);
118120
}
119121

122+
void Geometry::SetJointsTexture(const std::shared_ptr<Texture>& texture) {}
123+
120124
//------------------------------------------------------------------------------
121125
/// CuboidGeometry
122126
///
@@ -239,10 +243,31 @@ void SkinnedVertexBufferGeometry::BindToCommand(
239243
command.BindVertices(
240244
GetVertexBuffer(*scene_context.GetContext()->GetResourceAllocator()));
241245

246+
SamplerDescriptor sampler_desc;
247+
sampler_desc.min_filter = MinMagFilter::kNearest;
248+
sampler_desc.mag_filter = MinMagFilter::kNearest;
249+
sampler_desc.mip_filter = MipFilter::kNone;
250+
sampler_desc.width_address_mode = SamplerAddressMode::kRepeat;
251+
sampler_desc.label = "NN Repeat";
252+
253+
SkinnedVertexShader::BindJointsTexture(
254+
command,
255+
joints_texture_ ? joints_texture_ : scene_context.GetPlaceholderTexture(),
256+
scene_context.GetContext()->GetSamplerLibrary()->GetSampler(
257+
sampler_desc));
258+
242259
SkinnedVertexShader::VertInfo info;
243260
info.mvp = transform;
261+
info.enable_skinning = joints_texture_ ? 1 : 0;
262+
info.joint_texture_size =
263+
joints_texture_ ? joints_texture_->GetSize().width : 1;
244264
SkinnedVertexShader::BindVertInfo(command, buffer.EmplaceUniform(info));
245265
}
246266

267+
// |Geometry|
268+
void SkinnedVertexBufferGeometry::SetJointsTexture(
269+
const std::shared_ptr<Texture>& texture) {
270+
joints_texture_ = texture;
271+
}
247272
} // namespace scene
248273
} // namespace impeller

0 commit comments

Comments
 (0)