@@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
30
30
#include " shader.h"
31
31
#include " settings.h"
32
32
#include " util/directiontables.h"
33
+ #include < IMeshManipulator.h>
33
34
34
35
static void applyFacesShading (video::SColor& color, float factor)
35
36
{
@@ -1028,6 +1029,8 @@ static void updateAllFastFaceRows(MeshMakeData *data,
1028
1029
MapBlockMesh::MapBlockMesh (MeshMakeData *data, v3s16 camera_offset):
1029
1030
m_mesh(new scene::SMesh()),
1030
1031
m_gamedef(data->m_gamedef),
1032
+ m_tsrc(m_gamedef->getTextureSource ()),
1033
+ m_shdrsrc(m_gamedef->getShaderSource ()),
1031
1034
m_animation_force_timer(0 ), // force initial animation
1032
1035
m_last_crack(-1 ),
1033
1036
m_crack_materials(),
@@ -1110,8 +1113,6 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
1110
1113
/*
1111
1114
Convert MeshCollector to SMesh
1112
1115
*/
1113
- ITextureSource *tsrc = m_gamedef->tsrc ();
1114
- IShaderSource *shdrsrc = m_gamedef->getShaderSource ();
1115
1116
1116
1117
for (u32 i = 0 ; i < collector.prebuffers .size (); i++)
1117
1118
{
@@ -1123,13 +1124,13 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
1123
1124
{
1124
1125
// Find the texture name plus ^[crack:N:
1125
1126
std::ostringstream os (std::ios::binary);
1126
- os<<tsrc ->getTextureName (p.tile .texture_id )<<" ^[crack" ;
1127
+ os<<m_tsrc ->getTextureName (p.tile .texture_id )<<" ^[crack" ;
1127
1128
if (p.tile .material_flags & MATERIAL_FLAG_CRACK_OVERLAY)
1128
1129
os<<" o" ; // use ^[cracko
1129
1130
os<<" :" <<(u32)p.tile .animation_frame_count <<" :" ;
1130
1131
m_crack_materials.insert (std::make_pair (i, os.str ()));
1131
1132
// Replace tile texture with the cracked one
1132
- p.tile .texture = tsrc ->getTextureForMesh (
1133
+ p.tile .texture = m_tsrc ->getTextureForMesh (
1133
1134
os.str ()+" 0" ,
1134
1135
&p.tile .texture_id );
1135
1136
}
@@ -1158,20 +1159,21 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
1158
1159
1159
1160
for (u32 j = 0 ; j < p.vertices .size (); j++)
1160
1161
{
1162
+ video::S3DVertexTangents *vertex = &p.vertices [j];
1161
1163
// Note applyFacesShading second parameter is precalculated sqrt
1162
1164
// value for speed improvement
1163
1165
// Skip it for lightsources and top faces.
1164
- video::SColor &vc = p. vertices [j]. Color ;
1166
+ video::SColor &vc = vertex-> Color ;
1165
1167
if (!vc.getBlue ()) {
1166
- if (p. vertices [j]. Normal .Y < -0.5 ) {
1168
+ if (vertex-> Normal .Y < -0.5 ) {
1167
1169
applyFacesShading (vc, 0.447213 );
1168
- } else if (p. vertices [j]. Normal .X > 0.5 ) {
1170
+ } else if (vertex-> Normal .X > 0.5 ) {
1169
1171
applyFacesShading (vc, 0.670820 );
1170
- } else if (p. vertices [j]. Normal .X < -0.5 ) {
1172
+ } else if (vertex-> Normal .X < -0.5 ) {
1171
1173
applyFacesShading (vc, 0.670820 );
1172
- } else if (p. vertices [j]. Normal .Z > 0.5 ) {
1174
+ } else if (vertex-> Normal .Z > 0.5 ) {
1173
1175
applyFacesShading (vc, 0.836660 );
1174
- } else if (p. vertices [j]. Normal .Z < -0.5 ) {
1176
+ } else if (vertex-> Normal .Z < -0.5 ) {
1175
1177
applyFacesShading (vc, 0.836660 );
1176
1178
}
1177
1179
}
@@ -1199,33 +1201,30 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
1199
1201
material.MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
1200
1202
} else {
1201
1203
if (m_enable_shaders) {
1202
- material.MaterialType = shdrsrc ->getShaderInfo (p.tile .shader_id ).material ;
1204
+ material.MaterialType = m_shdrsrc ->getShaderInfo (p.tile .shader_id ).material ;
1203
1205
p.tile .applyMaterialOptionsWithShaders (material);
1204
1206
if (p.tile .normal_texture ) {
1205
1207
material.setTexture (1 , p.tile .normal_texture );
1206
- material.setTexture (2 , tsrc ->getTextureForMesh (" enable_img.png" ));
1208
+ material.setTexture (2 , m_tsrc ->getTextureForMesh (" enable_img.png" ));
1207
1209
} else {
1208
- material.setTexture (2 , tsrc ->getTextureForMesh (" disable_img.png" ));
1210
+ material.setTexture (2 , m_tsrc ->getTextureForMesh (" disable_img.png" ));
1209
1211
}
1210
1212
} else {
1211
1213
p.tile .applyMaterialOptions (material);
1212
1214
}
1213
1215
}
1214
-
1215
- // Create meshbuffer
1216
- // This is a "Standard MeshBuffer",
1217
- // it's a typedeffed CMeshBuffer<video::S3DVertex>
1218
- scene::SMeshBuffer *buf = new scene::SMeshBuffer ();
1219
- // Set material
1220
- buf->Material = material;
1221
- // Add to mesh
1222
- m_mesh->addMeshBuffer (buf);
1223
- // Mesh grabbed it
1224
- buf->drop ();
1225
- buf->append (&p.vertices [0 ], p.vertices .size (),
1226
- &p.indices [0 ], p.indices .size ());
1227
- }
1228
-
1216
+
1217
+ // Create meshbuffer
1218
+ scene::SMeshBufferTangents *buf = new scene::SMeshBufferTangents ();
1219
+ // Set material
1220
+ buf->Material = material;
1221
+ // Add to mesh
1222
+ m_mesh->addMeshBuffer (buf);
1223
+ // Mesh grabbed it
1224
+ buf->drop ();
1225
+ buf->append (&p.vertices [0 ], p.vertices .size (),
1226
+ &p.indices [0 ], p.indices .size ());
1227
+ }
1229
1228
m_camera_offset = camera_offset;
1230
1229
1231
1230
/*
@@ -1234,6 +1233,11 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
1234
1233
1235
1234
translateMesh (m_mesh, intToFloat (data->m_blockpos * MAP_BLOCKSIZE - camera_offset, BS));
1236
1235
1236
+ if (m_enable_shaders) {
1237
+ scene::IMeshManipulator* meshmanip = m_gamedef->getSceneManager ()->getMeshManipulator ();
1238
+ meshmanip->recalculateTangents (m_mesh, true , false , false );
1239
+ }
1240
+
1237
1241
if (m_mesh)
1238
1242
{
1239
1243
#if 0
@@ -1272,7 +1276,6 @@ MapBlockMesh::~MapBlockMesh()
1272
1276
1273
1277
bool MapBlockMesh::animate (bool faraway, float time, int crack, u32 daynight_ratio)
1274
1278
{
1275
-
1276
1279
if (!m_has_animation)
1277
1280
{
1278
1281
m_animation_force_timer = 100000 ;
@@ -1292,12 +1295,11 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
1292
1295
std::string basename = i->second ;
1293
1296
1294
1297
// Create new texture name from original
1295
- ITextureSource *tsrc = m_gamedef->getTextureSource ();
1296
1298
std::ostringstream os;
1297
1299
os<<basename<<crack;
1298
1300
u32 new_texture_id = 0 ;
1299
1301
video::ITexture *new_texture =
1300
- tsrc ->getTextureForMesh (os.str (), &new_texture_id);
1302
+ m_tsrc ->getTextureForMesh (os.str (), &new_texture_id);
1301
1303
buf->getMaterial ().setTexture (0 , new_texture);
1302
1304
1303
1305
// If the current material is also animated,
@@ -1333,16 +1335,15 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
1333
1335
m_animation_frames[i->first ] = frame;
1334
1336
1335
1337
scene::IMeshBuffer *buf = m_mesh->getMeshBuffer (i->first );
1336
- ITextureSource *tsrc = m_gamedef->getTextureSource ();
1337
1338
1338
1339
FrameSpec animation_frame = tile.frames [frame];
1339
1340
buf->getMaterial ().setTexture (0 , animation_frame.texture );
1340
1341
if (m_enable_shaders) {
1341
1342
if (animation_frame.normal_texture ) {
1342
1343
buf->getMaterial ().setTexture (1 , animation_frame.normal_texture );
1343
- buf->getMaterial ().setTexture (2 , tsrc ->getTextureForMesh (" enable_img.png" ));
1344
+ buf->getMaterial ().setTexture (2 , m_tsrc ->getTextureForMesh (" enable_img.png" ));
1344
1345
} else {
1345
- buf->getMaterial ().setTexture (2 , tsrc ->getTextureForMesh (" disable_img.png" ));
1346
+ buf->getMaterial ().setTexture (2 , m_tsrc ->getTextureForMesh (" disable_img.png" ));
1346
1347
}
1347
1348
}
1348
1349
}
@@ -1355,16 +1356,14 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
1355
1356
i != m_daynight_diffs.end (); i++)
1356
1357
{
1357
1358
scene::IMeshBuffer *buf = m_mesh->getMeshBuffer (i->first );
1358
- video::S3DVertex *vertices = (video::S3DVertex *)buf->getVertices ();
1359
+ video::S3DVertexTangents *vertices = (video::S3DVertexTangents *)buf->getVertices ();
1359
1360
for (std::map<u32, std::pair<u8, u8 > >::iterator
1360
1361
j = i->second .begin ();
1361
1362
j != i->second .end (); j++)
1362
1363
{
1363
- u32 vertexIndex = j->first ;
1364
1364
u8 day = j->second .first ;
1365
1365
u8 night = j->second .second ;
1366
- finalColorBlend (vertices[vertexIndex].Color ,
1367
- day, night, daynight_ratio);
1366
+ finalColorBlend (vertices[j->first ].Color , day, night, daynight_ratio);
1368
1367
}
1369
1368
}
1370
1369
m_last_daynight_ratio = daynight_ratio;
@@ -1388,7 +1387,7 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
1388
1387
i != m_highlighted_materials.end (); i++)
1389
1388
{
1390
1389
scene::IMeshBuffer *buf = m_mesh->getMeshBuffer (*i);
1391
- video::S3DVertex *vertices = (video::S3DVertex *)buf->getVertices ();
1390
+ video::S3DVertexTangents *vertices = (video::S3DVertexTangents *)buf->getVertices ();
1392
1391
for (u32 j = 0 ; j < buf->getVertexCount () ;j++)
1393
1392
vertices[j].Color = hc;
1394
1393
}
@@ -1413,42 +1412,40 @@ void MeshCollector::append(const TileSpec &tile,
1413
1412
const video::S3DVertex *vertices, u32 numVertices,
1414
1413
const u16 *indices, u32 numIndices)
1415
1414
{
1416
- if (numIndices > 65535 )
1417
- {
1415
+ if (numIndices > 65535 ) {
1418
1416
dstream<<" FIXME: MeshCollector::append() called with numIndices=" <<numIndices<<" (limit 65535)" <<std::endl;
1419
1417
return ;
1420
1418
}
1421
1419
1422
1420
PreMeshBuffer *p = NULL ;
1423
- for (u32 i=0 ; i<prebuffers.size (); i++)
1424
- {
1421
+ for (u32 i = 0 ; i < prebuffers.size (); i++) {
1425
1422
PreMeshBuffer &pp = prebuffers[i];
1426
- if (pp.tile != tile)
1423
+ if (pp.tile != tile)
1427
1424
continue ;
1428
- if (pp.indices .size () + numIndices > 65535 )
1425
+ if (pp.indices .size () + numIndices > 65535 )
1429
1426
continue ;
1430
1427
1431
1428
p = &pp;
1432
1429
break ;
1433
1430
}
1434
1431
1435
- if (p == NULL )
1436
- {
1432
+ if (p == NULL ) {
1437
1433
PreMeshBuffer pp;
1438
1434
pp.tile = tile;
1439
1435
prebuffers.push_back (pp);
1440
- p = &prebuffers[prebuffers.size ()- 1 ];
1436
+ p = &prebuffers[prebuffers.size () - 1 ];
1441
1437
}
1442
1438
1443
1439
u32 vertex_count = p->vertices .size ();
1444
- for (u32 i=0 ; i<numIndices; i++)
1445
- {
1440
+ for (u32 i = 0 ; i < numIndices; i++) {
1446
1441
u32 j = indices[i] + vertex_count;
1447
1442
p->indices .push_back (j);
1448
1443
}
1449
- for (u32 i=0 ; i<numVertices; i++)
1450
- {
1451
- p->vertices .push_back (vertices[i]);
1444
+
1445
+ for (u32 i = 0 ; i < numVertices; i++) {
1446
+ video::S3DVertexTangents vert (vertices[i].Pos , vertices[i].Normal ,
1447
+ vertices[i].Color , vertices[i].TCoords );
1448
+ p->vertices .push_back (vert);
1452
1449
}
1453
1450
}
1454
1451
@@ -1461,15 +1458,13 @@ void MeshCollector::append(const TileSpec &tile,
1461
1458
const u16 *indices, u32 numIndices,
1462
1459
v3f pos, video::SColor c)
1463
1460
{
1464
- if (numIndices > 65535 )
1465
- {
1461
+ if (numIndices > 65535 ) {
1466
1462
dstream<<" FIXME: MeshCollector::append() called with numIndices=" <<numIndices<<" (limit 65535)" <<std::endl;
1467
1463
return ;
1468
1464
}
1469
1465
1470
1466
PreMeshBuffer *p = NULL ;
1471
- for (u32 i=0 ; i<prebuffers.size (); i++)
1472
- {
1467
+ for (u32 i = 0 ; i < prebuffers.size (); i++) {
1473
1468
PreMeshBuffer &pp = prebuffers[i];
1474
1469
if (pp.tile != tile)
1475
1470
continue ;
@@ -1480,25 +1475,22 @@ void MeshCollector::append(const TileSpec &tile,
1480
1475
break ;
1481
1476
}
1482
1477
1483
- if (p == NULL )
1484
- {
1478
+ if (p == NULL ) {
1485
1479
PreMeshBuffer pp;
1486
1480
pp.tile = tile;
1487
1481
prebuffers.push_back (pp);
1488
- p = &prebuffers[prebuffers.size ()- 1 ];
1482
+ p = &prebuffers[prebuffers.size () - 1 ];
1489
1483
}
1490
1484
1491
1485
u32 vertex_count = p->vertices .size ();
1492
- for (u32 i=0 ; i<numIndices; i++)
1493
- {
1486
+ for (u32 i = 0 ; i < numIndices; i++) {
1494
1487
u32 j = indices[i] + vertex_count;
1495
1488
p->indices .push_back (j);
1496
1489
}
1497
- for (u32 i=0 ; i<numVertices; i++)
1498
- {
1499
- video::S3DVertex vert = vertices[i];
1500
- vert.Pos += pos;
1501
- vert.Color = c;
1490
+
1491
+ for (u32 i = 0 ; i < numVertices; i++) {
1492
+ video::S3DVertexTangents vert (vertices[i].Pos + pos, vertices[i].Normal ,
1493
+ c, vertices[i].TCoords );
1502
1494
p->vertices .push_back (vert);
1503
1495
}
1504
1496
}
2 commit comments
ShadowNinja commentedon Jun 15, 2015
In
minetest.conf.example
comments are supposed to be above the settings they document -- same as the C++ and Lua style.HybridDog commentedon Jun 19, 2015
@RealBadAngel l disabled parallax occlusion but the textures are repeating, e.g. at places where they shouldn't:

White stripes on the bottom of dirt with snow: