aboutsummaryrefslogtreecommitdiff
path: root/src/mesh.cpp
diff options
context:
space:
mode:
authorRealBadAngel <maciej.kasatkin@o2.pl>2015-07-21 23:56:41 +0200
committerRealBadAngel <maciej.kasatkin@o2.pl>2015-07-21 23:56:41 +0200
commit60350699c792b816b20704d59cfbda0894cdba39 (patch)
tree59e9a369d9ea87804035ee27ea902a81b4f90060 /src/mesh.cpp
parent5b0c719171eb9ccb8f2829eb1cc8b3fe9f24cd05 (diff)
downloadminetest-60350699c792b816b20704d59cfbda0894cdba39.tar.gz
minetest-60350699c792b816b20704d59cfbda0894cdba39.tar.bz2
minetest-60350699c792b816b20704d59cfbda0894cdba39.zip
Add wielded (and CAOs) shader
Diffstat (limited to 'src/mesh.cpp')
-rw-r--r--src/mesh.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/mesh.cpp b/src/mesh.cpp
index 4f70b7fa2..dab1575f3 100644
--- a/src/mesh.cpp
+++ b/src/mesh.cpp
@@ -33,6 +33,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define MY_ETLM_READ_ONLY video::ETLM_READ_ONLY
#endif
+static void applyFacesShading(video::SColor& color, float factor)
+{
+ color.setRed(core::clamp(core::round32(color.getRed()*factor), 0, 255));
+ color.setGreen(core::clamp(core::round32(color.getGreen()*factor), 0, 255));
+ color.setBlue(core::clamp(core::round32(color.getBlue()*factor), 0, 255));
+}
+
scene::IAnimatedMesh* createCubeMesh(v3f scale)
{
video::SColor c(255,255,255,255);
@@ -165,6 +172,35 @@ void setMeshColor(scene::IMesh *mesh, const video::SColor &color)
}
}
+void shadeMeshFaces(scene::IMesh *mesh)
+{
+ 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 *vertex = (video::S3DVertex *)(vertices + i * stride);
+ video::SColor &vc = vertex->Color;
+ if (vertex->Normal.Y < -0.5) {
+ applyFacesShading (vc, 0.447213);
+ } else if (vertex->Normal.Z > 0.5) {
+ applyFacesShading (vc, 0.670820);
+ } else if (vertex->Normal.Z < -0.5) {
+ applyFacesShading (vc, 0.670820);
+ } else if (vertex->Normal.X > 0.5) {
+ applyFacesShading (vc, 0.836660);
+ } else if (vertex->Normal.X < -0.5) {
+ applyFacesShading (vc, 0.836660);
+ }
+ }
+ }
+}
+
void setMeshColorByNormalXYZ(scene::IMesh *mesh,
const video::SColor &colorX,
const video::SColor &colorY,