34 #include <cugar/basic/types.h> 35 #include <cugar/linalg/vector.h> 51 FERMAT_HOST_DEVICE uint32& tri(
const uint32_t pixel) {
return m_tri[pixel]; }
52 FERMAT_HOST_DEVICE
const uint32& tri(
const uint32_t pixel)
const {
return m_tri[pixel]; }
53 FERMAT_HOST_DEVICE float4& geo(
const uint32_t pixel) {
return m_geo[pixel]; }
54 FERMAT_HOST_DEVICE
const float4& geo(
const uint32_t pixel)
const {
return m_geo[pixel]; }
55 FERMAT_HOST_DEVICE float4& uv(
const uint32_t pixel) {
return m_uv[pixel]; }
56 FERMAT_HOST_DEVICE
const float4& uv(
const uint32_t pixel)
const {
return m_uv[pixel]; }
57 FERMAT_HOST_DEVICE uint4& material(
const uint32_t pixel) {
return m_material[pixel]; }
58 FERMAT_HOST_DEVICE
const uint4& material(
const uint32_t pixel)
const {
return m_material[pixel]; }
59 FERMAT_HOST_DEVICE
float& depth(
const uint32_t pixel) {
return m_depth[pixel]; }
60 FERMAT_HOST_DEVICE
const float& depth(
const uint32_t pixel)
const {
return m_depth[pixel]; }
61 FERMAT_HOST_DEVICE float4& geo(
const uint32_t x,
const uint32_t y) {
return m_geo[y*res_x + x]; }
62 FERMAT_HOST_DEVICE
const float4& geo(
const uint32_t x,
const uint32_t y)
const {
return m_geo[y*res_x + x]; }
63 FERMAT_HOST_DEVICE float4& uv(
const uint32_t x,
const uint32_t y) {
return m_uv[y*res_x + x]; }
64 FERMAT_HOST_DEVICE
const float4& uv(
const uint32_t x,
const uint32_t y)
const {
return m_uv[y*res_x + x]; }
65 FERMAT_HOST_DEVICE
float& depth(
const uint32_t x,
const uint32_t y) {
return m_depth[y*res_x + x]; }
66 FERMAT_HOST_DEVICE
const float& depth(
const uint32_t x,
const uint32_t y)
const {
return m_depth[y*res_x + x]; }
67 FERMAT_HOST_DEVICE uint4& material(
const uint32_t x,
const uint32_t y) {
return m_material[y*res_x + x]; }
68 FERMAT_HOST_DEVICE
const uint4& material(
const uint32_t x,
const uint32_t y)
const {
return m_material[y*res_x + x]; }
70 FERMAT_HOST_DEVICE float4& geo(
const int2 pixel) {
return m_geo[pixel.y * res_x + pixel.x]; }
71 FERMAT_HOST_DEVICE
const float4& geo(
const int2 pixel)
const {
return m_geo[pixel.y * res_x + pixel.x]; }
72 FERMAT_HOST_DEVICE float4& geo(
const uint2 pixel) {
return m_geo[pixel.y * res_x + pixel.x]; }
73 FERMAT_HOST_DEVICE
const float4& geo(
const uint2 pixel)
const {
return m_geo[pixel.y * res_x + pixel.x]; }
74 FERMAT_HOST_DEVICE float4& uv(
const int2 pixel) {
return m_uv[pixel.y * res_x + pixel.x]; }
75 FERMAT_HOST_DEVICE
const float4& uv(
const int2 pixel)
const {
return m_uv[pixel.y * res_x + pixel.x]; }
76 FERMAT_HOST_DEVICE float4& uv(
const uint2 pixel) {
return m_uv[pixel.y * res_x + pixel.x]; }
77 FERMAT_HOST_DEVICE
const float4& uv(
const uint2 pixel)
const {
return m_uv[pixel.y * res_x + pixel.x]; }
78 FERMAT_HOST_DEVICE
float& depth(
const uint2 pixel) {
return m_depth[pixel.y * res_x + pixel.x]; }
79 FERMAT_HOST_DEVICE
float depth(
const uint2 pixel)
const {
return m_depth[pixel.y * res_x + pixel.x]; }
80 FERMAT_HOST_DEVICE uint4& material(
const int2 pixel) {
return m_material[pixel.y * res_x + pixel.x]; }
81 FERMAT_HOST_DEVICE
const uint4& material(
const int2 pixel)
const {
return m_material[pixel.y * res_x + pixel.x]; }
89 return make_float4(P.x, P.y, P.z, cugar::binary_cast<float>((uint32_t(miss) << 31) | n_i));
93 static bool is_miss(
const float4 geom)
95 return (cugar::binary_cast<uint32>(geom.w) & (1u << 31)) ? true :
false;
127 FERMAT_HOST_DEVICE float4& operator()(
const uint32_t pixel) {
return c_ptr[pixel]; }
128 FERMAT_HOST_DEVICE
const float4& operator()(
const uint32_t pixel)
const {
return c_ptr[pixel]; }
129 FERMAT_HOST_DEVICE float4& operator()(
const uint32_t x,
const uint32_t y) {
return c_ptr[y*res_x + x]; }
130 FERMAT_HOST_DEVICE
const float4& operator()(
const uint32_t x,
const uint32_t y)
const {
return c_ptr[y*res_x + x]; }
131 FERMAT_HOST_DEVICE float4& operator()(
const uint2 pixel) {
return c_ptr[pixel.y * res_x + pixel.x]; }
132 FERMAT_HOST_DEVICE
const float4& operator()(
const uint2 pixel)
const {
return c_ptr[pixel.y * res_x + pixel.x]; }
133 FERMAT_HOST_DEVICE float4& operator()(
const int2 pixel) {
return c_ptr[pixel.y * res_x + pixel.x]; }
134 FERMAT_HOST_DEVICE
const float4& operator()(
const int2 pixel)
const {
return c_ptr[pixel.y * res_x + pixel.x]; }
136 FERMAT_HOST_DEVICE
const float4* ptr()
const {
return c_ptr; }
137 FERMAT_HOST_DEVICE float4* ptr() {
return c_ptr; }
160 void resize(
const uint32_t _res_x,
const uint32_t _res_y)
165 geo.alloc(res_x * res_y);
166 uv.alloc(res_x * res_y);
167 tri.alloc(res_x * res_y);
168 depth.alloc(res_x * res_y);
169 material.alloc(res_x * res_y);
174 size_t size()
const {
return res_x * res_y; }
180 cudaMemset(geo.ptr(), 0xFF, geo.sizeInBytes());
181 cudaMemset(uv.ptr(), 0xFF, uv.sizeInBytes());
182 cudaMemset(tri.ptr(), 0xFF, tri.sizeInBytes());
183 cudaMemset(depth.ptr(), 0xFF, depth.sizeInBytes());
184 cudaMemset(material.ptr(), 0xFF, depth.sizeInBytes());
194 out.m_geo = geo.ptr();
196 out.m_tri = tri.ptr();
197 out.m_depth = depth.ptr();
198 out.m_material = material.ptr();
213 float4 operator()(
const uint32_t pixel)
const {
return c[pixel]; }
214 float4 operator()(
const uint32_t x,
const uint32_t y)
const {
return c[y*res_x + x]; }
216 const float4* ptr()
const {
return c.ptr(); }
217 float4* ptr() {
return c.ptr(); }
221 void resize(
const uint32_t _res_x,
const uint32_t _res_y)
226 c.alloc(res_x * res_y);
231 size_t size()
const {
return res_x * res_y; }
237 cudaMemset(c.ptr(), 0, c.sizeInBytes());
265 std::swap(res_x, other.res_x);
266 std::swap(res_y, other.res_y);
280 FERMAT_HOST_DEVICE
FBufferChannelView& operator() (
const uint32_t channel) {
return channels[channel]; }
281 FERMAT_HOST_DEVICE
const FBufferChannelView& operator() (
const uint32_t channel)
const {
return channels[channel]; }
283 FERMAT_HOST_DEVICE float4& operator() (
const uint32_t channel,
const uint32_t pixel) {
return channels[channel](pixel); }
284 FERMAT_HOST_DEVICE
const float4& operator() (
const uint32_t channel,
const uint32_t pixel)
const {
return channels[channel](pixel); }
285 FERMAT_HOST_DEVICE float4& operator() (
const uint32_t channel,
const uint32_t x,
const uint32_t y) {
return channels[channel](x, y); }
286 FERMAT_HOST_DEVICE
const float4& operator() (
const uint32_t channel,
const uint32_t x,
const uint32_t y)
const {
return channels[channel](x, y); }
297 typedef std::shared_ptr<FBufferChannelStorage> FBufferChannelPtr;
305 std::vector<std::string> names;
321 n_channels = _n_channels;
330 names[i] = std::string(name);
335 void resize(
const uint32_t _res_x,
const uint32_t _res_y)
340 gbuffer.
resize(res_x, res_y);
341 for (
size_t c = 0; c < n_channels; ++c)
342 channels[c].resize(res_x, res_y);
345 for (
size_t c = 0; c < n_channels; ++c)
346 _channel_views.ptr()[c] = channels[c].
view();
348 channel_views = _channel_views;
355 return uint32_t(n_channels);
360 size_t size()
const {
return res_x * res_y; }
367 out.gbuffer = gbuffer.
view();
368 out.channels = channel_views.ptr();
369 out.n_channels = n_channels;
376 template <
bool ALPHA_AS_VARIANCE>
382 mean += delta * inv_n;
384 if (ALPHA_AS_VARIANCE)
387 const float lum_delta = cugar::max_comp(delta.xyz());
388 const float lum_mean = cugar::max_comp(mean.xyz());
389 const float lum_f = cugar::max_comp(f.xyz());
390 const float lum_delta2 = lum_f - lum_mean;
391 mean.w = lum_delta * lum_delta2;
398 template <
bool ALPHA_AS_VARIANCE>
406 mean.x += delta.x * inv_n;
407 mean.y += delta.y * inv_n;
408 mean.z += delta.z * inv_n;
410 if (ALPHA_AS_VARIANCE)
413 const float lum_delta = cugar::max_comp(delta);
414 const float lum_mean = cugar::max_comp(mean.xyz());
415 const float lum_f = cugar::max_comp(f);
416 const float lum_delta2 = lum_f - lum_mean;
417 mean.w = lum_delta * lum_delta2;
425 template <
bool ALPHA_AS_VARIANCE>
433 mean.x += f.x * inv_n;
434 mean.y += f.y * inv_n;
435 mean.z += f.z * inv_n;
437 if (ALPHA_AS_VARIANCE)
440 const float lum_delta = cugar::max_comp(delta);
441 mean.w += lum_delta * lum_delta * inv_n;
~FBufferStorage()
Definition: framebuffer.h:315
Definition: framebuffer.h:147
Definition: framebuffer.h:205
FBufferChannelStorage & operator=(FBufferChannelStorage &other)
Definition: framebuffer.h:242
void clear()
Definition: framebuffer.h:235
FERMAT_HOST_DEVICE void add_in(FBufferChannelView &fb, const uint32_t pixel, const cugar::Vector3f f, const float inv_n)
Definition: framebuffer.h:427
void resize(const uint32_t _res_x, const uint32_t _res_y)
Definition: framebuffer.h:221
Definition: framebuffer.h:295
FBufferChannelView view()
Definition: framebuffer.h:252
Defines various spherical mappings.
void resize(const uint32_t _res_x, const uint32_t _res_y)
Definition: framebuffer.h:335
FBufferView view()
Definition: framebuffer.h:364
Definition: framebuffer.h:274
void set_channel(const uint32_t i, const char *name)
Definition: framebuffer.h:328
size_t size() const
Definition: framebuffer.h:231
CUGAR_HOST CUGAR_DEVICE Vector2f uniform_sphere_to_square(const Vector3f &vec)
Definition: mappings_inline.h:174
FBufferStorage()
Definition: framebuffer.h:311
void resize(const uint32_t _res_x, const uint32_t _res_y)
Definition: framebuffer.h:160
size_t size() const
Definition: framebuffer.h:360
void clear()
Definition: framebuffer.h:178
size_t size() const
Definition: framebuffer.h:174
Definition: framebuffer.h:125
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Out binary_cast(const In in)
Definition: types.h:288
CUGAR_HOST CUGAR_DEVICE Vector3f uniform_square_to_sphere(const Vector2f &uv)
Definition: mappings_inline.h:162
uint32_t channel_count() const
Definition: framebuffer.h:353
void swap(FBufferChannelStorage &other)
Definition: framebuffer.h:263
FERMAT_HOST_DEVICE void average_in(FBufferChannelView &fb, const uint32_t pixel, const cugar::Vector4f f, const float inv_n)
Definition: framebuffer.h:378
GBufferView view()
Definition: framebuffer.h:189
Definition: framebuffer.h:49
void set_channel_count(const uint32 _n_channels)
Definition: framebuffer.h:319