Merge pull request #2613 from lammps/ssao_bugfix
Fix bug in dump image SSAO depth shading
This commit is contained in:
@ -113,6 +113,11 @@ Image::Image(LAMMPS *lmp, int nmap_caller) : Pointers(lmp)
|
|||||||
backLightColor[2] = 0.9;
|
backLightColor[2] = 0.9;
|
||||||
|
|
||||||
random = nullptr;
|
random = nullptr;
|
||||||
|
|
||||||
|
// MPI_Gatherv vectors
|
||||||
|
|
||||||
|
recvcounts = nullptr;
|
||||||
|
displs = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
@ -134,6 +139,9 @@ Image::~Image()
|
|||||||
memory->destroy(rgbcopy);
|
memory->destroy(rgbcopy);
|
||||||
|
|
||||||
if (random) delete random;
|
if (random) delete random;
|
||||||
|
|
||||||
|
memory->destroy(recvcounts);
|
||||||
|
memory->destroy(displs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
@ -334,16 +342,37 @@ void Image::merge()
|
|||||||
// extra SSAO enhancement
|
// extra SSAO enhancement
|
||||||
// bcast full image to all procs
|
// bcast full image to all procs
|
||||||
// each works on subset of pixels
|
// each works on subset of pixels
|
||||||
// gather result back to proc 0
|
// MPI_Gather() result back to proc 0
|
||||||
|
// use Gatherv() if subset of pixels is not the same size on every proc
|
||||||
|
|
||||||
if (ssao) {
|
if (ssao) {
|
||||||
MPI_Bcast(imageBuffer,npixels*3,MPI_BYTE,0,world);
|
MPI_Bcast(imageBuffer,npixels*3,MPI_BYTE,0,world);
|
||||||
MPI_Bcast(surfaceBuffer,npixels*2,MPI_DOUBLE,0,world);
|
MPI_Bcast(surfaceBuffer,npixels*2,MPI_DOUBLE,0,world);
|
||||||
MPI_Bcast(depthBuffer,npixels,MPI_DOUBLE,0,world);
|
MPI_Bcast(depthBuffer,npixels,MPI_DOUBLE,0,world);
|
||||||
compute_SSAO();
|
compute_SSAO();
|
||||||
int pixelPart = height/nprocs * width*3;
|
|
||||||
MPI_Gather(imageBuffer+me*pixelPart,pixelPart,MPI_BYTE,
|
int pixelstart = 3 * static_cast<int> (1.0*me/nprocs * npixels);
|
||||||
rgbcopy,pixelPart,MPI_BYTE,0,world);
|
int pixelstop = 3 * static_cast<int> (1.0*(me+1)/nprocs * npixels);
|
||||||
|
int mypixels = pixelstop - pixelstart;
|
||||||
|
|
||||||
|
if (npixels % nprocs == 0) {
|
||||||
|
MPI_Gather(imageBuffer+pixelstart,mypixels,MPI_BYTE,
|
||||||
|
rgbcopy,mypixels,MPI_BYTE,0,world);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (recvcounts == nullptr) {
|
||||||
|
memory->create(recvcounts,nprocs,"image:recvcounts");
|
||||||
|
memory->create(displs,nprocs,"image:displs");
|
||||||
|
MPI_Allgather(&mypixels,1,MPI_INT,recvcounts,1,MPI_INT,world);
|
||||||
|
displs[0] = 0;
|
||||||
|
for (int i = 1; i < nprocs; i++)
|
||||||
|
displs[i] = displs[i-1] + recvcounts[i-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
MPI_Gatherv(imageBuffer+pixelstart,mypixels,MPI_BYTE,
|
||||||
|
rgbcopy,recvcounts,displs,MPI_BYTE,0,world);
|
||||||
|
}
|
||||||
|
|
||||||
writeBuffer = rgbcopy;
|
writeBuffer = rgbcopy;
|
||||||
} else {
|
} else {
|
||||||
writeBuffer = imageBuffer;
|
writeBuffer = imageBuffer;
|
||||||
@ -880,11 +909,19 @@ void Image::compute_SSAO()
|
|||||||
-tanPerPixel / zoom;
|
-tanPerPixel / zoom;
|
||||||
int pixelRadius = (int) trunc (SSAORadius / pixelWidth + 0.5);
|
int pixelRadius = (int) trunc (SSAORadius / pixelWidth + 0.5);
|
||||||
|
|
||||||
int x,y,s;
|
// each proc is assigned a subset of contiguous pixels from the full image
|
||||||
int hPart = height / nprocs;
|
// pixels are contiguous in x (columns within a row), then by row
|
||||||
int index = me * hPart * width;
|
// index = pixels from 0 to npixel-1
|
||||||
for (y = me * hPart; y < (me + 1) * hPart; y ++) {
|
// x = column # from 0 to width-1
|
||||||
for (x = 0; x < width; x ++, index ++) {
|
// y = row # from 0 to height-1
|
||||||
|
|
||||||
|
int pixelstart = static_cast<int> (1.0*me/nprocs * npixels);
|
||||||
|
int pixelstop = static_cast<int> (1.0*(me+1)/nprocs * npixels);
|
||||||
|
|
||||||
|
for (int index = pixelstart; index < pixelstop; index++) {
|
||||||
|
int x = index % width;
|
||||||
|
int y = index / width;
|
||||||
|
|
||||||
double cdepth = depthBuffer[index];
|
double cdepth = depthBuffer[index];
|
||||||
if (cdepth < 0) { continue; }
|
if (cdepth < 0) { continue; }
|
||||||
|
|
||||||
@ -895,7 +932,7 @@ void Image::compute_SSAO()
|
|||||||
double mytheta = random->uniform() * SSAOJitter;
|
double mytheta = random->uniform() * SSAOJitter;
|
||||||
double ao = 0.0;
|
double ao = 0.0;
|
||||||
|
|
||||||
for (s = 0; s < SSAOSamples; s ++) {
|
for (int s = 0; s < SSAOSamples; s ++) {
|
||||||
double hx = cos(mytheta);
|
double hx = cos(mytheta);
|
||||||
double hy = sin(mytheta);
|
double hy = sin(mytheta);
|
||||||
mytheta += delTheta;
|
mytheta += delTheta;
|
||||||
@ -985,7 +1022,6 @@ void Image::compute_SSAO()
|
|||||||
imageBuffer[index * 3 + 2] = (int) c[2];
|
imageBuffer[index * 3 + 2] = (int) c[2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|||||||
@ -73,6 +73,10 @@ class Image : protected Pointers {
|
|||||||
double *depthcopy,*surfacecopy;
|
double *depthcopy,*surfacecopy;
|
||||||
unsigned char *imageBuffer,*rgbcopy,*writeBuffer;
|
unsigned char *imageBuffer,*rgbcopy,*writeBuffer;
|
||||||
|
|
||||||
|
// MPI_Gatherv
|
||||||
|
|
||||||
|
int *recvcounts,*displs;
|
||||||
|
|
||||||
// constant view params
|
// constant view params
|
||||||
|
|
||||||
double FOV;
|
double FOV;
|
||||||
|
|||||||
Reference in New Issue
Block a user