2015-03-24 19:14:49 +00:00
|
|
|
|
// This code is in the public domain -- Ignacio Casta<74>o <castano@gmail.com>
|
|
|
|
|
|
|
|
|
|
#include "PackedFloat.h"
|
|
|
|
|
#include "Vector.inl"
|
|
|
|
|
#include "ftoi.h"
|
|
|
|
|
|
|
|
|
|
using namespace nv;
|
|
|
|
|
|
|
|
|
|
Vector3 nv::rgb9e5_to_vector3(FloatRGB9E5 v) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FloatRGB9E5 nv::vector3_to_rgb9e5(const Vector3 & v) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float nv::float11_to_float32(uint v) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float nv::float10_to_float32(uint v) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vector3 nv::r11g11b10_to_vector3(FloatR11G11B10 v) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FloatR11G11B10 nv::vector3_to_r11g11b10(const Vector3 & v) {
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-08 02:46:35 +00:00
|
|
|
|
// Implementation based on on:
|
|
|
|
|
// https://cbloomrants.blogspot.com/2020/06/widespread-error-in-radiance-hdr-rgbe.html
|
2015-03-24 19:14:49 +00:00
|
|
|
|
FloatRGBE8 nv::vector3_to_rgbe8(const Vector3 & v) {
|
|
|
|
|
|
|
|
|
|
float m = max3(v.x, v.y, v.z);
|
|
|
|
|
|
|
|
|
|
FloatRGBE8 rgbe;
|
|
|
|
|
|
2020-06-08 02:46:35 +00:00
|
|
|
|
if (m < 1e-32f) {
|
|
|
|
|
// Exponent byte = 0 is a special encoding that makes RGB output = 0
|
2015-03-24 19:14:49 +00:00
|
|
|
|
rgbe.v = 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
int e;
|
2020-06-08 02:46:35 +00:00
|
|
|
|
frexpf(m, &e);
|
|
|
|
|
float scale = ldexpf(1.0f, -exponent + 8);
|
|
|
|
|
rgbe.r = U8(v.x * scale);
|
|
|
|
|
rgbe.g = U8(v.y * scale);
|
|
|
|
|
rgbe.b = U8(v.z * scale);
|
2015-03-24 19:14:49 +00:00
|
|
|
|
rgbe.e = U8(e + 128);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rgbe;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Vector3 nv::rgbe8_to_vector3(FloatRGBE8 v) {
|
|
|
|
|
if (v.e != 0) {
|
2020-06-08 02:46:35 +00:00
|
|
|
|
float scale = ldexpf(1.0f, (int)v.e-128+8); // +8 to divide by 256.
|
|
|
|
|
return scale * Vector3(float(v.r + 0.5f), float(v.g + 0.5f), float(v.b + 0.5f));
|
2015-03-24 19:14:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Vector3(0);
|
|
|
|
|
}
|
|
|
|
|
|