aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2013-04-23 18:39:10 -0400
committerkwolekr <kwolekr@minetest.net>2013-04-23 22:15:51 -0400
commit770305e28dc0ed9aea0eefe041477a46d64eee58 (patch)
tree2306e3f96cdb54848c12f5ee159b12cdb55dcfb2 /src
parent36747794ab981e5d1cc085075979ef981e783b55 (diff)
downloadminetest-770305e28dc0ed9aea0eefe041477a46d64eee58.tar.gz
minetest-770305e28dc0ed9aea0eefe041477a46d64eee58.tar.bz2
minetest-770305e28dc0ed9aea0eefe041477a46d64eee58.zip
Add option to use texture alpha channel
Diffstat (limited to 'src')
-rw-r--r--src/mapblock_mesh.cpp4
-rw-r--r--src/nodedef.cpp14
-rw-r--r--src/scriptapi_content.cpp5
-rw-r--r--src/tile.h10
4 files changed, 22 insertions, 11 deletions
diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp
index f68a79e41..f8a0b5f06 100644
--- a/src/mapblock_mesh.cpp
+++ b/src/mapblock_mesh.cpp
@@ -1099,6 +1099,8 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data):
getShader("test_shader_1").material;
video::E_MATERIAL_TYPE shadermat2 = m_gamedef->getShaderSource()->
getShader("test_shader_2").material;
+ video::E_MATERIAL_TYPE shadermat3 = m_gamedef->getShaderSource()->
+ getShader("test_shader_3").material;
for(u32 i = 0; i < collector.prebuffers.size(); i++)
{
PreMeshBuffer &p = collector.prebuffers[i];
@@ -1174,7 +1176,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data):
= video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
material.setTexture(0, p.tile.texture.atlas);
if(enable_shaders)
- p.tile.applyMaterialOptionsWithShaders(material, shadermat1, shadermat2);
+ p.tile.applyMaterialOptionsWithShaders(material, shadermat1, shadermat2, shadermat3);
else
p.tile.applyMaterialOptions(material);
diff --git a/src/nodedef.cpp b/src/nodedef.cpp
index e2b72333f..e09c1910d 100644
--- a/src/nodedef.cpp
+++ b/src/nodedef.cpp
@@ -658,15 +658,11 @@ 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;
- }
+ u8 material_type;
+ if (is_liquid)
+ material_type = (f->alpha == 255) ? TILE_MATERIAL_LIQUID_OPAQUE : TILE_MATERIAL_LIQUID_TRANSPARENT;
+ else
+ material_type = (f->alpha == 255) ? TILE_MATERIAL_BASIC : TILE_MATERIAL_ALPHA;
// Tiles (fill in f->tiles[])
for(u16 j=0; j<6; j++){
diff --git a/src/scriptapi_content.cpp b/src/scriptapi_content.cpp
index 3b7ed5179..30fd70349 100644
--- a/src/scriptapi_content.cpp
+++ b/src/scriptapi_content.cpp
@@ -225,6 +225,11 @@ ContentFeatures read_content_features(lua_State *L, int index)
lua_pop(L, 1);
f.alpha = getintfield_default(L, index, "alpha", 255);
+
+ bool usealpha = getboolfield_default(L, index,
+ "use_texture_alpha", false);
+ if (usealpha)
+ f.alpha = 0;
/* Other stuff */
diff --git a/src/tile.h b/src/tile.h
index c5c7f9303..ea5c4be54 100644
--- a/src/tile.h
+++ b/src/tile.h
@@ -162,6 +162,7 @@ IWritableTextureSource* createTextureSource(IrrlichtDevice *device);
enum MaterialType{
TILE_MATERIAL_BASIC,
+ TILE_MATERIAL_ALPHA,
TILE_MATERIAL_LIQUID_TRANSPARENT,
TILE_MATERIAL_LIQUID_OPAQUE,
};
@@ -222,6 +223,9 @@ struct TileSpec
case TILE_MATERIAL_BASIC:
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
break;
+ case TILE_MATERIAL_ALPHA:
+ material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
+ break;
case TILE_MATERIAL_LIQUID_TRANSPARENT:
material.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
break;
@@ -233,12 +237,16 @@ struct TileSpec
}
void applyMaterialOptionsWithShaders(video::SMaterial &material,
const video::E_MATERIAL_TYPE &basic,
- const video::E_MATERIAL_TYPE &liquid) const
+ const video::E_MATERIAL_TYPE &liquid,
+ const video::E_MATERIAL_TYPE &alpha) const
{
switch(material_type){
case TILE_MATERIAL_BASIC:
material.MaterialType = basic;
break;
+ case TILE_MATERIAL_ALPHA:
+ material.MaterialType = alpha;
+ break;
case TILE_MATERIAL_LIQUID_TRANSPARENT:
material.MaterialType = liquid;
break;