Skip to content

Commit cdbe3c5

Browse files
authoredApr 19, 2020
Reuse object_shader for "wielditem" and "item" entity drawtypes (#9537)
1 parent c87d52a commit cdbe3c5

File tree

6 files changed

+24
-165
lines changed

6 files changed

+24
-165
lines changed
 

‎client/shaders/wielded_shader/opengl_fragment.glsl

-127
This file was deleted.

‎client/shaders/wielded_shader/opengl_vertex.glsl

-32
This file was deleted.

‎src/client/camera.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r
542542
m_wieldnode->setPosition(wield_position);
543543
m_wieldnode->setRotation(wield_rotation);
544544

545-
m_wieldnode->setColor(player->light_color);
545+
m_wieldnode->setNodeLightColor(player->light_color);
546546

547547
// Set render distance
548548
updateViewingRange();

‎src/client/content_cao.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -826,11 +826,12 @@ void GenericCAO::setNodeLight(u8 light)
826826
video::SColor color(255, light, light, light);
827827

828828
if (m_prop.visual == "wielditem" || m_prop.visual == "item") {
829-
// Since these types of visuals are using their own shader
830-
// they should be handled separately
831829
if (m_wield_meshnode)
832-
m_wield_meshnode->setColor(color);
833-
} else if (m_enable_shaders) {
830+
m_wield_meshnode->setNodeLightColor(color);
831+
return;
832+
}
833+
834+
if (m_enable_shaders) {
834835
scene::ISceneNode *node = getSceneNode();
835836

836837
if (node == nullptr)

‎src/client/wieldmesh.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ void WieldMeshSceneNode::setItem(const ItemStack &item, Client *client, bool che
347347
scene::SMesh *mesh = nullptr;
348348

349349
if (m_enable_shaders) {
350-
u32 shader_id = shdrsrc->getShader("wielded_shader", TILE_MATERIAL_BASIC, NDT_NORMAL);
350+
u32 shader_id = shdrsrc->getShader("object_shader", TILE_MATERIAL_BASIC, NDT_NORMAL);
351351
m_material_type = shdrsrc->getShaderInfo(shader_id).material;
352352
}
353353

@@ -471,6 +471,21 @@ void WieldMeshSceneNode::setColor(video::SColor c)
471471
}
472472
}
473473

474+
void WieldMeshSceneNode::setNodeLightColor(video::SColor color)
475+
{
476+
if (!m_meshnode)
477+
return;
478+
479+
if (m_enable_shaders) {
480+
for (u32 i = 0; i < m_meshnode->getMaterialCount(); ++i) {
481+
video::SMaterial &material = m_meshnode->getMaterial(i);
482+
material.EmissiveColor = color;
483+
}
484+
} else {
485+
setColor(color);
486+
}
487+
}
488+
474489
void WieldMeshSceneNode::render()
475490
{
476491
// note: if this method is changed to actually do something,

‎src/client/wieldmesh.h

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ class WieldMeshSceneNode : public scene::ISceneNode
8787
// Must only be used if the constructor was called with lighting = false
8888
void setColor(video::SColor color);
8989

90+
void setNodeLightColor(video::SColor color);
91+
9092
scene::IMesh *getMesh() { return m_meshnode->getMesh(); }
9193

9294
virtual void render();

0 commit comments

Comments
 (0)
Please sign in to comment.