progress new render mode

This commit is contained in:
T1ti
2024-03-02 08:50:45 +01:00
parent 58f12ebf96
commit 72b8d97c11
9 changed files with 277 additions and 85 deletions

View File

@@ -5,8 +5,10 @@
#include <QtCore/QSettings>
#include <cppconn/driver.h>
#include <cppconn/prepared_statement.h>
#include <driver.h>
#include <prepared_statement.h>
// #include <cppconn/driver.h>
// #include <cppconn/prepared_statement.h>
namespace
{

View File

@@ -31,11 +31,27 @@ void selected_chunk_type::updateDetails(Noggit::Ui::detail_infos* detail_widget)
<< (flags.flags.lq_magma ? "<br>lava" : "")
<< (flags.flags.lq_slime ? "<br>slime" : "");
select_info << "<br><b>Chunk Unit</b> (" << unit_index.x << ", " << unit_index.y << ")"
select_info << "\n<br><b>Chunk Unit</b> (" << unit_index.x << ", " << unit_index.y << ")"
<< "<br><b>Chunk Unit Effect Doodads disabled</b>: "
<< (chunk->getTextureSet()->getDoodadEnabledAt(unit_index.y, unit_index.x) ? "True" : "False")
<< "<br><b>Chunk Unit Active Doodad Effect Layer </b>: "
<< int(chunk->getTextureSet()->getDoodadActiveLayerIdAt(unit_index.x, unit_index.y));
<< int(chunk->getTextureSet()->getDoodadActiveLayerIdAt(unit_index.x, unit_index.y))
<< ""
<<"\n";
std::array<float, 4> weights = chunk->getTextureSet()->get_textures_weight_for_unit(unit_index.x, unit_index.y);
if (chunk->getTextureSet()->num())
{
select_info << "\n<br><b>DEBUG Chunk Unit texture weights:</b>"
<< "<br>0:" << weights[0] << "%";
}
if (chunk->getTextureSet()->num()>1)
select_info << "<br>1:" << weights[1] << "%";
if (chunk->getTextureSet()->num() > 2)
select_info << "<br>2:" << weights[2] << "%";
if (chunk->getTextureSet()->num() > 3)
select_info << "<br>3:" << weights[3] << "%";
// liquid details if the chunk has liquid data
if (chunk->mt->Water.hasData(0))
@@ -62,7 +78,7 @@ void selected_chunk_type::updateDetails(Noggit::Ui::detail_infos* detail_widget)
select_info << "<br><b>no liquid data</b>";
}
select_info << "<br><b>textures used:</b> " << chunk->texture_set->num()
select_info << "\n<br><b>textures used:</b> " << chunk->texture_set->num()
<< "<br><b>textures:</b><span>";
unsigned counter = 0;

View File

@@ -553,6 +553,7 @@ void Noggit::Rendering::TileRender::setChunkGroundEffectColor(unsigned int chunk
_chunk_instance_data[chunkid].ChunkGroundEffectColor[0] = color.r;
_chunk_instance_data[chunkid].ChunkGroundEffectColor[1] = color.g;
_chunk_instance_data[chunkid].ChunkGroundEffectColor[2] = color.b;
_chunk_instance_data[chunkid].ChunkGroundEffectColor[2] = 0.0; // not used
}
void TileRender::initChunkData(MapChunk* chunk)
@@ -569,39 +570,81 @@ void TileRender::initChunkData(MapChunk* chunk)
chunk_render_instance.ChunkGroundEffectColor[0] = 0.0f;
chunk_render_instance.ChunkGroundEffectColor[1] = 0.0f;
chunk_render_instance.ChunkGroundEffectColor[2] = 0.0f;
chunk_render_instance.ChunkGroundEffectColor[3] = 0.0f;
// setChunkGroundEffectData(chunk);
chunk_render_instance.ChunkDoodadsEnabled2_ChunksLayerEnabled2[0] = 0;
chunk_render_instance.ChunkDoodadsEnabled2_ChunksLayerEnabled2[1] = 0;
chunk_render_instance.ChunkDoodadsEnabled2_ChunksLayerEnabled2[2] = 0;
chunk_render_instance.ChunkDoodadsEnabled2_ChunksLayerEnabled2[3] = 0;
}
void TileRender::setChunkGroundEffectData(MapChunk* chunk)
{
auto& chunk_render_instance = _chunk_instance_data[chunk->px * 16 + chunk->py];
// chunk_render_instance.ChunkGroundEffectColor;
auto doodadMapping = chunk->texture_set->getDoodadMappingBase();
auto doodadExclusionMap = chunk->texture_set->getDoodadStencilBase();
// convert layer id to bool (IsCurrent)
// TODO
for (unsigned int x = 0; x < 8; x++)
{
for (unsigned int y = 0; y < 8; y++)
{
uint8_t layer_id = chunk->texture_set->getDoodadActiveLayerIdAt(x, y);
unsigned int effect_id = chunk->getTextureSet()->getEffectForLayer(layer_id);
}
}
// pack it to int32s
int32_t exclusionmap1 = (int32_t)((uint32_t)(doodadExclusionMap[0] << 0) | (uint32_t)(doodadExclusionMap[1] << 8)
| (uint32_t)(doodadExclusionMap[2] << 16) | (uint32_t)(doodadExclusionMap[3] << 24));
int32_t exclusionmap2 = (int32_t)((uint32_t)(doodadExclusionMap[4] << 0) | (uint32_t)(doodadExclusionMap[5] << 8)
| (uint32_t)(doodadExclusionMap[6] << 16) | (uint32_t)(doodadExclusionMap[7] << 24));
// (a << 0) | (b << 8) | (c << 16) | (d << 24);
auto& chunk_render_instance = _chunk_instance_data[chunk->px * 16 + chunk->py];
chunk_render_instance.ChunkDoodadsEnabled2_ChunksLayerEnabled2[0] = exclusionmap1;
chunk_render_instance.ChunkDoodadsEnabled2_ChunksLayerEnabled2[1] = exclusionmap2;
}
void Noggit::Rendering::TileRender::setChunkGroundEffectActiveData(MapChunk* chunk, std::string active_texture)
{
// 1 : check if chunk has our texture AND set
// if it does, then check if it's the active layer for each unit
// get the layer id of our texture
int layer_id = -1;
for (int i = 0; i < chunk->getTextureSet()->num(); ++i)
{
if (chunk->getTextureSet()->filename(i) == active_texture)
{
layer_id = i;
}
}
// int layer_id = chunk->getTextureSet()->texture_id(active_texture); // -1 if not present
auto& chunk_render_instance = _chunk_instance_data[chunk->px * 16 + chunk->py];
if (layer_id == -1)
{
chunk_render_instance.ChunkDoodadsEnabled2_ChunksLayerEnabled2[2] = 0;
chunk_render_instance.ChunkDoodadsEnabled2_ChunksLayerEnabled2[3] = 0;
return;
}
int32_t active_map1 = 0;
int32_t active_map2 = 0;
// convert layer id to bool (Is Active)
int bit = 0;
for (unsigned int x = 0; x < 8; x++)
{
for (unsigned int y = 0; y < 8; y++)
{
uint8_t unit_layer_id = chunk->texture_set->getDoodadActiveLayerIdAt(x, y);
bool is_active = layer_id == unit_layer_id;
if (is_active)
{
if (bit < 32)
active_map1 |= (1 << bit);
else
active_map2 |= (1 << (bit-32));
}
bit++;
}
}
chunk_render_instance.ChunkDoodadsEnabled2_ChunksLayerEnabled2[2] = active_map1;
chunk_render_instance.ChunkDoodadsEnabled2_ChunksLayerEnabled2[3] = active_map2;
}

View File

@@ -44,6 +44,7 @@ namespace Noggit::Rendering
void initChunkData(MapChunk* chunk);
void setChunkGroundEffectData(MapChunk* chunk);
void setChunkGroundEffectActiveData(MapChunk* chunk, std::string active_texture);
[[nodiscard]]
unsigned objectsFrustumCullTest() const { return _objects_frustum_cull_test; };

View File

@@ -282,54 +282,87 @@ void main()
if(draw_groundeffectid_overlay != 0)
{
out_color.rgb = out_color.rgb * 0.3 + instances[instanceID].ChunkGroundEffectColor.rgb;
}
if(draw_groundeffect_layerid_overlay != 0)
{
}
if(draw_noeffectdoodad_overlay != 0)
{
uint no_doodad = 0;
uvec2 tile_index = uvec2(uint(floor(vary_position.x / TILESIZE)), uint(floor(vary_position.z / TILESIZE)));
vec2 tile_base_pos = vec2(float(tile_index.x * TILESIZE), float(tile_index.y * TILESIZE));
uvec2 chunk_index = uvec2(uint(floor(instanceID / 16)), uint(floor(instanceID % 16)));
// uint chunk_x = uint(floor( (vary_position.x - tile_base_pos.x) / CHUNKSIZE));
// uint chunk_y = uint(floor( (vary_position.z - tile_base_pos.y) / CHUNKSIZE));
vec2 chunk_base_pos = vec2(float(chunk_index.x * CHUNKSIZE), float(chunk_index.y * CHUNKSIZE));
uint unit_x = uint(floor((vary_position.x - (tile_base_pos.x + chunk_base_pos.x)) / UNITSIZE));
uint unit_z = uint(floor((vary_position.z - (tile_base_pos.y + chunk_base_pos.y)) / UNITSIZE));
// swapped x and y order, the data is wrongly ordered when loaded
if (unit_z < 4)
if(draw_groundeffectid_overlay != 0)
{
no_doodad = uint(instances[instanceID].ChunkDoodadsEnabled2_ChunksLayerEnabled2.r) & (1 << ((unit_z * 8) + unit_x) );
}
else
{
no_doodad = uint(instances[instanceID].ChunkDoodadsEnabled2_ChunksLayerEnabled2.g) & (1 << ((unit_z * 8) + unit_x) - 32 ); // (unit_x-4) * 8 + unit_z)
out_color.rgb = out_color.rgb * 0.3 + instances[instanceID].ChunkGroundEffectColor.rgb;
}
if (no_doodad != 0)
if(draw_groundeffect_layerid_overlay != 0)
{
// if set, draw chunk in white
out_color.rgb = mix(vec3(1.0), out_color.rgb, 0.5);
}
else
{
// else, draw in black(default)
out_color.rgb = mix(vec3(0.0), out_color.rgb, 0.5);
// if chuck does not have our texture it is set as black color
if (instances[instanceID].ChunkGroundEffectColor.rgb == vec3(0.0, 0.0, 0.0))
{
out_color.rgb = out_color.rgb * 0.3 + instances[instanceID].ChunkGroundEffectColor.rgb;
}
else
{
uint is_active = 0;
uvec2 tile_index = uvec2(uint(floor(vary_position.x / TILESIZE)), uint(floor(vary_position.z / TILESIZE)));
vec2 tile_base_pos = vec2(float(tile_index.x * TILESIZE), float(tile_index.y * TILESIZE));
uvec2 chunk_index = uvec2(uint(floor(instanceID / 16)), uint(floor(instanceID % 16)));
vec2 chunk_base_pos = vec2(float(chunk_index.x * CHUNKSIZE), float(chunk_index.y * CHUNKSIZE));
uint unit_x = uint(floor((vary_position.x - (tile_base_pos.x + chunk_base_pos.x)) / UNITSIZE));
uint unit_z = uint(floor((vary_position.z - (tile_base_pos.y + chunk_base_pos.y)) / UNITSIZE));
// swapped x and y order, the data is wrongly ordered when loaded
if (unit_z < 4)
{
is_active = uint(instances[instanceID].ChunkDoodadsEnabled2_ChunksLayerEnabled2.b) & (1 << ((unit_z * 8) + unit_x) );
}
else
{
is_active = uint(instances[instanceID].ChunkDoodadsEnabled2_ChunksLayerEnabled2.a) & (1 << ((unit_z * 8) + unit_x) - 32 ); // (unit_x-4) * 8 + unit_z)
}
if (is_active != 0)
{
// if set, draw chunk in green
out_color.rgb = mix(vec3(0.0, 1.0, 0.0), out_color.rgb, 0.7);
}
else
{
// else, draw in red
out_color.rgb = mix(vec3(1.0, 0.0, 0.0), out_color.rgb, 0.7);
}
}
}
}
// render mode for ge doodads enabled on chunk unit. no_render set = white
if(draw_noeffectdoodad_overlay != 0)
{
uint no_doodad = 0;
uvec2 tile_index = uvec2(uint(floor(vary_position.x / TILESIZE)), uint(floor(vary_position.z / TILESIZE)));
vec2 tile_base_pos = vec2(float(tile_index.x * TILESIZE), float(tile_index.y * TILESIZE));
uvec2 chunk_index = uvec2(uint(floor(instanceID / 16)), uint(floor(instanceID % 16)));
// uint chunk_x = uint(floor( (vary_position.x - tile_base_pos.x) / CHUNKSIZE));
// uint chunk_y = uint(floor( (vary_position.z - tile_base_pos.y) / CHUNKSIZE));
vec2 chunk_base_pos = vec2(float(chunk_index.x * CHUNKSIZE), float(chunk_index.y * CHUNKSIZE));
uint unit_x = uint(floor((vary_position.x - (tile_base_pos.x + chunk_base_pos.x)) / UNITSIZE));
uint unit_z = uint(floor((vary_position.z - (tile_base_pos.y + chunk_base_pos.y)) / UNITSIZE));
// swapped x and y order, the data is wrongly ordered when loaded
if (unit_z < 4)
{
no_doodad = uint(instances[instanceID].ChunkDoodadsEnabled2_ChunksLayerEnabled2.r) & (1 << ((unit_z * 8) + unit_x) );
}
else
{
no_doodad = uint(instances[instanceID].ChunkDoodadsEnabled2_ChunksLayerEnabled2.g) & (1 << ((unit_z * 8) + unit_x) - 32 ); // (unit_x-4) * 8 + unit_z)
}
if (no_doodad != 0)
{
// if set, draw chunk in white
out_color.rgb = mix(vec3(1.0), out_color.rgb, 0.5);
}
else
{
// else, draw in black(default)
out_color.rgb = mix(vec3(0.0), out_color.rgb, 0.5);
}
}
if(draw_impass_overlay != 0 && instances[instanceID].ChunkHoles_DrawImpass_TexLayerCount_CantPaint.g != 0)
{

View File

@@ -1295,6 +1295,46 @@ void TextureSet::update_lod_texture_map()
std::array<float, 4> TextureSet::get_textures_weight_for_unit(unsigned int unit_x, unsigned int unit_y)
{
float total_layer_0 = 0.f;
float total_layer_1 = 0.f;
float total_layer_2 = 0.f;
float total_layer_3 = 0.f;
// 8x8 bits per unit
for (int x = unit_x; x < unit_x + 8; x++)
{
for (int y = unit_y; y < unit_y + 8; y++)
{
float base_alpha = 255.f;
for (int alpha_layer = 0; alpha_layer < nTextures - 1; ++alpha_layer)
{
float f = static_cast<float>(alphamaps[alpha_layer]->getAlpha(64 * y + x));
if (alpha_layer == 0)
total_layer_1 += f;
else if (alpha_layer == 1)
total_layer_2 += f;
else if (alpha_layer == 2)
total_layer_3 += f;
base_alpha -= f;
}
total_layer_0 += base_alpha;
}
}
float sum = total_layer_0 + total_layer_1 + total_layer_2 + total_layer_3;
std::array<float, 4> weights = { total_layer_0 / sum * 100.f,
total_layer_1 / sum * 100.f,
total_layer_2 / sum * 100.f,
total_layer_3 / sum * 100.f };
return weights;
}
uint8_t TextureSet::sum_alpha(size_t offset) const
{
uint8_t sum = 0;

View File

@@ -104,6 +104,9 @@ public:
void setNTextures(size_t n) { nTextures = n; };
std::vector<scoped_blp_texture_reference>* getTextures() { return &textures; };
// get the weight of each texture in a chunk unit
std::array<float, 4> get_textures_weight_for_unit(unsigned int unit_x, unsigned int unit_y);
private:
uint8_t sum_alpha(size_t offset) const;

View File

@@ -721,14 +721,17 @@ namespace Noggit
_render_type_group = new QButtonGroup(_render_group_box);
_render_active_sets = new QRadioButton("Effect Id/Set", this);
_render_active_sets->setToolTip("Render all the loaded effect sets for this texture in various colors");
_render_type_group->addButton(_render_active_sets);
render_layout->addWidget(_render_active_sets);
_render_exclusion_map = new QRadioButton("Doodads Disabled", this);
_render_exclusion_map->setToolTip("Render chunk units where effect doodads are disabled as white, rest as black");
_render_type_group->addButton(_render_exclusion_map);
render_layout->addWidget(_render_exclusion_map);
_render_placement_map = new QRadioButton("Active layer", this); // if chunk contains texture/Effect : render as green or red if the effect layer is active or not
_render_placement_map = new QRadioButton("Selected set active", this); // if chunk contains texture/Effect : render as green or red if the effect layer is active or not
_render_placement_map->setToolTip("For the currently selected set, render as red if set is present in the chunk unit and NOT the current active layer, render as green if it's active.");
_render_type_group->addButton(_render_placement_map);
render_layout->addWidget(_render_placement_map);
@@ -769,7 +772,7 @@ namespace Noggit
_effect_sets_list->setSelectionBehavior(QAbstractItemView::SelectItems);
_effect_sets_list->setUniformItemSizes(true);
_effect_sets_list->setMinimumHeight(_object_list->iconSize().height() * 6);
// _effect_sets_list->setMinimumHeight(_object_list->iconSize().height() * 6);
// effect settings
{
@@ -957,20 +960,18 @@ namespace Noggit
*/
QObject::connect(_effect_sets_list, &QListWidget::itemClicked, [this](QListWidgetItem* item)
{
//_effect_sets_list->currentItem
int index = _effect_sets_list->currentIndex().row();
int index = _effect_sets_list->currentIndex().row();
if (_loaded_effects.empty() || !_effect_sets_list->count() || index == -1)
return;
auto effect = getSelectedGroundEffect();
if (!effect.has_value())
return;
auto effect = _loaded_effects[index];
SetActiveGroundEffect(effect.value());
SetActiveGroundEffect(effect);
// _cbbox_effect_sets->setStyleSheet
QPalette pal = _effect_sets_list->palette();
pal.setColor(_effect_sets_list->backgroundRole(), QColor::fromRgbF(_effects_colors[index].r, _effects_colors[index].g, _effects_colors[index].b));
_effect_sets_list->setPalette(pal);
// _cbbox_effect_sets->setStyleSheet
// QPalette pal = _effect_sets_list->palette();
// pal.setColor(_effect_sets_list->backgroundRole(), QColor::fromRgbF(_effects_colors[index].r, _effects_colors[index].g, _effects_colors[index].b));
// _effect_sets_list->setPalette(pal);
});
// TODO fix this shit
@@ -1123,7 +1124,15 @@ namespace Noggit
// _cbbox_effect_sets->setCurrentIndex(0);
auto first_item = _effect_sets_list->itemAt(0, 0);
if (_effect_sets_list->count() && first_item)
{
_effect_sets_list->setCurrentItem(first_item);
auto effect = getSelectedGroundEffect();
if (!effect.has_value())
return;
SetActiveGroundEffect(effect.value());
}
}
void ground_effect_tool::genEffectColors()
@@ -1160,12 +1169,18 @@ namespace Noggit
for (int y = 0; y < 16; y++)
{
auto chunk = tile->getChunk(x, y);
int chunk_index = chunk->px * 16 + chunk->py;
// reset to black by default
tile->renderer()->setChunkGroundEffectColor(chunk->px * 16 + chunk->py, glm::vec3(0.0, 0.0, 0.0));
tile->renderer()->setChunkGroundEffectColor(chunk_index, glm::vec3(0.0, 0.0, 0.0));
// ! Set the chunk active layer data
tile->renderer()->setChunkGroundEffectActiveData(chunk, active_texture);
for (int layer_id = 0; layer_id < chunk->getTextureSet()->num(); layer_id++)
{
auto texture_name = chunk->getTextureSet()->filename(layer_id);
if (texture_name == active_texture)
{
unsigned int const effect_id = chunk->getTextureSet()->getEffectForLayer(layer_id);
@@ -1187,7 +1202,7 @@ namespace Noggit
{
if (effect_id == effect_set.ID)
{
tile->renderer()->setChunkGroundEffectColor(chunk->px * 16 + chunk->py, _effects_colors[count]);
tile->renderer()->setChunkGroundEffectColor(chunk_index, _effects_colors[count]);
break;
}
if (_chkbox_merge_duplicates->isChecked() && (ground_effect == &effect_set)) // do deep comparison, find those that have the same effect as loaded effects, but diff id.
@@ -1197,10 +1212,14 @@ namespace Noggit
// same color
tile->renderer()->setChunkGroundEffectColor(chunk->px * 16 + chunk->py, _effects_colors[count]);
break;
}
count++;
}
if (_render_placement_map->isChecked())
{
}
}
}
}
@@ -1273,6 +1292,29 @@ namespace Noggit
delete _preview_renderer;
}
std::optional<ground_effect_set> ground_effect_tool::getSelectedGroundEffect()
{
//_effect_sets_list->currentItem
int index = _effect_sets_list->currentIndex().row();
if (_loaded_effects.empty() || !_effect_sets_list->count() || index == -1)
return std::nullopt;
auto effect = _loaded_effects[index];
return effect;
}
std::optional<glm::vec3> ground_effect_tool::getSelectedEffectColor()
{
int index = _effect_sets_list->currentIndex().row();
if (_loaded_effects.empty() || !_effect_sets_list->count() || index == -1)
return std::nullopt;
glm::vec3 effect_color = _effects_colors[index];
return effect_color;
}
void ground_effect_tool::SetActiveGroundEffect(ground_effect_set const& effect)
{
// sets a ground effect to be actively selected in the UI.

View File

@@ -125,6 +125,9 @@ namespace Noggit
bool show_placement_map_overlay() const { return _render_placement_map->isChecked() && _render_group_box->isChecked(); };
bool show_exclusion_map_overlay() const { return _render_exclusion_map->isChecked() && _render_group_box->isChecked(); };
private:
std::optional<ground_effect_set> getSelectedGroundEffect();
std::optional<glm::vec3> getSelectedEffectColor();
void SetActiveGroundEffect(ground_effect_set const& effect);
void updateDoodadPreviewRender(int slot_index);
@@ -137,7 +140,7 @@ namespace Noggit
int active_doodad_widget = 0;
// std::unordered_map<unsigned int, int> _texture_effect_ids;
std::vector< ground_effect_set> _loaded_effects;
std::vector<ground_effect_set> _loaded_effects;
std::unordered_map<unsigned int, ground_effect_set> _ground_effect_cache; // store them for faster iteration on duplicates
@@ -150,8 +153,17 @@ namespace Noggit
QGroupBox* _render_group_box;
QButtonGroup* _render_type_group;
// render all the loaded effect sets for this texture in various colors
QRadioButton* _render_active_sets;
// only for the active/selected set of the current texture :
// - render as red if set is present in the chunk and NOT the current active layer
// - render as green if set is present in the chunk and is the current active layer
// - render as black is set is not present
QRadioButton* _render_placement_map;
// render chunk units where effect doodads are disabled as white, rest as black
QRadioButton* _render_exclusion_map;
QCheckBox* _chkbox_merge_duplicates;