46 const std::size_t pixel_count =
static_cast<std::size_t
>(
width_) *
height_;
56 const std::size_t pixel_count =
static_cast<std::size_t
>(
width_) *
height_;
57 for (std::size_t i = 0; i < pixel_count; ++i) {
58 const std::size_t offset = i * 4;
94 const std::size_t idx =
static_cast<std::size_t
>(pixel_y) *
width_ + pixel_x;
97 const std::size_t color_idx = idx * 4;
118 if (pixel_x >=
width_ || pixel_y >=
height_ || color.a == 0) {
121 const std::size_t idx =
static_cast<std::size_t
>(pixel_y) *
width_ + pixel_x;
123 const std::size_t color_idx = idx * 4;
124 const auto alpha_factor =
static_cast<float>(color.a) / 255.0F;
125 const auto add_r =
static_cast<uint32_t
>(
static_cast<float>(color.r) * alpha_factor);
126 const auto add_g =
static_cast<uint32_t
>(
static_cast<float>(color.g) * alpha_factor);
127 const auto add_b =
static_cast<uint32_t
>(
static_cast<float>(color.b) * alpha_factor);
130 std::min(255U,
static_cast<uint32_t
>(
color_buffer_[color_idx]) + add_r));
132 std::min(255U,
static_cast<uint32_t
>(
color_buffer_[color_idx + 1]) + add_g));
134 std::min(255U,
static_cast<uint32_t
>(
color_buffer_[color_idx + 2]) + add_b));
146 [[nodiscard]]
float getDepth(uint32_t pixel_x, uint32_t pixel_y)
const noexcept {
CPK color palette and visualization radii for atomic 3D rendering.
uint32_t height_
Definition SoftwareFramebuffer.hpp:164
bool blendAdditivePixel(uint32_t pixel_x, uint32_t pixel_y, float depth, RgbaColor color) noexcept
Performs depth-tested additive alpha blending into the color buffer without writing depth.
Definition SoftwareFramebuffer.hpp:116
std::vector< uint8_t > color_buffer_
Definition SoftwareFramebuffer.hpp:165
const std::vector< float > & depthBuffer() const noexcept
Definition SoftwareFramebuffer.hpp:160
const std::vector< uint8_t > & colorBuffer() const noexcept
Definition SoftwareFramebuffer.hpp:158
void clearDepth(float depth=1.0F) noexcept
Clears depth buffer to specified value.
Definition SoftwareFramebuffer.hpp:70
std::vector< float > depth_buffer_
Definition SoftwareFramebuffer.hpp:166
std::span< const uint8_t > colorBytes() const noexcept
Definition SoftwareFramebuffer.hpp:156
uint32_t height() const noexcept
Definition SoftwareFramebuffer.hpp:154
uint32_t width() const noexcept
Definition SoftwareFramebuffer.hpp:153
float getDepth(uint32_t pixel_x, uint32_t pixel_y) const noexcept
Reads depth value at pixel.
Definition SoftwareFramebuffer.hpp:146
bool testAndSetPixel(uint32_t pixel_x, uint32_t pixel_y, float depth, RgbaColor color) noexcept
Tests depth and writes pixel if closer than current depth.
Definition SoftwareFramebuffer.hpp:90
uint32_t width_
Definition SoftwareFramebuffer.hpp:163
SoftwareFramebuffer(uint32_t width, uint32_t height)
Constructs a framebuffer with specific pixel dimensions.
Definition SoftwareFramebuffer.hpp:36
void clear(RgbaColor color, float depth=1.0F) noexcept
Clears both color and depth buffers.
Definition SoftwareFramebuffer.hpp:77
SoftwareFramebuffer()=default
Constructs an empty framebuffer.
void clearColor(RgbaColor color) noexcept
Clears color buffer to specified RGBA color.
Definition SoftwareFramebuffer.hpp:55
void resize(uint32_t width, uint32_t height)
Resizes color and depth buffers.
Definition SoftwareFramebuffer.hpp:43
Definition Camera3D.hpp:14
8-bit RGBA color representation for vertex colors and framebuffers.
Definition ElementColors.hpp:23