]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/content_mapblock.cpp
Made dark places tint slightly in blue
[dragonfireclient.git] / src / content_mapblock.cpp
index e7c7051778b1cbcf5f9ffdce22794ecfd026f646..e542cb3359ef7c5ec4bd0b982facd63415514c6b 100644 (file)
@@ -20,6 +20,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "content_mapblock.h"
 #include "content_mapnode.h"
 #include "main.h" // For g_settings and g_texturesource
+#include "mineral.h"
+#include "mapblock_mesh.h" // For MapBlock_LightColor()
 
 #ifndef SERVER
 // Create a cuboid.
@@ -129,6 +131,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
        bool new_style_water = g_settings.getBool("new_style_water");
        bool new_style_leaves = g_settings.getBool("new_style_leaves");
        //bool smooth_lighting = g_settings.getBool("smooth_lighting");
+       bool invisible_stone = g_settings.getBool("invisible_stone");
        
        float node_water_level = 1.0;
        if(new_style_water)
@@ -178,6 +181,35 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
                        g_texturesource->getTextureId("wood.png"));
        material_wood.setTexture(0, pa_wood.atlas);
 
+       // General ground material for special output
+       // Texture is modified just before usage
+       video::SMaterial material_general;
+       material_general.setFlag(video::EMF_LIGHTING, false);
+       material_general.setFlag(video::EMF_BILINEAR_FILTER, false);
+       material_general.setFlag(video::EMF_FOG_ENABLE, true);
+       material_general.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+
+
+       // Papyrus material
+       video::SMaterial material_papyrus;
+       material_papyrus.setFlag(video::EMF_LIGHTING, false);
+       material_papyrus.setFlag(video::EMF_BILINEAR_FILTER, false);
+       material_papyrus.setFlag(video::EMF_FOG_ENABLE, true);
+       material_papyrus.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+       AtlasPointer pa_papyrus = g_texturesource->getTexture(
+                       g_texturesource->getTextureId("papyrus.png"));
+       material_papyrus.setTexture(0, pa_papyrus.atlas);
+
+       // junglegrass material
+       video::SMaterial material_junglegrass;
+       material_junglegrass.setFlag(video::EMF_LIGHTING, false);
+       material_junglegrass.setFlag(video::EMF_BILINEAR_FILTER, false);
+       material_junglegrass.setFlag(video::EMF_FOG_ENABLE, true);
+       material_junglegrass.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+       AtlasPointer pa_junglegrass = g_texturesource->getTexture(
+                       g_texturesource->getTextureId("junglegrass.png"));
+       material_junglegrass.setTexture(0, pa_junglegrass.atlas);
+
        for(s16 z=0; z<MAP_BLOCKSIZE; z++)
        for(s16 y=0; y<MAP_BLOCKSIZE; y++)
        for(s16 x=0; x<MAP_BLOCKSIZE; x++)
@@ -252,10 +284,10 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
                /*
                        Signs on walls
                */
-               if(n.d == CONTENT_SIGN_WALL)
+               else if(n.d == CONTENT_SIGN_WALL)
                {
                        u8 l = decode_light(n.getLightBlend(data->m_daynight_ratio));
-                       video::SColor c(255,l,l,l);
+                       video::SColor c = MapBlock_LightColor(255, l);
                                
                        float d = (float)BS/16;
                        // Wall at X+ of node
@@ -321,7 +353,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
                        // Otherwise use the light of this node (the water)
                        else
                                l = decode_light(n.getLightBlend(data->m_daynight_ratio));
-                       video::SColor c(WATER_ALPHA,l,l,l);
+                       video::SColor c = MapBlock_LightColor(WATER_ALPHA, l);
                        
                        // Neighbor water levels (key = relative position)
                        // Includes current node
@@ -355,7 +387,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
                                        if(n2.d == CONTENT_WATERSOURCE)
                                                level = (-0.5+node_water_level) * BS;
                                        else if(n2.d == CONTENT_WATER)
-                                               level = (-0.5 + ((float)n2.param2 + 0.5) / 8.0
+                                               level = (-0.5 + ((float)(n2.param2 & LIQUID_LEVEL_MASK) + 0.5) / 8.0
                                                                * node_water_level) * BS;
 
                                        // Check node above neighbor.
@@ -587,7 +619,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
                                continue;
 
                        u8 l = decode_light(n.getLightBlend(data->m_daynight_ratio));
-                       video::SColor c(WATER_ALPHA,l,l,l);
+                       video::SColor c = MapBlock_LightColor(WATER_ALPHA, l);
                        
                        video::S3DVertex vertices[4] =
                        {
@@ -622,7 +654,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
                {
                        /*u8 l = decode_light(n.getLightBlend(data->m_daynight_ratio));*/
                        u8 l = decode_light(undiminish_light(n.getLightBlend(data->m_daynight_ratio)));
-                       video::SColor c(255,l,l,l);
+                       video::SColor c = MapBlock_LightColor(255, l);
 
                        for(u32 j=0; j<6; j++)
                        {
@@ -689,7 +721,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
                else if(n.d == CONTENT_GLASS)
                {
                        u8 l = decode_light(undiminish_light(n.getLightBlend(data->m_daynight_ratio)));
-                       video::SColor c(255,l,l,l);
+                       video::SColor c = MapBlock_LightColor(255, l);
 
                        for(u32 j=0; j<6; j++)
                        {
@@ -752,7 +784,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
                else if(n.d == CONTENT_FENCE)
                {
                        u8 l = decode_light(undiminish_light(n.getLightBlend(data->m_daynight_ratio)));
-                       video::SColor c(255,l,l,l);
+                       video::SColor c = MapBlock_LightColor(255, l);
 
                        const f32 post_rad=(f32)BS/10;
                        const f32 bar_rad=(f32)BS/20;
@@ -824,7 +856,283 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
                        }
 
                }
+#if 1
+               /*
+                       Add stones with minerals if stone is invisible
+               */
+               else if(n.d == CONTENT_STONE && invisible_stone && n.getMineral() != MINERAL_NONE)
+               {
+                       for(u32 j=0; j<6; j++)
+                       {
+                               // NOTE: Hopefully g_6dirs[j] is the right direction...
+                               v3s16 dir = g_6dirs[j];
+                               /*u8 l = 0;
+                               MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + dir);
+                               if(content_features(n2.d).param_type == CPT_LIGHT)
+                                       l = decode_light(n2.getLightBlend(data->m_daynight_ratio));
+                               else
+                                       l = 255;*/
+                               u8 l = 255;
+                               video::SColor c = MapBlock_LightColor(255, l);
+                               
+                               // Get the right texture
+                               TileSpec ts = n.getTile(dir);
+                               AtlasPointer ap = ts.texture;
+                               material_general.setTexture(0, ap.atlas);
+                               video::S3DVertex vertices[4] =
+                               {
+                                       /*video::S3DVertex(-BS/2,-BS/2,BS/2, 0,0,0, c, 0,1),
+                                       video::S3DVertex(BS/2,-BS/2,BS/2, 0,0,0, c, 1,1),
+                                       video::S3DVertex(BS/2,BS/2,BS/2, 0,0,0, c, 1,0),
+                                       video::S3DVertex(-BS/2,BS/2,BS/2, 0,0,0, c, 0,0),*/
+                                       video::S3DVertex(-BS/2,-BS/2,BS/2, 0,0,0, c,
+                                               ap.x0(), ap.y1()),
+                                       video::S3DVertex(BS/2,-BS/2,BS/2, 0,0,0, c,
+                                               ap.x1(), ap.y1()),
+                                       video::S3DVertex(BS/2,BS/2,BS/2, 0,0,0, c,
+                                               ap.x1(), ap.y0()),
+                                       video::S3DVertex(-BS/2,BS/2,BS/2, 0,0,0, c,
+                                               ap.x0(), ap.y0()),
+                               };
+
+                               if(j == 0)
+                               {
+                                       for(u16 i=0; i<4; i++)
+                                               vertices[i].Pos.rotateXZBy(0);
+                               }
+                               else if(j == 1)
+                               {
+                                       for(u16 i=0; i<4; i++)
+                                               vertices[i].Pos.rotateXZBy(180);
+                               }
+                               else if(j == 2)
+                               {
+                                       for(u16 i=0; i<4; i++)
+                                               vertices[i].Pos.rotateXZBy(-90);
+                               }
+                               else if(j == 3)
+                               {
+                                       for(u16 i=0; i<4; i++)
+                                               vertices[i].Pos.rotateXZBy(90);
+                               }
+                               else if(j == 4)
+
+                               for(u16 i=0; i<4; i++)
+                               {
+                                       vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
+                               }
+
+                               u16 indices[] = {0,1,2,2,3,0};
+                               // Add to mesh collector
+                               collector.append(material_general, vertices, 4, indices, 6);
+                       }
+               }
+#endif
+               else if(n.d == CONTENT_PAPYRUS)
+               {
+                       u8 l = decode_light(undiminish_light(n.getLightBlend(data->m_daynight_ratio)));
+                       video::SColor c = MapBlock_LightColor(255, l);
+
+                       for(u32 j=0; j<4; j++)
+                       {
+                               video::S3DVertex vertices[4] =
+                               {
+                                       video::S3DVertex(-BS/2,-BS/2,0, 0,0,0, c,
+                                               pa_papyrus.x0(), pa_papyrus.y1()),
+                                       video::S3DVertex(BS/2,-BS/2,0, 0,0,0, c,
+                                               pa_papyrus.x1(), pa_papyrus.y1()),
+                                       video::S3DVertex(BS/2,BS/2,0, 0,0,0, c,
+                                               pa_papyrus.x1(), pa_papyrus.y0()),
+                                       video::S3DVertex(-BS/2,BS/2,0, 0,0,0, c,
+                                               pa_papyrus.x0(), pa_papyrus.y0()),
+                               };
+
+                               if(j == 0)
+                               {
+                                       for(u16 i=0; i<4; i++)
+                                               vertices[i].Pos.rotateXZBy(45);
+                               }
+                               else if(j == 1)
+                               {
+                                       for(u16 i=0; i<4; i++)
+                                               vertices[i].Pos.rotateXZBy(-45);
+                               }
+                               else if(j == 2)
+                               {
+                                       for(u16 i=0; i<4; i++)
+                                               vertices[i].Pos.rotateXZBy(135);
+                               }
+                               else if(j == 3)
+                               {
+                                       for(u16 i=0; i<4; i++)
+                                               vertices[i].Pos.rotateXZBy(-135);
+                               }
+
+                               for(u16 i=0; i<4; i++)
+                               {
+                                       vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
+                               }
+
+                               u16 indices[] = {0,1,2,2,3,0};
+                               // Add to mesh collector
+                               collector.append(material_papyrus, vertices, 4, indices, 6);
+                       }
+               }
+               else if(n.d == CONTENT_JUNGLEGRASS)
+               {
+                       u8 l = decode_light(undiminish_light(n.getLightBlend(data->m_daynight_ratio)));
+                       video::SColor c = MapBlock_LightColor(255, l);
+
+                       for(u32 j=0; j<4; j++)
+                       {
+                               video::S3DVertex vertices[4] =
+                               {
+                                       video::S3DVertex(-BS/2,-BS/2,0, 0,0,0, c,
+                                               pa_papyrus.x0(), pa_papyrus.y1()),
+                                       video::S3DVertex(BS/2,-BS/2,0, 0,0,0, c,
+                                               pa_papyrus.x1(), pa_papyrus.y1()),
+                                       video::S3DVertex(BS/2,BS/1,0, 0,0,0, c,
+                                               pa_papyrus.x1(), pa_papyrus.y0()),
+                                       video::S3DVertex(-BS/2,BS/1,0, 0,0,0, c,
+                                               pa_papyrus.x0(), pa_papyrus.y0()),
+                               };
+
+                               if(j == 0)
+                               {
+                                       for(u16 i=0; i<4; i++)
+                                               vertices[i].Pos.rotateXZBy(45);
+                               }
+                               else if(j == 1)
+                               {
+                                       for(u16 i=0; i<4; i++)
+                                               vertices[i].Pos.rotateXZBy(-45);
+                               }
+                               else if(j == 2)
+                               {
+                                       for(u16 i=0; i<4; i++)
+                                               vertices[i].Pos.rotateXZBy(135);
+                               }
+                               else if(j == 3)
+                               {
+                                       for(u16 i=0; i<4; i++)
+                                               vertices[i].Pos.rotateXZBy(-135);
+                               }
+
+                               for(u16 i=0; i<4; i++)
+                               {
+                                       vertices[i].Pos *= 1.3;
+                                       vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
+                               }
+
+                               u16 indices[] = {0,1,2,2,3,0};
+                               // Add to mesh collector
+                               collector.append(material_junglegrass, vertices, 4, indices, 6);
+                       }
+               }
+               else if(n.d == CONTENT_RAIL)
+               {
+                       u8 l = decode_light(n.getLightBlend(data->m_daynight_ratio));
+                       video::SColor c = MapBlock_LightColor(255, l);
+
+                       bool is_rail_x [] = { false, false };  /* x-1, x+1 */
+                       bool is_rail_z [] = { false, false };  /* z-1, z+1 */
+
+                       MapNode n_minus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1,y,z));
+                       MapNode n_plus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1,y,z));
+                       MapNode n_minus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z-1));
+                       MapNode n_plus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z+1));
+
+                       if(n_minus_x.d == CONTENT_RAIL)
+                               is_rail_x[0] = true;
+                       if(n_plus_x.d == CONTENT_RAIL)
+                               is_rail_x[1] = true;
+                       if(n_minus_z.d == CONTENT_RAIL)
+                               is_rail_z[0] = true;
+                       if(n_plus_z.d == CONTENT_RAIL)
+                               is_rail_z[1] = true;
+
+                       float d = (float)BS/16;
+                       video::S3DVertex vertices[4] =
+                       {
+                               video::S3DVertex(-BS/2,-BS/2+d,-BS/2, 0,0,0, c,
+                                       0, 1),
+                               video::S3DVertex(BS/2,-BS/2+d,-BS/2, 0,0,0, c,
+                                       1, 1),
+                               video::S3DVertex(BS/2,-BS/2+d,BS/2, 0,0,0, c,
+                                       1, 0),
+                               video::S3DVertex(-BS/2,-BS/2+d,BS/2, 0,0,0, c,
+                                       0, 0),
+                       };
+
+                       video::SMaterial material_rail;
+                       material_rail.setFlag(video::EMF_LIGHTING, false);
+                       material_rail.setFlag(video::EMF_BACK_FACE_CULLING, false);
+                       material_rail.setFlag(video::EMF_BILINEAR_FILTER, false);
+                       material_rail.setFlag(video::EMF_FOG_ENABLE, true);
+                       material_rail.MaterialType
+                                       = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+
+                       int adjacencies = is_rail_x[0] + is_rail_x[1] + is_rail_z[0] + is_rail_z[1];
+
+                       // Assign textures
+                       if(adjacencies < 2)
+                               material_rail.setTexture(0, g_texturesource->getTextureRaw("rail.png"));
+                       else if(adjacencies == 2)
+                       {
+                               if((is_rail_x[0] && is_rail_x[1]) || (is_rail_z[0] && is_rail_z[1]))
+                                       material_rail.setTexture(0, g_texturesource->getTextureRaw("rail.png"));
+                               else
+                                       material_rail.setTexture(0, g_texturesource->getTextureRaw("rail_curved.png"));
+                       }
+                       else if(adjacencies == 3)
+                               material_rail.setTexture(0, g_texturesource->getTextureRaw("rail_t_junction.png"));
+                       else if(adjacencies == 4)
+                               material_rail.setTexture(0, g_texturesource->getTextureRaw("rail_crossing.png"));
+
+                       // Rotate textures
+                       int angle = 0;
+
+                       if(adjacencies == 1)
+                       {
+                               if(is_rail_x[0] || is_rail_x[1])
+                                       angle = 90;
+                       }
+                       else if(adjacencies == 2)
+                       {
+                               if(is_rail_x[0] && is_rail_x[1])
+                                       angle = 90;
+                               else if(is_rail_x[0] && is_rail_z[0])
+                                       angle = 270;
+                               else if(is_rail_x[0] && is_rail_z[1])
+                                       angle = 180;
+                               else if(is_rail_x[1] && is_rail_z[1])
+                                       angle = 90;
+                       }
+                       else if(adjacencies == 3)
+                       {
+                               if(!is_rail_x[0])
+                                       angle=0;
+                               if(!is_rail_x[1])
+                                       angle=180;
+                               if(!is_rail_z[0])
+                                       angle=90;
+                               if(!is_rail_z[1])
+                                       angle=270;
+                       }
 
+                       if(angle != 0) {
+                               for(u16 i=0; i<4; i++)
+                                       vertices[i].Pos.rotateXZBy(angle);
+                       }
+
+                       for(s32 i=0; i<4; i++)
+                       {
+                               vertices[i].Pos += intToFloat(p + blockpos_nodes, BS);
+                       }
+
+                       u16 indices[] = {0,1,2,2,3,0};
+                       collector.append(material_rail, vertices, 4, indices, 6);
+               }
        }
 }
 #endif