Skip to content

Commit 97845d1

Browse files
committed
Paper-ready version. Configuration needs improvement
1 parent 14909ce commit 97845d1

26 files changed

+221
-85
lines changed

DeepestScatter_DataGen/DeepestScatter_DataGen.sln

+15
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,19 @@ Global
5555
GlobalSection(Performance) = preSolution
5656
HasPerformanceSessions = true
5757
EndGlobalSection
58+
GlobalSection(Performance) = preSolution
59+
HasPerformanceSessions = true
60+
EndGlobalSection
61+
GlobalSection(Performance) = preSolution
62+
HasPerformanceSessions = true
63+
EndGlobalSection
64+
GlobalSection(Performance) = preSolution
65+
HasPerformanceSessions = true
66+
EndGlobalSection
67+
GlobalSection(Performance) = preSolution
68+
HasPerformanceSessions = true
69+
EndGlobalSection
70+
GlobalSection(Performance) = preSolution
71+
HasPerformanceSessions = true
72+
EndGlobalSection
5873
EndGlobal

DeepestScatter_DataGen/DeepestScatter_DataGen/src/CUDA/bakedCamera.cu

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ RT_PROGRAM void copyToFrameResult()
3838
if (directRadianceBuffer[launchID].hasScattered)
3939
{
4040
frameResultBuffer[launchID + rectOrigin] =
41-
make_float4(predictedRadianceBuffer[launchID]) +
42-
make_float4(directRadianceBuffer[launchID].radiance);
41+
(make_float4(predictedRadianceBuffer[launchID]) +
42+
make_float4(directRadianceBuffer[launchID].radiance)) * (1 - directRadianceBuffer[launchID].transmittance);
4343
}
4444
}

DeepestScatter_DataGen/DeepestScatter_DataGen/src/CUDA/disneyCamera.cu

+11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ using namespace DeepestScatter::Gpu;
1111
rtDeclareVariable(uint2, launchID, rtLaunchIndex, );
1212
rtBuffer<DisneyNetworkInput, 2> networkInputBuffer;
1313
rtBuffer<IntersectionInfo, 2> directRadianceBuffer;
14+
rtBuffer<float, 2> predictedRadianceBuffer;
1415
rtBuffer<float4, 2> frameResultBuffer;
1516

1617
rtDeclareVariable(float3, lightDirection, , );
@@ -34,6 +35,16 @@ RT_PROGRAM void pinholeCamera()
3435
}
3536
}
3637

38+
RT_PROGRAM void copyToFrameResult()
39+
{
40+
if (directRadianceBuffer[launchID].hasScattered)
41+
{
42+
frameResultBuffer[launchID + rectOrigin] =
43+
(make_float4(predictedRadianceBuffer[launchID]) +
44+
make_float4(directRadianceBuffer[launchID].radiance)) * (1 - directRadianceBuffer[launchID].transmittance);
45+
}
46+
}
47+
3748
RT_PROGRAM void clearRect()
3849
{
3950
//todo: probably uncomment these. Right now it jut makes performance worse.

DeepestScatter_DataGen/DeepestScatter_DataGen/src/CUDA/disneyDescriptorMaterial.cu

+10-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
using namespace DeepestScatter::Gpu;
1010

11-
rtDeclareVariable(DisneyDescriptorRayData, resultDescriptor, rtPayload, );
11+
rtDeclareVariable(DisneyDescriptorRayData, rayData, rtPayload, );
1212
rtDeclareVariable(uint2, launchID, rtLaunchIndex, );
1313

1414
RT_PROGRAM void sampleDisneyDescriptor()
@@ -26,19 +26,22 @@ RT_PROGRAM void sampleDisneyDescriptor()
2626
//const float jitter = rnd(seed) / step;
2727
//float opticalDistance = (subframeId % step) * 1.0f / step + jitter;
2828

29-
const ScatteringEvent scatter = getNextScatteringEvent(seed, pos, direction);
29+
const float transmittance = getNextScatteringEvent(seed, pos, direction, false).transmittance;
30+
const ScatteringEvent scatter = getNextScatteringEvent(1 - rnd(seed) * (1 - transmittance), pos, direction);
31+
32+
rayData.intersectionInfo->transmittance = transmittance;
3033

3134
if (!scatter.hasScattered || !isInBox(scatter.scatterPos))
3235
{
33-
resultDescriptor.intersectionInfo->hasScattered = false;
34-
resultDescriptor.intersectionInfo->radiance = make_float3(0);
36+
rayData.intersectionInfo->hasScattered = false;
37+
rayData.intersectionInfo->radiance = make_float3(0);
3538
}
3639
else
3740
{
38-
resultDescriptor.intersectionInfo->hasScattered = true;
39-
resultDescriptor.intersectionInfo->radiance = getInScattering(scatter, direction, false);
41+
rayData.intersectionInfo->hasScattered = true;
42+
rayData.intersectionInfo->radiance = getInScattering(scatter, direction, false);
4043
setupHierarchicalDescriptor<DisneyNetworkInput, float>(
41-
*resultDescriptor.descriptor, scatter.scatterPos - 0.5f * bboxSize, direction);
44+
*rayData.descriptor, scatter.scatterPos - 0.5f * bboxSize, direction);
4245
}
4346

4447
}

DeepestScatter_DataGen/DeepestScatter_DataGen/src/CUDA/lightProbeMaterial.cu

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ RT_PROGRAM void sampleLightProbe()
3939
//const float jitter = rnd(seed) / step;
4040
//float opticalDistance = (subframeId % step) * 1.0f / step + jitter;
4141

42-
const ScatteringEvent scatter = getNextScatteringEvent(seed, pos, direction);
42+
const float transmittance = getNextScatteringEvent(seed, pos, direction, false).transmittance;
43+
const ScatteringEvent scatter = getNextScatteringEvent(1 - rnd(seed) * (1 - transmittance), pos, direction);
44+
45+
rayData.intersectionInfo->transmittance = transmittance;
4346

4447
if (!scatter.hasScattered || !isInBox(scatter.scatterPos))
4548
{
4649
rayData.intersectionInfo->hasScattered = false;
50+
rayData.intersectionInfo->radiance = make_float3(0);
4751
}
4852
else
4953
{

DeepestScatter_DataGen/DeepestScatter_DataGen/src/CUDA/rayData.cuh

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct ScatteringRayData
2828
struct IntersectionInfo
2929
{
3030
optix::float3 radiance;
31+
float transmittance;
3132
bool hasScattered;
3233
};
3334

DeepestScatter_DataGen/DeepestScatter_DataGen/src/ExecutionLoop/GuiExecutionLoop.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ namespace DeepestScatter
3535

3636
static GuiExecutionLoop* instance;
3737

38-
uint32_t width = 1024u;
39-
uint32_t height = 768u;
38+
uint32_t width = 1792u;
39+
uint32_t height = 1024u;
4040

4141
// Mouse state
4242
optix::int2 mousePrevPos = optix::make_int2(0, 0);

DeepestScatter_DataGen/DeepestScatter_DataGen/src/ExecutionLoop/Tasks.cpp

+37-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#include "Tasks.h"
2+
3+
#include <filesystem>
4+
25
#include "Util/Dataset/Dataset.h"
36
#include "installers.h"
47
#include "DisneyDescriptor.pb.h"
@@ -18,8 +21,27 @@ namespace DeepestScatter
1821
{
1922
namespace di = Hypodermic;
2023

21-
uint32_t width = 512u;
22-
uint32_t height = 256u;
24+
uint32_t width = 1792u;
25+
uint32_t height = 1024u;
26+
27+
enum class LightDirection {
28+
Front, Back, Side
29+
};
30+
31+
optix::float3 getLightDirection(LightDirection direction)
32+
{
33+
switch (direction) {
34+
case LightDirection::Front:
35+
return optix::make_float3(-0.586f, -0.766f, -0.271f);
36+
case LightDirection::Side:
37+
return optix::make_float3(-0.03f, -0.25f, 0.8f);
38+
case LightDirection::Back:
39+
return optix::make_float3(0.586f, -0.766f, -0.271f);
40+
default:
41+
throw std::exception("Unexpected direction");
42+
}
43+
44+
}
2345

2446
std::queue<GuiExecutionLoop::LazyTask> Tasks::renderCloud(const std::string &cloudPath, float sizeM)
2547
{
@@ -32,17 +54,24 @@ namespace DeepestScatter
3254
Persistance::SceneSetup sceneSetup{};
3355
sceneSetup.set_cloud_path(cloudPath);
3456
sceneSetup.set_cloud_size_m(sizeM);
35-
sceneSetup.mutable_light_direction()->set_x(-0.586f);
36-
sceneSetup.mutable_light_direction()->set_y(-0.766f);
37-
sceneSetup.mutable_light_direction()->set_z(-0.271f);
57+
58+
optix::float3 direction = getLightDirection(LightDirection::Front);
59+
sceneSetup.mutable_light_direction()->set_x(direction.x);
60+
sceneSetup.mutable_light_direction()->set_y(direction.y);
61+
sceneSetup.mutable_light_direction()->set_z(direction.z);
62+
3863
//sceneSetup.mutable_light_direction()->set_x(0.8f);
3964
//sceneSetup.mutable_light_direction()->set_y(-0.25f);
4065
//sceneSetup.mutable_light_direction()->set_z(0.11f);
4166

42-
taskBuilder.addRegistrations(installFramework(width, height));
67+
using TRenderer = BakedRenderer;
68+
taskBuilder.registerType<TRenderer>().as<ARenderer>().singleInstance();
69+
auto outputPath =
70+
std::filesystem::path("../../Data/Renders") /
71+
std::filesystem::path(cloudPath).filename().replace_extension(TRenderer::NAME + ".exr");
72+
taskBuilder.addRegistrations(installFramework(width, height, outputPath));
4373
taskBuilder.addRegistrations(installSceneSetup(sceneSetup, ".", Cloud::Rendering::Mode::SunAndSkyAllScatter, Cloud::Model::Mipmaps::On));
4474
taskBuilder.addRegistrations(installApp());
45-
taskBuilder.registerType<BakedRenderer>().as<ARenderer>().singleInstance();
4675

4776
auto container = taskBuilder.build();
4877

@@ -76,7 +105,7 @@ namespace DeepestScatter
76105
{
77106
di::ContainerBuilder taskBuilder;
78107

79-
taskBuilder.addRegistrations(installFramework(width, height));
108+
taskBuilder.addRegistrations(installFramework(width, height, std::filesystem::path()));
80109
taskBuilder.addRegistrations(installSceneSetup(
81110
sceneSetup, cloudRoot, Cloud::Rendering::Mode::SunMultipleScatter, Cloud::Model::Mipmaps::On));
82111
taskBuilder.addRegistrations(installApp());

DeepestScatter_DataGen/DeepestScatter_DataGen/src/Installers.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
#include "Scene/CloudMaterial.h"
1010

11+
namespace std {
12+
namespace filesystem {
13+
class path;
14+
}
15+
}
16+
1117
namespace DeepestScatter
1218
{
1319
Hypodermic::ContainerBuilder installApp();
@@ -20,5 +26,5 @@ namespace DeepestScatter
2026
Cloud::Rendering::Mode renderingMode,
2127
Cloud::Model::Mipmaps mipmaps);
2228

23-
Hypodermic::ContainerBuilder installFramework(uint32_t width, uint32_t height);
29+
Hypodermic::ContainerBuilder installFramework(uint32_t width, uint32_t height, const std::filesystem::path& ouputPath);
2430
}

DeepestScatter_DataGen/DeepestScatter_DataGen/src/Scene/Cameras/BakedRenderer.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace DeepestScatter
1010
{
1111
static constexpr optix::uint2 RECT_SIZE{ 512, 256 };
12-
static const std::string modelDirectory = "../../DeepestScatter_Train/runs/Jun06_23-37-32_DESKTOP-D5QPR6V/";
12+
static const std::string modelDirectory = "../../DeepestScatter_Train/runs/Jun09_01-00-29_DESKTOP-D5QPR6V/";
1313

1414
optix::Program BakedRenderer::getCamera()
1515
{
@@ -87,7 +87,7 @@ namespace DeepestScatter
8787
{
8888
std::cout << "Baking Light Probes... " << probeCount.x << " " << probeCount.y << " " << probeCount.z << std::endl;
8989

90-
torch::NoGradGuard no_grad_guard;
90+
torch::NoGradGuard noGradGuard;
9191
for (uint32_t i = 0; i < probeCount.z; i++)
9292
{
9393
bakeAtZ(i);
@@ -131,7 +131,7 @@ namespace DeepestScatter
131131

132132
void BakedRenderer::render(optix::Buffer frameResultBuffer)
133133
{
134-
torch::NoGradGuard no_grad_guard;
134+
torch::NoGradGuard noGradGuard;
135135
size_t width, height;
136136
frameResultBuffer->getSize(width, height);
137137

DeepestScatter_DataGen/DeepestScatter_DataGen/src/Scene/Cameras/BakedRenderer.h

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace DeepestScatter
2828
void init() override;
2929
void render(optix::Buffer frameResultBuffer) override;
3030

31+
inline static const std::string NAME = "BNN";
3132
private:
3233

3334
class Baker

DeepestScatter_DataGen/DeepestScatter_DataGen/src/Scene/Cameras/Camera.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -146,26 +146,25 @@ namespace DeepestScatter
146146
program["averageLuminance"]->setBuffer(reinhardAverageLuminance);
147147
}
148148

149-
void Camera::saveToDisk()
149+
void Camera::saveToDisk() const
150150
{
151151
using namespace Imath;
152152
using namespace Imf;
153153

154154
Header header(width, height, 1, V2f(0, 0), 1, DECREASING_Y);
155-
header.lineOrder() = DECREASING_Y;
156155
header.channels().insert("R", Channel(Imf::FLOAT));
157156
header.channels().insert("G", Channel(Imf::FLOAT));
158157
header.channels().insert("B", Channel(Imf::FLOAT));
159158

160159
BufferBind<optix::float4> frame(progressiveBuffer);
161160

162-
optix::float4* start = &frame[0];
161+
float* start = reinterpret_cast<float*>(&frame[0]);
163162
const size_t xStride = sizeof(optix::float4);
164163
const size_t yStride = sizeof(optix::float4) * width;
165164

166165
std::cout << frame[width * height / 2 + width / 2].x << std::endl;
167166

168-
OutputFile file("test.exr", header);
167+
OutputFile file(outputFile.string().c_str(), header);
169168
FrameBuffer frameBuffer;
170169
frameBuffer.insert("R", Slice(Imf::FLOAT, reinterpret_cast<char*>(start++), xStride, yStride));
171170
frameBuffer.insert("G", Slice(Imf::FLOAT, reinterpret_cast<char*>(start++), xStride, yStride));
@@ -216,8 +215,8 @@ namespace DeepestScatter
216215
}
217216
else
218217
{
219-
220-
saveToDisk();
218+
completed = true;
219+
std::cout << "rendering subframe " << subframeId << std::endl;
221220
}
222221

223222
GLenum glDataType = GL_UNSIGNED_BYTE;
@@ -232,7 +231,7 @@ namespace DeepestScatter
232231

233232
bool Camera::isConverged()
234233
{
235-
if (subframeId < 1000)
234+
if (subframeId < 100)
236235
{
237236
return false;
238237
}

DeepestScatter_DataGen/DeepestScatter_DataGen/src/Scene/Cameras/Camera.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "Scene/SceneItem.h"
1010
#include "ARenderer.h"
11+
#include <filesystem>
1112

1213
namespace DeepestScatter
1314
{
@@ -18,19 +19,20 @@ namespace DeepestScatter
1819
public:
1920
struct Settings
2021
{
21-
Settings(uint32_t width, uint32_t height) :
22-
width(width), height(height) {}
22+
Settings(uint32_t width, uint32_t height, std::filesystem::path outputFile) :
23+
width(width), height(height), outputFile(outputFile) {}
2324

2425
uint32_t width;
2526
uint32_t height;
27+
std::filesystem::path outputFile;
2628
};
2729

2830
Camera(
2931
std::shared_ptr<Settings> settings,
3032
std::shared_ptr<optix::Context> context,
3133
std::shared_ptr<Resources> resources,
3234
std::shared_ptr<ARenderer> renderer) :
33-
width(settings->width), height(settings->height),
35+
width(settings->width), height(settings->height), outputFile(settings->outputFile),
3436
context(*context.get()),
3537
resources(std::move(resources)),
3638
renderer(std::move(renderer))
@@ -55,7 +57,7 @@ namespace DeepestScatter
5557
private:
5658
void setupVariables(optix::Program& program);
5759

58-
void saveToDisk();
60+
void saveToDisk() const;
5961

6062
void render();
6163

@@ -65,6 +67,7 @@ namespace DeepestScatter
6567

6668
uint32_t width;
6769
uint32_t height;
70+
std::filesystem::path outputFile;
6871

6972
optix::Context context;
7073
std::shared_ptr<Resources> resources;

0 commit comments

Comments
 (0)