cube inventory texture rendering thing (not good yet)
[oweals/minetest.git] / src / mapblock.cpp
index e66d4dd8f2954f52cf4fd17a7081709e77e22576..63f33ffc0d2d0cedb4a3264a728ced5a70946c3b 100644 (file)
@@ -148,25 +148,6 @@ u8 MapBlock::getFaceLight(u32 daynight_ratio, MapNode n, MapNode n2,
                v3s16 face_dir)
 {
        try{
-               // DEBUG
-               /*{
-                       if(n.d == CONTENT_WATER)
-                       {
-                               u8 l = n.param2*2;
-                               if(l > LIGHT_MAX)
-                                       l = LIGHT_MAX;
-                               return l;
-                       }
-                       if(n2.d == CONTENT_WATER)
-                       {
-                               u8 l = n2.param2*2;
-                               if(l > LIGHT_MAX)
-                                       l = LIGHT_MAX;
-                               return l;
-                       }
-               }*/
-
-
                u8 light;
                u8 l1 = n.getLightBlend(daynight_ratio);
                u8 l2 = n2.getLightBlend(daynight_ratio);
@@ -177,11 +158,13 @@ u8 MapBlock::getFaceLight(u32 daynight_ratio, MapNode n, MapNode n2,
 
                // Make some nice difference to different sides
 
+               // This makes light come from a corner
                /*if(face_dir.X == 1 || face_dir.Z == 1 || face_dir.Y == -1)
                        light = diminish_light(diminish_light(light));
                else if(face_dir.X == -1 || face_dir.Z == -1)
                        light = diminish_light(light);*/
-
+               
+               // All neighboring faces have different shade (like in minecraft)
                if(face_dir.X == 1 || face_dir.X == -1 || face_dir.Y == -1)
                        light = diminish_light(diminish_light(light));
                else if(face_dir.Z == 1 || face_dir.Z == -1)
@@ -341,20 +324,21 @@ TileSpec MapBlock::getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir,
                                Get texture id, translate it to name, append stuff to
                                name, get texture id
                        */
+
                        // Get original texture name
                        u32 orig_id = spec.texture.id;
                        std::string orig_name = g_texturesource->getTextureName(orig_id);
+
                        // Create new texture name
                        std::ostringstream os;
                        os<<orig_name<<"^[crack"<<mod.param;
-                       //os<<orig_name<<"^[progressbar0.5";
-                       //os<<"mese.png";
+
                        // Get new texture
                        u32 new_id = g_texturesource->getTextureId(os.str());
                        
-                       dstream<<"MapBlock::getNodeTile(): Switching from "
+                       /*dstream<<"MapBlock::getNodeTile(): Switching from "
                                        <<orig_name<<" to "<<os.str()<<" ("
-                                       <<orig_id<<" to "<<new_id<<")"<<std::endl;
+                                       <<orig_id<<" to "<<new_id<<")"<<std::endl;*/
                        
                        spec.texture = g_texturesource->getTexture(new_id);
                }
@@ -677,7 +661,7 @@ void MapBlock::updateMesh(u32 daynight_ratio)
        
        float node_water_level = 1.0;
        if(new_style_water)
-               node_water_level = 0.9;
+               node_water_level = 0.85;
        
        /*
                We are including the faces of the trailing edges of the block.
@@ -790,7 +774,7 @@ void MapBlock::updateMesh(u32 daynight_ratio)
        // Flowing water material
        video::SMaterial material_water1;
        material_water1.setFlag(video::EMF_LIGHTING, false);
-       material_water1.setFlag(video::EMF_BACK_FACE_CULLING, false);
+       //material_water1.setFlag(video::EMF_BACK_FACE_CULLING, false);
        material_water1.setFlag(video::EMF_BILINEAR_FILTER, false);
        material_water1.setFlag(video::EMF_FOG_ENABLE, true);
        material_water1.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
@@ -864,20 +848,20 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                        //material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
                        material.MaterialType
                                        = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
-                       //TODO
-                       /*if(dir == v3s16(0,-1,0))
+
+                       if(dir == v3s16(0,-1,0))
                                material.setTexture(0,
-                                               g_irrlicht->getTexture("torch_on_floor.png"));
+                                               g_texturesource->getTextureRaw("torch_on_floor.png"));
                        else if(dir == v3s16(0,1,0))
                                material.setTexture(0,
-                                               g_irrlicht->getTexture("torch_on_ceiling.png"));
+                                               g_texturesource->getTextureRaw("torch_on_ceiling.png"));
                        // For backwards compatibility
                        else if(dir == v3s16(0,0,0))
                                material.setTexture(0,
-                                               g_irrlicht->getTexture("torch_on_floor.png"));
+                                               g_texturesource->getTextureRaw("torch_on_floor.png"));
                        else
                                material.setTexture(0, 
-                                               g_irrlicht->getTexture("torch.png"));*/
+                                               g_texturesource->getTextureRaw("torch.png"));
 
                        u16 indices[] = {0,1,2,2,3,0};
                        // Add to mesh collector
@@ -1039,9 +1023,9 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                                        video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,1),
                                        video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
                                        video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),*/
-                                       video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
+                                       video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
                                                        pa_water1.x0(), pa_water1.y1()),
-                                       video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
+                                       video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
                                                        pa_water1.x1(), pa_water1.y1()),
                                        video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
                                                        pa_water1.x1(), pa_water1.y0()),
@@ -1117,21 +1101,25 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                                        video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,1),
                                        video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
                                        video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),*/
-                                       video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
+                                       video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
                                                        pa_water1.x0(), pa_water1.y1()),
-                                       video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
-                                                       pa_water1.x1(), pa_water1.y1()),
                                        video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
+                                                       pa_water1.x1(), pa_water1.y1()),
+                                       video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
                                                        pa_water1.x1(), pa_water1.y0()),
-                                       video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
+                                       video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
                                                        pa_water1.x0(), pa_water1.y0()),
                                };
+                               
+                               // This fixes a strange bug
+                               s32 corner_resolve[4] = {3,2,1,0};
 
                                for(s32 i=0; i<4; i++)
                                {
                                        //vertices[i].Pos.Y += water_level;
                                        //vertices[i].Pos.Y += neighbor_levels[v3s16(0,0,0)];
-                                       vertices[i].Pos.Y += corner_levels[i];
+                                       s32 j = corner_resolve[i];
+                                       vertices[i].Pos.Y += corner_levels[j];
                                        vertices[i].Pos += intToFloat(p + getPosRelative());
                                }
 
@@ -1169,13 +1157,13 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                                video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c, 1,1),
                                video::S3DVertex(BS/2,0,BS/2, 0,0,0, c, 1,0),
                                video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c, 0,0),*/
-                               video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
+                               video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
                                                pa_water1.x0(), pa_water1.y1()),
-                               video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
-                                               pa_water1.x1(), pa_water1.y1()),
                                video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
+                                               pa_water1.x1(), pa_water1.y1()),
+                               video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
                                                pa_water1.x1(), pa_water1.y0()),
-                               video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
+                               video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
                                                pa_water1.x0(), pa_water1.y0()),
                        };
 
@@ -1194,7 +1182,8 @@ void MapBlock::updateMesh(u32 daynight_ratio)
                */
                else if(n.d == CONTENT_LEAVES && new_style_leaves)
                {
-                       u8 l = decode_light(n.getLightBlend(daynight_ratio));
+                       /*u8 l = decode_light(n.getLightBlend(daynight_ratio));*/
+                       u8 l = decode_light(undiminish_light(n.getLightBlend(daynight_ratio)));
                        video::SColor c(255,l,l,l);
 
                        for(u32 j=0; j<6; j++)