@@ -1072,12 +1072,18 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data):
1072
1072
Also store animation info
1073
1073
*/
1074
1074
bool enable_shaders = (g_settings->getS32 (" enable_shaders" ) > 0 );
1075
+ bool enable_bumpmapping = g_settings->getBool (" enable_bumpmapping" );
1075
1076
video::E_MATERIAL_TYPE shadermat1 = m_gamedef->getShaderSource ()->
1076
1077
getShader (" test_shader_1" ).material ;
1077
1078
video::E_MATERIAL_TYPE shadermat2 = m_gamedef->getShaderSource ()->
1078
1079
getShader (" test_shader_2" ).material ;
1079
1080
video::E_MATERIAL_TYPE shadermat3 = m_gamedef->getShaderSource ()->
1080
1081
getShader (" test_shader_3" ).material ;
1082
+ video::E_MATERIAL_TYPE bumpmaps1 = m_gamedef->getShaderSource ()->
1083
+ getShader (" bumpmaps_solids" ).material ;
1084
+ video::E_MATERIAL_TYPE bumpmaps2 = m_gamedef->getShaderSource ()->
1085
+ getShader (" bumpmaps_liquids" ).material ;
1086
+
1081
1087
for (u32 i = 0 ; i < collector.prebuffers .size (); i++)
1082
1088
{
1083
1089
PreMeshBuffer &p = collector.prebuffers [i];
@@ -1154,8 +1160,33 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data):
1154
1160
material.MaterialType
1155
1161
= video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
1156
1162
material.setTexture (0 , p.tile .texture );
1157
- if (enable_shaders)
1158
- p.tile .applyMaterialOptionsWithShaders (material, shadermat1, shadermat2, shadermat3);
1163
+ if (enable_shaders)
1164
+ {
1165
+ if (enable_bumpmapping)
1166
+ {
1167
+ ITextureSource *tsrc = data->m_gamedef ->tsrc ();
1168
+ std::string basename,normal ,replace;
1169
+ replace = " _normal.png" ;
1170
+ basename = tsrc->getTextureName (p.tile .texture_id );
1171
+ unsigned pos = basename.find (" ." );
1172
+ normal = basename.substr (0 , pos) + replace;
1173
+ if (tsrc->isKnownSourceImage (normal ))
1174
+ {
1175
+ // look for image extension and replace it
1176
+ for (std::string::size_type i = 0 ; (i = basename.find (" ." , i)) != std::string::npos;)
1177
+ {
1178
+ basename.replace (i, 4 , replace);
1179
+ i += replace.length ();
1180
+ }
1181
+ material.setTexture (1 , tsrc->getTexture (basename));
1182
+ p.tile .applyMaterialOptionsWithShaders (material, bumpmaps1,bumpmaps2, shadermat3);
1183
+ }
1184
+ else
1185
+ p.tile .applyMaterialOptionsWithShaders (material, shadermat1, shadermat2, shadermat3);
1186
+ }
1187
+ else
1188
+ p.tile .applyMaterialOptionsWithShaders (material, shadermat1, shadermat2, shadermat3);
1189
+ }
1159
1190
else
1160
1191
p.tile .applyMaterialOptions (material);
1161
1192
@@ -1217,6 +1248,9 @@ MapBlockMesh::~MapBlockMesh()
1217
1248
1218
1249
bool MapBlockMesh::animate (bool faraway, float time, int crack, u32 daynight_ratio)
1219
1250
{
1251
+ bool enable_shaders = (g_settings->getS32 (" enable_shaders" ) > 0 );
1252
+ bool enable_bumpmapping = g_settings->getBool (" enable_bumpmapping" );
1253
+
1220
1254
if (!m_has_animation)
1221
1255
{
1222
1256
m_animation_force_timer = 100000 ;
@@ -1271,6 +1305,19 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
1271
1305
os<<" ^[verticalframe:" <<(int )tile.animation_frame_count <<" :" <<frame;
1272
1306
// Set the texture
1273
1307
buf->getMaterial ().setTexture (0 , tsrc->getTexture (os.str ()));
1308
+ if (enable_shaders && enable_bumpmapping)
1309
+ {
1310
+ std::string basename,normal ;
1311
+ basename = tsrc->getTextureName (tile.texture_id );
1312
+ unsigned pos;
1313
+ pos = basename.find (" ." );
1314
+ normal = basename.substr (0 , pos);
1315
+ normal += " _normal.png" ;
1316
+ os.str (" " );
1317
+ os<<normal <<" ^[verticalframe:" <<(int )tile.animation_frame_count <<" :" <<frame;
1318
+ if (tsrc->isKnownSourceImage (normal ))
1319
+ buf->getMaterial ().setTexture (1 , tsrc->getTexture (os.str ()));
1320
+ }
1274
1321
}
1275
1322
1276
1323
// Day-night transition
0 commit comments