Skip to content

Commit

Permalink
Update shader to allow for vertices to follow brushes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonny K authored and Jonny K committed Oct 26, 2024
1 parent 7f6fee8 commit 91a6a86
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
6 changes: 5 additions & 1 deletion app/resources/shader/Face.fragsh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ void main() {
}


if (UseVertexColor){
if (UseVertexColor &&
(vertColor.a
+ vertColor.r
+ vertColor.g
+ vertColor.b) > 0.0){
texel = texel - (1.0 - vertColor);
texel.a = vertColor.a;
} else{
Expand Down
10 changes: 9 additions & 1 deletion common/src/mdl/Brush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1236,14 +1236,22 @@ Result<void> Brush::transform(
const vm::mat4x4d& transformation,
const bool lockMaterials)
{

for (auto& face : m_faces)
{
if (!face.transform(transformation, lockMaterials).is_success())
{
return Error{"Brush has invalid face"};
}
}


std::unordered_map<vm::vec3, Color> cached_colors;
for (auto [ pos, color ] : m_cachedColors)
{
cached_colors.emplace(transformation * pos, std::move(color));
}
m_cachedColors = std::move(cached_colors);

return updateGeometryFromFaces(worldBounds);
}

Expand Down
9 changes: 7 additions & 2 deletions common/src/render/BrushRendererBrushCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ void BrushRendererBrushCache::validateVertexCache(const mdl::BrushNode& brushNod

m_cachedFacesSortedByMaterial.clear();
m_cachedFacesSortedByMaterial.reserve(brush.faceCount());

Color blankColor;
if(brush.hasVertexColors()){
blankColor = Color(vm::vec<float, 4>{1.0, 1.0, 1.0, 1.0});
} else{
blankColor = Color(vm::vec<float, 4>{-1.0, -1.0, -1.0, -1.0});
}
for (const auto& face : brush.faces())
{
const auto indexOfFirstVertexRelativeToBrush = m_cachedVertices.size();
Expand All @@ -90,7 +95,7 @@ void BrushRendererBrushCache::validateVertexCache(const mdl::BrushNode& brushNod
const auto& position = vertex->position();

//DONE: Get the correct color from the vertex index.
Color vertColor = Color(vm::vec<float, 4>{1.0, 1.0, 1.0, 1.0});
Color vertColor = blankColor;
auto colorValue = brushNode.brush().colors().find(position);
if(colorValue != brushNode.brush().colors().end()){
vertColor = colorValue->second;
Expand Down
17 changes: 17 additions & 0 deletions common/src/ui/ViewPreferencePane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ QWidget* ViewPreferencePane::createViewPreferences()
m_gridAlphaSlider->setMaximumWidth(400);
m_gridAlphaSlider->setToolTip(
"Sets the visibility of the grid lines in the 3D editing view.");
m_faceAlphaSlider = new SliderWithLabel{0, 100};
m_faceAlphaSlider->setMaximumWidth(400);
m_faceAlphaSlider->setToolTip(
"Sets the visibility of brushes marked transparent.");
m_fovSlider = new SliderWithLabel{50, 150};
m_fovSlider->setMaximumWidth(400);
m_fovSlider->setToolTip("Sets the field of vision in the 3D editing view.");
Expand Down Expand Up @@ -188,6 +192,7 @@ QWidget* ViewPreferencePane::createViewPreferences()
layout->addRow("Layout", viewLayoutLayout);
layout->addRow("Brightness", m_brightnessSlider);
layout->addRow("Grid", m_gridAlphaSlider);
layout->addRow("Transparency", m_faceAlphaSlider);
layout->addRow("FOV", m_fovSlider);
layout->addRow("Show axes", m_showAxes);
layout->addRow("Filter mode", m_filterModeCombo);
Expand Down Expand Up @@ -227,6 +232,11 @@ void ViewPreferencePane::bindEvents()
&SliderWithLabel::valueChanged,
this,
&ViewPreferencePane::gridAlphaChanged);
connect(
m_faceAlphaSlider,
&SliderWithLabel::valueChanged,
this,
&ViewPreferencePane::faceAlphaChanged);
connect(
m_fovSlider, &SliderWithLabel::valueChanged, this, &ViewPreferencePane::fovChanged);
connect(
Expand Down Expand Up @@ -374,6 +384,13 @@ void ViewPreferencePane::gridAlphaChanged(const int /* value */)
auto& prefs = PreferenceManager::instance();
prefs.set(Preferences::GridAlpha, ratio);
}

void ViewPreferencePane::faceAlphaChanged(const int /* value */)
{
const auto ratio = m_faceAlphaSlider->ratio();
auto& prefs = PreferenceManager::instance();
prefs.set(Preferences::TransparentFaceAlpha, ratio);
}

void ViewPreferencePane::fovChanged(const int value)
{
Expand Down
2 changes: 2 additions & 0 deletions common/src/ui/ViewPreferencePane.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ViewPreferencePane : public PreferencePane
QCheckBox* m_link2dCameras = nullptr;
SliderWithLabel* m_brightnessSlider = nullptr;
SliderWithLabel* m_gridAlphaSlider = nullptr;
SliderWithLabel* m_faceAlphaSlider = nullptr;
SliderWithLabel* m_fovSlider = nullptr;
QCheckBox* m_showAxes = nullptr;
QComboBox* m_filterModeCombo = nullptr;
Expand Down Expand Up @@ -67,6 +68,7 @@ private slots:
void link2dCamerasChanged(int state);
void brightnessChanged(int value);
void gridAlphaChanged(int value);
void faceAlphaChanged(int value);
void fovChanged(int value);
void showAxesChanged(int state);
void enableMsaaChanged(int state);
Expand Down

0 comments on commit 91a6a86

Please sign in to comment.