Fixed normal map conversion.

This commit is contained in:
Branimir Karadžić
2017-07-11 18:20:32 -07:00
parent e67c895d3c
commit 66b7f4c12f
2 changed files with 30 additions and 6 deletions

View File

@@ -3079,10 +3079,6 @@ namespace bimg
bx::memCopy(_dst, _src, _dstPitch*_height);
break;
case TextureFormat::RGBA8:
imageRgba8ToRgba32f(_dst, _width, _height, _width*4, _src);
break;
default:
if (isCompressed(_format) )
{
@@ -3539,7 +3535,7 @@ namespace bimg
{
for (uint8_t side = 0; side < numSides && _err->isOk(); ++side)
{
if (imageGetRawData(_imageContainer, layer*numSides + side, lod, _data, _size, mip) )
if (imageGetRawData(_imageContainer, uint16_t(layer*numSides + side), lod, _data, _size, mip) )
{
total += bx::write(_writer, mip.m_data, mip.m_size, _err);
}

View File

@@ -7,6 +7,7 @@
#include <bx/allocator.h>
#include <bx/readerwriter.h>
#include <bx/endian.h>
#include <bx/fpumath.h>
#include <bimg/decode.h>
#include <bimg/encode.h>
@@ -25,7 +26,7 @@
#include <string>
#define BIMG_TEXTUREC_VERSION_MAJOR 1
#define BIMG_TEXTUREC_VERSION_MINOR 4
#define BIMG_TEXTUREC_VERSION_MINOR 5
struct Options
{
@@ -73,6 +74,26 @@ struct Options
bool alphaTest;
};
void imageRgba32fNormalize(void* _dst, uint32_t _width, uint32_t _height, uint32_t _srcPitch, const void* _src)
{
const uint8_t* src = (const uint8_t*)_src;
uint8_t* dst = (uint8_t*)_dst;
for (uint32_t yy = 0, ystep = _srcPitch; yy < _height; ++yy, src += ystep)
{
const float* rgba = (const float*)&src[0];
for (uint32_t xx = 0; xx < _width; ++xx, rgba += 4, dst += 16)
{
float xyz[3];
xyz[0] = rgba[0];
xyz[1] = rgba[1];
xyz[2] = rgba[2];
bx::vec3Norm( (float*)dst, xyz);
}
}
}
bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData, uint32_t _inputSize, const Options& _options, bx::Error* _err)
{
BX_ERROR_SCOPE(_err);
@@ -233,6 +254,13 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
}
}
imageRgba32fNormalize(rgba
, dstMip.m_width
, dstMip.m_height
, dstMip.m_width*16
, rgba
);
bimg::imageRgba32f11to01(rgbaDst
, dstMip.m_width
, dstMip.m_height