diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/camera.cpp | 9 | ||||
-rw-r--r-- | src/camera.h | 1 | ||||
-rw-r--r-- | src/client/tile.cpp | 17 | ||||
-rw-r--r-- | src/client/tile.h | 6 | ||||
-rw-r--r-- | src/mesh.cpp | 36 | ||||
-rw-r--r-- | src/mesh.h | 6 | ||||
-rw-r--r-- | src/nodedef.cpp | 4 | ||||
-rw-r--r-- | src/wieldmesh.cpp | 33 | ||||
-rw-r--r-- | src/wieldmesh.h | 3 |
9 files changed, 75 insertions, 40 deletions
diff --git a/src/camera.cpp b/src/camera.cpp index 46df0575c..0c6d03e4e 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -92,10 +92,9 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control, // all other 3D scene nodes and before the GUI. m_wieldmgr = smgr->createNewSceneManager(); m_wieldmgr->addCameraSceneNode(); - m_wieldnode = new WieldMeshSceneNode(m_wieldmgr->getRootSceneNode(), m_wieldmgr, -1, true); + m_wieldnode = new WieldMeshSceneNode(m_wieldmgr->getRootSceneNode(), m_wieldmgr, -1, false); m_wieldnode->setItem(ItemStack(), m_gamedef); m_wieldnode->drop(); // m_wieldmgr grabbed it - m_wieldlightnode = m_wieldmgr->addLightSceneNode(NULL, v3f(0.0, 50.0, 0.0)); /* TODO: Add a callback function so these can be updated when a setting * changes. At this point in time it doesn't matter (e.g. /set @@ -451,11 +450,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, m_wieldnode->setPosition(wield_position); m_wieldnode->setRotation(wield_rotation); - // Shine light upon the wield mesh - video::SColor black(255,0,0,0); - m_wieldmgr->setAmbientLight(player->light_color.getInterpolated(black, 0.7)); - m_wieldlightnode->getLightData().DiffuseColor = player->light_color.getInterpolated(black, 0.3); - m_wieldlightnode->setPosition(v3f(30+5*sin(2*player->getYaw()*M_PI/180), -50, 0)); + m_wieldnode->setColor(player->light_color); // Render distance feedback loop updateViewingRange(frametime, busytime); diff --git a/src/camera.h b/src/camera.h index b0d190a3a..006f4b3ce 100644 --- a/src/camera.h +++ b/src/camera.h @@ -159,7 +159,6 @@ private: scene::ISceneManager* m_wieldmgr; WieldMeshSceneNode* m_wieldnode; - scene::ILightSceneNode* m_wieldlightnode; // draw control MapDrawControl& m_draw_control; diff --git a/src/client/tile.cpp b/src/client/tile.cpp index 5ad564b65..03badd817 100644 --- a/src/client/tile.cpp +++ b/src/client/tile.cpp @@ -385,7 +385,8 @@ public: video::ITexture* getNormalTexture(const std::string &name); video::SColor getTextureAverageColor(const std::string &name); - video::ITexture *getShaderFlagsTexture(TileDef *tiledef, TileSpec *tile); + video::ITexture *getShaderFlagsTexture( + bool normamap_present, bool tileable_vertical, bool tileable_horizontal); private: @@ -2050,14 +2051,14 @@ video::SColor TextureSource::getTextureAverageColor(const std::string &name) return c; } -video::ITexture *TextureSource::getShaderFlagsTexture(TileDef *tiledef, TileSpec *tile) + +video::ITexture *TextureSource::getShaderFlagsTexture( + bool normalmap_present, bool tileable_vertical, bool tileable_horizontal) { std::string tname = "__shaderFlagsTexture"; - - bool normalmap_present = tile->normal_texture ? true : false; tname += normalmap_present ? "1" : "0"; - tname += tiledef->tileable_horizontal ? "1" : "0"; - tname += tiledef->tileable_vertical ? "1" : "0"; + tname += tileable_horizontal ? "1" : "0"; + tname += tileable_vertical ? "1" : "0"; if (isKnownSourceImage(tname)) { return getTexture(tname); @@ -2069,8 +2070,8 @@ video::ITexture *TextureSource::getShaderFlagsTexture(TileDef *tiledef, TileSpec video::SColor c( 255, normalmap_present ? 255 : 0, - tiledef->tileable_horizontal ? 255 : 0, - tiledef->tileable_vertical ? 255 : 0); + tileable_horizontal ? 255 : 0, + tileable_vertical ? 255 : 0); flags_image->setPixel(0, 0, c); insertSourceImage(tname, flags_image); flags_image->drop(); diff --git a/src/client/tile.h b/src/client/tile.h index 13f1a8b34..744aa2c3d 100644 --- a/src/client/tile.h +++ b/src/client/tile.h @@ -113,7 +113,8 @@ public: const TextureFromMeshParams ¶ms)=0; virtual video::ITexture* getNormalTexture(const std::string &name)=0; virtual video::SColor getTextureAverageColor(const std::string &name)=0; - virtual video::ITexture *getShaderFlagsTexture(TileDef *tiledef, TileSpec *tile)=0; + virtual video::ITexture *getShaderFlagsTexture(bool normamap_present, + bool tileable_vertical, bool tileable_horizontal)=0; }; class IWritableTextureSource : public ITextureSource @@ -136,7 +137,8 @@ public: virtual void rebuildImagesAndTextures()=0; virtual video::ITexture* getNormalTexture(const std::string &name)=0; virtual video::SColor getTextureAverageColor(const std::string &name)=0; - virtual video::ITexture *getShaderFlagsTexture(TileDef *tiledef, TileSpec *tile)=0; + virtual video::ITexture *getShaderFlagsTexture(bool normamap_present, + bool tileable_vertical, bool tileable_horizontal)=0; }; IWritableTextureSource* createTextureSource(IrrlichtDevice *device); 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, diff --git a/src/mesh.h b/src/mesh.h index 761842b0d..ec109e9e9 100644 --- a/src/mesh.h +++ b/src/mesh.h @@ -49,6 +49,12 @@ void translateMesh(scene::IMesh *mesh, v3f vec); void setMeshColor(scene::IMesh *mesh, const video::SColor &color); /* + Shade mesh faces according to their normals +*/ + +void shadeMeshFaces(scene::IMesh *mesh); + +/* Set the color of all vertices in the mesh. For each vertex, determine the largest absolute entry in the normal vector, and choose one of colorX, colorY or diff --git a/src/nodedef.cpp b/src/nodedef.cpp index bb4f102da..c9c461b20 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -1012,7 +1012,9 @@ void CNodeDefManager::fillTileAttribs(ITextureSource *tsrc, TileSpec *tile, if (use_normal_texture) { tile->normal_texture = tsrc->getNormalTexture(tiledef->name); } - tile->flags_texture = tsrc->getShaderFlagsTexture(tiledef, tile); + tile->flags_texture = tsrc->getShaderFlagsTexture( + tile->normal_texture ? true : false, + tiledef->tileable_horizontal, tiledef->tileable_vertical); // Material flags tile->material_flags = 0; diff --git a/src/wieldmesh.cpp b/src/wieldmesh.cpp index 036b25a90..56c84b959 100644 --- a/src/wieldmesh.cpp +++ b/src/wieldmesh.cpp @@ -34,7 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #define WIELD_SCALE_FACTOR 30.0 #define WIELD_SCALE_FACTOR_EXTRUDED 40.0 -#define MIN_EXTRUSION_MESH_RESOLUTION 32 // not 16: causes too many "holes" +#define MIN_EXTRUSION_MESH_RESOLUTION 16 #define MAX_EXTRUSION_MESH_RESOLUTION 512 static scene::IMesh* createExtrusionMesh(int resolution_x, int resolution_y) @@ -114,6 +114,7 @@ static scene::IMesh* createExtrusionMesh(int resolution_x, int resolution_y) mesh->addMeshBuffer(buf); buf->drop(); scaleMesh(mesh, scale); // also recalculates bounding box + mesh = (scene::SMesh *)createForsythOptimizedMesh(mesh); return mesh; } @@ -281,7 +282,9 @@ void WieldMeshSceneNode::setExtruded(const std::string &imagename, // Customize material video::SMaterial &material = m_meshnode->getMaterial(0); - material.setTexture(0, tsrc->getTextureForMesh(imagename)); + material.setTexture(0, tsrc->getTexture(imagename)); + material.TextureLayer[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE; + material.TextureLayer[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE; material.MaterialType = m_material_type; material.setFlag(video::EMF_BACK_FACE_CULLING, true); // Enable bi/trilinear filtering only for high resolution textures @@ -297,31 +300,25 @@ void WieldMeshSceneNode::setExtruded(const std::string &imagename, #if (IRRLICHT_VERSION_MAJOR >= 1 && IRRLICHT_VERSION_MINOR >= 8) || IRRLICHT_VERSION_MAJOR >= 2 material.setFlag(video::EMF_USE_MIP_MAPS, false); #endif - -#if 0 -//// TODO(RealBadAngel): Reactivate when shader is added for wield items - if (m_enable_shaders) - material.setTexture(2, tsrc->getTexture("disable_img.png")); -#endif + if (m_enable_shaders) { + material.setTexture(2, tsrc->getShaderFlagsTexture(false, true, true)); + } } void WieldMeshSceneNode::setItem(const ItemStack &item, IGameDef *gamedef) { ITextureSource *tsrc = gamedef->getTextureSource(); IItemDefManager *idef = gamedef->getItemDefManager(); - //IShaderSource *shdrsrc = gamedef->getShaderSource(); + IShaderSource *shdrsrc = gamedef->getShaderSource(); INodeDefManager *ndef = gamedef->getNodeDefManager(); const ItemDefinition &def = item.getDefinition(idef); const ContentFeatures &f = ndef->get(def.name); content_t id = ndef->getId(def.name); -#if 0 -//// TODO(RealBadAngel): Reactivate when shader is added for wield items if (m_enable_shaders) { - u32 shader_id = shdrsrc->getShader("nodes_shader", TILE_MATERIAL_BASIC, NDT_NORMAL); + u32 shader_id = shdrsrc->getShader("wielded_shader", TILE_MATERIAL_BASIC, NDT_NORMAL); m_material_type = shdrsrc->getShaderInfo(shader_id).material; } -#endif // If wield_image is defined, it overrides everything else if (def.wield_image != "") { @@ -345,8 +342,6 @@ void WieldMeshSceneNode::setItem(const ItemStack &item, IGameDef *gamedef) } else if (f.drawtype == NDT_NORMAL || f.drawtype == NDT_ALLFACES) { setCube(f.tiles, def.wield_scale, tsrc); } else { - //// TODO: Change false in the following constructor args to - //// appropriate value when shader is added for wield items (if applicable) MeshMakeData mesh_make_data(gamedef, false); MapNode mesh_make_node(id, 255, 0); mesh_make_data.fillSingleNode(&mesh_make_node); @@ -376,8 +371,6 @@ void WieldMeshSceneNode::setItem(const ItemStack &item, IGameDef *gamedef) material.setTexture(0, f.tiles[i].texture); } material.MaterialType = m_material_type; -#if 0 -//// TODO(RealBadAngel): Reactivate when shader is added for wield items if (m_enable_shaders) { if (f.tiles[i].normal_texture) { if (animated) { @@ -386,12 +379,9 @@ void WieldMeshSceneNode::setItem(const ItemStack &item, IGameDef *gamedef) } else { material.setTexture(1, f.tiles[i].normal_texture); } - material.setTexture(2, tsrc->getTexture("enable_img.png")); - } else { - material.setTexture(2, tsrc->getTexture("disable_img.png")); } + material.setTexture(2, f.tiles[i].flags_texture); } -#endif } return; } @@ -408,6 +398,7 @@ void WieldMeshSceneNode::setColor(video::SColor color) { assert(!m_lighting); setMeshColor(m_meshnode->getMesh(), color); + shadeMeshFaces(m_meshnode->getMesh()); } void WieldMeshSceneNode::render() diff --git a/src/wieldmesh.h b/src/wieldmesh.h index 933b53763..3f4f4fc04 100644 --- a/src/wieldmesh.h +++ b/src/wieldmesh.h @@ -48,6 +48,9 @@ public: // Must only be used if the constructor was called with lighting = false void setColor(video::SColor color); + scene::IMesh *getMesh() + { return m_meshnode->getMesh(); } + virtual void render(); virtual const core::aabbox3d<f32>& getBoundingBox() const |