Hello, World!
Yeah this is quite a thicc first commit but there's no way I'm untangling this mess just for a nice set of starting commits :^)
This commit is contained in:
43
include/Raychel/Render/Camera.h
Normal file
43
include/Raychel/Render/Camera.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* \file Camera.h
|
||||
* \author Weckyy702 (weckyy702@gmail.com)
|
||||
* \brief Header file for Camera class
|
||||
* \date 2022-04-11
|
||||
*
|
||||
* MIT License
|
||||
* Copyright (c) [2022] [Weckyy702 (weckyy702@gmail.com | https://github.com/Weckyy702)]
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
#ifndef RAYCHEL_CAMERA_H
|
||||
#define RAYCHEL_CAMERA_H
|
||||
|
||||
#include "Raychel/Core/Types.h"
|
||||
|
||||
namespace Raychel {
|
||||
|
||||
struct Camera
|
||||
{
|
||||
Transform transform;
|
||||
double zoom{1.0};
|
||||
};
|
||||
|
||||
} // namespace Raychel
|
||||
|
||||
#endif //!RAYCHEL_CAMERA_H
|
||||
50
include/Raychel/Render/Denoise.h
Normal file
50
include/Raychel/Render/Denoise.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* \file Denoise.h
|
||||
* \author Weckyy702 (weckyy702@gmail.com)
|
||||
* \brief Header file for Denoise class
|
||||
* \date 2022-05-06
|
||||
*
|
||||
* MIT License
|
||||
* Copyright (c) [2022] [Weckyy702 (weckyy702@gmail.com | https://github.com/Weckyy702)]
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
#ifndef RAYCHEL_DENOISE_H
|
||||
#define RAYCHEL_DENOISE_H
|
||||
|
||||
#include "FatPixel.h"
|
||||
#include "Framebuffer.h"
|
||||
|
||||
namespace Raychel {
|
||||
|
||||
struct DenoisingOptions
|
||||
{
|
||||
std::size_t half_patch_size{1};
|
||||
std::size_t half_search_window_size{6};
|
||||
double distance_threshold{1.};
|
||||
std::size_t num_scales{3};
|
||||
};
|
||||
|
||||
Framebuffer denoise_single_scale(const FatFramebuffer& input_pixels, DenoisingOptions options = {}) noexcept;
|
||||
|
||||
Framebuffer denoise_multiscale(const FatFramebuffer& input_pixels, DenoisingOptions options = {}) noexcept;
|
||||
|
||||
} // namespace Raychel
|
||||
|
||||
#endif //!RAYCHEL_DENOISE_H
|
||||
64
include/Raychel/Render/FatPixel.h
Normal file
64
include/Raychel/Render/FatPixel.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* \file FatPixel.h
|
||||
* \author Weckyy702 (weckyy702@gmail.com)
|
||||
* \brief Header file for FatPixel class
|
||||
* \date 2022-05-01
|
||||
*
|
||||
* MIT License
|
||||
* Copyright (c) [2022] [Weckyy702 (weckyy702@gmail.com | https://github.com/Weckyy702)]
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
#ifndef RAYCHEL_FAT_PIXEL_H
|
||||
#define RAYCHEL_FAT_PIXEL_H
|
||||
|
||||
#include "RayHistogram.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace Raychel {
|
||||
|
||||
namespace details {
|
||||
template <std::size_t NumBins>
|
||||
struct FatPixel
|
||||
{
|
||||
using Histogram = RayHistogram<NumBins>;
|
||||
|
||||
FatPixel operator+(const FatPixel& other) const noexcept
|
||||
{
|
||||
return {noisy_color + other.noisy_color, histogram + other.histogram};
|
||||
}
|
||||
|
||||
template <std::convertible_to<double> T>
|
||||
FatPixel operator/(T s) const noexcept
|
||||
{
|
||||
return {noisy_color / s, histogram / s};
|
||||
}
|
||||
|
||||
color noisy_color{};
|
||||
Histogram histogram{};
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
|
||||
using FatPixel = details::FatPixel<30U>;
|
||||
|
||||
} // namespace Raychel
|
||||
|
||||
#endif //!RAYCHEL_FAT_PIXEL_H
|
||||
77
include/Raychel/Render/Framebuffer.h
Normal file
77
include/Raychel/Render/Framebuffer.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* \file Framebuffer.h
|
||||
* \author Weckyy702 (weckyy702@gmail.com)
|
||||
* \brief Header file for Framebuffer class
|
||||
* \date 2022-04-11
|
||||
*
|
||||
* MIT License
|
||||
* Copyright (c) [2022] [Weckyy702 (weckyy702@gmail.com | https://github.com/Weckyy702)]
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
#ifndef RAYCHEL_FRAMEBUFFER_H
|
||||
#define RAYCHEL_FRAMEBUFFER_H
|
||||
|
||||
#include "FatPixel.h"
|
||||
#include "Raychel/Core/Types.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace Raychel {
|
||||
|
||||
namespace details {
|
||||
template <typename Pixel>
|
||||
struct BasicFramebuffer
|
||||
{
|
||||
|
||||
constexpr Pixel& at(std::size_t x, std::size_t y)
|
||||
{
|
||||
return const_cast<Pixel&>(const_cast<const BasicFramebuffer*>(this)->at(x, y));
|
||||
}
|
||||
|
||||
constexpr const Pixel& at(std::size_t x, std::size_t y) const
|
||||
{
|
||||
RAYCHEL_ASSERT((x < size.x()) && (y < size.y()));
|
||||
|
||||
return pixel_data.at(x + (y * size.x()));
|
||||
}
|
||||
|
||||
const Size2D size{};
|
||||
std::vector<Pixel> pixel_data{};
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
constexpr auto begin(const BasicFramebuffer<T>& obj)
|
||||
{
|
||||
return obj.pixel_data.begin();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
constexpr auto end(const BasicFramebuffer<T>& obj)
|
||||
{
|
||||
return obj.pixel_data.end();
|
||||
}
|
||||
} // namespace details
|
||||
|
||||
using Framebuffer = details::BasicFramebuffer<color>;
|
||||
using FatFramebuffer = details::BasicFramebuffer<FatPixel>;
|
||||
|
||||
} // namespace Raychel
|
||||
|
||||
#endif //!RAYCHEL_FRAMEBUFFER_H
|
||||
130
include/Raychel/Render/MaterialContainer.h
Normal file
130
include/Raychel/Render/MaterialContainer.h
Normal file
@@ -0,0 +1,130 @@
|
||||
/**
|
||||
* \file MaterialContainer.h
|
||||
* \author Weckyy702 (weckyy702@gmail.com)
|
||||
* \brief Header file for MaterialContainer class
|
||||
* \date 2022-04-10
|
||||
*
|
||||
* MIT License
|
||||
* Copyright (c) [2022] [Weckyy702 (weckyy702@gmail.com | https://github.com/Weckyy702)]
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
#ifndef RAYCHEL_MATERIAL_CONTAINER_H
|
||||
#define RAYCHEL_MATERIAL_CONTAINER_H
|
||||
|
||||
#include "Materials.h"
|
||||
|
||||
#include "Raychel/Core/Types.h"
|
||||
#include "RaychelCore/Badge.h"
|
||||
#include "RaychelCore/ClassMacros.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace Raychel {
|
||||
|
||||
namespace details {
|
||||
|
||||
struct IMaterialContainerImpl
|
||||
{
|
||||
IMaterialContainerImpl() = default;
|
||||
|
||||
RAYCHEL_MAKE_NONCOPY_NONMOVE(IMaterialContainerImpl)
|
||||
|
||||
[[nodiscard]] virtual color get_surface_color_internal(const ShadingData& data) const noexcept = 0;
|
||||
|
||||
[[nodiscard]] virtual double get_material_ior_internal() const noexcept = 0;
|
||||
|
||||
virtual ~IMaterialContainerImpl() = default;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class MaterialContainerImpl final : public IMaterialContainerImpl
|
||||
{
|
||||
public:
|
||||
explicit MaterialContainerImpl(T&& object) noexcept(std::is_nothrow_move_constructible_v<T>)
|
||||
: object_{std::forward<T>(object)}
|
||||
{}
|
||||
|
||||
[[nodiscard]] color get_surface_color_internal(const ShadingData& data) const noexcept override
|
||||
{
|
||||
return get_surface_color(object_, data);
|
||||
}
|
||||
|
||||
[[nodiscard]] double get_material_ior_internal() const noexcept override
|
||||
{
|
||||
if constexpr (is_transparent_material_v<T>)
|
||||
return get_material_ior(object_);
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
[[nodiscard]] T& object() noexcept
|
||||
{
|
||||
return object_;
|
||||
}
|
||||
|
||||
[[nodiscard]] const T& object() const noexcept
|
||||
{
|
||||
return object_;
|
||||
}
|
||||
|
||||
private:
|
||||
T object_;
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
|
||||
class MaterialContainer
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
using Impl = details::MaterialContainerImpl<T>;
|
||||
|
||||
template <typename T>
|
||||
requires(!std::is_same_v<T, MaterialContainer>) explicit MaterialContainer(T&& object) noexcept(
|
||||
std::is_nothrow_move_constructible_v<T>)
|
||||
: impl_{std::make_unique<details::MaterialContainerImpl<T>>(std::forward<T>(object))}
|
||||
{}
|
||||
|
||||
RAYCHEL_MAKE_NONCOPY(MaterialContainer)
|
||||
RAYCHEL_MAKE_DEFAULT_MOVE(MaterialContainer)
|
||||
|
||||
[[nodiscard]] color get_surface_color(const ShadingData& data) const noexcept
|
||||
{
|
||||
return impl_->get_surface_color_internal(data);
|
||||
}
|
||||
|
||||
[[nodiscard]] double get_material_ior() const noexcept
|
||||
{
|
||||
return impl_->get_material_ior_internal();
|
||||
}
|
||||
|
||||
[[nodiscard]] auto* unsafe_impl() const noexcept
|
||||
{
|
||||
return impl_.get();
|
||||
}
|
||||
|
||||
~MaterialContainer() = default;
|
||||
|
||||
private:
|
||||
std::unique_ptr<details::IMaterialContainerImpl> impl_{};
|
||||
};
|
||||
|
||||
} //namespace Raychel
|
||||
|
||||
#endif //!RAYCHEL_MATERIAL_CONTAINER_H
|
||||
66
include/Raychel/Render/Materials.h
Normal file
66
include/Raychel/Render/Materials.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* \file Materials.h
|
||||
* \author Weckyy702 (weckyy702@gmail.com)
|
||||
* \brief Header file for Materials class
|
||||
* \date 2022-05-20
|
||||
*
|
||||
* MIT License
|
||||
* Copyright (c) [2022] [Weckyy702 (weckyy702@gmail.com | https://github.com/Weckyy702)]
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
#ifndef RAYCHEL_MATERIALS_H
|
||||
#define RAYCHEL_MATERIALS_H
|
||||
|
||||
#include "Raychel/Core/Types.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace Raychel {
|
||||
|
||||
struct RenderState;
|
||||
|
||||
struct ShadingData
|
||||
{
|
||||
vec3 position;
|
||||
vec3 normal;
|
||||
vec3 incoming_direction;
|
||||
|
||||
const RenderState& state;
|
||||
std::size_t recursion_depth;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct is_transparent_material : std::false_type
|
||||
{};
|
||||
|
||||
template <typename T>
|
||||
constexpr bool is_transparent_material_v = is_transparent_material<T>::value;
|
||||
|
||||
struct DeserializationErrorMaterial
|
||||
{};
|
||||
|
||||
constexpr color get_surface_color(DeserializationErrorMaterial /*unused*/, const ShadingData& /*unused*/) noexcept
|
||||
{
|
||||
return color{1, 0, 1};
|
||||
}
|
||||
|
||||
} // namespace Raychel
|
||||
|
||||
#endif //!RAYCHEL_MATERIALS_H
|
||||
153
include/Raychel/Render/RayHistogram.h
Normal file
153
include/Raychel/Render/RayHistogram.h
Normal file
@@ -0,0 +1,153 @@
|
||||
/**
|
||||
* \file RayHistogram.h
|
||||
* \author Weckyy702 (weckyy702@gmail.com)
|
||||
* \brief Header file for RayHistogram class
|
||||
* \date 2022-04-30
|
||||
*
|
||||
* MIT License
|
||||
* Copyright (c) [2022] [Weckyy702 (weckyy702@gmail.com | https://github.com/Weckyy702)]
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
#ifndef RAYCHEL_RAY_HISTOGRAM_H
|
||||
#define RAYCHEL_RAY_HISTOGRAM_H
|
||||
|
||||
#include "Raychel/Core/Types.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
namespace Raychel {
|
||||
|
||||
namespace details {
|
||||
|
||||
struct BinData
|
||||
{
|
||||
std::size_t low_bin_index{};
|
||||
double low_bin_weight{};
|
||||
|
||||
std::size_t high_bin_index{};
|
||||
double high_bin_weight{};
|
||||
};
|
||||
}; // namespace details
|
||||
|
||||
template <std::size_t NumBins>
|
||||
requires(NumBins > 2U) class RayHistogram
|
||||
{
|
||||
using BinnedChannel = std::array<double, NumBins>;
|
||||
|
||||
public:
|
||||
RayHistogram() = default;
|
||||
|
||||
void add_sample(color c) noexcept
|
||||
{
|
||||
_add_channel(red_, c.r());
|
||||
_add_channel(green_, c.g());
|
||||
_add_channel(blue_, c.b());
|
||||
}
|
||||
|
||||
const auto& red_channel() const noexcept
|
||||
{
|
||||
return red_;
|
||||
}
|
||||
|
||||
const auto& green_channel() const noexcept
|
||||
{
|
||||
return green_;
|
||||
}
|
||||
|
||||
const auto& blue_channel() const noexcept
|
||||
{
|
||||
return blue_;
|
||||
}
|
||||
|
||||
RayHistogram operator+(const RayHistogram& other) const noexcept
|
||||
{
|
||||
BinnedChannel union_red{}, union_green{}, union_blue{};
|
||||
|
||||
for (std::size_t i{}; i != NumBins; ++i) {
|
||||
union_red[i] = red_[i] + other.red_[i];
|
||||
union_green[i] = green_[i] + other.green_[i];
|
||||
union_blue[i] = blue_[i] + other.blue_[i];
|
||||
}
|
||||
|
||||
return {std::move(union_red), std::move(union_green), std::move(union_blue)};
|
||||
}
|
||||
|
||||
template <std::convertible_to<double> T>
|
||||
RayHistogram operator/(T _s) const noexcept
|
||||
{
|
||||
const auto s = static_cast<double>(_s);
|
||||
|
||||
BinnedChannel new_red{}, new_green{}, new_blue{};
|
||||
for (std::size_t i{}; i != NumBins; ++i) {
|
||||
new_red[i] = red_[i] / s;
|
||||
new_green[i] = green_[i] / s;
|
||||
new_blue[i] = blue_[i] / s;
|
||||
}
|
||||
|
||||
return {std::move(new_red), std::move(new_green), std::move(new_blue)};
|
||||
}
|
||||
|
||||
private:
|
||||
RayHistogram(BinnedChannel red, BinnedChannel green, BinnedChannel blue)
|
||||
: red_{std::move(red)}, green_{std::move(green)}, blue_{std::move(blue)}
|
||||
{}
|
||||
|
||||
static void _add_channel(BinnedChannel& channel, double value) noexcept
|
||||
{
|
||||
const auto [low_bin, low_weight, high_bin, high_weight] = _get_bin_data(value);
|
||||
channel.at(low_bin) += low_weight;
|
||||
channel.at(high_bin) += high_weight;
|
||||
}
|
||||
|
||||
static details::BinData _get_bin_data(double value) noexcept
|
||||
{
|
||||
constexpr auto max_value = 7.5;
|
||||
constexpr auto saturated_value = 2.5;
|
||||
constexpr auto fbin_factor = static_cast<double>(NumBins - 2U);
|
||||
|
||||
auto v = std::max(value, 0.0);
|
||||
v = std::pow(v, 1.0 / 2.2);
|
||||
v /= max_value;
|
||||
|
||||
v = std::min(saturated_value, v);
|
||||
|
||||
const auto fbin = v * fbin_factor;
|
||||
|
||||
const auto bin_low = static_cast<std::size_t>(fbin);
|
||||
if (bin_low < (NumBins - 2U)) {
|
||||
const auto high_weight = std::fmod(fbin, 1.0);
|
||||
const auto low_weight = 1.0 - high_weight;
|
||||
|
||||
return {bin_low, low_weight, bin_low + 1U, high_weight};
|
||||
}
|
||||
const auto high_weight = (v - 1) / (saturated_value - 1);
|
||||
const auto low_weight = 1.0 - high_weight;
|
||||
|
||||
return {NumBins - 2U, low_weight, NumBins - 1U, high_weight};
|
||||
}
|
||||
|
||||
BinnedChannel red_{};
|
||||
BinnedChannel green_{};
|
||||
BinnedChannel blue_{};
|
||||
};
|
||||
} // namespace Raychel
|
||||
|
||||
#endif //!RAYCHEL_RAY_HISTOGRAM_H
|
||||
55
include/Raychel/Render/RenderUtils.h
Normal file
55
include/Raychel/Render/RenderUtils.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* \file RenderHelper.h
|
||||
* \author Weckyy702 (weckyy702@gmail.com)
|
||||
* \brief Header file for RenderHelper class
|
||||
* \date 2022-04-12
|
||||
*
|
||||
* MIT License
|
||||
* Copyright (c) [2022] [Weckyy702 (weckyy702@gmail.com | https://github.com/Weckyy702)]
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
#ifndef RAYCHEL_RENDER_UTILS_H
|
||||
#define RAYCHEL_RENDER_UTILS_H
|
||||
|
||||
#include "Renderer.h"
|
||||
|
||||
namespace Raychel {
|
||||
|
||||
struct RefractionData
|
||||
{
|
||||
vec3 surface_point;
|
||||
vec3 incoming_direction;
|
||||
vec3 normal;
|
||||
|
||||
double material_ior;
|
||||
double ior_variation;
|
||||
|
||||
const RenderState& state;
|
||||
std::size_t recursion_depth;
|
||||
};
|
||||
|
||||
[[nodiscard]] color get_shaded_color(const RenderData& data) noexcept;
|
||||
|
||||
[[nodiscard]] color get_diffuse_lighting(const ShadingData& data) noexcept;
|
||||
|
||||
[[nodiscard]] color get_refraction(const RefractionData& data) noexcept;
|
||||
} // namespace Raychel
|
||||
|
||||
#endif //!RAYCHEL_RENDER_UTILS_H
|
||||
95
include/Raychel/Render/Renderer.h
Normal file
95
include/Raychel/Render/Renderer.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* \file Renderer.h
|
||||
* \author Weckyy702 (weckyy702@gmail.com)
|
||||
* \brief Header file for Renderer class
|
||||
* \date 2022-04-11
|
||||
*
|
||||
* MIT License
|
||||
* Copyright (c) [2022] [Weckyy702 (weckyy702@gmail.com | https://github.com/Weckyy702)]
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
#ifndef RAYCHEL_RENDERER_H
|
||||
#define RAYCHEL_RENDERER_H
|
||||
|
||||
#include "Camera.h"
|
||||
#include "Framebuffer.h"
|
||||
#include "MaterialContainer.h"
|
||||
#include "Raychel/Core/SDFContainer.h"
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
namespace Raychel {
|
||||
|
||||
struct RenderOptions
|
||||
{
|
||||
//Size of the output image
|
||||
Size2D output_size{1280, 720};
|
||||
|
||||
//Maximum number of steps until raymarching terminates
|
||||
std::size_t max_ray_steps{1'024};
|
||||
|
||||
//Maximum depth for recursive algorithms
|
||||
std::size_t max_recursion_depth{6};
|
||||
|
||||
//Maximum number of light bounces for indirect lighting
|
||||
std::size_t max_lighting_bounces{2};
|
||||
|
||||
//Number of samples per pixel for rendering. Dramatically increases render times!
|
||||
std::size_t samples_per_pixel{128};
|
||||
|
||||
//If antialiasing is used. (Low performance impact)
|
||||
bool do_aa{true};
|
||||
|
||||
//How many threads are used for rendering. If 0, the library will choose
|
||||
std::size_t thread_count{0};
|
||||
|
||||
//Maximum distance a ray can travel
|
||||
double max_ray_depth{500};
|
||||
|
||||
//Maximum distance between the ray and a surface
|
||||
double surface_epsilon{1e-6};
|
||||
//Radius used for normal calculation. Should be smaller than surface_epsilon to avoid weirdness
|
||||
double normal_epsilon{1e-12};
|
||||
//Offset along the surface normal to avoid shadow weirdness. Should be larger than surface_epsilon
|
||||
double shading_epsilon{1e-5};
|
||||
};
|
||||
|
||||
struct RenderState
|
||||
{
|
||||
const std::vector<SDFContainer>& surfaces;
|
||||
const std::vector<MaterialContainer>& materials;
|
||||
BackgroundFunction get_background{};
|
||||
RenderOptions options{};
|
||||
};
|
||||
|
||||
struct RenderData
|
||||
{
|
||||
vec3 origin, direction;
|
||||
|
||||
const RenderState& state;
|
||||
std::size_t recursion_depth;
|
||||
};
|
||||
|
||||
FatFramebuffer render_scene(const Scene& scene, const Camera& camera, const RenderOptions& options = {}) noexcept;
|
||||
|
||||
} // namespace Raychel
|
||||
|
||||
#endif //!RAYCHEL_RENDERER_H
|
||||
Reference in New Issue
Block a user