Skip to content

Commit

Permalink
per pixel light directions when computing normals.
Browse files Browse the repository at this point in the history
  • Loading branch information
ponchio committed Jul 15, 2024
1 parent 274d327 commit 84e66d0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
19 changes: 15 additions & 4 deletions relight/normalstask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ void NormalsTask::run()
//uint8_t* data = normals.data() + idx;
float* data = &normals[idx];

std::function<void(void)> run = [this, &line, &imageSet, data](void)->void {
NormalsWorker task(solver, line, data, imageSet.lights);
std::function<void(void)> run = [this, &i, &line, &imageSet, data](void)->void {
NormalsWorker task(solver, i, line, data, imageSet);
return task.run();
};

Expand Down Expand Up @@ -169,13 +169,15 @@ void NormalsWorker::run()

void NormalsWorker::solveL2()
{
std::vector<Vector3f> &m_Lights = m_Imageset.lights;
// Pixel data
Eigen::MatrixXd mLights(m_Lights.size(), 3);
Eigen::MatrixXd mPixel(m_Lights.size(), 1);
Eigen::MatrixXd mLights(m_Lights.size(), 3);
Eigen::MatrixXd mPixel(m_Lights.size(), 1);
Eigen::MatrixXd mNormals;

unsigned int normalIdx = 0;


// Fill the lights matrix
for (size_t i = 0; i < m_Lights.size(); i++)
for (int j = 0; j < 3; j++)
Expand All @@ -188,6 +190,15 @@ void NormalsWorker::solveL2()
for (size_t m = 0; m < m_Lights.size(); m++)
mPixel(m, 0) = m_Row[p][m].mean();

if(m_Imageset.light3d) {
for(int i = 0; i < m_Lights.size(); i++) {
Vector3f lights = m_Imageset.relativeLight(m_Lights[i], p, row);
for (int j = 0; j < 3; j++)
mLights(i, j) = m_Lights[i][j];
}
}


// Solve
mNormals = (mLights.transpose() * mLights).ldlt().solve(mLights.transpose() * mPixel);
mNormals.col(0).normalize();
Expand Down
9 changes: 6 additions & 3 deletions relight/normalstask.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <QMutex>
#include <QRect>
#include "../src/relight_vector.h"
#include "../src/imageset.h"
#include "task.h"
#include <QRunnable>

Expand Down Expand Up @@ -43,19 +44,21 @@ public slots:
class NormalsWorker
{
public:
NormalsWorker(NormalSolver _solver, PixelArray& toProcess, float* normals, std::vector<Vector3f> lights) :
solver(_solver), m_Row(toProcess), m_Normals(normals), m_Lights(lights){}
NormalsWorker(NormalSolver _solver, int _row, PixelArray& toProcess, float* normals, ImageSet &imageset) :
solver(_solver), row(_row), m_Row(toProcess), m_Normals(normals), m_Imageset(imageset){}

void run();
private:
void solveL2();
void solveSBL();
void solveRPCA();
private:

NormalSolver solver;
int row;
PixelArray m_Row;
//uint8_t* m_Normals;
float* m_Normals;
std::vector<Vector3f> m_Lights;
ImageSet &m_Imageset;
QMutex m_Mutex;
};

0 comments on commit 84e66d0

Please sign in to comment.