Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Reuse object_shader for "wielditem" and "item" entity drawtypes (#9537)
  • Loading branch information
FunkyDck committed Apr 19, 2020
1 parent c87d52a commit cdbe3c5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 165 deletions.
127 changes: 0 additions & 127 deletions client/shaders/wielded_shader/opengl_fragment.glsl

This file was deleted.

32 changes: 0 additions & 32 deletions client/shaders/wielded_shader/opengl_vertex.glsl

This file was deleted.

2 changes: 1 addition & 1 deletion src/client/camera.cpp
Expand Up @@ -542,7 +542,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r
m_wieldnode->setPosition(wield_position);
m_wieldnode->setRotation(wield_rotation);

m_wieldnode->setColor(player->light_color);
m_wieldnode->setNodeLightColor(player->light_color);

// Set render distance
updateViewingRange();
Expand Down
9 changes: 5 additions & 4 deletions src/client/content_cao.cpp
Expand Up @@ -826,11 +826,12 @@ void GenericCAO::setNodeLight(u8 light)
video::SColor color(255, light, light, light);

if (m_prop.visual == "wielditem" || m_prop.visual == "item") {
// Since these types of visuals are using their own shader
// they should be handled separately
if (m_wield_meshnode)
m_wield_meshnode->setColor(color);
} else if (m_enable_shaders) {
m_wield_meshnode->setNodeLightColor(color);
return;
}

if (m_enable_shaders) {
scene::ISceneNode *node = getSceneNode();

if (node == nullptr)
Expand Down
17 changes: 16 additions & 1 deletion src/client/wieldmesh.cpp
Expand Up @@ -347,7 +347,7 @@ void WieldMeshSceneNode::setItem(const ItemStack &item, Client *client, bool che
scene::SMesh *mesh = nullptr;

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

Expand Down Expand Up @@ -471,6 +471,21 @@ void WieldMeshSceneNode::setColor(video::SColor c)
}
}

void WieldMeshSceneNode::setNodeLightColor(video::SColor color)
{
if (!m_meshnode)
return;

if (m_enable_shaders) {
for (u32 i = 0; i < m_meshnode->getMaterialCount(); ++i) {
video::SMaterial &material = m_meshnode->getMaterial(i);
material.EmissiveColor = color;
}
} else {
setColor(color);
}
}

void WieldMeshSceneNode::render()
{
// note: if this method is changed to actually do something,
Expand Down
2 changes: 2 additions & 0 deletions src/client/wieldmesh.h
Expand Up @@ -87,6 +87,8 @@ class WieldMeshSceneNode : public scene::ISceneNode
// Must only be used if the constructor was called with lighting = false
void setColor(video::SColor color);

void setNodeLightColor(video::SColor color);

scene::IMesh *getMesh() { return m_meshnode->getMesh(); }

virtual void render();
Expand Down

0 comments on commit cdbe3c5

Please sign in to comment.