Skip to content

Commit

Permalink
Merge branch 'release/3.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
naavis committed Feb 21, 2021
2 parents 89a159c + ddaec51 commit 41658f4
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 44 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 3.1.0 - 2021-02-21

### Changed

- Improved logging and error messages in case shader compilation fails
- Population weight was changed from an integer to a decimal number for more granular control

## 3.0.0 - 2021-02-21

### Added
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ Here are some general settings for the whole simulation.
HaloRay allows you to simulate multiple different ice crystal populations
simultaneously. You give each population a name for easier reference by typing
in the **Crystal population** dropdown menu. Each population has a relative
weight, which can be changed by adjusting the **Population weight** spin box.
For example, giving weights 1 and 3 to two crystal populations respectively
weight, which can be changed by adjusting the **Population weight** slider.
For example, giving weights 1.0 and 3.0 to two crystal populations respectively
would trace three times as many rays through the latter population than the
former. It is also possible to enable or disable a crystal population
temporarily with the **Population enabled** checkbox.
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.0.0-{build}"
version: "3.1.0-{build}"
branches:
only:
- master
Expand All @@ -24,6 +24,6 @@ deploy:
description: ""
skip_tags: true
auth_token:
secure: pb9keaNklmNgmLaw1doReZDdP5Oh/pLZPdwjt+anpcoi34MyqAbFoJbiHJMcWkgD
secure: qxadIRLRDKo8Tji0y+kZ03BIbNPJzdmp2HkzE6+G5lp1xtRCoeSpp6c4m4KU99D4
on:
branch: master
10 changes: 4 additions & 6 deletions src/haloray-core/gui/crystalSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ CrystalSettingsWidget::CrystalSettingsWidget(CrystalModel *model, QWidget *paren
m_mapper->addMapping(m_lowerApexAngleSpinBox, CrystalModel::LowerApexAngle);
m_mapper->addMapping(m_lowerApexHeightAverageSlider, CrystalModel::LowerApexHeightAverage);
m_mapper->addMapping(m_lowerApexHeightStdSlider, CrystalModel::LowerApexHeightStd);
m_mapper->addMapping(m_weightSpinBox, CrystalModel::PopulationWeight);
m_mapper->addMapping(m_weightSlider, CrystalModel::PopulationWeight);
m_mapper->addMapping(m_populationEnabledCheckBox, CrystalModel::Enabled);
m_mapper->addMapping(m_populationComboBox, CrystalModel::PopulationName, "currentText");
for (auto i = 0; i < 6; ++i)
Expand All @@ -69,7 +69,7 @@ CrystalSettingsWidget::CrystalSettingsWidget(CrystalModel *model, QWidget *paren
to the submit slot of the mapper.
*/
connect(m_populationEnabledCheckBox, &QCheckBox::toggled, m_mapper, &QDataWidgetMapper::submit, Qt::QueuedConnection);
connect(m_weightSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), m_mapper, &QDataWidgetMapper::submit, Qt::QueuedConnection);
connect(m_weightSlider, &SliderSpinBox::valueChanged, m_mapper, &QDataWidgetMapper::submit, Qt::QueuedConnection);
connect(m_caRatioSlider, &SliderSpinBox::valueChanged, m_mapper, &QDataWidgetMapper::submit, Qt::QueuedConnection);
connect(m_caRatioStdSlider, &SliderSpinBox::valueChanged, m_mapper, &QDataWidgetMapper::submit, Qt::QueuedConnection);
connect(m_tiltDistributionComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), m_mapper, &QDataWidgetMapper::submit, Qt::QueuedConnection);
Expand Down Expand Up @@ -199,9 +199,7 @@ void CrystalSettingsWidget::setupUi()

m_lowerApexHeightStdSlider = new SliderSpinBox(0.0, 5.0);

m_weightSpinBox = new QSpinBox();
m_weightSpinBox->setMinimum(0);
m_weightSpinBox->setMaximum(10000);
m_weightSlider = new SliderSpinBox(0.0, 20.0);

for (auto i = 0; i < 6; ++i)
{
Expand All @@ -221,7 +219,7 @@ void CrystalSettingsWidget::setupUi()
auto populationSettingsLayout = new QFormLayout(populationSettingsWidget);
populationSettingsLayout->addRow(populationManagementLayout);
populationSettingsLayout->addRow(tr("Population enabled"), m_populationEnabledCheckBox);
populationSettingsLayout->addRow(tr("Population weight"), m_weightSpinBox);
populationSettingsLayout->addRow(tr("Population weight"), m_weightSlider);
mainLayout->addWidget(populationSettingsWidget);

mainLayout->addWidget(tabWidget);
Expand Down
2 changes: 1 addition & 1 deletion src/haloray-core/gui/crystalSettingsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CrystalSettingsWidget : public CollapsibleBox

SliderSpinBox *m_prismFaceDistanceSliders[6];

QSpinBox *m_weightSpinBox;
SliderSpinBox *m_weightSlider;

CrystalModel *m_model;
QDataWidgetMapper *m_mapper;
Expand Down
4 changes: 2 additions & 2 deletions src/haloray-core/gui/models/crystalModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ bool CrystalModel::setData(const QModelIndex &index, const QVariant &value, int
crystal.lowerApexHeightStd = value.toFloat();
break;
case PopulationWeight:
m_crystals->setWeight(row, value.toUInt());
m_crystals->setWeight(row, value.toDouble());
break;
case PopulationName:
m_crystals->setName(row, value.toString().toStdString());
Expand Down Expand Up @@ -197,7 +197,7 @@ void CrystalModel::addRow(CrystalPopulationPreset preset)
endInsertRows();
}

void CrystalModel::addRow(CrystalPopulation population, unsigned int weight, QString name)
void CrystalModel::addRow(CrystalPopulation population, double weight, QString name)
{
auto row = m_crystals->getCount();
beginInsertRows(QModelIndex(), row, row);
Expand Down
2 changes: 1 addition & 1 deletion src/haloray-core/gui/models/crystalModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CrystalModel : public QAbstractTableModel
Qt::ItemFlags flags(const QModelIndex &index) const override;

void addRow(CrystalPopulationPreset preset = CrystalPopulationPreset::Random);
void addRow(CrystalPopulation population, unsigned int weight, QString name);
void addRow(CrystalPopulation population, double weight, QString name);
bool removeRow(int row);
void clear();
void setName(int row, QString name);
Expand Down
9 changes: 9 additions & 0 deletions src/haloray-core/gui/openGLWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,18 @@ void OpenGLWidget::initializeGL()

int maxComputeGroups;
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 0, &maxComputeGroups);
qInfo("Maximum supported number of compute shader workgroups: %i", maxComputeGroups);
const int absoluteMaxRaysPerFrame = 5000000;
int maxRaysPerFrame = std::min(absoluteMaxRaysPerFrame, maxComputeGroups);
m_viewModel->setRaysPerFrameUpperLimit(maxRaysPerFrame);

int maxWorkGroupSizeX;
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 0, &maxWorkGroupSizeX);
int maxWorkGroupSizeY;
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 0, &maxWorkGroupSizeY);
int maxWorkGroupSizeZ;
glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_SIZE, 0, &maxWorkGroupSizeZ);
qInfo("Maximum supported compute shader workgroup size: %i, %i, %i", maxWorkGroupSizeX, maxWorkGroupSizeY, maxWorkGroupSizeZ);
}

void OpenGLWidget::mousePressEvent(QMouseEvent *event)
Expand Down
2 changes: 1 addition & 1 deletion src/haloray-core/gui/stateSaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ void StateSaver::LoadState(QString filename, SimulationStateModel *simState, Cry
{
settings.setArrayIndex(i);
auto pop = CrystalPopulation::createRandom();
unsigned int weight = settings.value("Weight", 1).toUInt();
pop.enabled = settings.value("Enabled", pop.enabled).toBool();

pop.caRatioAverage = settings.value("CaRatioAverage", pop.caRatioAverage).toFloat();
Expand All @@ -119,6 +118,7 @@ void StateSaver::LoadState(QString filename, SimulationStateModel *simState, Cry
pop.lowerApexHeightStd = settings.value("LowerApexHeightStd", pop.lowerApexHeightStd).toFloat();

auto name = settings.value("Name", "Default name").toString();
double weight = settings.value("Weight", 1.0).toDouble();

crystalModel->addRow(pop, weight, name);
}
Expand Down
19 changes: 17 additions & 2 deletions src/haloray-core/opengl/textureRenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "textureRenderer.h"
#include <memory>
#include <string>
#include <QtGlobal>
#include <stdexcept>

namespace OpenGL
Expand All @@ -9,11 +10,25 @@ namespace OpenGL
std::unique_ptr<QOpenGLShaderProgram> TextureRenderer::initializeTexDrawShaderProgram()
{
auto program = std::make_unique<QOpenGLShaderProgram>();
program->addCacheableShaderFromSourceFile(QOpenGLShader::ShaderTypeBit::Vertex, ":/shaders/renderer.vert");
program->addCacheableShaderFromSourceFile(QOpenGLShader::ShaderTypeBit::Fragment, ":/shaders/renderer.frag");
bool vertexShaderCompilationSucceeded = program->addCacheableShaderFromSourceFile(QOpenGLShader::ShaderTypeBit::Vertex, ":/shaders/renderer.vert");

if (vertexShaderCompilationSucceeded == false)
{
qWarning("Texture renderer vertex shader compilation failed");
throw std::runtime_error(program->log().toUtf8());
}

bool fragmentShaderCompilationSucceeded = program->addCacheableShaderFromSourceFile(QOpenGLShader::ShaderTypeBit::Fragment, ":/shaders/renderer.frag");

if (fragmentShaderCompilationSucceeded == false)
{
qWarning("Texture renderer fragment shader compilation failed");
throw std::runtime_error(program->log().toUtf8());
}

if (program->link() == false)
{
qWarning("Texture renderer shader linking failed");
throw std::runtime_error(program->log().toUtf8());
}

Expand Down
16 changes: 8 additions & 8 deletions src/haloray-core/resources/shaders/raytrace.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ vec3 triangleNormalCache[triangles.length()];

uint wang_hash(uint a)
{
a -= (a << 6);
a ^= (a >> 17);
a -= (a << 9);
a ^= (a << 4);
a -= (a << 3);
a ^= (a << 10);
a ^= (a >> 15);
return a;
a -= (a << 6);
a ^= (a >> 17);
a -= (a << 9);
a ^= (a << 4);
a -= (a << 3);
a ^= (a << 10);
a ^= (a >> 15);
return a;
}

uint rngState = wang_hash(rngSeed + uint(gl_GlobalInvocationID.x));
Expand Down
20 changes: 10 additions & 10 deletions src/haloray-core/simulation/crystalPopulationRepository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ void CrystalPopulationRepository::add(CrystalPopulationPreset preset)
m_crystals.push_back(CrystalPopulation::presetPopulation(preset));
m_names.push_back(QString("%1 population %2").arg(presetNameMap[preset]).arg(m_nextId).toStdString());
m_nextId = m_nextId + 1;
m_weights.push_back(1);
m_weights.push_back(1.0);
}

void CrystalPopulationRepository::add(CrystalPopulation population, unsigned int weight, std::string name)
void CrystalPopulationRepository::add(CrystalPopulation population, double weight, std::string name)
{
m_crystals.push_back(population);
m_names.push_back(name);
Expand All @@ -36,15 +36,15 @@ void CrystalPopulationRepository::addDefaults()
{
m_crystals.push_back(CrystalPopulation::presetPopulation(CrystalPopulationPreset::Column));
m_names.push_back("Column");
m_weights.push_back(1);
m_weights.push_back(1.0);

m_crystals.push_back(CrystalPopulation::presetPopulation(CrystalPopulationPreset::Plate));
m_names.push_back("Plate");
m_weights.push_back(1);
m_weights.push_back(1.0);

m_crystals.push_back(CrystalPopulation::presetPopulation(CrystalPopulationPreset::Random));
m_names.push_back("Random");
m_weights.push_back(1);
m_weights.push_back(1.0);
}

void CrystalPopulationRepository::remove(unsigned int index)
Expand Down Expand Up @@ -80,20 +80,20 @@ double CrystalPopulationRepository::getProbability(unsigned int index) const
{
if (m_crystals[index].enabled == false) return 0.0;

auto totalWeights = 0u;
auto totalWeights = 0.0;
for (auto i = 0u; i < getCount(); ++i)
{
totalWeights += m_crystals[i].enabled ? m_weights[i] : 0;
totalWeights += m_crystals[i].enabled ? m_weights[i] : 0.0;
}
return static_cast<double>(m_weights[index]) / totalWeights;
return m_weights[index] / totalWeights;
}

unsigned int CrystalPopulationRepository::getWeight(unsigned int index) const
double CrystalPopulationRepository::getWeight(unsigned int index) const
{
return m_weights[index];
}

void CrystalPopulationRepository::setWeight(unsigned int index, unsigned int weight)
void CrystalPopulationRepository::setWeight(unsigned int index, double weight)
{
m_weights[index] = weight;
}
Expand Down
8 changes: 4 additions & 4 deletions src/haloray-core/simulation/crystalPopulationRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CrystalPopulationRepository
public:
CrystalPopulationRepository();
void add(CrystalPopulationPreset preset = Random);
void add(CrystalPopulation population, unsigned int weight, std::string name);
void add(CrystalPopulation population, double weight, std::string name);
void remove(unsigned int index);
void clear();

Expand All @@ -20,16 +20,16 @@ class CrystalPopulationRepository
void setName(unsigned int index, std::string name);
std::string getName(unsigned int index) const;

unsigned int getWeight(unsigned int index) const;
void setWeight(unsigned int index, unsigned int weight);
double getWeight(unsigned int index) const;
void setWeight(unsigned int index, double weight);
double getProbability(unsigned int index) const;

unsigned int getCount() const;

private:
void addDefaults();
std::vector<CrystalPopulation> m_crystals;
std::vector<unsigned int> m_weights;
std::vector<double> m_weights;
std::vector<std::string> m_names;
unsigned int m_nextId;
};
Expand Down
17 changes: 15 additions & 2 deletions src/haloray-core/simulation/simulationEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,29 @@ void SimulationEngine::initialize()
void SimulationEngine::initializeShaders()
{
m_simulationShader = std::make_unique<QOpenGLShaderProgram>();
m_simulationShader->addCacheableShaderFromSourceFile(QOpenGLShader::ShaderTypeBit::Compute, ":/shaders/raytrace.glsl");
bool raytraceShaderCompilationSucceeded = m_simulationShader->addCacheableShaderFromSourceFile(QOpenGLShader::ShaderTypeBit::Compute, ":/shaders/raytrace.glsl");
if (raytraceShaderCompilationSucceeded == false)
{
qWarning("Compiling raytracing shader failed");
throw std::runtime_error(m_simulationShader->log().toUtf8());
}

if (m_simulationShader->link() == false)
{
qWarning("Linking raytracing shader failed");
throw std::runtime_error(m_simulationShader->log().toUtf8());
}

m_skyShader = new QOpenGLShaderProgram(this);
m_skyShader->addCacheableShaderFromSourceFile(QOpenGLShader::ShaderTypeBit::Compute, ":/shaders/sky.glsl");
bool skyShaderCompilationSucceeded = m_skyShader->addCacheableShaderFromSourceFile(QOpenGLShader::ShaderTypeBit::Compute, ":/shaders/sky.glsl");
if (skyShaderCompilationSucceeded == false)
{
qWarning("Compiling sky shader failed");
throw std::runtime_error(m_skyShader->log().toUtf8());
}
if (m_skyShader->link() == false)
{
qWarning("Linking sky shader failed");
throw std::runtime_error(m_skyShader->log().toUtf8());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ private slots:
void evenWeightsByDefault()
{
auto repository = HaloRay::CrystalPopulationRepository();
QCOMPARE(repository.getWeight(0), 1);
QCOMPARE(repository.getWeight(1), 1);
QCOMPARE(repository.getWeight(2), 1);
QCOMPARE(repository.getWeight(0), 1.0);
QCOMPARE(repository.getWeight(1), 1.0);
QCOMPARE(repository.getWeight(2), 1.0);
}

void disabledPopulationsDoNotCountTowardsProbability()
Expand Down

0 comments on commit 41658f4

Please sign in to comment.