add tiled edges option for vertex shader import

This commit is contained in:
ihm-tswow
2023-05-07 11:17:15 +02:00
parent b2d376ee5a
commit 73e329f5a1
6 changed files with 84 additions and 14 deletions

View File

@@ -1420,7 +1420,7 @@ QImage MapTile::getVertexColorsImage()
return std::move(image);
}
void MapTile::setVertexColorImage(QImage const& image, int mode)
void MapTile::setVertexColorImage(QImage const& image, int mode, bool tiledEdges)
{
unsigned const LONG{9}, SHORT{8}, SUM{LONG + SHORT}, DSUM{SUM * 2};
@@ -1444,6 +1444,11 @@ void MapTile::setVertexColorImage(QImage const& image, int mode)
bool const erp = plain % DSUM / SUM;
unsigned const idx {(plain - (is_virtual ? (erp ? SUM : 1) : 0)) / 2};
if (tiledEdges && ((y == 16 && l == 15) || (x == 16 && k == 15)))
{
continue;
}
switch (mode)
{
case 0: // Set
@@ -1483,10 +1488,70 @@ void MapTile::setVertexColorImage(QImage const& image, int mode)
}
}
chunk->registerChunkUpdate(ChunkUpdateFlags::MCCV);
}
}
if (tiledEdges)
{
if (index.z > 0)
{
getWorld()->for_tile_at(TileIndex{ index.x, index.z-1}
, [&](MapTile* tile)
{
for (int chunk_x = 0; chunk_x < 16; ++chunk_x)
{
MapChunk* targetChunk = tile->getChunk(chunk_x, 15);
MapChunk* sourceChunk = this->getChunk(chunk_x, 0);
targetChunk->registerChunkUpdate(ChunkUpdateFlags::MCCV);
for (int vert_x = 0; vert_x < 9; ++vert_x)
{
int target_vert = 136 + vert_x;
int source_vert = vert_x;
targetChunk->getVertexColors()[target_vert] = sourceChunk->getVertexColors()[source_vert];
}
}
tile->registerChunkUpdate(ChunkUpdateFlags::MCCV);
}
);
}
if (index.x > 1)
{
getWorld()->for_tile_at(TileIndex{ index.x-1, index.z}
, [&](MapTile* tile)
{
for (int chunk_y = 0; chunk_y < 16; ++chunk_y)
{
MapChunk* targetChunk = tile->getChunk(15, chunk_y);
MapChunk* sourceChunk = this->getChunk(0, chunk_y);
targetChunk->registerChunkUpdate(ChunkUpdateFlags::MCCV);
for (int vert_y = 0; vert_y < 9; ++vert_y)
{
int target_vert = vert_y * 17 + 8;
int source_vert = vert_y * 17;
targetChunk->getVertexColors()[target_vert] = sourceChunk->getVertexColors()[source_vert];
}
}
tile->registerChunkUpdate(ChunkUpdateFlags::MCCV);
}
);
}
if (index.x > 1 && index.z > 1)
{
getWorld()->for_tile_at(TileIndex { index.x-1, index.z-1 }
, [&] (MapTile* tile)
{
MapChunk* targetChunk = tile->getChunk(15, 15);
targetChunk->registerChunkUpdate(ChunkUpdateFlags::MCCV);
tile->getChunk(15,15)->getVertexColors()[144] = this->getChunk(0,0)->getVertexColors()[0];
tile->registerChunkUpdate(ChunkUpdateFlags::MCCV);
}
);
}
}
}

View File

@@ -143,7 +143,7 @@ public:
QImage getNormalmapImage();
void setHeightmapImage(QImage const& image, float multiplier, int mode, bool tiledEdges);
void setAlphaImage(QImage const& image, unsigned layer);
void setVertexColorImage(QImage const& image, int mode);
void setVertexColorImage(QImage const& image, int mode, bool tiledEdges);
void registerChunkUpdate(unsigned flags) { _chunk_update_flags |= flags; };
void endChunkUpdates() { _chunk_update_flags = 0; };
std::array<float, 145 * 256 * 4>& getChunkHeightmapBuffer() { return _chunk_heightmap_buffer; };

View File

@@ -1612,6 +1612,9 @@ void MapView::setupAssistMenu()
adt_import_vcol_params_layout->addWidget(adt_import_vcol_params_mode);
adt_import_vcol_params_mode->addItems({"Set", "Add", "Subtract", "Multiply"});
QCheckBox* adt_import_vcol_params_mode_tiled_edges = new QCheckBox("Tiled Edges", adt_import_vcol_params);
adt_import_vcol_params_layout->addWidget(adt_import_vcol_params_mode_tiled_edges);
QPushButton* adt_import_vcol_params_okay = new QPushButton("Okay", adt_import_vcol_params);
adt_import_vcol_params_layout->addWidget(adt_import_vcol_params_okay);
@@ -1646,7 +1649,7 @@ void MapView::setupAssistMenu()
img.load(filepath, "PNG");
NOGGIT_ACTION_MGR->beginAction(this, Noggit::ActionFlags::eCHUNKS_VERTEX_COLOR);
_world->importADTVertexColorMap(_camera.position, img, adt_import_vcol_params_mode->currentIndex());
_world->importADTVertexColorMap(_camera.position, img, adt_import_vcol_params_mode->currentIndex(), adt_import_vcol_params_mode_tiled_edges->isChecked());
NOGGIT_ACTION_MGR->endAction();
}
}

View File

@@ -1934,7 +1934,7 @@ void World::importADTVertexColorMap(glm::vec3 const& pos, int mode)
if (img.width() != 257 || img.height() != 257)
img = img.scaled(257, 257, Qt::AspectRatioMode::IgnoreAspectRatio);
tile->setVertexColorImage(img, mode);
tile->setVertexColorImage(img, mode, false);
}
);
@@ -1964,7 +1964,7 @@ void World::ensureAllTilesetsADT(glm::vec3 const& pos)
});
}
void World::importADTVertexColorMap(glm::vec3 const& pos, QImage const& image, int mode)
void World::importADTVertexColorMap(glm::vec3 const& pos, QImage const& image, int mode, bool tiledEdges)
{
ZoneScoped;
for_all_chunks_on_tile(pos, [](MapChunk* chunk)
@@ -1972,14 +1972,16 @@ void World::importADTVertexColorMap(glm::vec3 const& pos, QImage const& image, i
NOGGIT_CUR_ACTION->registerChunkVertexColorChange(chunk);
});
if (image.width() != 257 || image.height() != 257)
int desiredDimensions = tiledEdges ? 256 : 257;
if (image.width() != desiredDimensions || image.height() != desiredDimensions)
{
QImage scaled = image.scaled(257, 257, Qt::AspectRatioMode::IgnoreAspectRatio);
QImage scaled = image.scaled(desiredDimensions, desiredDimensions, Qt::AspectRatioMode::IgnoreAspectRatio);
for_tile_at ( pos
, [&] (MapTile* tile)
{
tile->setVertexColorImage(scaled, mode);
tile->setVertexColorImage(scaled, mode, tiledEdges);
}
);
@@ -1989,7 +1991,7 @@ void World::importADTVertexColorMap(glm::vec3 const& pos, QImage const& image, i
for_tile_at ( pos
, [&] (MapTile* tile)
{
tile->setVertexColorImage(image, mode);
tile->setVertexColorImage(image, mode, tiledEdges);
}
);
}
@@ -2895,11 +2897,11 @@ void World::importAllADTVertexColorMaps(unsigned int mode)
if (img.width() != 257 || img.height() != 257)
{
QImage scaled = img.scaled(257, 257, Qt::IgnoreAspectRatio);
mTile->setVertexColorImage(scaled, mode);
mTile->setVertexColorImage(scaled, mode, false);
}
else
{
mTile->setVertexColorImage(img, mode);
mTile->setVertexColorImage(img, mode, false);
}
mTile->saveTile(this);

View File

@@ -238,7 +238,7 @@ public:
void importADTHeightmap(glm::vec3 const& pos, QImage const& image, float multiplier, unsigned mode, bool tiledEdges);
void importADTHeightmap(glm::vec3 const& pos, float multiplier, unsigned mode);
void importADTVertexColorMap(glm::vec3 const& pos, int mode);
void importADTVertexColorMap(glm::vec3 const& pos, QImage const& image, int mode);
void importADTVertexColorMap(glm::vec3 const& pos, QImage const& image, int mode, bool tiledEdges);
void importAllADTsAlphamaps();
void importAllADTsHeightmaps(float multiplier, unsigned mode);

View File

@@ -50,7 +50,7 @@ void TileSetVertexColorsImageNode::compute()
image_to_use = &scaled;
}
tile->setVertexColorImage(*image_to_use, _operation->currentIndex());
tile->setVertexColorImage(*image_to_use, _operation->currentIndex(), false);
_out_ports[0].out_value = std::make_shared<LogicData>(true);
_node->onDataUpdated(0);