#include "settings.h"
#include "util/directiontables.h"
-float srgb_linear_multiply(float f, float m, float max)
+void applyContrast(video::SColor& color, float Factor)
{
- f = f * f; // SRGB -> Linear
- f *= m;
- f = sqrt(f); // Linear -> SRGB
- if(f > max)
- f = max;
- return f;
+ float r = color.getRed();
+ float g = color.getGreen();
+ float b = color.getBlue();
+ color.setRed(irr::core::clamp((int)sqrt(r * r * Factor), 0, 255));
+ color.setGreen(irr::core::clamp((int)sqrt(g * g * Factor), 0, 255));
+ color.setBlue(irr::core::clamp((int)sqrt(b * b * Factor), 0, 255));
}
/*
//return decode_light(light_source);
light = light_source;
- // Make some nice difference to different sides
-
- // This makes light come from a corner
- /*if(face_dir.X == 1 || face_dir.Z == 1 || face_dir.Y == -1)
- light = diminish_light(diminish_light(light));
- else if(face_dir.X == -1 || face_dir.Z == -1)
- light = diminish_light(light);*/
-
- // All neighboring faces have different shade (like in minecraft)
- if(face_dir.X == 1 || face_dir.X == -1 || face_dir.Y == -1)
- light = diminish_light(diminish_light(light));
- else if(face_dir.Z == 1 || face_dir.Z == -1)
- light = diminish_light(light);
-
return decode_light(light);
}
{
MapNode n = data->m_vmanip.getNodeNoEx(p - dirs8[i]);
+ // if it's CONTENT_IGNORE we can't do any light calculations
if (n.getContent() == CONTENT_IGNORE) {
- ambient_occlusion++;
continue;
}
light += decode_light(n.getLight(bank, ndef));
light_count++;
}
+ else {
+ ambient_occlusion++;
+ }
}
if(light_count == 0)
1, 4, 6, 6, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
- if(b < 0)
- b = 0;
- if(b > 255)
- b = 255;
b += emphase_blue_when_dark[b / 8];
+ b = irr::core::clamp (b, 0, 255);
// Artificial light is yellow-ish
static u8 emphase_yellow_when_artificial[16] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 10, 15, 15, 15
};
rg += emphase_yellow_when_artificial[night/16];
- if(rg < 0)
- rg = 0;
- if(rg > 255)
- rg = 255;
+ rg = irr::core::clamp (rg, 0, 255);
result.setRed(rg);
result.setGreen(rg);
os.str(),
&p.tile.texture_id);
}
- // - Classic lighting (shaders handle this by themselves)
- if(!enable_shaders)
+
+ for(u32 j = 0; j < p.vertices.size(); j++)
{
- for(u32 j = 0; j < p.vertices.size(); j++)
+ video::SColor &vc = p.vertices[j].Color;
+ if(p.vertices[j].Normal.Y > 0.5) {
+ applyContrast (vc, 1.2);
+ } else if (p.vertices[j].Normal.Y < -0.5) {
+ applyContrast (vc, 0.3);
+ } else if (p.vertices[j].Normal.X > 0.5) {
+ applyContrast (vc, 0.5);
+ } else if (p.vertices[j].Normal.X < -0.5) {
+ applyContrast (vc, 0.5);
+ } else if (p.vertices[j].Normal.Z > 0.5) {
+ applyContrast (vc, 0.8);
+ } else if (p.vertices[j].Normal.Z < -0.5) {
+ applyContrast (vc, 0.8);
+ }
+ if(!enable_shaders)
{
- video::SColor &vc = p.vertices[j].Color;
+ // - Classic lighting (shaders handle this by themselves)
// Set initial real color and store for later updates
u8 day = vc.getRed();
u8 night = vc.getGreen();
finalColorBlend(vc, day, night, 1000);
if(day != night)
m_daynight_diffs[i][j] = std::make_pair(day, night);
- // Brighten topside (no shaders)
- if(p.vertices[j].Normal.Y > 0.5)
- {
- vc.setRed (srgb_linear_multiply(vc.getRed(), 1.3, 255.0));
- vc.setGreen(srgb_linear_multiply(vc.getGreen(), 1.3, 255.0));
- vc.setBlue (srgb_linear_multiply(vc.getBlue(), 1.3, 255.0));
- }
}
}
u8 night = j->second.second;
finalColorBlend(vertices[vertexIndex].Color,
day, night, daynight_ratio);
- // Make sides and bottom darker than the top
- video::SColor &vc = vertices[vertexIndex].Color;
- if(vertices[vertexIndex].Normal.Y > 0.5) {
- vc.setRed (srgb_linear_multiply(vc.getRed(), 1.2, 255.0));
- vc.setGreen(srgb_linear_multiply(vc.getGreen(), 1.2, 255.0));
- vc.setBlue (srgb_linear_multiply(vc.getBlue(), 1.2, 255.0));
- } else if (vertices[vertexIndex].Normal.Y < -0.5) {
- vc.setRed (srgb_linear_multiply(vc.getRed(), 0.3, 255.0));
- vc.setGreen(srgb_linear_multiply(vc.getGreen(), 0.3, 255.0));
- vc.setBlue (srgb_linear_multiply(vc.getBlue(), 0.3, 255.0));
- } else if (vertices[vertexIndex].Normal.X > 0.5) {
- vc.setRed (srgb_linear_multiply(vc.getRed(), 0.8, 255.0));
- vc.setGreen(srgb_linear_multiply(vc.getGreen(), 0.8, 255.0));
- vc.setBlue (srgb_linear_multiply(vc.getBlue(), 0.8, 255.0));
- } else if (vertices[vertexIndex].Normal.X < -0.5) {
- vc.setRed (srgb_linear_multiply(vc.getRed(), 0.8, 255.0));
- vc.setGreen(srgb_linear_multiply(vc.getGreen(), 0.8, 255.0));
- vc.setBlue (srgb_linear_multiply(vc.getBlue(), 0.8, 255.0));
- } else if (vertices[vertexIndex].Normal.Z > 0.5) {
- vc.setRed (srgb_linear_multiply(vc.getRed(), 0.5, 255.0));
- vc.setGreen(srgb_linear_multiply(vc.getGreen(), 0.5, 255.0));
- vc.setBlue (srgb_linear_multiply(vc.getBlue(), 0.5, 255.0));
- } else if (vertices[vertexIndex].Normal.Z < -0.5) {
- vc.setRed (srgb_linear_multiply(vc.getRed(), 0.5, 255.0));
- vc.setGreen(srgb_linear_multiply(vc.getGreen(), 0.5, 255.0));
- vc.setBlue (srgb_linear_multiply(vc.getBlue(), 0.5, 255.0));
- }
}
}
m_last_daynight_ratio = daynight_ratio;