@@ -32,14 +32,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
32
32
#include " settings.h"
33
33
#include " util/directiontables.h"
34
34
35
- void applyContrast (video::SColor& color, float Factor )
35
+ static void applyContrast (video::SColor& color, float factor )
36
36
{
37
- float r = color.getRed ();
38
- float g = color.getGreen ();
39
- float b = color.getBlue ();
40
- color.setRed (irr::core::clamp ((int )sqrt (r * r * Factor), 0 , 255 ));
41
- color.setGreen (irr::core::clamp ((int )sqrt (g * g * Factor), 0 , 255 ));
42
- color.setBlue (irr::core::clamp ((int )sqrt (b * b * Factor), 0 , 255 ));
37
+ color.setRed (core::clamp (core::round32 (color.getRed ()*factor), 0 , 255 ));
38
+ color.setGreen (core::clamp (core::round32 (color.getGreen ()*factor), 0 , 255 ));
39
+ color.setBlue (core::clamp (core::round32 (color.getBlue ()*factor), 0 , 255 ));
43
40
}
44
41
45
42
/*
@@ -1099,8 +1096,6 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
1099
1096
IShaderSource *shdrsrc = m_gamedef->getShaderSource ();
1100
1097
1101
1098
bool enable_shaders = g_settings->getBool (" enable_shaders" );
1102
- bool enable_bumpmapping = g_settings->getBool (" enable_bumpmapping" );
1103
- bool enable_parallax_occlusion = g_settings->getBool (" enable_parallax_occlusion" );
1104
1099
1105
1100
for (u32 i = 0 ; i < collector.prebuffers .size (); i++)
1106
1101
{
@@ -1141,33 +1136,31 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
1141
1136
m_animation_frame_offsets[i] = 0 ;
1142
1137
}
1143
1138
// Replace tile texture with the first animation frame
1144
- std::ostringstream os (std::ios::binary);
1145
- os<<tsrc->getTextureName (p.tile .texture_id );
1146
- os<<" ^[verticalframe:" <<(int )p.tile .animation_frame_count <<" :0" ;
1147
- p.tile .texture = tsrc->getTexture (
1148
- os.str (),
1149
- &p.tile .texture_id );
1139
+ FrameSpec animation_frame = p.tile .frames .find (0 )->second ;
1140
+ p.tile .texture = animation_frame.texture ;
1150
1141
}
1151
1142
1152
1143
for (u32 j = 0 ; j < p.vertices .size (); j++)
1153
1144
{
1145
+ // Note applyContrast second parameter is precalculated sqrt from original
1146
+ // values for speed improvement
1154
1147
video::SColor &vc = p.vertices [j].Color ;
1155
1148
if (p.vertices [j].Normal .Y > 0.5 ) {
1156
- applyContrast (vc, 1.2 );
1149
+ applyContrast (vc, 1.095445 );
1157
1150
} else if (p.vertices [j].Normal .Y < -0.5 ) {
1158
- applyContrast (vc, 0.3 );
1151
+ applyContrast (vc, 0.547723 );
1159
1152
} else if (p.vertices [j].Normal .X > 0.5 ) {
1160
- applyContrast (vc, 0.5 );
1153
+ applyContrast (vc, 0.707107 );
1161
1154
} else if (p.vertices [j].Normal .X < -0.5 ) {
1162
- applyContrast (vc, 0.5 );
1155
+ applyContrast (vc, 0.707107 );
1163
1156
} else if (p.vertices [j].Normal .Z > 0.5 ) {
1164
- applyContrast (vc, 0.8 );
1157
+ applyContrast (vc, 0.894427 );
1165
1158
} else if (p.vertices [j].Normal .Z < -0.5 ) {
1166
- applyContrast (vc, 0.8 );
1159
+ applyContrast (vc, 0.894427 );
1167
1160
}
1168
1161
if (!enable_shaders)
1169
1162
{
1170
- // - Classic lighting (shaders handle this by themselves)
1163
+ // - Classic lighting (shaders handle this by themselves)
1171
1164
// Set initial real color and store for later updates
1172
1165
u8 day = vc.getRed ();
1173
1166
u8 night = vc.getGreen ();
@@ -1191,34 +1184,17 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
1191
1184
if (enable_shaders) {
1192
1185
material.MaterialType = shdrsrc->getShaderInfo (p.tile .shader_id ).material ;
1193
1186
p.tile .applyMaterialOptionsWithShaders (material);
1194
- material.setTexture (2 , tsrc->getTexture (" disable_img.png" ));
1195
- if (enable_bumpmapping || enable_parallax_occlusion) {
1196
- if (tsrc->isKnownSourceImage (" override_normal.png" )){
1197
- material.setTexture (1 , tsrc->getTexture (" override_normal.png" ));
1198
- material.setTexture (2 , tsrc->getTexture (" enable_img.png" ));
1199
- } else {
1200
- std::string fname_base = tsrc->getTextureName (p.tile .texture_id );
1201
- std::string normal_ext = " _normal.png" ;
1202
- size_t pos = fname_base.find (" ." );
1203
- std::string fname_normal = fname_base.substr (0 , pos) + normal_ext;
1204
-
1205
- if (tsrc->isKnownSourceImage (fname_normal)) {
1206
- // look for image extension and replace it
1207
- size_t i = 0 ;
1208
- while ((i = fname_base.find (" ." , i)) != std::string::npos) {
1209
- fname_base.replace (i, 4 , normal_ext);
1210
- i += normal_ext.length ();
1211
- }
1212
- material.setTexture (1 , tsrc->getTexture (fname_base));
1213
- material.setTexture (2 , tsrc->getTexture (" enable_img.png" ));
1214
- }
1215
- }
1187
+ if (p.tile .normal_texture ) {
1188
+ material.setTexture (1 , p.tile .normal_texture );
1189
+ material.setTexture (2 , tsrc->getTexture (" enable_img.png" ));
1190
+ } else {
1191
+ material.setTexture (2 , tsrc->getTexture (" disable_img.png" ));
1216
1192
}
1217
1193
} else {
1218
1194
p.tile .applyMaterialOptions (material);
1219
1195
}
1220
- // Create meshbuffer
1221
1196
1197
+ // Create meshbuffer
1222
1198
// This is a "Standard MeshBuffer",
1223
1199
// it's a typedeffed CMeshBuffer<video::S3DVertex>
1224
1200
scene::SMeshBuffer *buf = new scene::SMeshBuffer ();
@@ -1278,8 +1254,6 @@ MapBlockMesh::~MapBlockMesh()
1278
1254
bool MapBlockMesh::animate (bool faraway, float time, int crack, u32 daynight_ratio)
1279
1255
{
1280
1256
bool enable_shaders = g_settings->getBool (" enable_shaders" );
1281
- bool enable_bumpmapping = g_settings->getBool (" enable_bumpmapping" );
1282
- bool enable_parallax_occlusion = g_settings->getBool (" enable_parallax_occlusion" );
1283
1257
1284
1258
if (!m_has_animation)
1285
1259
{
@@ -1342,35 +1316,15 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
1342
1316
1343
1317
scene::IMeshBuffer *buf = m_mesh->getMeshBuffer (i->first );
1344
1318
ITextureSource *tsrc = m_gamedef->getTextureSource ();
1345
- IShaderSource *shdrsrc = m_gamedef->getShaderSource ();
1346
-
1347
- // Create new texture name from original
1348
- std::ostringstream os (std::ios::binary);
1349
- os<<tsrc->getTextureName (tile.texture_id );
1350
- os<<" ^[verticalframe:" <<(int )tile.animation_frame_count <<" :" <<frame;
1351
- // Set the texture
1352
- buf->getMaterial ().setTexture (0 , tsrc->getTexture (os.str ()));
1353
- if (enable_shaders){
1354
- buf->getMaterial ().setTexture (2 , tsrc->getTexture (" disable_img.png" ));
1355
- buf->getMaterial ().MaterialType = shdrsrc->getShaderInfo (tile.shader_id ).material ;
1356
- if (enable_bumpmapping || enable_parallax_occlusion){
1357
- if (tsrc->isKnownSourceImage (" override_normal.png" )){
1358
- buf->getMaterial ().setTexture (1 , tsrc->getTexture (" override_normal.png" ));
1359
- buf->getMaterial ().setTexture (2 , tsrc->getTexture (" enable_img.png" ));
1360
- } else {
1361
- std::string fname_base,fname_normal;
1362
- fname_base = tsrc->getTextureName (tile.texture_id );
1363
- unsigned pos;
1364
- pos = fname_base.find (" ." );
1365
- fname_normal = fname_base.substr (0 , pos);
1366
- fname_normal += " _normal.png" ;
1367
- if (tsrc->isKnownSourceImage (fname_normal)){
1368
- os.str (" " );
1369
- os<<fname_normal<<" ^[verticalframe:" <<(int )tile.animation_frame_count <<" :" <<frame;
1370
- buf->getMaterial ().setTexture (1 , tsrc->getTexture (os.str ()));
1371
- buf->getMaterial ().setTexture (2 , tsrc->getTexture (" enable_img.png" ));
1372
- }
1373
- }
1319
+
1320
+ FrameSpec animation_frame = tile.frames .find (frame)->second ;
1321
+ buf->getMaterial ().setTexture (0 , animation_frame.texture );
1322
+ if (enable_shaders) {
1323
+ if (animation_frame.normal_texture ) {
1324
+ buf->getMaterial ().setTexture (1 , animation_frame.normal_texture );
1325
+ buf->getMaterial ().setTexture (2 , tsrc->getTexture (" enable_img.png" ));
1326
+ } else {
1327
+ buf->getMaterial ().setTexture (2 , tsrc->getTexture (" disable_img.png" ));
1374
1328
}
1375
1329
}
1376
1330
}
0 commit comments