27template<
class ReaderType>
30 using PackedFloat = std::array<uint8_t, 3>;
31 using PackedFloat3 = std::array<PackedFloat, 3>;
33 if (!reader.read(packed)) {
38 fixed[i] = packed[i][0];
39 fixed[i] |= packed[i][1] << 8;
40 fixed[i] |= packed[i][2] << 16;
41 fixed[i] |= (fixed[i] & 0x800000) ? 0xff000000 : 0;
49 return std::log(
x / (1.0f -
x));
54template<
class ReaderType>
56 const int fractional_bits,
64 BLI_assert(fractional_bits >= 0 && fractional_bits < 24);
65 const float scale = 1.0f / (1 << fractional_bits);
76template<
class ReaderType>
79 for (
float4 &base : radiance_base) {
81 if (!reader.read(alpha)) {
93 base.w =
float(alpha) / 255.0f;
99template<
class ReaderType>
106 constexpr float COLOR_SCALE = 0.15f;
107 const float INV_COLOR_SCALE = 1.0f / COLOR_SCALE;
109 for (
float4 &base : radiance_base) {
110 std::array<uint8_t, 3> color_buffer;
111 if (!reader.read_buffer(color_buffer)) {
114 base.x = ((color_buffer[0] / 255.0f) - 0.5f) * INV_COLOR_SCALE;
115 base.y = ((color_buffer[1] / 255.0f) - 0.5f) * INV_COLOR_SCALE;
116 base.z = ((color_buffer[2] / 255.0f) - 0.5f) * INV_COLOR_SCALE;
122template<
class ReaderType>
130 std::array<uint8_t, 3> encoded;
131 if (!reader.read_buffer(encoded)) {
134 scale =
float3(encoded[0], encoded[1], encoded[2]) / 16.0f - 10.0f;
140template<
class ReaderType>
152 std::array<uint8_t, 3> packed;
153 if (!reader.read_buffer(packed)) {
157 const float3 first3 =
float3(packed[0], packed[1], packed[2]) / 127.5f - 1.0f;
158 rotation.w = std::sqrt(std::max(0.0f, 1.0f -
math::dot(first3, first3)));
159 rotation.x = first3.x;
160 rotation.y = first3.y;
161 rotation.z = first3.z;
174 constexpr uint32_t COMPONENT_MASK = (1 << 9) - 1;
177 std::array<uint8_t, 4> packed_bytes;
178 if (!reader.read_buffer(packed_bytes)) {
181 float spz_rotation[4];
182 uint32_t packed = packed_bytes[0] + (packed_bytes[1] << 8) + (packed_bytes[2] << 16) +
183 (packed_bytes[3] << 24);
184 const int largest_index = packed >> 30;
186 for (
int i = 3; i >= 0; --i) {
187 if (i == largest_index) {
190 const uint32_t mag = packed & COMPONENT_MASK;
191 const float sign = ((packed >> 9) & 0x1) == 1 ? -1.0f : 1.0f;
193 sum_sq += spz_rotation[i] * spz_rotation[i];
194 packed = packed >> 10;
196 spz_rotation[largest_index] =
sqrt(
math::max(1.0f - sum_sq, 0.0f));
199 spz_rotation[3], spz_rotation[0], spz_rotation[1], spz_rotation[2]);
207template<
class ReaderType>
221 const int64_t num_points = sh[0].size();
222 const int num_coefficients = sh.size();
226 for (
int64_t i = 0; i < num_points; ++i) {
227 if (!reader.read_buffer(packed_coefficients)) {
230 for (
int j = 0; j < num_coefficients; ++j) {
231 const float3 coefficients(packed_coefficients[3 * j + 0],
232 packed_coefficients[3 * j + 1],
233 packed_coefficients[3 * j + 2]);
234 sh[j][i] = (coefficients - 128.0f) / 128.0f;
float3x3 scale(float3x3 mat, float2 scale)
float inv_sigmoid(const float x)
bool read_single_position_as_fixed(ReaderType &reader, int3 &fixed)
bool read_sh(ReaderType &reader, const Span< MutableSpan< float3 > > sh)
bool read_positions(ReaderType &reader, const int fractional_bits, const MutableSpan< float3 > positions)
void convert_axis_to_blender(const MutableSpan< float3 > positions, const MutableSpan< math::Quaternion > rotations, const Span< MutableSpan< float3 > > sh_attrs)
bool read_colors(ReaderType &reader, const MutableSpan< float4 > radiance_base)
bool read_alphas(ReaderType &reader, const MutableSpan< float4 > radiance_base)
bool read_scales(ReaderType &reader, const MutableSpan< float3 > scales)
bool read_rotations(ReaderType &reader, const int version, const MutableSpan< math::Quaternion > rotations)
QuaternionBase< float > Quaternion
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
T max(const T &a, const T &b)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
VecBase< float, 4 > float4
VecBase< int32_t, 3 > int3
VecBase< float, 3 > float3
constexpr void unroll(Fn fn)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
static float decode_opacity(const float opacity)
static float3 decode_scale(const float3 scale)