Merge changes from The Witness.
This commit is contained in:
61
src/nvmath/PackedFloat.cpp
Executable file
61
src/nvmath/PackedFloat.cpp
Executable file
@ -0,0 +1,61 @@
|
||||
// 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) {
|
||||
}
|
||||
|
||||
// These are based on:
|
||||
// http://www.graphics.cornell.edu/~bjw/rgbe/rgbe.c
|
||||
// While this may not be the best way to encode/decode RGBE8, I'm not making any changes to maintain compatibility.
|
||||
FloatRGBE8 nv::vector3_to_rgbe8(const Vector3 & v) {
|
||||
|
||||
float m = max3(v.x, v.y, v.z);
|
||||
|
||||
FloatRGBE8 rgbe;
|
||||
|
||||
if (m < 1e-32) {
|
||||
rgbe.v = 0;
|
||||
}
|
||||
else {
|
||||
int e;
|
||||
float scale = frexpf(m, &e) * 256.0f / m;
|
||||
rgbe.r = U8(ftoi_round(v.x * scale));
|
||||
rgbe.g = U8(ftoi_round(v.y * scale));
|
||||
rgbe.b = U8(ftoi_round(v.z * scale));
|
||||
rgbe.e = U8(e + 128);
|
||||
}
|
||||
|
||||
return rgbe;
|
||||
}
|
||||
|
||||
|
||||
Vector3 nv::rgbe8_to_vector3(FloatRGBE8 v) {
|
||||
if (v.e != 0) {
|
||||
float scale = ldexpf(1.0f, v.e-(int)(128+8)); // +8 to divide by 256. @@ Shouldn't we divide by 255 instead?
|
||||
return scale * Vector3(float(v.r), float(v.g), float(v.b));
|
||||
}
|
||||
|
||||
return Vector3(0);
|
||||
}
|
||||
|
79
src/nvmath/PackedFloat.h
Executable file
79
src/nvmath/PackedFloat.h
Executable file
@ -0,0 +1,79 @@
|
||||
// This code is in the public domain -- castano@gmail.com
|
||||
|
||||
#pragma once
|
||||
#ifndef NV_MATH_PACKEDFLOAT_H
|
||||
#define NV_MATH_PACKEDFLOAT_H
|
||||
|
||||
#include "nvmath.h"
|
||||
#include "Vector.h"
|
||||
|
||||
namespace nv
|
||||
{
|
||||
|
||||
union FloatRGB9E5 {
|
||||
uint32 v;
|
||||
struct {
|
||||
#if NV_BIG_ENDIAN
|
||||
uint32 e : 5;
|
||||
uint32 zm : 9;
|
||||
uint32 ym : 9;
|
||||
uint32 xm : 9;
|
||||
#else
|
||||
uint32 xm : 9;
|
||||
uint32 ym : 9;
|
||||
uint32 zm : 9;
|
||||
uint32 e : 5;
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
union FloatR11G11B10 {
|
||||
uint32 v;
|
||||
struct {
|
||||
#if NV_BIG_ENDIAN
|
||||
uint32 ze : 5;
|
||||
uint32 zm : 5;
|
||||
uint32 ye : 5;
|
||||
uint32 ym : 6;
|
||||
uint32 xe : 5;
|
||||
uint32 xm : 6;
|
||||
#else
|
||||
uint32 xm : 6;
|
||||
uint32 xe : 5;
|
||||
uint32 ym : 6;
|
||||
uint32 ye : 5;
|
||||
uint32 zm : 5;
|
||||
uint32 ze : 5;
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
union FloatRGBE8 {
|
||||
uint32 v;
|
||||
struct {
|
||||
#if NV_LITTLE_ENDIAN
|
||||
uint8 r, g, b, e;
|
||||
#else
|
||||
uint8 e: 8;
|
||||
uint8 b: 8;
|
||||
uint8 g: 8;
|
||||
uint8 r: 8;
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
NVMATH_API Vector3 rgb9e5_to_vector3(FloatRGB9E5 v);
|
||||
NVMATH_API FloatRGB9E5 vector3_to_rgb9e5(const Vector3 & v);
|
||||
|
||||
NVMATH_API float float11_to_float32(uint v);
|
||||
NVMATH_API float float10_to_float32(uint v);
|
||||
|
||||
NVMATH_API Vector3 r11g11b10_to_vector3(FloatR11G11B10 v);
|
||||
NVMATH_API FloatR11G11B10 vector3_to_r11g11b10(const Vector3 & v);
|
||||
|
||||
NVMATH_API Vector3 rgbe8_to_vector3(FloatRGBE8 v);
|
||||
NVMATH_API FloatRGBE8 vector3_to_rgbe8(const Vector3 & v);
|
||||
|
||||
} // nv
|
||||
|
||||
#endif // NV_MATH_PACKEDFLOAT_H
|
@ -2,29 +2,6 @@
|
||||
|
||||
#include "Vector.h" // Vector3, Vector4
|
||||
|
||||
// Set some reasonable defaults.
|
||||
#ifndef NV_USE_ALTIVEC
|
||||
# define NV_USE_ALTIVEC NV_CPU_PPC
|
||||
//# define NV_USE_ALTIVEC defined(__VEC__)
|
||||
#endif
|
||||
|
||||
#ifndef NV_USE_SSE
|
||||
# if NV_CPU_X86 || NV_CPU_X86_64
|
||||
# define NV_USE_SSE 2
|
||||
# endif
|
||||
# if defined(__SSE2__)
|
||||
# define NV_USE_SSE 2
|
||||
# elif defined(__SSE__)
|
||||
# define NV_USE_SSE 1
|
||||
# else
|
||||
# define NV_USE_SSE 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// Internally set NV_USE_SIMD when either altivec or sse is available.
|
||||
#if NV_USE_ALTIVEC && NV_USE_SSE
|
||||
# error "Cannot enable both altivec and sse!"
|
||||
#endif
|
||||
|
||||
#if NV_USE_ALTIVEC
|
||||
# include "SimdVector_VE.h"
|
||||
|
@ -283,6 +283,49 @@ namespace nv
|
||||
f.value = x;
|
||||
return (f.field.biasedexponent - 127);
|
||||
}
|
||||
|
||||
|
||||
// FloatRGB9E5
|
||||
union Float3SE {
|
||||
uint32 v;
|
||||
struct {
|
||||
#if NV_BIG_ENDIAN
|
||||
uint32 e : 5;
|
||||
uint32 zm : 9;
|
||||
uint32 ym : 9;
|
||||
uint32 xm : 9;
|
||||
#else
|
||||
uint32 xm : 9;
|
||||
uint32 ym : 9;
|
||||
uint32 zm : 9;
|
||||
uint32 e : 5;
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
// FloatR11G11B10
|
||||
union Float3PK {
|
||||
uint32 v;
|
||||
struct {
|
||||
#if NV_BIG_ENDIAN
|
||||
uint32 ze : 5;
|
||||
uint32 zm : 5;
|
||||
uint32 ye : 5;
|
||||
uint32 ym : 6;
|
||||
uint32 xe : 5;
|
||||
uint32 xm : 6;
|
||||
#else
|
||||
uint32 xm : 6;
|
||||
uint32 xe : 5;
|
||||
uint32 ym : 6;
|
||||
uint32 ye : 5;
|
||||
uint32 zm : 5;
|
||||
uint32 ze : 5;
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
} // nv
|
||||
|
||||
#endif // NV_MATH_H
|
||||
|
Reference in New Issue
Block a user