Skip to content

Commit 5ad759c

Browse files
committed
Choose whether to use HW skinning shader appropriately
1 parent 7fabd88 commit 5ad759c

File tree

4 files changed

+35
-25
lines changed

4 files changed

+35
-25
lines changed

irr/include/IAnimatedMesh.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class IAnimatedMesh : public IMesh
2121

2222
virtual void prepareForAnimation(u16 max_hw_joints) = 0;
2323

24+
//! Whether the mesh needs shader-based hardware skinning
25+
virtual bool needsHwSkinning() const = 0;
26+
2427
//! Returns the type of the animated mesh. Useful for safe downcasts.
2528
E_ANIMATED_MESH_TYPE getMeshType() const = 0;
2629
};

irr/include/SMesh.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ struct SMesh final : public IAnimatedMesh
139139

140140
f32 getMaxFrameNumber() const override { return 0.0f; }
141141
void prepareForAnimation(u16 max_hw_joints) override {}
142+
bool needsHwSkinning() const override { return false; }
142143
E_ANIMATED_MESH_TYPE getMeshType() const override { return EAMT_STATIC; }
143144
};
144145

irr/include/SkinnedMesh.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class SkinnedMesh : public IAnimatedMesh
6060

6161
void prepareForAnimation(u16 max_hw_joints) override;
6262

63+
bool needsHwSkinning() const override { return !UseSwSkinning && HasWeights; }
64+
6365
bool useSoftwareSkinning() const { return UseSwSkinning; }
6466

6567
//! Turns the given array of local matrices into an array of global matrices

src/client/content_cao.cpp

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -581,33 +581,34 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr)
581581
infostream << "GenericCAO::addToScene(): " <<
582582
enum_to_string(es_ObjectVisual, m_prop.visual)<< std::endl;
583583

584-
if (m_prop.visual != OBJECTVISUAL_NODE &&
585-
m_prop.visual != OBJECTVISUAL_WIELDITEM &&
586-
m_prop.visual != OBJECTVISUAL_ITEM)
587-
{
588-
IShaderSource *shader_source = m_client->getShaderSource();
589-
MaterialType material_type;
590-
591-
if (m_prop.shaded && m_prop.glow == 0)
592-
material_type = (m_prop.use_texture_alpha) ?
593-
TILE_MATERIAL_ALPHA : TILE_MATERIAL_BASIC;
594-
else
595-
material_type = (m_prop.use_texture_alpha) ?
596-
TILE_MATERIAL_PLAIN_ALPHA : TILE_MATERIAL_PLAIN;
597-
598-
u32 shader_id = shader_source->getShader("object_shader", material_type, NDT_NORMAL,
599-
false, true);
600-
// TODO proper condition for whether we'll need skinning
601-
m_material_type = shader_source->getShaderInfo(shader_id).material;
602-
} else {
603-
// Not used, so make sure it's not valid
604-
m_material_type = video::EMT_INVALID;
605-
}
584+
auto updateMaterialType = [this](bool hw_skin) {
585+
if (m_prop.visual != OBJECTVISUAL_NODE &&
586+
m_prop.visual != OBJECTVISUAL_WIELDITEM &&
587+
m_prop.visual != OBJECTVISUAL_ITEM)
588+
{
589+
IShaderSource *shader_source = m_client->getShaderSource();
590+
MaterialType material_type;
591+
592+
if (m_prop.shaded && m_prop.glow == 0)
593+
material_type = (m_prop.use_texture_alpha) ?
594+
TILE_MATERIAL_ALPHA : TILE_MATERIAL_BASIC;
595+
else
596+
material_type = (m_prop.use_texture_alpha) ?
597+
TILE_MATERIAL_PLAIN_ALPHA : TILE_MATERIAL_PLAIN;
598+
599+
u32 shader_id = shader_source->getShader("object_shader", material_type, NDT_NORMAL,
600+
false, hw_skin);
601+
m_material_type = shader_source->getShaderInfo(shader_id).material;
602+
} else {
603+
// Not used, so make sure it's not valid
604+
m_material_type = video::EMT_INVALID;
605+
}
606+
};
606607

607608
m_matrixnode = m_smgr->addDummyTransformationSceneNode();
608609
m_matrixnode->grab();
609610

610-
auto setMaterial = [this] (video::SMaterial &mat) {
611+
auto setMaterial = [this](video::SMaterial &mat) {
611612
if (m_material_type != video::EMT_INVALID)
612613
mat.MaterialType = m_material_type;
613614
mat.FogEnable = true;
@@ -617,12 +618,15 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr)
617618
});
618619
};
619620

620-
auto setSceneNodeMaterials = [setMaterial] (scene::ISceneNode *node) {
621+
auto setSceneNodeMaterials = [&] (scene::ISceneNode *node, bool hw_skin = false) {
622+
updateMaterialType(hw_skin);
621623
node->forEachMaterial(setMaterial);
622624
};
623625

624626
switch(m_prop.visual) {
625627
case OBJECTVISUAL_UPRIGHT_SPRITE: {
628+
updateMaterialType(false);
629+
626630
auto mesh = make_irr<scene::SMesh>();
627631
f32 dx = BS * m_prop.visual_size.X / 2;
628632
f32 dy = BS * m_prop.visual_size.Y / 2;
@@ -696,7 +700,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr)
696700
// set vertex colors to ensure alpha is set
697701
setMeshColor(m_animated_meshnode->getMesh(), video::SColor(0xFFFFFFFF));
698702

699-
setSceneNodeMaterials(m_animated_meshnode);
703+
setSceneNodeMaterials(m_animated_meshnode, mesh->needsHwSkinning());
700704

701705
m_animated_meshnode->forEachMaterial([this] (auto &mat) {
702706
mat.BackfaceCulling = m_prop.backface_culling;

0 commit comments

Comments
 (0)