@@ -32,14 +32,14 @@ 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
- float srgb_linear_multiply ( float f , float m, float max )
35
+ void applyContrast (video::SColor& color , float Factor )
36
36
{
37
- f = f * f; // SRGB -> Linear
38
- f *= m ;
39
- f = sqrt (f); // Linear -> SRGB
40
- if (f > max)
41
- f = max ;
42
- return f ;
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 )) ;
43
43
}
44
44
45
45
/*
@@ -203,20 +203,6 @@ static u8 getFaceLight(enum LightBank bank, MapNode n, MapNode n2,
203
203
// return decode_light(light_source);
204
204
light = light_source;
205
205
206
- // Make some nice difference to different sides
207
-
208
- // This makes light come from a corner
209
- /* if(face_dir.X == 1 || face_dir.Z == 1 || face_dir.Y == -1)
210
- light = diminish_light(diminish_light(light));
211
- else if(face_dir.X == -1 || face_dir.Z == -1)
212
- light = diminish_light(light);*/
213
-
214
- // All neighboring faces have different shade (like in minecraft)
215
- if (face_dir.X == 1 || face_dir.X == -1 || face_dir.Y == -1 )
216
- light = diminish_light (diminish_light (light));
217
- else if (face_dir.Z == 1 || face_dir.Z == -1 )
218
- light = diminish_light (light);
219
-
220
206
return decode_light (light);
221
207
}
222
208
@@ -352,21 +338,15 @@ static void finalColorBlend(video::SColor& result,
352
338
1 , 4 , 6 , 6 , 6 , 5 , 4 , 3 , 2 , 1 , 0 , 0 , 0 , 0 , 0 , 0 ,
353
339
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
354
340
};
355
- if (b < 0 )
356
- b = 0 ;
357
- if (b > 255 )
358
- b = 255 ;
359
341
b += emphase_blue_when_dark[b / 8 ];
342
+ b = irr::core::clamp (b, 0 , 255 );
360
343
361
344
// Artificial light is yellow-ish
362
345
static u8 emphase_yellow_when_artificial[16 ] = {
363
346
0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 5 , 10 , 15 , 15 , 15
364
347
};
365
348
rg += emphase_yellow_when_artificial[night/16 ];
366
- if (rg < 0 )
367
- rg = 0 ;
368
- if (rg > 255 )
369
- rg = 255 ;
349
+ rg = irr::core::clamp (rg, 0 , 255 );
370
350
371
351
result.setRed (rg);
372
352
result.setGreen (rg);
@@ -1168,25 +1148,32 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
1168
1148
os.str (),
1169
1149
&p.tile .texture_id );
1170
1150
}
1171
- // - Classic lighting (shaders handle this by themselves)
1172
- if (!enable_shaders )
1151
+
1152
+ for (u32 j = 0 ; j < p. vertices . size (); j++ )
1173
1153
{
1174
- for (u32 j = 0 ; j < p.vertices .size (); j++)
1154
+ video::SColor &vc = p.vertices [j].Color ;
1155
+ if (p.vertices [j].Normal .Y > 0.5 ) {
1156
+ applyContrast (vc, 1.2 );
1157
+ } else if (p.vertices [j].Normal .Y < -0.5 ) {
1158
+ applyContrast (vc, 0.3 );
1159
+ } else if (p.vertices [j].Normal .X > 0.5 ) {
1160
+ applyContrast (vc, 0.5 );
1161
+ } else if (p.vertices [j].Normal .X < -0.5 ) {
1162
+ applyContrast (vc, 0.5 );
1163
+ } else if (p.vertices [j].Normal .Z > 0.5 ) {
1164
+ applyContrast (vc, 0.8 );
1165
+ } else if (p.vertices [j].Normal .Z < -0.5 ) {
1166
+ applyContrast (vc, 0.8 );
1167
+ }
1168
+ if (!enable_shaders)
1175
1169
{
1176
- video::SColor &vc = p. vertices [j]. Color ;
1170
+ // - Classic lighting (shaders handle this by themselves)
1177
1171
// Set initial real color and store for later updates
1178
1172
u8 day = vc.getRed ();
1179
1173
u8 night = vc.getGreen ();
1180
1174
finalColorBlend (vc, day, night, 1000 );
1181
1175
if (day != night)
1182
1176
m_daynight_diffs[i][j] = std::make_pair (day, night);
1183
- // Brighten topside (no shaders)
1184
- if (p.vertices [j].Normal .Y > 0.5 )
1185
- {
1186
- vc.setRed (srgb_linear_multiply (vc.getRed (), 1.3 , 255.0 ));
1187
- vc.setGreen (srgb_linear_multiply (vc.getGreen (), 1.3 , 255.0 ));
1188
- vc.setBlue (srgb_linear_multiply (vc.getBlue (), 1.3 , 255.0 ));
1189
- }
1190
1177
}
1191
1178
}
1192
1179
@@ -1293,7 +1280,6 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
1293
1280
bool enable_shaders = g_settings->getBool (" enable_shaders" );
1294
1281
bool enable_bumpmapping = g_settings->getBool (" enable_bumpmapping" );
1295
1282
bool enable_parallax_occlusion = g_settings->getBool (" enable_parallax_occlusion" );
1296
- bool smooth_lighting = g_settings->getBool (" smooth_lighting" );
1297
1283
1298
1284
if (!m_has_animation)
1299
1285
{
@@ -1407,36 +1393,6 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
1407
1393
u8 night = j->second .second ;
1408
1394
finalColorBlend (vertices[vertexIndex].Color ,
1409
1395
day, night, daynight_ratio);
1410
- // If no smooth lighting, shading is already correct
1411
- if (!smooth_lighting)
1412
- continue ;
1413
- // Make sides and bottom darker than the top
1414
- video::SColor &vc = vertices[vertexIndex].Color ;
1415
- if (vertices[vertexIndex].Normal .Y > 0.5 ) {
1416
- vc.setRed (srgb_linear_multiply (vc.getRed (), 1.2 , 255.0 ));
1417
- vc.setGreen (srgb_linear_multiply (vc.getGreen (), 1.2 , 255.0 ));
1418
- vc.setBlue (srgb_linear_multiply (vc.getBlue (), 1.2 , 255.0 ));
1419
- } else if (vertices[vertexIndex].Normal .Y < -0.5 ) {
1420
- vc.setRed (srgb_linear_multiply (vc.getRed (), 0.3 , 255.0 ));
1421
- vc.setGreen (srgb_linear_multiply (vc.getGreen (), 0.3 , 255.0 ));
1422
- vc.setBlue (srgb_linear_multiply (vc.getBlue (), 0.3 , 255.0 ));
1423
- } else if (vertices[vertexIndex].Normal .X > 0.5 ) {
1424
- vc.setRed (srgb_linear_multiply (vc.getRed (), 0.8 , 255.0 ));
1425
- vc.setGreen (srgb_linear_multiply (vc.getGreen (), 0.8 , 255.0 ));
1426
- vc.setBlue (srgb_linear_multiply (vc.getBlue (), 0.8 , 255.0 ));
1427
- } else if (vertices[vertexIndex].Normal .X < -0.5 ) {
1428
- vc.setRed (srgb_linear_multiply (vc.getRed (), 0.8 , 255.0 ));
1429
- vc.setGreen (srgb_linear_multiply (vc.getGreen (), 0.8 , 255.0 ));
1430
- vc.setBlue (srgb_linear_multiply (vc.getBlue (), 0.8 , 255.0 ));
1431
- } else if (vertices[vertexIndex].Normal .Z > 0.5 ) {
1432
- vc.setRed (srgb_linear_multiply (vc.getRed (), 0.5 , 255.0 ));
1433
- vc.setGreen (srgb_linear_multiply (vc.getGreen (), 0.5 , 255.0 ));
1434
- vc.setBlue (srgb_linear_multiply (vc.getBlue (), 0.5 , 255.0 ));
1435
- } else if (vertices[vertexIndex].Normal .Z < -0.5 ) {
1436
- vc.setRed (srgb_linear_multiply (vc.getRed (), 0.5 , 255.0 ));
1437
- vc.setGreen (srgb_linear_multiply (vc.getGreen (), 0.5 , 255.0 ));
1438
- vc.setBlue (srgb_linear_multiply (vc.getBlue (), 0.5 , 255.0 ));
1439
- }
1440
1396
}
1441
1397
}
1442
1398
m_last_daynight_ratio = daynight_ratio;
0 commit comments