Skip to content

Commit 39fabd3

Browse files
committed
Fixed Extract/Merge Cubemap batch files + Usage in Renderer
1 parent 6828309 commit 39fabd3

File tree

5 files changed

+117
-22
lines changed

5 files changed

+117
-22
lines changed

examples_tests/22.RaytracedAO/Renderer.cpp

Lines changed: 96 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,14 +1500,13 @@ void Renderer::takeAndSaveScreenShot(const std::filesystem::path& screenshotFile
15001500
filename_wo_ext.replace_extension();
15011501
if (m_tonemapOutput)
15021502
ext::ScreenShot::createScreenShot(m_driver,m_assetManager,m_tonemapOutput.get(),filename_wo_ext.string()+".exr",format);
1503+
if (m_albedoRslv)
1504+
ext::ScreenShot::createScreenShot(m_driver,m_assetManager,m_albedoRslv.get(),filename_wo_ext.string()+"_albedo.exr",format);
1505+
if (m_normalRslv)
1506+
ext::ScreenShot::createScreenShot(m_driver,m_assetManager,m_normalRslv.get(),filename_wo_ext.string()+"_normal.exr",format);
15031507

15041508
if(denoise)
15051509
{
1506-
if (m_albedoRslv)
1507-
ext::ScreenShot::createScreenShot(m_driver,m_assetManager,m_albedoRslv.get(),filename_wo_ext.string()+"_albedo.exr",format);
1508-
if (m_normalRslv)
1509-
ext::ScreenShot::createScreenShot(m_driver,m_assetManager,m_normalRslv.get(),filename_wo_ext.string()+"_normal.exr",format);
1510-
15111510
const std::string defaultBloomFile = "../../media/kernels/physical_flare_512.exr";
15121511
const std::string defaultTonemapperArgs = "ACES=0.4,0.8";
15131512
constexpr auto defaultBloomScale = 0.1f;
@@ -1535,6 +1534,98 @@ void Renderer::takeAndSaveScreenShot(const std::filesystem::path& screenshotFile
15351534
}
15361535
}
15371536

1537+
void Renderer::denoiseCubemapFaces(
1538+
std::filesystem::path filePaths[6],
1539+
const std::string& mergedFileName,
1540+
int borderPixels,
1541+
const DenoiserArgs& denoiserArgs)
1542+
{
1543+
auto commandQueue = m_rrManager->getCLCommandQueue();
1544+
ocl::COpenCLHandler::ocl.pclFinish(commandQueue);
1545+
1546+
glFinish();
1547+
1548+
std::string renderFilePaths[6] = {};
1549+
std::string albedoFilePaths[6] = {};
1550+
std::string normalFilePaths[6] = {};
1551+
for(uint32_t i = 0; i < 6; ++i)
1552+
renderFilePaths[i] = filePaths[i].replace_extension().string() + ".exr";
1553+
for(uint32_t i = 0; i < 6; ++i)
1554+
albedoFilePaths[i] = filePaths[i].replace_extension().string() + "_albedo.exr";
1555+
for(uint32_t i = 0; i < 6; ++i)
1556+
normalFilePaths[i] = filePaths[i].replace_extension().string() + "_normal.exr";
1557+
1558+
std::string mergedRenderFilePath = mergedFileName + ".exr";
1559+
std::string mergedAlbedoFilePath = mergedFileName + "_albedo.exr";
1560+
std::string mergedNormalFilePath = mergedFileName + "_normal.exr";
1561+
std::string mergedDenoisedFilePath = mergedFileName + "_denoised.exr";
1562+
1563+
std::ostringstream mergeRendersCmd;
1564+
mergeRendersCmd << "call ../mergeCubemap.bat";
1565+
for(uint32_t i = 0; i < 6; ++i)
1566+
mergeRendersCmd << " " << renderFilePaths[i];
1567+
mergeRendersCmd << " " << mergedRenderFilePath;
1568+
std::system(mergeRendersCmd.str().c_str());
1569+
1570+
std::ostringstream mergeAlbedosCmd;
1571+
mergeAlbedosCmd << "call ../mergeCubemap.bat ";
1572+
for(uint32_t i = 0; i < 6; ++i)
1573+
mergeAlbedosCmd << " " << albedoFilePaths[i];
1574+
mergeAlbedosCmd << " " << mergedAlbedoFilePath;
1575+
std::system(mergeAlbedosCmd.str().c_str());
1576+
1577+
std::ostringstream mergeNormalsCmd;
1578+
mergeNormalsCmd << "call ../mergeCubemap.bat ";
1579+
for(uint32_t i = 0; i < 6; ++i)
1580+
mergeNormalsCmd << " " << normalFilePaths[i];
1581+
mergeNormalsCmd << " " << mergedNormalFilePath;
1582+
std::system(mergeNormalsCmd.str().c_str());
1583+
1584+
const std::string defaultBloomFile = "../../media/kernels/physical_flare_512.exr";
1585+
const std::string defaultTonemapperArgs = "ACES=0.4,0.8";
1586+
constexpr auto defaultBloomScale = 0.1f;
1587+
constexpr auto defaultBloomIntensity = 0.1f;
1588+
auto bloomFilePathStr = (denoiserArgs.bloomFilePath.string().empty()) ? defaultBloomFile : denoiserArgs.bloomFilePath.string();
1589+
auto bloomScale = (denoiserArgs.bloomScale == 0.0f) ? defaultBloomScale : denoiserArgs.bloomScale;
1590+
auto bloomIntensity = (denoiserArgs.bloomIntensity == 0.0f) ? defaultBloomIntensity : denoiserArgs.bloomIntensity;
1591+
auto tonemapperArgs = (denoiserArgs.tonemapperArgs.empty()) ? defaultTonemapperArgs : denoiserArgs.tonemapperArgs;
1592+
1593+
std::ostringstream denoiserCmd;
1594+
// 1.ColorFile 2.AlbedoFile 3.NormalFile 4.BloomPsfFilePath(STRING) 5.BloomScale(FLOAT) 6.BloomIntensity(FLOAT) 7.TonemapperArgs(STRING)
1595+
denoiserCmd << "call ../denoiser_hook.bat";
1596+
denoiserCmd << " \"" << mergedRenderFilePath << "\"";
1597+
denoiserCmd << " \"" << mergedAlbedoFilePath << "\"";
1598+
denoiserCmd << " \"" << mergedNormalFilePath << "\"";
1599+
denoiserCmd << " \"" << bloomFilePathStr << "\"";
1600+
denoiserCmd << " " << bloomScale;
1601+
denoiserCmd << " " << bloomIntensity;
1602+
denoiserCmd << " " << "\"" << tonemapperArgs << "\"";
1603+
// NOTE/TODO/FIXME : Do as I say, not as I do
1604+
// https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152177
1605+
std::cout << "\n---[DENOISER_BEGIN]---" << std::endl;
1606+
std::system(denoiserCmd.str().c_str());
1607+
std::cout << "\n---[DENOISER_END]---" << std::endl;
1608+
1609+
auto extractCubemapFaces = [&](const std::string& extension) -> void
1610+
{
1611+
std::ostringstream extractImagesCmd;
1612+
auto mergedDenoisedWithoutExtension = std::filesystem::path(mergedDenoisedFilePath).replace_extension().string();
1613+
extractImagesCmd << "call ../extractCubemap.bat ";
1614+
extractImagesCmd << " " << std::to_string(borderPixels);
1615+
extractImagesCmd << " " << mergedDenoisedWithoutExtension + extension;
1616+
for(uint32_t i = 0; i < 6; ++i)
1617+
{
1618+
auto renderFilePathWithoutExtension = std::filesystem::path(renderFilePaths[i]).replace_extension().string();
1619+
extractImagesCmd << " " << renderFilePathWithoutExtension + "_denoised" + extension;
1620+
}
1621+
std::system(extractImagesCmd.str().c_str());
1622+
};
1623+
1624+
extractCubemapFaces(".exr");
1625+
extractCubemapFaces(".png");
1626+
extractCubemapFaces(".jpg");
1627+
}
1628+
15381629
// one day it will just work like that
15391630
//#include <nbl/builtin/glsl/sampling/box_muller_transform.glsl>
15401631

examples_tests/22.RaytracedAO/Renderer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class Renderer : public nbl::core::IReferenceCounted, public nbl::core::Interfac
5151
void resetSampleAndFrameCounters();
5252

5353
void takeAndSaveScreenShot(const std::filesystem::path& screenshotFilePath, bool denoise = false, const DenoiserArgs& denoiserArgs = {});
54+
55+
void denoiseCubemapFaces(std::filesystem::path filePaths[6], const std::string& mergedFileName, int borderPixels, const DenoiserArgs& denoiserArgs = {});
5456

5557
bool render(nbl::ITimer* timer, const bool beauty=true);
5658

examples_tests/22.RaytracedAO/extractCubemap.bat

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,4 @@ magick convert %img% -crop %extractedImgSz%x%extractedImgSz%+%x1%+%y0% %left%
3030
magick convert %img% -crop %extractedImgSz%x%extractedImgSz%+%x2%+%y0% %top%
3131
magick convert %img% -crop %extractedImgSz%x%extractedImgSz%+%x0%+%y1% %bottom%
3232
magick convert %img% -crop %extractedImgSz%x%extractedImgSz%+%x1%+%y1% %front%
33-
magick convert %img% -crop %extractedImgSz%x%extractedImgSz%+%x2%+%y1% %back%
34-
35-
PAUSE
33+
magick convert %img% -crop %extractedImgSz%x%extractedImgSz%+%x2%+%y1% %back%

examples_tests/22.RaytracedAO/main.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,14 @@ int main(int argc, char** argv)
612612
for(uint32_t i = 0; i < 6; ++i)
613613
{
614614
SensorData cubemapFaceSensorData = mainSensorData;
615-
615+
cubemapFaceSensorData.width = mainSensorData.width + mainSensorData.highQualityEdges * 2;
616+
cubemapFaceSensorData.height = mainSensorData.height + mainSensorData.highQualityEdges * 2;
617+
if(mainSensorData.width != mainSensorData.height)
618+
{
619+
std::cout << "[ERROR] Cannot generate cubemap faces where film.width and film.height are not equal. (Aspect Ration must be 1)" << std::endl;
620+
assert(false);
621+
}
622+
616623
if (cubemapFaceSensorData.outputFilePath.empty())
617624
{
618625
if(shouldHaveSensorIdxInFileName)
@@ -636,15 +643,9 @@ int main(int argc, char** argv)
636643
staticCamera->setTarget((mainCamPos + camView).getAsVector3df());
637644
staticCamera->setUpVector(upVector);
638645

639-
auto borderPixels = cubemapFaceSensorData.highQualityEdges;
640-
// TODO: compute fov based on borderPixels
641-
auto fov = core::radians(90.0f);
646+
// auto fov = core::radians(90.0f);
647+
auto fov = atanf(float(cubemapFaceSensorData.width) / float(mainSensorData.width)) * 2.0f;
642648
auto aspectRatio = 1.0f;
643-
if(mainSensorData.width != mainSensorData.height)
644-
{
645-
std::cout << "[ERROR] Cannot generate cubemap faces where film.width and film.height are not equal. (Aspect Ration must be 1)" << std::endl;
646-
assert(false);
647-
}
648649

649650
if (mainSensorData.rightHandedCamera)
650651
staticCamera->setProjectionMatrix(core::matrix4SIMD::buildProjectionMatrixPerspectiveFovRH(fov, 1.0f, nearClip, farClip));
@@ -804,11 +805,16 @@ int main(int argc, char** argv)
804805
assert(beginIdx + 6 <= sensors.size());
805806
auto borderPixels = sensors[beginIdx].highQualityEdges;
806807

807-
// TODO: use the new batch file to merge/denoise/extract these 6 images.
808+
std::filesystem::path filePaths[6] = {};
809+
808810
for(uint32_t f = beginIdx; f < beginIdx + 6; ++f)
809811
{
810812
const auto & sensor = sensors[f];
813+
filePaths[f] = sensor.outputFilePath;
811814
}
815+
816+
std::string mergedFileName = "Merge_CubeMap_" + mainFileName;
817+
renderer->denoiseCubemapFaces(filePaths, mergedFileName, borderPixels, sensors[beginIdx].denoiserInfo);
812818
}
813819

814820
// Interactive

examples_tests/22.RaytracedAO/mergeCubemap.bat

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set top=%3
66
set bottom=%4
77
set front=%5
88
set back=%6
9-
set output=%7
9+
set output=%~dpn7
1010

1111
REM examplary usage:
1212
REM mergeCubemap.bat right.png left.png top.png bottom.png front.png back.png outputImageName
@@ -28,6 +28,4 @@ magick convert -size %outputwidth%x%outputHeight% canvas:none ^
2828
-draw "image over 0,%sz% 0,0 '%bottom%'" ^
2929
-draw "image over %sz%,%sz% 0,0 '%front%'" ^
3030
-draw "image over %szx2%,%sz% 0,0 '%back%'" ^
31-
%output%.%format%
32-
33-
PAUSE
31+
%output%.%format%

0 commit comments

Comments
 (0)