Fix texture coordinates of cuboid drawtypes#16091
Conversation
9ac4db3 to
c6c5e80
Compare
c6c5e80 to
a64a314
Compare
| break; | ||
| case TileRotation::R270: | ||
| tcoords.set(tcoords.Y, -tcoords.X); | ||
| tcoords.set(tcoords.Y, 1 - tcoords.X); |
There was a problem hiding this comment.
Subtracting from 1 here is always correct, since even for texture coordinates from oversized nodeboxes, it stays aligned to the [0,1] range, and always has scale 1.
(visual_scale changes the mesh scale and not the texture coords scale.)
So we are not subtracting from the corresponding entry in txc.
Co-authored-by: sfan5 <sfan5@live.de>
|
to check UV coords: diff --git a/src/client/meshgen/collector.cpp b/src/client/meshgen/collector.cpp
--- a/src/client/meshgen/collector.cpp
+++ b/src/client/meshgen/collector.cpp
@@ -25,8 +25,9 @@ void MeshCollector::append(const TileLayer &layer, const video::S3DVertex *verti
u32 vertex_count = p.vertices.size();
for (u32 i = 0; i < numVertices; i++) {
+ v2f uv{core::clamp(vertices[i].TCoords.X, 0.f, 1.f), core::clamp(vertices[i].TCoords.Y, 0.f, 1.f)};
p.vertices.emplace_back(vertices[i].Pos + offset, vertices[i].Normal,
- vertices[i].Color, vertices[i].TCoords);
+ vertices[i].Color, uv);
m_bounding_radius_sq = std::max(m_bounding_radius_sq,
(vertices[i].Pos - m_center_pos).getLengthSQ());
} |
| } | ||
|
|
||
| tcoords.set(x * scale_factor, y * scale_factor); | ||
| } |
There was a problem hiding this comment.
this could probably be generalized by performing maths on the normal vector of the tile (do we have that?) but whatever
Desour
left a comment
There was a problem hiding this comment.
glasslike_framed is broken. (Also uses drawAutoLightedCuboid and expects nodebox-like uv.)
Found no issues otherwise (also tested with tileable_vertical, it works now. 🎉 ). Thanks!
| assert(tilecount >= 1 && tilecount <= 6); // pre-condition | ||
|
|
||
| auto vertices = setupCuboidVertices(box, txc, tiles, tilecount); | ||
| auto vertices = setupCuboidVertices(box, txc, tiles, tilecount, cur_node.p); |
There was a problem hiding this comment.
Btw. you could easily fix scale being limited to int fractions of 16 (currently it's mesh chunk size dependent then), by adding blockpos_nodes here. (Maybe follow up PR.)
|
Oh, I must have thought that glasslike_framed is just a normal node mesh, should be fixed now. |
Co-authored-by: DS <ds.desour@proton.me>
|
Some meshgen tests were added in #13616. Would testing the texture coordinates there be possible?
Hmm, it doesn't seem to be working for me, Devtest "Dirt with Snow" still appears to use repeat instead of clamp. With texture filtering enabled, and texture_min_size disabled by source code change (also visible without, but this makes it much more obvious):
luanti/games/devtest/mods/basenodes/init.lua Lines 37 to 45 in 486fb7c (Feel free to consider things out of scope.) |
|
Maybe, I'm not very familiar with our unittests. I haven't looked into |
Some unit tests are better than no unit tests :)
Yeah, this is definitely a step in the right direction to get that working. luanti/src/client/content_mapblock.cpp Lines 429 to 434 in 486fb7c Presumably this was done as a hacky fix for everything turning broken with tileable_vertical/horizontal=false, and is no longer needed after the fixes in this PR. (The flags are regularly set here: Lines 696 to 705 in 486fb7c ) EDIT: looks like I was right :) |
|
While unit testing meshgen is good I think we would also benefit from having a static scene that can be rendered in CI and the screenshot compared to a known good snapshot. |
I meant that it doesn't completely break nodes anymore. Fixing this can also be done in another PR. 🤷 Unittests would of course always be nice. I approve anyways. |
|
I found a small issue: It would be nice if we could also properly support glasslike and flowingliquid, and the shiny part of glasslike_framed. |
|
Adding to next release due to high-risk bug fix (IMO). |
|
According to our documentation, If I'm not wrong, according to our code, |



To do
Ready for review
How to test
See that texture coordinates are correct,
align style and other texture coordinates features like rotation still work.
and check nodebox drawtype nodes.