summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDániel Juhász <juhdanad@gmail.com>2017-06-01 23:18:55 +0200
committerLoïc Blot <nerzhul@users.noreply.github.com>2017-06-01 23:18:55 +0200
commit001de6ffbac83bcd41ecda075d79d265a69c7d42 (patch)
tree59b1857bb89be11a59746d4479f047806a7a42f6 /src
parent1c69476d9f10540088ead63c8bcae91f46bc84d8 (diff)
downloadminetest-001de6ffbac83bcd41ecda075d79d265a69c7d42.tar.gz
minetest-001de6ffbac83bcd41ecda075d79d265a69c7d42.tar.bz2
minetest-001de6ffbac83bcd41ecda075d79d265a69c7d42.zip
Do not shade inventory items with textures (#5869)
This commit restores the old behavior: if an inventory item has an own inventory texture, it will not be shaded.
Diffstat (limited to 'src')
-rw-r--r--src/hud.cpp5
-rw-r--r--src/mesh.cpp18
-rw-r--r--src/mesh.h9
-rw-r--r--src/wieldmesh.cpp5
-rw-r--r--src/wieldmesh.h7
5 files changed, 34 insertions, 10 deletions
diff --git a/src/hud.cpp b/src/hud.cpp
index 72145b4da..a2f031b4c 100644
--- a/src/hud.cpp
+++ b/src/hud.cpp
@@ -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;
diff --git a/src/mesh.cpp b/src/mesh.cpp
index 824d6891b..3ab67510a 100644
--- a/src/mesh.cpp
+++ b/src/mesh.cpp
@@ -175,6 +175,14 @@ 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)
{
@@ -182,14 +190,8 @@ void setMeshColor(scene::IMesh *mesh, const video::SColor &color)
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)
diff --git a/src/mesh.h b/src/mesh.h
index adaf0c836..423e43aee 100644
--- a/src/mesh.h
+++ b/src/mesh.h
@@ -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);
/*
diff --git a/src/wieldmesh.cpp b/src/wieldmesh.cpp
index 8b1477bb7..7736ec2a2 100644
--- a/src/wieldmesh.cpp
+++ b/src/wieldmesh.cpp
@@ -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]);
diff --git a/src/wieldmesh.h b/src/wieldmesh.h
index ef164c11f..faedce484 100644
--- a/src/wieldmesh.h
+++ b/src/wieldmesh.h
@@ -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) {}
};
/*