mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Handle day-night transition in shader and make light sources brighter when shaders are used
This commit is contained in:
parent
566f7f638a
commit
cd1f604ffe
7 changed files with 132 additions and 50 deletions
|
@ -435,7 +435,7 @@ struct FastFace
|
|||
};
|
||||
|
||||
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;
|
||||
|
||||
|
@ -477,16 +477,16 @@ static void makeFastFace(TileSpec tile, u16 li0, u16 li1, u16 li2, u16 li3,
|
|||
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;
|
||||
|
@ -658,7 +658,8 @@ static void getTileInfo(
|
|||
v3s16 &p_corrected,
|
||||
v3s16 &face_dir_corrected,
|
||||
u16 *lights,
|
||||
TileSpec &tile
|
||||
TileSpec &tile,
|
||||
u8 &light_source
|
||||
)
|
||||
{
|
||||
VoxelManipulator &vmanip = data->m_vmanip;
|
||||
|
@ -688,18 +689,20 @@ static void getTileInfo(
|
|||
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] =
|
||||
|
@ -743,9 +746,10 @@ static void updateFastFaceRow(
|
|||
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++)
|
||||
{
|
||||
|
@ -759,6 +763,7 @@ static void updateFastFaceRow(
|
|||
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
|
||||
|
@ -769,7 +774,7 @@ static void updateFastFaceRow(
|
|||
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
|
||||
|
@ -778,7 +783,8 @@ static void updateFastFaceRow(
|
|||
&& 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;
|
||||
}
|
||||
|
@ -854,7 +860,7 @@ static void updateFastFaceRow(
|
|||
}
|
||||
|
||||
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);
|
||||
|
@ -873,6 +879,7 @@ static void updateFastFaceRow(
|
|||
lights[2] = next_lights[2];
|
||||
lights[3] = next_lights[3];
|
||||
tile = next_tile;
|
||||
light_source = next_light_source;
|
||||
}
|
||||
|
||||
p = p_next;
|
||||
|
@ -1058,18 +1065,20 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data):
|
|||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue