2024-10-28 15:57:39 +01:00
|
|
|
// Luanti
|
|
|
|
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
// Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2024-02-27 19:03:46 +01:00
|
|
|
|
|
|
|
#include "tile.h"
|
|
|
|
|
2025-02-15 14:25:04 +01:00
|
|
|
void TileLayer::applyMaterialOptions(video::SMaterial &material, int layer) const
|
2024-02-27 19:03:46 +01:00
|
|
|
{
|
2025-02-15 14:25:04 +01:00
|
|
|
material.setTexture(0, texture);
|
2024-02-27 19:03:46 +01:00
|
|
|
|
|
|
|
material.BackfaceCulling = (material_flags & MATERIAL_FLAG_BACKFACE_CULLING) != 0;
|
|
|
|
if (!(material_flags & MATERIAL_FLAG_TILEABLE_HORIZONTAL)) {
|
|
|
|
material.TextureLayers[0].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
|
|
|
|
material.TextureLayers[1].TextureWrapU = video::ETC_CLAMP_TO_EDGE;
|
|
|
|
}
|
|
|
|
if (!(material_flags & MATERIAL_FLAG_TILEABLE_VERTICAL)) {
|
|
|
|
material.TextureLayers[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
|
|
|
|
material.TextureLayers[1].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
|
|
|
|
}
|
2025-02-15 14:25:04 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The second layer is for overlays, but uses the same vertex positions
|
|
|
|
* as the first, which easily leads to Z-fighting.
|
2025-03-16 17:56:32 +01:00
|
|
|
* To fix this we offset the polygons of the *first layer* away from the camera.
|
2025-02-15 14:25:04 +01:00
|
|
|
* This only affects the depth buffer and leads to no visual gaps in geometry.
|
2025-03-16 17:56:32 +01:00
|
|
|
*
|
|
|
|
* However, doing so intrudes the "Z space" of the overlay of the next node
|
|
|
|
* so that leads to inconsistent Z-sorting again. :(
|
|
|
|
* HACK: For lack of a better approach we restrict this to cases where
|
|
|
|
* an overlay is actually present.
|
2025-02-15 14:25:04 +01:00
|
|
|
*/
|
2025-03-16 17:56:32 +01:00
|
|
|
if (need_polygon_offset) {
|
|
|
|
material.PolygonOffsetSlopeScale = 1;
|
|
|
|
material.PolygonOffsetDepthBias = 1;
|
2025-02-15 14:25:04 +01:00
|
|
|
}
|
2024-02-27 19:03:46 +01:00
|
|
|
}
|