Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[qmlSfmData] SfmDataEntity: Handle fixed point size in the shader #81

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 64 additions & 40 deletions src/qmlSfmData/SfmDataEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace sfmdataentity {

SfmDataEntity::SfmDataEntity(Qt3DCore::QNode* parent)
: Qt3DCore::QEntity(parent),
_fixedPointSizeParameter(new Qt3DRender::QParameter),
_pointSizeParameter(new Qt3DRender::QParameter),
_ioThread(new IOThread())
{
Expand All @@ -37,6 +38,19 @@ void SfmDataEntity::setSource(const QUrl& value)
Q_EMIT sourceChanged();
}

void SfmDataEntity::setFixedPointSize(const bool& value)
{
if (_fixedPointSize == value)
{
return;
}

_fixedPointSize = value;
_fixedPointSizeParameter->setValue(value);

Q_EMIT fixedPointSizeChanged();
}

void SfmDataEntity::setPointSize(const float& value)
{
if (_pointSize == value)
Expand Down Expand Up @@ -182,46 +196,51 @@ void SfmDataEntity::createMaterials()
technique->graphicsApiFilter()->setProfile(QGraphicsApiFilter::CoreProfile);

shaderProgram->setShaderCode(QShaderProgram::Vertex, R"(#version 450
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec3 vertexColor;
layout(location = 0) out vec3 color;
layout(std140, binding = 0) uniform qt3d_render_view_uniforms {
mat4 viewMatrix;
mat4 projectionMatrix;
mat4 uncorrectedProjectionMatrix;
mat4 clipCorrectionMatrix;
mat4 viewProjectionMatrix;
mat4 inverseViewMatrix;
mat4 inverseProjectionMatrix;
mat4 inverseViewProjectionMatrix;
mat4 viewportMatrix;
mat4 inverseViewportMatrix;
vec4 textureTransformMatrix;
vec3 eyePosition;
float aspectRatio;
float gamma;
float exposure;
float time;
};
layout(std140, binding = 1) uniform qt3d_command_uniforms {
mat4 modelMatrix;
mat4 inverseModelMatrix;
mat4 modelViewMatrix;
mat3 modelNormalMatrix;
mat4 inverseModelViewMatrix;
mat4 mvp;
mat4 inverseModelViewProjectionMatrix;
};
layout(std140, binding = 2) uniform custom_ubo {
float pointSize;
};

void main()
{
color = vertexColor;
gl_Position = mvp * vec4(vertexPosition, 1.0);
gl_PointSize = max(viewportMatrix[1][1] * projectionMatrix[1][1] * pointSize / gl_Position.w, 1.0);
}
layout(location = 0) in vec3 vertexPosition;
layout(location = 1) in vec3 vertexColor;
layout(location = 0) out vec3 color;
layout(std140, binding = 0) uniform qt3d_render_view_uniforms {
mat4 viewMatrix;
mat4 projectionMatrix;
mat4 uncorrectedProjectionMatrix;
mat4 clipCorrectionMatrix;
mat4 viewProjectionMatrix;
mat4 inverseViewMatrix;
mat4 inverseProjectionMatrix;
mat4 inverseViewProjectionMatrix;
mat4 viewportMatrix;
mat4 inverseViewportMatrix;
vec4 textureTransformMatrix;
vec3 eyePosition;
float aspectRatio;
float gamma;
float exposure;
float time;
};
layout(std140, binding = 1) uniform qt3d_command_uniforms {
mat4 modelMatrix;
mat4 inverseModelMatrix;
mat4 modelViewMatrix;
mat3 modelNormalMatrix;
mat4 inverseModelViewMatrix;
mat4 mvp;
mat4 inverseModelViewProjectionMatrix;
};
layout(std140, binding = 2) uniform custom_ubo {
float pointSize;
bool fixedPointSize;
};

void main()
{
color = vertexColor;
gl_Position = mvp * vec4(vertexPosition, 1.0);
if (fixedPointSize) {
gl_PointSize = pointSize;
} else {
gl_PointSize = max(viewportMatrix[1][1] * projectionMatrix[1][1] * pointSize * 0.01 / gl_Position.w, 1.0);
}
}
)");

shaderProgram->setShaderCode(QShaderProgram::Fragment, R"(#version 450
Expand All @@ -233,6 +252,11 @@ void SfmDataEntity::createMaterials()
}
)");

// Add a fixedPointSize uniform
_fixedPointSizeParameter->setName("fixedPointSize");
_fixedPointSizeParameter->setValue(_fixedPointSize);
_cloudMaterial->addParameter(_fixedPointSizeParameter);

// Add a pointSize uniform
_pointSizeParameter->setName("pointSize");
_pointSizeParameter->setValue(_pointSize);
Expand Down
6 changes: 6 additions & 0 deletions src/qmlSfmData/SfmDataEntity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class SfmDataEntity : public Qt3DCore::QEntity
Q_OBJECT
Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
Q_PROPERTY(bool skipHidden MEMBER _skipHidden NOTIFY skipHiddenChanged)
Q_PROPERTY(bool fixedPointSize READ fixedPointSize WRITE setFixedPointSize NOTIFY fixedPointSizeChanged)
Q_PROPERTY(float pointSize READ pointSize WRITE setPointSize NOTIFY pointSizeChanged)
Q_PROPERTY(float locatorScale READ locatorScale WRITE setLocatorScale NOTIFY locatorScaleChanged)
Q_PROPERTY(QQmlListProperty<sfmdataentity::CameraLocatorEntity> cameras READ cameras NOTIFY camerasChanged)
Expand All @@ -47,12 +48,14 @@ class SfmDataEntity : public Qt3DCore::QEntity
~SfmDataEntity() override = default;

Q_SLOT const QUrl& source() const { return _source; }
Q_SLOT bool fixedPointSize() const { return _fixedPointSize; }
Q_SLOT float pointSize() const { return _pointSize; }
Q_SLOT float locatorScale() const { return _locatorScale; }
Q_SLOT aliceVision::IndexT selectedViewId() const { return _selectedViewId; }
Q_SLOT aliceVision::IndexT resectionId() const { return _resectionId; }
Q_SLOT bool displayResections() const { return _displayResections; }
Q_SLOT void setSource(const QUrl& source);
Q_SLOT void setFixedPointSize(const bool& value);
Q_SLOT void setPointSize(const float& value);
Q_SLOT void setLocatorScale(const float& value);
Q_SLOT void setSelectedViewId(const aliceVision::IndexT& viewId);
Expand All @@ -71,6 +74,7 @@ class SfmDataEntity : public Qt3DCore::QEntity

Q_SIGNAL void sourceChanged();
Q_SIGNAL void camerasChanged();
Q_SIGNAL void fixedPointSizeChanged();
Q_SIGNAL void pointSizeChanged();
Q_SIGNAL void pointCloudsChanged();
Q_SIGNAL void locatorScaleChanged();
Expand Down Expand Up @@ -100,11 +104,13 @@ class SfmDataEntity : public Qt3DCore::QEntity
Status _status = SfmDataEntity::None;
QUrl _source;
bool _skipHidden = false;
bool _fixedPointSize = false;
float _pointSize = 0.5f;
float _locatorScale = 1.0f;
aliceVision::IndexT _selectedViewId = 0;
aliceVision::IndexT _resectionId = 0;
bool _displayResections = false;
Qt3DRender::QParameter* _fixedPointSizeParameter;
Qt3DRender::QParameter* _pointSizeParameter;
Qt3DRender::QMaterial* _cloudMaterial;
Qt3DRender::QMaterial* _cameraMaterial;
Expand Down