Skip to content

Commit

Permalink
Do not shade inventory items with textures (#5869)
Browse files Browse the repository at this point in the history
This commit restores the old behavior: if an inventory item has an own
inventory texture, it will not be shaded.
  • Loading branch information
juhdanad authored and nerzhul committed Jun 1, 2017
1 parent 1c69476 commit 001de6f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/hud.cpp
Expand Up @@ -698,7 +698,10 @@ void drawItemStack(video::IVideoDriver *driver,
if (p->override_base)
c = p->color;
}
colorizeMeshBuffer(buf, &c);
if (imesh->needs_shading)
colorizeMeshBuffer(buf, &c);
else
setMeshBufferColor(buf, c);
video::SMaterial &material = buf->getMaterial();
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
material.Lighting = false;
Expand Down
18 changes: 10 additions & 8 deletions src/mesh.cpp
Expand Up @@ -175,21 +175,23 @@ void translateMesh(scene::IMesh *mesh, v3f vec)
mesh->setBoundingBox(bbox);
}

void setMeshBufferColor(scene::IMeshBuffer *buf, const video::SColor &color)
{
const u32 stride = getVertexPitchFromType(buf->getVertexType());
u32 vertex_count = buf->getVertexCount();
u8 *vertices = (u8 *) buf->getVertices();
for (u32 i = 0; i < vertex_count; i++)
((video::S3DVertex *) (vertices + i * stride))->Color = color;
}

void setMeshColor(scene::IMesh *mesh, const video::SColor &color)
{
if (mesh == NULL)
return;

u32 mc = mesh->getMeshBufferCount();
for (u32 j = 0; j < mc; j++) {
scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
const u32 stride = getVertexPitchFromType(buf->getVertexType());
u32 vertex_count = buf->getVertexCount();
u8 *vertices = (u8 *)buf->getVertices();
for (u32 i = 0; i < vertex_count; i++)
((video::S3DVertex *)(vertices + i * stride))->Color = color;
}
for (u32 j = 0; j < mc; j++)
setMeshBufferColor(mesh->getMeshBuffer(j), color);
}

void colorizeMeshBuffer(scene::IMeshBuffer *buf, const video::SColor *buffercolor)
Expand Down
9 changes: 9 additions & 0 deletions src/mesh.h
Expand Up @@ -49,11 +49,20 @@ void scaleMesh(scene::IMesh *mesh, v3f scale);
*/
void translateMesh(scene::IMesh *mesh, v3f vec);

/*!
* Sets a constant color for all vertices in the mesh buffer.
*/
void setMeshBufferColor(scene::IMeshBuffer *buf, const video::SColor &color);

/*
Set a constant color for all vertices in the mesh
*/
void setMeshColor(scene::IMesh *mesh, const video::SColor &color);

/*!
* Overwrites the color of a mesh buffer.
* The color is darkened based on the normal vector of the vertices.
*/
void colorizeMeshBuffer(scene::IMeshBuffer *buf, const video::SColor *buffercolor);

/*
Expand Down
5 changes: 5 additions & 0 deletions src/wieldmesh.cpp
Expand Up @@ -440,10 +440,15 @@ void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result)

scene::SMesh *mesh = NULL;

// Shading is on by default
result->needs_shading = true;

// If inventory_image is defined, it overrides everything else
if (def.inventory_image != "") {
mesh = getExtrudedMesh(tsrc, def.inventory_image);
result->buffer_colors.push_back(ItemPartColor());
// Items with inventory images do not need shading
result->needs_shading = false;
} else if (def.type == ITEM_NODE) {
if (f.mesh_ptr[0]) {
mesh = cloneMesh(f.mesh_ptr[0]);
Expand Down
7 changes: 6 additions & 1 deletion src/wieldmesh.h
Expand Up @@ -59,8 +59,13 @@ struct ItemMesh
* Stores the color of each mesh buffer.
*/
std::vector<ItemPartColor> buffer_colors;
/*!
* If false, all faces of the item should have the same brightness.
* Disables shading based on normal vectors.
*/
bool needs_shading;

ItemMesh() : mesh(NULL), buffer_colors() {}
ItemMesh() : mesh(NULL), buffer_colors(), needs_shading(true) {}
};

/*
Expand Down

0 comments on commit 001de6f

Please sign in to comment.