Fix alpha for liquid nodes (#5494)
[oweals/minetest.git] / src / particles.cpp
index 5f17763e013373cf2ef4423facbb1122635496fe..7f406d874eb2a26030a3c3029e10d30bf661444e 100644 (file)
@@ -56,7 +56,8 @@ Particle::Particle(
        v2f texpos,
        v2f texsize,
        const struct TileAnimationParams &anim,
-       u8 glow
+       u8 glow,
+       video::SColor color
 ):
        scene::ISceneNode(smgr->getRootSceneNode(), smgr)
 {
@@ -77,6 +78,10 @@ Particle::Particle(
        m_animation_frame = 0;
        m_animation_time = 0.0;
 
+       // Color
+       m_base_color = color;
+       m_color = color;
+
        // Particle related
        m_pos = pos;
        m_velocity = velocity;
@@ -183,12 +188,15 @@ void Particle::updateLight()
        else
                light = blend_light(m_env->getDayNightRatio(), LIGHT_SUN, 0);
 
-       m_light = decode_light(light + m_glow);
+       u8 m_light = decode_light(light + m_glow);
+       m_color.set(255,
+               m_light * m_base_color.getRed() / 255,
+               m_light * m_base_color.getGreen() / 255,
+               m_light * m_base_color.getBlue() / 255);
 }
 
 void Particle::updateVertices()
 {
-       video::SColor c(255, m_light, m_light, m_light);
        f32 tx0, tx1, ty0, ty1;
 
        if (m_animation.type != TAT_NONE) {
@@ -210,14 +218,14 @@ void Particle::updateVertices()
                ty1 = m_texpos.Y + m_texsize.Y;
        }
 
-       m_vertices[0] = video::S3DVertex(-m_size/2,-m_size/2,0, 0,0,0,
-                       c, tx0, ty1);
-       m_vertices[1] = video::S3DVertex(m_size/2,-m_size/2,0, 0,0,0,
-                       c, tx1, ty1);
-       m_vertices[2] = video::S3DVertex(m_size/2,m_size/2,0, 0,0,0,
-                       c, tx1, ty0);
-       m_vertices[3] = video::S3DVertex(-m_size/2,m_size/2,0, 0,0,0,
-                       c, tx0, ty0);
+       m_vertices[0] = video::S3DVertex(-m_size / 2, -m_size / 2,
+               0, 0, 0, 0, m_color, tx0, ty1);
+       m_vertices[1] = video::S3DVertex(m_size / 2, -m_size / 2,
+               0, 0, 0, 0, m_color, tx1, ty1);
+       m_vertices[2] = video::S3DVertex(m_size / 2, m_size / 2,
+               0, 0, 0, 0, m_color, tx1, ty0);
+       m_vertices[3] = video::S3DVertex(-m_size / 2, m_size / 2,
+               0, 0, 0, 0, m_color, tx0, ty0);
 
        v3s16 camera_offset = m_env->getCameraOffset();
        for(u16 i=0; i<4; i++)
@@ -589,35 +597,39 @@ void ParticleManager::handleParticleEvent(ClientEvent *event, Client *client,
        }
 }
 
-void ParticleManager::addDiggingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
-               LocalPlayer *player, v3s16 pos, const TileSpec tiles[])
+void ParticleManager::addDiggingParticles(IGameDef* gamedef,
+       scene::ISceneManager* smgr, LocalPlayer *player, v3s16 pos,
+       const MapNode &n, const ContentFeatures &f)
 {
        for (u16 j = 0; j < 32; j++) // set the amount of particles here
        {
-               addNodeParticle(gamedef, smgr, player, pos, tiles);
+               addNodeParticle(gamedef, smgr, player, pos, n, f);
        }
 }
 
-void ParticleManager::addPunchingParticles(IGameDef* gamedef, scene::ISceneManager* smgr,
-               LocalPlayer *player, v3s16 pos, const TileSpec tiles[])
+void ParticleManager::addPunchingParticles(IGameDef* gamedef,
+       scene::ISceneManager* smgr, LocalPlayer *player, v3s16 pos,
+       const MapNode &n, const ContentFeatures &f)
 {
-       addNodeParticle(gamedef, smgr, player, pos, tiles);
+       addNodeParticle(gamedef, smgr, player, pos, n, f);
 }
 
-void ParticleManager::addNodeParticle(IGameDef* gamedef, scene::ISceneManager* smgr,
-               LocalPlayer *player, v3s16 pos, const TileSpec tiles[])
+void ParticleManager::addNodeParticle(IGameDef* gamedef,
+       scene::ISceneManager* smgr, LocalPlayer *player, v3s16 pos,
+       const MapNode &n, const ContentFeatures &f)
 {
        // Texture
        u8 texid = myrand_range(0, 5);
+       const TileLayer &tile = f.tiles[texid].layers[0];
        video::ITexture *texture;
        struct TileAnimationParams anim;
        anim.type = TAT_NONE;
 
        // Only use first frame of animated texture
-       if (tiles[texid].material_flags & MATERIAL_FLAG_ANIMATION)
-               texture = tiles[texid].frames[0].texture;
+       if (tile.material_flags & MATERIAL_FLAG_ANIMATION)
+               texture = tile.frames[0].texture;
        else
-               texture = tiles[texid].texture;
+               texture = tile.texture;
 
        float size = rand() % 64 / 512.;
        float visual_size = BS * size;
@@ -638,6 +650,12 @@ void ParticleManager::addNodeParticle(IGameDef* gamedef, scene::ISceneManager* s
                (f32) pos.Z + rand() %100 /200. - 0.25
        );
 
+       video::SColor color;
+       if (tile.has_color)
+               color = tile.color;
+       else
+               n.getColor(f, &color);
+
        Particle* toadd = new Particle(
                gamedef,
                smgr,
@@ -655,7 +673,8 @@ void ParticleManager::addNodeParticle(IGameDef* gamedef, scene::ISceneManager* s
                texpos,
                texsize,
                anim,
-               0);
+               0,
+               color);
 
        addParticle(toadd);
 }