SPH
FrameBuffer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "gui/objects/Bitmap.h"
4 #include "gui/objects/Filmic.h"
5 
7 
8 class IColorMap : public Polymorphic {
9 public:
10  virtual Bitmap<Rgba> map(const Bitmap<Rgba>& values) const = 0;
11 };
12 
14 private:
15  float factor = 2.f;
16 
17 public:
18  explicit LogarithmicColorMap(const float factor)
19  : factor(factor) {}
20 
21  virtual Bitmap<Rgba> map(const Bitmap<Rgba>& values) const override {
22  Bitmap<Rgba> colormapped(values.size());
23  for (int y = 0; y < values.size().y; ++y) {
24  for (int x = 0; x < values.size().x; ++x) {
25  const Rgba color = values[Pixel(x, y)];
26  colormapped[Pixel(x, y)] = Rgba(map(color.r()), map(color.g()), map(color.b()), color.a());
27  }
28  }
29  return colormapped;
30  }
31 
32  void setFactor(const float newFactor) {
33  factor = newFactor;
34  }
35 
36 private:
37  inline float map(const float x) const {
38  return 1.f / factor * log(1.f + factor * x);
39  }
40 };
41 
42 class FilmicColorMap : public IColorMap {
43 private:
44  FilmicMapping filmic;
45 
46 public:
49  params.toeStrength = 0.1f;
50  params.toeLength = 0.1f;
51  params.shoulderStrength = 2.f;
52  params.shoulderLength = 0.4f;
53  params.shoulderAngle = 0.f;
54  filmic.create(params);
55  }
56 
57  virtual Bitmap<Rgba> map(const Bitmap<Rgba>& values) const override {
58  Bitmap<Rgba> colormapped(values.size());
59  for (int y = 0; y < values.size().y; ++y) {
60  for (int x = 0; x < values.size().x; ++x) {
61  const Rgba color = values[Pixel(x, y)];
62  colormapped[Pixel(x, y)] =
63  Rgba(filmic(color.r()), filmic(color.g()), filmic(color.b()), color.a());
64  }
65  }
66  return colormapped;
67  }
68 };
69 
70 class FrameBuffer : public Noncopyable {
71 private:
72  Bitmap<Rgba> values;
73  Size passCnt = 0;
74 
75 public:
76  FrameBuffer(const Pixel resolution) {
77  values.resize(resolution, Rgba::transparent());
78  }
79 
80  void accumulate(const Bitmap<Rgba>& pass) {
81  SPH_ASSERT(pass.size() == values.size());
82  for (int y = 0; y < values.size().y; ++y) {
83  for (int x = 0; x < values.size().x; ++x) {
84  Pixel p(x, y);
85  const Rgba accumulatedColor = (pass[p] + values[p] * passCnt) / (passCnt + 1);
86  values[p] = accumulatedColor.over(values[p]);
87  }
88  }
89  passCnt++;
90  }
91 
92  void override(Bitmap<Rgba>&& pass) {
93  values = std::move(pass);
94  passCnt = 1;
95  }
96 
97  const Bitmap<Rgba>& getBitmap() const {
98  return values;
99  }
100 };
101 
#define SPH_ASSERT(x,...)
Definition: Assert.h:94
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Wrapper of wxBitmap, will be possibly replaced by custom implementation.
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
#define NAMESPACE_SPH_END
Definition: Object.h:12
void resize(const Pixel newResolution, const Type &value)
Definition: Bitmap.h:38
Pixel size() const
Definition: Bitmap.h:72
virtual Bitmap< Rgba > map(const Bitmap< Rgba > &values) const override
Definition: FrameBuffer.h:57
Using http://filmicworlds.com/blog/filmic-tonemapping-with-piecewise-power-curves/.
Definition: Filmic.h:8
void create(const UserParams &userParams)
Definition: Filmic.cpp:21
const Bitmap< Rgba > & getBitmap() const
Definition: FrameBuffer.h:97
void accumulate(const Bitmap< Rgba > &pass)
Definition: FrameBuffer.h:80
FrameBuffer(const Pixel resolution)
Definition: FrameBuffer.h:76
virtual Bitmap< Rgba > map(const Bitmap< Rgba > &values) const =0
void setFactor(const float newFactor)
Definition: FrameBuffer.h:32
virtual Bitmap< Rgba > map(const Bitmap< Rgba > &values) const override
Definition: FrameBuffer.h:21
LogarithmicColorMap(const float factor)
Definition: FrameBuffer.h:18
Definition: Color.h:8
float & a()
Definition: Color.h:63
static Rgba transparent()
Definition: Color.h:202
float & g()
Definition: Color.h:47
float & r()
Definition: Color.h:39
float & b()
Definition: Color.h:55
Rgba over(const Rgba &other) const
Blends two colors together using "over" operation.
Definition: Color.h:120
Object with deleted copy constructor and copy operator.
Definition: Object.h:54
Definition: Point.h:101
Base class for all polymorphic objects.
Definition: Object.h:88