1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-09-15 18:57:08 +00:00

Fixes and proper tangent space

This commit is contained in:
Gefüllte Taubenbrust 2024-11-11 17:07:52 +01:00
parent 6ad43575ff
commit 2fd22c1850
12 changed files with 417 additions and 70 deletions

View file

@ -40,10 +40,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
MeshMakeData
*/
MeshMakeData::MeshMakeData(const NodeDefManager *ndef, u16 side_length, bool use_shaders):
MeshMakeData::MeshMakeData(const NodeDefManager *ndef, u16 side_length, bool use_shaders, bool use_tangent_vertices):
side_length(side_length),
nodedef(ndef),
m_use_shaders(use_shaders)
m_use_shaders(use_shaders),
m_use_tangent_vertices(use_tangent_vertices)
{}
void MeshMakeData::fillBlockDataBegin(const v3s16 &blockpos)
@ -617,6 +618,7 @@ MapBlockMesh::MapBlockMesh(Client *client, MeshMakeData *data, v3s16 camera_offs
for (auto &m : m_mesh)
m = make_irr<scene::SMesh>();
m_enable_shaders = data->m_use_shaders;
m_use_tangent_vertices = data->m_use_tangent_vertices;
auto mesh_grid = client->getMeshGrid();
v3s16 bp = data->m_blockpos;
@ -752,27 +754,44 @@ MapBlockMesh::MapBlockMesh(Client *client, MeshMakeData *data, v3s16 camera_offs
p.layer.applyMaterialOptions(material);
}
scene::SMeshBuffer *buf = new scene::SMeshBuffer();
buf->Material = material;
if (p.layer.isTransparent()) {
buf->append(&p.vertices[0], p.vertices.size(), nullptr, 0);
MeshTriangle t;
t.buffer = buf;
m_transparent_triangles.reserve(p.indices.size() / 3);
for (u32 i = 0; i < p.indices.size(); i += 3) {
t.p1 = p.indices[i];
t.p2 = p.indices[i + 1];
t.p3 = p.indices[i + 2];
t.updateAttributes();
m_transparent_triangles.push_back(t);
}
} else {
buf->append(&p.vertices[0], p.vertices.size(),
if (m_use_tangent_vertices && !p.layer.isTransparent()) {
scene::SMeshBufferTangents* buf = new scene::SMeshBufferTangents();
buf->Material = material;
std::vector<video::S3DVertexTangents> vertices;
vertices.reserve(p.vertices.size());
for (video::S3DVertex &v : p.vertices)
vertices.push_back(video::S3DVertexTangents(v.Pos, v.Normal, v.Color, v.TCoords));
buf->append(&vertices[0], vertices.size(),
&p.indices[0], p.indices.size());
buf->recalculateBoundingBox();
scene::IMeshManipulator* meshmanip =
client->getSceneManager()->getMeshManipulator();
meshmanip->recalculateTangents(buf);
mesh->addMeshBuffer(buf);
buf->drop();
} else {
scene::SMeshBuffer *buf = new scene::SMeshBuffer();
buf->Material = material;
if (p.layer.isTransparent()) {
buf->append(&p.vertices[0], p.vertices.size(), nullptr, 0);
MeshTriangle t;
t.buffer = buf;
m_transparent_triangles.reserve(p.indices.size() / 3);
for (u32 i = 0; i < p.indices.size(); i += 3) {
t.p1 = p.indices[i];
t.p2 = p.indices[i + 1];
t.p3 = p.indices[i + 2];
t.updateAttributes();
m_transparent_triangles.push_back(t);
}
} else {
buf->append(&p.vertices[0], p.vertices.size(),
&p.indices[0], p.indices.size());
}
mesh->addMeshBuffer(buf);
buf->drop();
}
mesh->addMeshBuffer(buf);
buf->drop();
}
if (mesh) {

View file

@ -51,8 +51,9 @@ struct MeshMakeData
const NodeDefManager *nodedef;
bool m_use_shaders;
bool m_use_tangent_vertices;
MeshMakeData(const NodeDefManager *ndef, u16 side_length, bool use_shaders);
MeshMakeData(const NodeDefManager *ndef, u16 side_length, bool use_shaders, bool use_tangent_vertices = false);
/*
Copy block data manually (to allow optimizations by the caller)
@ -251,6 +252,7 @@ private:
v3f m_bounding_sphere_center;
bool m_enable_shaders;
bool m_use_tangent_vertices;
// Must animate() be called before rendering?
bool m_has_animation;

View file

@ -55,6 +55,7 @@ MeshUpdateQueue::MeshUpdateQueue(Client *client):
m_client(client)
{
m_cache_enable_shaders = g_settings->getBool("enable_shaders");
m_cache_use_tangent_vertices = m_cache_enable_shaders && g_settings->getBool("enable_bumpmaps");
m_cache_smooth_lighting = g_settings->getBool("smooth_lighting");
}
@ -192,7 +193,7 @@ void MeshUpdateQueue::done(v3s16 pos)
void MeshUpdateQueue::fillDataFromMapBlocks(QueuedMeshUpdate *q)
{
auto mesh_grid = m_client->getMeshGrid();
MeshMakeData *data = new MeshMakeData(m_client->ndef(), MAP_BLOCKSIZE * mesh_grid.cell_size, m_cache_enable_shaders);
MeshMakeData *data = new MeshMakeData(m_client->ndef(), MAP_BLOCKSIZE * mesh_grid.cell_size, m_cache_enable_shaders, m_cache_use_tangent_vertices);
q->data = data;
data->fillBlockDataBegin(q->p);

View file

@ -86,6 +86,7 @@ private:
// TODO: Add callback to update these when g_settings changes
bool m_cache_enable_shaders;
bool m_cache_use_tangent_vertices;
bool m_cache_smooth_lighting;
void fillDataFromMapBlocks(QueuedMeshUpdate *q);

View file

@ -68,7 +68,7 @@ struct Vignette {
* Colors in ASL CDL follow the following equation:
*
* out = pow(in * slope + offset, power)
*
*
*/
struct ColorDecisionList {
core::vector3df slope{1.2, 1.0, 0.8};