uniform mat4 mWorldViewProj;\r
uniform mat4 mInvWorld;\r
uniform mat4 mTransWorld;\r
+uniform float dayNightRatio;\r
\r
varying vec3 vPosition;\r
\r
\r
vPosition = (mWorldViewProj * gl_Vertex).xyz;\r
\r
- if(gl_Normal.y > 0.5)\r
- gl_FrontColor = gl_BackColor = gl_Color;\r
- else\r
- gl_FrontColor = gl_BackColor = gl_Color * 0.7;\r
+ vec4 color;\r
+ //color = vec4(1.0, 1.0, 1.0, 1.0);\r
\r
- /*if(gl_Normal.y > 0.5)\r
- gl_FrontColor = gl_BackColor = vec4(1.0, 1.0, 1.0, 1.0);\r
- else\r
- gl_FrontColor = gl_BackColor = vec4(1.0, 1.0, 1.0, 1.0) * 0.7;*/\r
+ float day = gl_Color.r;\r
+ float night = gl_Color.g;\r
+ float light_source = gl_Color.b;\r
+\r
+ /*color.r = mix(night, day, dayNightRatio);\r
+ color.g = color.r;\r
+ color.b = color.r;*/\r
+\r
+ float rg = mix(night, day, dayNightRatio);\r
+ rg += light_source * 1.0; // Make light sources brighter\r
+ float b = rg;\r
+\r
+ // Moonlight is blue\r
+ b += (day - night) / 13.0;\r
+ rg -= (day - night) / 13.0;\r
+\r
+ // Emphase blue a bit in darker places\r
+ // See C++ implementation in mapblock_mesh.cpp finalColorBlend()\r
+ b += max(0.0, (1.0 - abs(b - 0.13)/0.17) * 0.025);\r
+\r
+ // Artificial light is yellow-ish\r
+ // See C++ implementation in mapblock_mesh.cpp finalColorBlend()\r
+ rg += max(0.0, (1.0 - abs(rg - 0.85)/0.15) * 0.065);\r
+\r
+ color.r = rg;\r
+ color.g = rg;\r
+ color.b = b;\r
+\r
+ if(gl_Normal.y <= 0.5)\r
+ color *= 0.7;\r
+\r
+ color.a = gl_Color.a;\r
+\r
+ gl_FrontColor = gl_BackColor = color;\r
\r
gl_TexCoord[0] = gl_MultiTexCoord0;\r
}\r
uniform mat4 mWorldViewProj;\r
uniform mat4 mInvWorld;\r
uniform mat4 mTransWorld;\r
+uniform float dayNightRatio;\r
\r
varying vec3 vPosition;\r
\r
\r
vPosition = (mWorldViewProj * gl_Vertex).xyz;\r
\r
- gl_FrontColor = gl_BackColor = gl_Color;\r
- //gl_FrontColor = gl_BackColor = vec4(1.0, 1.0, 1.0, 1.0);\r
+ vec4 color;\r
+ //color = vec4(1.0, 1.0, 1.0, 1.0);\r
+\r
+ float day = gl_Color.r;\r
+ float night = gl_Color.g;\r
+ float light_source = gl_Color.b;\r
+\r
+ /*color.r = mix(night, day, dayNightRatio);\r
+ color.g = color.r;\r
+ color.b = color.r;*/\r
+\r
+ float rg = mix(night, day, dayNightRatio);\r
+ rg += light_source * 1.0; // Make light sources brighter\r
+ float b = rg;\r
+\r
+ // Moonlight is blue\r
+ b += (day - night) / 13.0;\r
+ rg -= (day - night) / 13.0;\r
+\r
+ // Emphase blue a bit in darker places\r
+ // See C++ implementation in mapblock_mesh.cpp finalColorBlend()\r
+ b += max(0.0, (1.0 - abs(b - 0.13)/0.17) * 0.025);\r
+\r
+ // Artificial light is yellow-ish\r
+ // See C++ implementation in mapblock_mesh.cpp finalColorBlend()\r
+ rg += max(0.0, (1.0 - abs(rg - 0.85)/0.15) * 0.065);\r
+\r
+ color.r = rg;\r
+ color.g = rg;\r
+ color.b = b;\r
+\r
+ color.a = gl_Color.a;\r
+\r
+ gl_FrontColor = gl_BackColor = color;\r
\r
gl_TexCoord[0] = gl_MultiTexCoord0;\r
}\r
continue;
u16 l = getInteriorLight(n, 0, data);
- video::SColor c = MapBlock_LightColor(f.alpha, l);
+ video::SColor c = MapBlock_LightColor(f.alpha, l, decode_light(f.light_source));
video::S3DVertex vertices[4] =
{
// Otherwise use the light of this node (the liquid)
else
l = getInteriorLight(n, 0, data);
- video::SColor c = MapBlock_LightColor(f.alpha, l);
+ video::SColor c = MapBlock_LightColor(f.alpha, l, decode_light(f.light_source));
// Neighbor liquid levels (key = relative position)
// Includes current node
AtlasPointer ap = tile.texture;
u16 l = getInteriorLight(n, 1, data);
- video::SColor c = MapBlock_LightColor(255, l);
+ video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
for(u32 j=0; j<6; j++)
{
AtlasPointer pa_leaves = tile_leaves.texture;
u16 l = getInteriorLight(n, 1, data);
- video::SColor c = MapBlock_LightColor(255, l);
+ video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
v3f pos = intToFloat(p, BS);
aabb3f box(-BS/2,-BS/2,-BS/2,BS/2,BS/2,BS/2);
AtlasPointer ap = tile.texture;
- video::SColor c(255,255,255,255);
+ u16 l = getInteriorLight(n, 1, data);
+ video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
// Wall at X+ of node
video::S3DVertex vertices[4] =
AtlasPointer ap = tile.texture;
u16 l = getInteriorLight(n, 0, data);
- video::SColor c = MapBlock_LightColor(255, l);
+ video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
float d = (float)BS/16;
// Wall at X+ of node
AtlasPointer ap = tile.texture;
u16 l = getInteriorLight(n, 1, data);
- video::SColor c = MapBlock_LightColor(255, l);
+ video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
for(u32 j=0; j<4; j++)
{
tile.texture.id) + "^[transformR90");
u16 l = getInteriorLight(n, 1, data);
- video::SColor c = MapBlock_LightColor(255, l);
+ video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
const f32 post_rad=(f32)BS/8;
const f32 bar_rad=(f32)BS/16;
AtlasPointer ap = tile.texture;
u16 l = getInteriorLight(n, 0, data);
- video::SColor c = MapBlock_LightColor(255, l);
+ video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
float d = (float)BS/64;
}
u16 l = getInteriorLight(n, 0, data);
- video::SColor c = MapBlock_LightColor(255, l);
+ video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
v3f pos = intToFloat(p, BS);
Sky *m_sky;
bool *m_force_fog_off;
f32 *m_fog_range;
+ Client *m_client;
public:
GameGlobalShaderConstantSetter(Sky *sky, bool *force_fog_off,
- f32 *fog_range):
+ f32 *fog_range, Client *client):
m_sky(sky),
m_force_fog_off(force_fog_off),
- m_fog_range(fog_range)
+ m_fog_range(fog_range),
+ m_client(client)
{}
~GameGlobalShaderConstantSetter() {}
if(*m_force_fog_off)
fog_distance = 10000*BS;
services->setPixelShaderConstant("fogDistance", &fog_distance, 1);
- }
-private:
- IrrlichtDevice *m_device;
+ // Day-night ratio
+ u32 daynight_ratio = m_client->getEnv().getDayNightRatio();
+ float daynight_ratio_f = (float)daynight_ratio / 1000.0;
+ services->setPixelShaderConstant("dayNightRatio", &daynight_ratio_f, 1);
+ }
};
void the_game(
/*
Shader constants
*/
- shsrc->addGlobalConstantSetter(
- new GameGlobalShaderConstantSetter(sky, &force_fog_off, &fog_range));
+ shsrc->addGlobalConstantSetter(new GameGlobalShaderConstantSetter(
+ sky, &force_fog_off, &fog_range, &client));
/*
Main loop
#include "tile.h"
#endif
#include "log.h"
+#include "main.h" // g_settings
+#include "settings.h"
#include "util/serialize.h"
#include "util/container.h"
#include "util/thread.h"
scene::IMesh *node_mesh = mapblock_mesh.getMesh();
assert(node_mesh);
- setMeshColor(node_mesh, video::SColor(255, 255, 255, 255));
+ video::SColor c(255, 255, 255, 255);
+ if(g_settings->getS32("enable_shaders") != 0)
+ c = MapBlock_LightColor(255, 0xffff, decode_light(f.light_source));
+ setMeshColor(node_mesh, c);
/*
Scale and translate the mesh so it's a unit cube
};
static void makeFastFace(TileSpec tile, u16 li0, u16 li1, u16 li2, u16 li3,
- v3f p, v3s16 dir, v3f scale, core::array<FastFace> &dest)
+ v3f p, v3s16 dir, v3f scale, u8 light_source, core::array<FastFace> &dest)
{
FastFace face;
float h = tile.texture.size.Y;
face.vertices[0] = video::S3DVertex(vertex_pos[0], normal,
- MapBlock_LightColor(alpha, li0),
+ MapBlock_LightColor(alpha, li0, light_source),
core::vector2d<f32>(x0+w*abs_scale, y0+h));
face.vertices[1] = video::S3DVertex(vertex_pos[1], normal,
- MapBlock_LightColor(alpha, li1),
+ MapBlock_LightColor(alpha, li1, light_source),
core::vector2d<f32>(x0, y0+h));
face.vertices[2] = video::S3DVertex(vertex_pos[2], normal,
- MapBlock_LightColor(alpha, li2),
+ MapBlock_LightColor(alpha, li2, light_source),
core::vector2d<f32>(x0, y0));
face.vertices[3] = video::S3DVertex(vertex_pos[3], normal,
- MapBlock_LightColor(alpha, li3),
+ MapBlock_LightColor(alpha, li3, light_source),
core::vector2d<f32>(x0+w*abs_scale, y0));
face.tile = tile;
v3s16 &p_corrected,
v3s16 &face_dir_corrected,
u16 *lights,
- TileSpec &tile
+ TileSpec &tile,
+ u8 &light_source
)
{
VoxelManipulator &vmanip = data->m_vmanip;
tile = tile0;
p_corrected = p;
face_dir_corrected = face_dir;
+ light_source = ndef->get(n0).light_source;
}
else
{
tile = tile1;
p_corrected = p + face_dir;
face_dir_corrected = -face_dir;
+ light_source = ndef->get(n1).light_source;
}
// eg. water and glass
if(equivalent)
tile.material_flags |= MATERIAL_FLAG_BACKFACE_CULLING;
-
+
if(data->m_smooth_lighting == false)
{
lights[0] = lights[1] = lights[2] = lights[3] =
v3s16 face_dir_corrected;
u16 lights[4] = {0,0,0,0};
TileSpec tile;
+ u8 light_source = 0;
getTileInfo(data, p, face_dir,
makes_face, p_corrected, face_dir_corrected,
- lights, tile);
+ lights, tile, light_source);
for(u16 j=0; j<MAP_BLOCKSIZE; j++)
{
v3s16 next_face_dir_corrected;
u16 next_lights[4] = {0,0,0,0};
TileSpec next_tile;
+ u8 next_light_source = 0;
// If at last position, there is nothing to compare to and
// the face must be drawn anyway
getTileInfo(data, p_next, face_dir,
next_makes_face, next_p_corrected,
next_face_dir_corrected, next_lights,
- next_tile);
+ next_tile, next_light_source);
if(next_makes_face == makes_face
&& next_p_corrected == p_corrected + translate_dir
&& next_lights[1] == lights[1]
&& next_lights[2] == lights[2]
&& next_lights[3] == lights[3]
- && next_tile == tile)
+ && next_tile == tile
+ && next_light_source == light_source)
{
next_is_different = false;
}
}
makeFastFace(tile, lights[0], lights[1], lights[2], lights[3],
- sp, face_dir_corrected, scale,
+ sp, face_dir_corrected, scale, light_source,
dest);
g_profiler->avg("Meshgen: faces drawn by tiling", 0);
lights[2] = next_lights[2];
lights[3] = next_lights[3];
tile = next_tile;
+ light_source = next_light_source;
}
p = p_next;
os<<"^[verticalframe:"<<(int)p.tile.animation_frame_count<<":0";
p.tile.texture = tsrc->getTexture(os.str());
}
- // - Lighting
- for(u32 j = 0; j < p.vertices.size(); j++)
+ // - Classic lighting (shaders handle this by themselves)
+ if(!enable_shaders)
{
- video::SColor &vc = p.vertices[j].Color;
- 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);
+ for(u32 j = 0; j < p.vertices.size(); j++)
+ {
+ video::SColor &vc = p.vertices[j].Color;
+ 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);
+ }
}
-
// Create material
video::SMaterial material;
material.setFlag(video::EMF_LIGHTING, false);
// alpha in the A channel of the returned SColor
// day light (0-255) in the R channel of the returned SColor
// night light (0-255) in the G channel of the returned SColor
-inline video::SColor MapBlock_LightColor(u8 alpha, u16 light)
+// light source (0-255) in the B channel of the returned SColor
+inline video::SColor MapBlock_LightColor(u8 alpha, u16 light, u8 light_source=0)
{
- return video::SColor(alpha, (light & 0xff), (light >> 8), 0);
+ return video::SColor(alpha, (light & 0xff), (light >> 8), light_source);
}
// Compute light at node