Skip to content

Commit

Permalink
[bugfix] not processing non-updated region of frame; otherwise, other…
Browse files Browse the repository at this point in the history
… parts of the frame got tone-mapped multiple times in asynchronous render result queries
  • Loading branch information
TzuChieh committed Sep 3, 2019
1 parent e9cde65 commit a36de40
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 175 deletions.
5 changes: 3 additions & 2 deletions Engine/Include/ph_core.h
Expand Up @@ -10,8 +10,8 @@ To correctly use Photon-v2 API, please read the following notes:
should be called on the same thread.
- phCreate/Delete<X>() and phAsync<X>() functions can be used in a multithreaded
environment, namely, they are thread-safe. An exception would be that create &
delete should be on the same thread.
environment, namely, they are thread-safe. An exception would be that create
and delete should be called from the same thread.
- Resources created by phCreate<X>() cannot be manipulated concurrently. Any
function requiring some resource ID inputs (except phAsync<X>() functions) is
Expand Down Expand Up @@ -150,6 +150,7 @@ extern PH_API void phGetObservableRenderData(
extern PH_API void phDeleteEngine(PHuint64 engineId);
extern PH_API void phSetWorkingDirectory(PHuint64 engineId, const PHchar* workingDirectory);

// REFACTOR: rename aquire to retrieve
extern PH_API void phAquireFrame(PHuint64 engineId, PHuint64 channelIndex, PHuint64 frameId);
extern PH_API void phAquireFrameRaw(PHuint64 engineId, PHuint64 channelIndex, PHuint64 frameId);

Expand Down
12 changes: 8 additions & 4 deletions Engine/Source/Core/Engine.cpp
Expand Up @@ -30,8 +30,8 @@ void Engine::update()
m_data.update(0.0_r);

// HACK
m_id = m_frameProcessor.addPipeline();
m_frameProcessor.getPipeline(m_id)->appendOperator(std::make_unique<JRToneMapping>());
//m_id = m_frameProcessor.addPipeline();
//m_frameProcessor.getPipeline(m_id)->appendOperator(std::make_unique<JRToneMapping>());
/*m_filmSet.setProcessor(EAttribute::LIGHT_ENERGY, processor);
m_filmSet.setProcessor(EAttribute::NORMAL, processor);*/

Expand All @@ -55,7 +55,9 @@ void Engine::retrieveFrame(

if(applyPostProcessing)
{
m_frameProcessor.process(out_frame, m_id);
//m_frameProcessor.process(out_frame, m_id);
// HACK
JRToneMapping().operate(out_frame);
}
}

Expand Down Expand Up @@ -91,7 +93,9 @@ void Engine::asyncPeekFrame(

if(applyPostProcessing)
{
m_frameProcessor.process(out_frame, m_id);
//m_frameProcessor.process(out_frame, m_id);
// HACK
JRToneMapping().operateLocal(out_frame, TAABB2D<uint32>(region));
}
}

Expand Down
4 changes: 2 additions & 2 deletions Engine/Source/Core/Engine.h
Expand Up @@ -56,9 +56,9 @@ class Engine final
std::shared_ptr<Renderer> m_renderer;
uint32 m_numRenderThreads;

FrameProcessor m_frameProcessor;
//FrameProcessor m_frameProcessor;
// TODO: associate each attribute with a pipeline
FrameProcessor::PipelineId m_id;
//FrameProcessor::PipelineId m_id;
};

// In-header Implementations:
Expand Down
1 change: 1 addition & 0 deletions Engine/Source/Core/Filmic/HdrRgbFilm.cpp
Expand Up @@ -153,6 +153,7 @@ void HdrRgbFilm::developRegion(HdrRgbFrame& out_frame, const TAABB2D<int64>& reg
float64 reciWeight;
std::size_t fx, fy, filmIndex;

// FIXME: we should iterate in frameIndexBound only
for(int64 y = 0; y < getActualResPx().y; y++)
{
for(int64 x = 0; x < getActualResPx().x; x++)
Expand Down
3 changes: 2 additions & 1 deletion Engine/Source/Core/Renderer/Renderer.cpp
Expand Up @@ -123,6 +123,7 @@ SdlTypeInfo Renderer::ciTypeInfo()
return SdlTypeInfo(ETypeCategory::REF_RENDERER, "renderer");
}

void Renderer::ciRegister(CommandRegister& cmdRegister) {}
void Renderer::ciRegister(CommandRegister& cmdRegister)
{}

}// end namespace ph
7 changes: 6 additions & 1 deletion Engine/Source/Frame/Operator/JRToneMapping.cpp
Expand Up @@ -14,7 +14,12 @@ JRToneMapping::JRToneMapping() :

void JRToneMapping::operate(HdrRgbFrame& frame) const
{
frame.forEachPixel([this](const HdrRgbFrame::Pixel& pixel)
operateLocal(frame, {{0, 0}, frame.getSizePx()});
}

void JRToneMapping::operateLocal(HdrRgbFrame& frame, const TAABB2D<uint32>& region) const
{
frame.forEachPixel(region, [this](const HdrRgbFrame::Pixel& pixel)
{
HdrRgbFrame::Pixel color = pixel;
color.mulLocal(m_exposure);
Expand Down
2 changes: 2 additions & 0 deletions Engine/Source/Frame/Operator/JRToneMapping.h
Expand Up @@ -2,6 +2,7 @@

#include "Frame/Operator/FrameOperator.h"
#include "Common/primitive_type.h"
#include "Core/Bound/TAABB2D.h"

namespace ph
{
Expand All @@ -21,6 +22,7 @@ class JRToneMapping : public FrameOperator

void operate(HdrRgbFrame& frame) const override;

void operateLocal(HdrRgbFrame& frame, const TAABB2D<uint32>& region) const;
void setExposure(real exposure);

private:
Expand Down
126 changes: 6 additions & 120 deletions PhotonCLI/ProcessedArguments.cpp
Expand Up @@ -7,19 +7,14 @@

PH_CLI_NAMESPACE_BEGIN

namespace
{
constexpr std::string_view DEFAULT_SCENE_FILE_PATH = "./scene.p2";
constexpr std::string_view DEFAULT_DEFAULT_IMAGE_FILE_PATH = "./rendered_scene.png";
}

ProcessedArguments::ProcessedArguments(int argc, char* argv[]) :
ProcessedArguments(CommandLineArguments(argc, argv))
{}

ProcessedArguments::ProcessedArguments(CommandLineArguments arguments) :
m_sceneFilePath (DEFAULT_SCENE_FILE_PATH),
m_imageFilePath (DEFAULT_DEFAULT_IMAGE_FILE_PATH),
m_sceneFilePath ("./scene.p2"),
m_imageOutputPath ("./rendered_scene"),
m_imageFileFormat ("png"),
m_numRenderThreads (1),
m_isPostProcessRequested (true),
m_isHelpMessageRequested (false),
Expand All @@ -28,9 +23,9 @@ ProcessedArguments::ProcessedArguments(CommandLineArguments arguments) :
m_wildcardFinish (""),
m_outputPercentageProgress(std::numeric_limits<float>::max()),

// HACK
m_isFrameDiagRequested(false)
{
std::string imageFileFormat;
while(!arguments.isEmpty())
{
const std::string argument = arguments.retrieveOne();
Expand All @@ -41,11 +36,11 @@ ProcessedArguments::ProcessedArguments(CommandLineArguments arguments) :
}
else if(argument == "-o")
{
m_imageFilePath = arguments.retrieveOne();
m_imageOutputPath = arguments.retrieveOne();
}
else if(argument == "-of")
{
imageFileFormat = arguments.retrieveOne();
m_imageFileFormat = arguments.retrieveOne();
}
else if(argument == "-t")
{
Expand Down Expand Up @@ -113,115 +108,6 @@ ProcessedArguments::ProcessedArguments(CommandLineArguments arguments) :
std::cerr << "warning: unknown command <" << argument << "> specified, ignoring" << std::endl;
}
}// end while more arguments exist

// possibly override image format if a more specific order is given
if(!imageFileFormat.empty())
{
m_imageFilePath += "." + imageFileFormat;
}

// TODO: check arguments
}

std::string ProcessedArguments::getSceneFilePath() const
{
return m_sceneFilePath;
}

std::string ProcessedArguments::getImageFilePath() const
{
return m_imageFilePath;
}

int ProcessedArguments::getNumRenderThreads() const
{
return m_numRenderThreads;
}

bool ProcessedArguments::isPostProcessRequested() const
{
return m_isPostProcessRequested;
}

bool ProcessedArguments::isHelpMessageRequested() const
{
return m_isHelpMessageRequested;
}

bool ProcessedArguments::isImageSeriesRequested() const
{
return m_isImageSeriesRequested;
}

std::string ProcessedArguments::wildcardStart() const
{
return m_wildcardStart;
}

std::string ProcessedArguments::wildcardFinish() const
{
return m_wildcardFinish;
}

float ProcessedArguments::getOutputPercentageProgress() const
{
return m_outputPercentageProgress;
}

void ProcessedArguments::printHelpMessage()
{
std::cout << R"(
===============================================================================
-s <path>
Specify path to scene file. To render an image series, you can specify
"myScene*.p2" as <path> where * is a wildcard for any string (--series is
required in this case). (default path: "./scene.p2")
===============================================================================
-o <path>
Specify image output path. This should be a filename for single image and a
directory for image series. (default path: "./rendered_scene.png")
===============================================================================
-of <format>
Specify the format of output image. Supported formats are: png, jpg, bmp, tga,
hdr, exr. If this option is omitted, format is deduced from filename extension.
===============================================================================
-t <number>
Set number of threads used for rendering. (default: single thread)
===============================================================================
-p <interval> <is_overwriting>
Output an intermediate image whenever the specified <interval> has passed,
e.g., write 2.3% to output whenever the rendering has progressed 2.3 percent;
or write 7s to output every 7 seconds. Specify <is_overwriting> as true will
make the program overwrite previous intermediate image; false for the
opposite effect.
===============================================================================
--raw
Do not perform any post-processing. (default: perform post-processing)
===============================================================================
--help
Print this help message then exit.
===============================================================================
--series
Render an image series. The order for rendering will be lexicographical order
of the wildcarded string. Currently only .png is supported.
===============================================================================
--start <*>
Render image series starting from a specific wildcarded string.
===============================================================================
--finish <*>
Render image series until a specific wildcarded string is matched. (inclusive)
===============================================================================
)" << std::endl;
}

PH_CLI_NAMESPACE_END

0 comments on commit a36de40

Please sign in to comment.