fix bugged brush sampling algorithms
This commit is contained in:
@@ -891,11 +891,19 @@ bool MapChunk::stampMCCV(math::vector_3d const& pos, math::vector_4d const& colo
|
||||
|
||||
math::vector_3d const diff{mVertices[i] - pos};
|
||||
|
||||
int pixel_x = std::floor(diff.x + radius);
|
||||
int pixel_y = std::floor(diff.z + radius);
|
||||
int pixel_x = std::round(((diff.x + radius) / (2.f * radius)) * img->width());
|
||||
int pixel_y = std::round(((diff.z + radius) / (2.f * radius)) * img->height());
|
||||
|
||||
auto mask_color = img->pixelColor(pixel_x, pixel_y);
|
||||
float image_factor = (mask_color.redF() + mask_color.greenF() + mask_color.blueF()) / 3.0f;
|
||||
float image_factor;
|
||||
if (pixel_x >= 0 && pixel_x < 257 && pixel_y >= 0 && pixel_y < 257)
|
||||
{
|
||||
auto mask_color = img->pixelColor(pixel_x, pixel_y);
|
||||
image_factor = (mask_color.redF() + mask_color.greenF() + mask_color.blueF()) / 3.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
image_factor = 0.f;
|
||||
}
|
||||
|
||||
float edit = image_factor * (paint ? ((change * (1.0f - dist / radius))) : (change * 20.f));
|
||||
if (editMode)
|
||||
@@ -1161,12 +1169,22 @@ auto MapChunk::stamp(math::vector_3d const& pos, float dt, QImage const* img, fl
|
||||
|
||||
math::vector_3d const diff{mVertices[i] - pos};
|
||||
|
||||
int pixel_x = std::floor(diff.x + radiusOuter);
|
||||
int pixel_y = std::floor(diff.z + radiusOuter);
|
||||
int pixel_x = std::round(((diff.x + radiusOuter) / (2.f * radiusOuter)) * img->width());
|
||||
int pixel_y = std::round(((diff.z + radiusOuter) / (2.f * radiusOuter)) * img->height());
|
||||
|
||||
auto color = img->pixelColor(pixel_x, pixel_y);
|
||||
float image_factor;
|
||||
|
||||
mVertices[i].y += delta * ((color.redF() + color.greenF() + color.blueF()) / 3.0f);
|
||||
if (pixel_x >= 0 && pixel_x < 257 && pixel_y >= 0 && pixel_y < 257)
|
||||
{
|
||||
auto color = img->pixelColor(pixel_x, pixel_y);
|
||||
image_factor = (color.redF() + color.greenF() + color.blueF()) / 3.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
image_factor = 0;
|
||||
}
|
||||
|
||||
mVertices[i].y += delta * image_factor;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1188,12 +1206,23 @@ auto MapChunk::stamp(math::vector_3d const& pos, float dt, QImage const* img, fl
|
||||
|
||||
math::vector_3d const diff{math::vector_3d{original_heightmap[i * 3], original_heightmap[i * 3 + 1], original_heightmap[i * 3 + 2]} - pos};
|
||||
|
||||
int pixel_x = std::floor(diff.x + radiusOuter);
|
||||
int pixel_y = std::floor(diff.z + radiusOuter);
|
||||
|
||||
auto color = img->pixelColor(pixel_x, pixel_y);
|
||||
int pixel_x = std::round(((diff.x + radiusOuter) / (2.f * radiusOuter)) * img->width());
|
||||
int pixel_y = std::round(((diff.z + radiusOuter) / (2.f * radiusOuter)) * img->height());
|
||||
|
||||
mVertices[i].y = original_heightmap[i * 3 + 1] + (delta * ((color.redF() + color.greenF() + color.blueF()) / 3.0f));
|
||||
float image_factor;
|
||||
|
||||
if (pixel_x >= 0 && pixel_x < 257 && pixel_y >= 0 && pixel_y < 257)
|
||||
{
|
||||
auto color = img->pixelColor(pixel_x, pixel_y);
|
||||
image_factor = (color.redF() + color.greenF() + color.blueF()) / 3.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
image_factor = 0;
|
||||
}
|
||||
|
||||
mVertices[i].y = original_heightmap[i * 3 + 1] + (delta * image_factor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
12
src/noggit/Red/LightEditor/LightEditor.cpp
Normal file
12
src/noggit/Red/LightEditor/LightEditor.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#include "LightEditor.hpp"
|
||||
|
||||
using namespace noggit::Red;
|
||||
|
||||
LightEditor::LightEditor(MapView* map_view, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, _map_view(map_view)
|
||||
{
|
||||
|
||||
}
|
||||
22
src/noggit/Red/LightEditor/LightEditor.hpp
Normal file
22
src/noggit/Red/LightEditor/LightEditor.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
// This file is part of Noggit3, licensed under GNU General Public License (version 3).
|
||||
|
||||
#ifndef NOGGIT_LIGHTEDITOR_HPP
|
||||
#define NOGGIT_LIGHTEDITOR_HPP
|
||||
|
||||
#include <QWidget>
|
||||
#include <noggit/MapView.h>
|
||||
|
||||
namespace noggit::Red
|
||||
{
|
||||
class LightEditor : public QWidget
|
||||
{
|
||||
public:
|
||||
LightEditor(MapView* map_view, QWidget* parent = nullptr);
|
||||
|
||||
private:
|
||||
MapView* _map_view;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif //NOGGIT_LIGHTEDITOR_HPP
|
||||
@@ -59,7 +59,7 @@ ImageMaskSelector::ImageMaskSelector( MapView* map_view, QWidget* parent)
|
||||
|
||||
void ImageMaskSelector::setImageMask(QString const& path)
|
||||
{
|
||||
_pixmap = QPixmap(path);
|
||||
_pixmap = QPixmap(path, "PNG");
|
||||
|
||||
_ui.curImageLabel->setPixmap(_pixmap.scaled(128, 128));
|
||||
_ui.curImageLabel->setToolTip(path);
|
||||
|
||||
@@ -402,11 +402,6 @@ bool TextureSet::stampTexture(float xbase, float zbase, float x, float z, Brush*
|
||||
|
||||
radius = brush->getRadius();
|
||||
|
||||
if (misc::getShortestDist(x, z, xbase, zbase, CHUNKSIZE) > radius)
|
||||
{
|
||||
return changed;
|
||||
}
|
||||
|
||||
create_temporary_alphamaps_if_needed();
|
||||
auto& amaps = tmp_edit_values.get();
|
||||
|
||||
@@ -427,12 +422,20 @@ bool TextureSet::stampTexture(float xbase, float zbase, float x, float z, Brush*
|
||||
|
||||
math::vector_3d const diff{math::vector_3d{xPos + TEXDETAILSIZE / 2.0f, 0.f, zPos + TEXDETAILSIZE / 2.0f} - math::vector_3d{x, 0.f, z}};
|
||||
|
||||
int pixel_x = std::floor(diff.x + radius);
|
||||
int pixel_y = std::floor(diff.z + radius);
|
||||
int pixel_x = std::round(((diff.x + radius) / (2.f * radius)) * image->width());
|
||||
int pixel_y = std::round(((diff.z + radius) / (2.f * radius)) * image->height());
|
||||
|
||||
auto color = image->pixelColor(pixel_x, pixel_y);
|
||||
float image_factor = (color.redF() + color.greenF() + color.blueF()) / 3.0f;
|
||||
float image_factor;
|
||||
|
||||
if (pixel_x >= 0 && pixel_x < 1024 && pixel_y >= 0 && pixel_y < 1024)
|
||||
{
|
||||
auto color = image->pixelColor(pixel_x, pixel_y);
|
||||
image_factor = (color.redF() + color.greenF() + color.blueF()) / 3.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
image_factor = 0;
|
||||
}
|
||||
|
||||
std::size_t offset = i + 64 * j;
|
||||
// use double for more precision
|
||||
@@ -446,7 +449,7 @@ bool TextureSet::stampTexture(float xbase, float zbase, float x, float z, Brush*
|
||||
|
||||
double current_alpha = alpha_values[tex_layer];
|
||||
double sum_other_alphas = (total - current_alpha);
|
||||
double alpha_change = image_factor * (strength - current_alpha) * pressure * brush->getValue(dist);
|
||||
double alpha_change = image_factor * (strength - current_alpha) * pressure;
|
||||
|
||||
// alpha too low, set it to 0 directly
|
||||
if (alpha_change < 0. && current_alpha + alpha_change < 1.)
|
||||
|
||||
@@ -259,8 +259,7 @@ namespace noggit
|
||||
QPixmap* pixmap = _image_mask_group->getPixmap();
|
||||
QTransform matrix;
|
||||
matrix.rotateRadians(_image_mask_group->getRotation() / 360.0f * 2.0f * M_PI);
|
||||
int const k{static_cast<int>(std::ceil(_radius_slider->value())) * 2};
|
||||
_mask_image = pixmap->toImage().transformed(matrix).scaled(k, k);
|
||||
_mask_image = pixmap->toImage().transformed(matrix, Qt::SmoothTransformation);
|
||||
_map_view->setBrushTexture(&_mask_image);
|
||||
}
|
||||
|
||||
|
||||
@@ -224,8 +224,7 @@ namespace noggit
|
||||
QPixmap* pixmap = _image_mask_group->getPixmap();
|
||||
QTransform matrix;
|
||||
matrix.rotateRadians(_image_mask_group->getRotation() / 360.0f * 2.0f * M_PI);
|
||||
int const k{static_cast<int>(std::ceil(_radius_slider->value())) * 2};
|
||||
_mask_image = pixmap->toImage().transformed(matrix).scaled(k, k);
|
||||
_mask_image = pixmap->toImage().transformed(matrix, Qt::SmoothTransformation);
|
||||
_map_view->setBrushTexture(&_mask_image);
|
||||
}
|
||||
|
||||
|
||||
@@ -336,8 +336,7 @@ namespace noggit
|
||||
QPixmap* pixmap = _image_mask_group->getPixmap();
|
||||
QTransform matrix;
|
||||
matrix.rotateRadians(_image_mask_group->getRotation() * M_PI / 180.f);
|
||||
int const k{static_cast<int>(std::ceil(_radius_slider->value())) * 2};
|
||||
_mask_image = pixmap->toImage().transformed(matrix).scaled(k, k);
|
||||
_mask_image = pixmap->toImage().transformed(matrix, Qt::SmoothTransformation);
|
||||
_map_view->setBrushTexture(&_mask_image);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user