Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a diagnostic AOV for invalid samples #1888

Merged
merged 1 commit into from
Mar 8, 2018

Conversation

oktomus
Copy link
Member

@oktomus oktomus commented Mar 6, 2018

This implements #1815.

@@ -73,6 +73,10 @@ namespace renderer

namespace
{

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove this line

@oktomus oktomus changed the title Create a diagnostic AOV for invalid samples in adaptive sampling [WIP] Create a diagnostic AOV for invalid samples in adaptive sampling Mar 6, 2018
@oktomus oktomus changed the title Create a diagnostic AOV for invalid samples in adaptive sampling Create a diagnostic AOV for invalid samples Mar 7, 2018
Copy link
Member

@dictoon dictoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your approach, it's very sound architecturally. Clean code too! I've made a number of remarks which need to be addressed.

Thanks!


// Forward declarations.
namespace foundation { class Tile; }
namespace renderer { class AOVAccumulatorContainer; }
namespace renderer { class Frame; }
namespace renderer { class TileStack; }

using namespace foundation;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We completely forbid using declarations in header files since this defeats the point of namespaces entirely. Please use fully qualified names.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, we should change that also on the adaptive pixel renderer


// appleseed.foundation headers.
#include "foundation/image/tile.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume you need this for std::unique_ptr<>? If you do, then please remove the Tile forward declaration below.

@@ -32,20 +32,26 @@

// appleseed.renderer headers.
#include "renderer/kernel/rendering/ipixelrenderer.h"
#include "renderer/modeling/frame/frame.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already a Frame forward declaration so this seems redundant.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, my bad

@@ -60,6 +66,8 @@ class PixelRendererBase
// Constructor.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to plural now that there are two constructors.

@@ -60,6 +66,8 @@ class PixelRendererBase
// Constructor.
PixelRendererBase();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this blank line so that the comment applies to both constructors.

@@ -41,6 +42,8 @@ using namespace foundation;

namespace renderer
{
const uint8 InvalidSampleHint = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move after the "PixelRendererBase class implementation" block comment since this is technically part of the implementation of PixelRendererBase.

@@ -32,6 +32,7 @@

// appleseed.renderer headers.
#include "renderer/kernel/rendering/ipixelrenderer.h"
#include "renderer/modeling/frame/frame.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer forward decls whenever possible (to reduce coupling and compile times).

@@ -181,7 +183,7 @@ namespace
m_total_sampling_dim.insert(child_sampling_context.get_total_dimension());

// Merge the sample into the framebuffer.
if (shading_result.is_valid())
if (shading_result.is_valid() && shading_result.m_main.r < 0.8f)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be part of the PR :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops, that's weird, I used --patch `to add and was careful.

@@ -148,6 +150,7 @@ namespace
Tile& tile,
TileStack& aov_tiles) override
{
PixelRendererBase::on_tile_end(frame, tile, aov_tiles);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest adding a blank line after this to make it stand out.

@@ -129,6 +130,7 @@ namespace
Tile& tile,
TileStack& aov_tiles) override
{
PixelRendererBase::on_tile_begin(frame, tile, aov_tiles);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest adding a blank line after this to make it stand out.

@oktomus
Copy link
Member Author

oktomus commented Mar 7, 2018

Thanks for the review @dictoon. Regarding different colors for different kind of errors, I was thinking of:

  • Create another ShadingResult::is_valid so that we can get a error code (an enum telling what is the error)
  • Don't extend the original one to avoid useless tests when we don't want the AOV

@dictoon
Copy link
Member

dictoon commented Mar 7, 2018

Create another ShadingResult::is_valid so that we can get a error code (an enum telling what is the error)

That sounds good, my only concerns are about complexity and especially performance. Let's try it (in a separate PR) and see how it goes!

@@ -58,7 +62,7 @@ class PixelRendererBase
{
public:
// Constructor.
PixelRendererBase();
PixelRendererBase(const Frame& frame, const size_t thread_index, const ParamArray& params);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make this more readable by having one parameter per line.

protected:
const Parameters m_base_params;
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a second blank line before block comments. That's the only case where we use two blank lines.

size_t m_invalid_pixel_count;
struct Parameters
{
const bool m_diagnostics;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would look nicer to forget about trying to align this to anything. There's no hard rule here, we're clearly in the domain of aesthetics :)

, m_sample_renderer(factory->create(thread_index))
{
if (m_params.m_diagnostics)
if (m_base_params.m_diagnostics)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's quite problematic to have parameters in two places, m_base_params and m_params. I would suggest simply keeping m_base_params in the base class, and renaming it to m_params.

@@ -126,11 +124,13 @@ namespace

void on_tile_begin(
const Frame& frame,
Tile& tile,
foundation::Tile& tile,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're in the .cpp file and there's a using namespace foundation statement so you can remove the qualification here (and everywhere in the file).

@@ -139,16 +139,19 @@ namespace
frame.aov_images().size(),
frame.get_filter()));

if (m_params.m_diagnostics)
m_diagnostics.reset(new Tile(tile.get_width(), tile.get_height(), 2, PixelFormatFloat));
if (m_base_params.m_diagnostics)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap the body of multiline if statements with braces:

if (m_base_params.m_diagnostics)
{
    ...
}

tile.get_pixel(x, y, color);
// 20% of luminance
color.rgb().set(foundation::luminance(color.rgb()));
color.rgb().set(color.r * 0.2f);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks a bit weird. Why not simply

color.rgb().set(0.2f * luminance(color.rgb()));

@@ -107,4 +176,25 @@ void PixelRendererBase::signal_invalid_sample()
++m_invalid_sample_count;
}

//
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add another blank line here too.

Copy link
Member

@dictoon dictoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! A few very minor changes left and it's good to merge.

Impressed with the quality of your code!

}

// Invalid samples diagnostic
if (tile_bbox.contains(pt) && m_params.m_diagnostics)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make sense to swap the conditions to avoid calling AABB::contains() if m_params.m_diagnostics is false.

{
public:
// Constructor.
UniformPixelRendererFactory(
const Frame& frame,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to forward declare Frame.

@@ -41,8 +41,7 @@
#include <cstddef>

// Forward declarations.
namespace foundation { class Dictionary; }
namespace renderer { class Frame; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to restore the forward decl of Frame.

@@ -139,16 +142,19 @@ namespace
frame.aov_images().size(),
frame.get_filter()));

if (m_params.m_diagnostics)
m_diagnostics.reset(new Tile(tile.get_width(), tile.get_height(), 2, PixelFormatFloat));
if (PixelRendererBase::m_params.m_diagnostics)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add braces around multiline body.

@oktomus
Copy link
Member Author

oktomus commented Mar 8, 2018

Thanks, I'm happy to know that my code is of quality 😄

@dictoon dictoon merged commit 91e2fbd into appleseedhq:master Mar 8, 2018
@oktomus oktomus deleted the invalidsamples_aov branch July 10, 2018 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants