Added RGBM encoding in GTC_packing #420
This commit is contained in:
@@ -451,6 +451,8 @@ namespace glm
|
||||
/// The first vector component specifies the 11 least-significant bits of the result;
|
||||
/// the last component specifies the 10 most-significant bits.
|
||||
///
|
||||
/// packF3x9_E1x5 allows encoding into RGBE / RGB9E5 format
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see vec3 unpackF3x9_E1x5(uint32 const & p)
|
||||
GLM_FUNC_DECL uint32 packF3x9_E1x5(vec3 const & v);
|
||||
@@ -460,11 +462,34 @@ namespace glm
|
||||
///
|
||||
/// The first component of the returned vector will be extracted from the least significant bits of the input;
|
||||
/// the last component will be extracted from the most significant bits.
|
||||
///
|
||||
///
|
||||
/// unpackF3x9_E1x5 allows decoding RGBE / RGB9E5 data
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see uint32 packF3x9_E1x5(vec3 const & v)
|
||||
GLM_FUNC_DECL vec3 unpackF3x9_E1x5(uint32 p);
|
||||
|
||||
/// Returns an unsigned integer vector obtained by converting the components of a floating-point vector
|
||||
/// to the 16-bit floating-point representation found in the OpenGL Specification.
|
||||
/// The first vector component specifies the 16 least-significant bits of the result;
|
||||
/// the forth component specifies the 16 most-significant bits.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see tvec3<T, P> unpackRGBM(tvec4<T, P> const & p)
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_DECL tvec4<T, P> packRGBM(tvec3<T, P> const & rgb);
|
||||
|
||||
/// Returns a floating-point vector with components obtained by reinterpreting an integer vector as 16-bit floating-point numbers and converting them to 32-bit floating-point values.
|
||||
/// The first component of the vector is obtained from the 16 least-significant bits of v;
|
||||
/// the forth component is obtained from the 16 most-significant bits of v.
|
||||
///
|
||||
/// @see gtc_packing
|
||||
/// @see tvec4<T, P> packRGBM(tvec3<float, P> const & v)
|
||||
/// @see <a href="http://www.opengl.org/registry/doc/GLSLangSpec.4.20.8.pdf">GLSL 4.20.8 specification, section 8.4 Floating-Point Pack and Unpack Functions</a>
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_DECL tvec3<T, P> unpackRGBM(tvec4<T, P> const & rgbm);
|
||||
|
||||
/// Returns an unsigned integer vector obtained by converting the components of a floating-point vector
|
||||
/// to the 16-bit floating-point representation found in the OpenGL Specification.
|
||||
/// The first vector component specifies the 16 least-significant bits of the result;
|
||||
|
||||
@@ -639,6 +639,22 @@ namespace detail
|
||||
return vec3(Unpack.data.x, Unpack.data.y, Unpack.data.z) * pow(2.0f, Unpack.data.w - 15.f - 9.f);
|
||||
}
|
||||
|
||||
// From http://graphicrants.blogspot.fr/2009/04/rgbm-color-encoding.html
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_QUALIFIER tvec4<T, P> packRGBM(tvec3<T, P> const & rgb)
|
||||
{
|
||||
tvec3<T, P> const Color(rgb * static_cast<T>(1.0 / 6.0));
|
||||
T Alpha = clamp(max(max(Color.x, Color.y), max(Color.z, static_cast<T>(1e-6))), static_cast<T>(0), static_cast<T>(1));
|
||||
Alpha = ceil(Alpha * static_cast<T>(255.0)) / static_cast<T>(255.0);
|
||||
return tvec4<T, P>(Color / Alpha, Alpha);
|
||||
}
|
||||
|
||||
template <typename T, precision P>
|
||||
GLM_FUNC_QUALIFIER tvec3<T, P> unpackRGBM(tvec4<T, P> const & rgbm)
|
||||
{
|
||||
return tvec3<T, P>(rgbm.x, rgbm.y, rgbm.z) * rgbm.w * static_cast<T>(6);
|
||||
}
|
||||
|
||||
template <precision P, template <typename, precision> class vecType>
|
||||
GLM_FUNC_QUALIFIER vecType<uint16, P> packHalf(vecType<float, P> const & v)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user