Fix tile MaterialType to make sense and make lava surface be shader'd lower like...
authorPerttu Ahola <celeron55@gmail.com>
Sun, 2 Dec 2012 00:57:14 +0000 (02:57 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 2 Dec 2012 00:59:15 +0000 (02:59 +0200)
src/mapblock_mesh.cpp
src/nodedef.cpp
src/tile.h

index c871b6dbe460c3fd0af4d5594f1099ab39204474..a9f14f8f06cbd2d73c86cfc9d524c77ac7d09bc8 100644 (file)
@@ -1081,14 +1081,10 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data):
                material.MaterialType
                                = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
                material.setTexture(0, p.tile.texture.atlas);
-               p.tile.applyMaterialOptions(material);
-
-               if(enable_shaders){
-                       if(material.MaterialType == video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF)
-                               material.MaterialType = shadermat1;
-                       if(material.MaterialType == video::EMT_TRANSPARENT_VERTEX_ALPHA)
-                               material.MaterialType = shadermat2;
-               }
+               if(enable_shaders)
+                       p.tile.applyMaterialOptionsWithShaders(material, shadermat1, shadermat2);
+               else
+                       p.tile.applyMaterialOptions(material);
 
                // Create meshbuffer
 
index c48e2ff976cf012d7ed3f99811771d0db8b00f0f..36fa798fd4492a2c734d220e554314f5ce607d45 100644 (file)
@@ -555,6 +555,7 @@ public:
                                        tiledef[j].name = "unknown_block.png";
                        }
 
+                       bool is_liquid = false;
                        switch(f->drawtype){
                        default:
                        case NDT_NORMAL:
@@ -573,12 +574,14 @@ public:
                                        f->solidness = 1;
                                        f->backface_culling = false;
                                }
+                               is_liquid = true;
                                break;
                        case NDT_FLOWINGLIQUID:
                                assert(f->liquid_type == LIQUID_FLOWING);
                                f->solidness = 0;
                                if(opaque_water)
                                        f->alpha = 255;
+                               is_liquid = true;
                                break;
                        case NDT_GLASSLIKE:
                                f->solidness = 0;
@@ -611,16 +614,24 @@ public:
                                break;
                        }
 
+                       u8 material_type = 0;
+                       if(is_liquid){
+                               if(f->alpha == 255)
+                                       material_type = TILE_MATERIAL_LIQUID_OPAQUE;
+                               else
+                                       material_type = TILE_MATERIAL_LIQUID_TRANSPARENT;
+                       } else{
+                               material_type = TILE_MATERIAL_BASIC;
+                       }
+
                        // Tiles (fill in f->tiles[])
                        for(u16 j=0; j<6; j++){
                                // Texture
                                f->tiles[j].texture = tsrc->getTexture(tiledef[j].name);
                                // Alpha
                                f->tiles[j].alpha = f->alpha;
-                               if(f->alpha == 255)
-                                       f->tiles[j].material_type = MATERIAL_ALPHA_SIMPLE;
-                               else
-                                       f->tiles[j].material_type = MATERIAL_ALPHA_VERTEX;
+                               // Material type
+                               f->tiles[j].material_type = material_type;
                                // Material flags
                                f->tiles[j].material_flags = 0;
                                if(f->backface_culling)
@@ -661,10 +672,8 @@ public:
                                                tsrc->getTexture(f->tiledef_special[j].name);
                                // Alpha
                                f->special_tiles[j].alpha = f->alpha;
-                               if(f->alpha == 255)
-                                       f->special_tiles[j].material_type = MATERIAL_ALPHA_SIMPLE;
-                               else
-                                       f->special_tiles[j].material_type = MATERIAL_ALPHA_VERTEX;
+                               // Material type
+                               f->special_tiles[j].material_type = material_type;
                                // Material flags
                                f->special_tiles[j].material_flags = 0;
                                if(f->tiledef_special[j].backface_culling)
index 12c40c833e72e5f0456fb450eecb48a7dbad3409..b00c1c6c671e67985e9084e6ef161acb6e9af7e2 100644 (file)
@@ -161,10 +161,9 @@ public:
 IWritableTextureSource* createTextureSource(IrrlichtDevice *device);
 
 enum MaterialType{
-       MATERIAL_ALPHA_NONE,
-       MATERIAL_ALPHA_VERTEX,
-       MATERIAL_ALPHA_SIMPLE, // >127 = opaque
-       MATERIAL_ALPHA_BLEND,
+       TILE_MATERIAL_BASIC,
+       TILE_MATERIAL_LIQUID_TRANSPARENT,
+       TILE_MATERIAL_LIQUID_OPAQUE,
 };
 
 // Material flags
@@ -178,6 +177,8 @@ enum MaterialType{
 // Animation made up by splitting the texture to vertical frames, as
 // defined by extra parameters
 #define MATERIAL_FLAG_ANIMATION_VERTICAL_FRAMES 0x08
+// Whether liquid shader should be used
+#define MATERIAL_FLAG_
 
 /*
        This fully defines the looks of a tile.
@@ -188,9 +189,7 @@ struct TileSpec
        TileSpec():
                texture(0),
                alpha(255),
-               //material_type(MATERIAL_ALPHA_NONE),
-               // Use this so that leaves don't need a separate material
-               material_type(MATERIAL_ALPHA_SIMPLE),
+               material_type(TILE_MATERIAL_BASIC),
                material_flags(
                        //0 // <- DEBUG, Use the one below
                        MATERIAL_FLAG_BACKFACE_CULLING
@@ -218,15 +217,34 @@ struct TileSpec
        // Sets everything else except the texture in the material
        void applyMaterialOptions(video::SMaterial &material) const
        {
-               if(material_type == MATERIAL_ALPHA_NONE)
-                       material.MaterialType = video::EMT_SOLID;
-               else if(material_type == MATERIAL_ALPHA_VERTEX)
-                       material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
-               else if(material_type == MATERIAL_ALPHA_SIMPLE)
+               switch(material_type){
+               case TILE_MATERIAL_BASIC:
                        material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
-               else if(material_type == MATERIAL_ALPHA_BLEND)
-                       material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
-
+                       break;
+               case TILE_MATERIAL_LIQUID_TRANSPARENT:
+                       material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
+                       break;
+               case TILE_MATERIAL_LIQUID_OPAQUE:
+                       material.MaterialType = video::EMT_SOLID;
+                       break;
+               }
+               material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) ? true : false;
+       }
+       void applyMaterialOptionsWithShaders(video::SMaterial &material,
+                       const video::E_MATERIAL_TYPE &basic,
+                       const video::E_MATERIAL_TYPE &liquid) const
+       {
+               switch(material_type){
+               case TILE_MATERIAL_BASIC:
+                       material.MaterialType = basic;
+                       break;
+               case TILE_MATERIAL_LIQUID_TRANSPARENT:
+                       material.MaterialType = liquid;
+                       break;
+               case TILE_MATERIAL_LIQUID_OPAQUE:
+                       material.MaterialType = liquid;
+                       break;
+               }
                material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) ? true : false;
        }