mirror of
https://github.com/bkaradzic/bimg.git
synced 2026-02-17 20:52:38 +01:00
texturec: Fixed normal map decoding.
This commit is contained in:
@@ -404,15 +404,15 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
|||||||
, bimg::TextureFormat::RGBA32F
|
, bimg::TextureFormat::RGBA32F
|
||||||
);
|
);
|
||||||
temp = BX_ALLOC(_allocator, size);
|
temp = BX_ALLOC(_allocator, size);
|
||||||
float* rgba = (float*)temp;
|
float* rgba32f = (float*)temp;
|
||||||
float* rgbaDst = (float*)BX_ALLOC(_allocator, size);
|
float* rgbaDst = (float*)BX_ALLOC(_allocator, size);
|
||||||
|
|
||||||
bimg::imageDecodeToRgba32f(_allocator
|
bimg::imageDecodeToRgba32f(_allocator
|
||||||
, rgba
|
, rgba32f
|
||||||
, mip.m_data
|
, mip.m_data
|
||||||
, dstMip.m_width
|
, mip.m_width
|
||||||
, dstMip.m_height
|
, mip.m_height
|
||||||
, dstMip.m_depth
|
, mip.m_depth
|
||||||
, dstMip.m_width*16
|
, dstMip.m_width*16
|
||||||
, mip.m_format
|
, mip.m_format
|
||||||
);
|
);
|
||||||
@@ -424,7 +424,7 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
|||||||
for (uint32_t xx = 0; xx < mip.m_width; ++xx)
|
for (uint32_t xx = 0; xx < mip.m_width; ++xx)
|
||||||
{
|
{
|
||||||
const uint32_t offset = (yy*mip.m_width + xx) * 4;
|
const uint32_t offset = (yy*mip.m_width + xx) * 4;
|
||||||
float* inout = &rgba[offset];
|
float* inout = &rgba32f[offset];
|
||||||
inout[0] = inout[0] * 2.0f - 1.0f;
|
inout[0] = inout[0] * 2.0f - 1.0f;
|
||||||
inout[1] = inout[1] * 2.0f - 1.0f;
|
inout[1] = inout[1] * 2.0f - 1.0f;
|
||||||
inout[2] = inout[2] * 2.0f - 1.0f;
|
inout[2] = inout[2] * 2.0f - 1.0f;
|
||||||
@@ -433,23 +433,26 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
imageRgba32fNormalize(rgba
|
imageRgba32fNormalize(
|
||||||
|
rgba32f
|
||||||
, dstMip.m_width
|
, dstMip.m_width
|
||||||
, dstMip.m_height
|
, dstMip.m_height
|
||||||
, dstMip.m_width*16
|
, dstMip.m_width*16
|
||||||
, rgba
|
, rgba32f
|
||||||
);
|
);
|
||||||
|
|
||||||
bimg::imageRgba32f11to01(rgbaDst
|
bimg::imageRgba32f11to01(
|
||||||
|
rgbaDst
|
||||||
, dstMip.m_width
|
, dstMip.m_width
|
||||||
, dstMip.m_height
|
, dstMip.m_height
|
||||||
, dstMip.m_depth
|
, dstMip.m_depth
|
||||||
, dstMip.m_width*16
|
, dstMip.m_width*16
|
||||||
, rgba
|
, rgba32f
|
||||||
);
|
);
|
||||||
|
|
||||||
bimg::Quality::Enum nmapQuality = bimg::Quality::Enum(_options.quality + bimg::Quality::NormalMapDefault);
|
bimg::Quality::Enum nmapQuality = bimg::Quality::Enum(_options.quality + bimg::Quality::NormalMapDefault);
|
||||||
bimg::imageEncodeFromRgba32f(_allocator
|
bimg::imageEncodeFromRgba32f(
|
||||||
|
_allocator
|
||||||
, dstData
|
, dstData
|
||||||
, rgbaDst
|
, rgbaDst
|
||||||
, dstMip.m_width
|
, dstMip.m_width
|
||||||
@@ -462,26 +465,29 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
|||||||
|
|
||||||
for (uint8_t lod = 1; lod < numMips && _err->isOk(); ++lod)
|
for (uint8_t lod = 1; lod < numMips && _err->isOk(); ++lod)
|
||||||
{
|
{
|
||||||
bimg::imageRgba32fDownsample2x2NormalMap(rgba
|
bimg::imageRgba32fDownsample2x2NormalMap(
|
||||||
|
rgba32f
|
||||||
, dstMip.m_width
|
, dstMip.m_width
|
||||||
, dstMip.m_height
|
, dstMip.m_height
|
||||||
, dstMip.m_width*16
|
, dstMip.m_width*16
|
||||||
, bx::strideAlign(dstMip.m_width/2, blockWidth)*16
|
, bx::strideAlign(dstMip.m_width/2, blockWidth)*16
|
||||||
, rgba
|
, rgba32f
|
||||||
);
|
);
|
||||||
|
|
||||||
bimg::imageRgba32f11to01(rgbaDst
|
bimg::imageRgba32f11to01(
|
||||||
|
rgbaDst
|
||||||
, dstMip.m_width
|
, dstMip.m_width
|
||||||
, dstMip.m_height
|
, dstMip.m_height
|
||||||
, dstMip.m_depth
|
, dstMip.m_depth
|
||||||
, dstMip.m_width*16
|
, dstMip.m_width*16
|
||||||
, rgba
|
, rgba32f
|
||||||
);
|
);
|
||||||
|
|
||||||
bimg::imageGetRawData(*output, side, lod, output->m_data, output->m_size, dstMip);
|
bimg::imageGetRawData(*output, side, lod, output->m_data, output->m_size, dstMip);
|
||||||
dstData = const_cast<uint8_t*>(dstMip.m_data);
|
dstData = const_cast<uint8_t*>(dstMip.m_data);
|
||||||
|
|
||||||
bimg::imageEncodeFromRgba32f(_allocator
|
bimg::imageEncodeFromRgba32f(
|
||||||
|
_allocator
|
||||||
, dstData
|
, dstData
|
||||||
, rgbaDst
|
, rgbaDst
|
||||||
, dstMip.m_width
|
, dstMip.m_width
|
||||||
@@ -515,13 +521,14 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
|||||||
float* rgba32f = (float*)temp;
|
float* rgba32f = (float*)temp;
|
||||||
float* rgbaDst = (float*)BX_ALLOC(_allocator, size);
|
float* rgbaDst = (float*)BX_ALLOC(_allocator, size);
|
||||||
|
|
||||||
bimg::imageDecodeToRgba32f(_allocator
|
bimg::imageDecodeToRgba32f(
|
||||||
|
_allocator
|
||||||
, rgba32f
|
, rgba32f
|
||||||
, mip.m_data
|
, mip.m_data
|
||||||
, mip.m_width
|
, mip.m_width
|
||||||
, mip.m_height
|
, mip.m_height
|
||||||
, mip.m_depth
|
, mip.m_depth
|
||||||
, mip.m_width*16
|
, dstMip.m_width*16
|
||||||
, mip.m_format
|
, mip.m_format
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -536,7 +543,8 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bimg::imageEncodeFromRgba32f(_allocator
|
bimg::imageEncodeFromRgba32f(
|
||||||
|
_allocator
|
||||||
, dstData
|
, dstData
|
||||||
, rgba32f
|
, rgba32f
|
||||||
, dstMip.m_width
|
, dstMip.m_width
|
||||||
@@ -560,7 +568,8 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
|||||||
|
|
||||||
for (uint8_t lod = 1; lod < numMips && _err->isOk(); ++lod)
|
for (uint8_t lod = 1; lod < numMips && _err->isOk(); ++lod)
|
||||||
{
|
{
|
||||||
bimg::imageRgba32fLinearDownsample2x2(rgba32f
|
bimg::imageRgba32fLinearDownsample2x2(
|
||||||
|
rgba32f
|
||||||
, dstMip.m_width
|
, dstMip.m_width
|
||||||
, dstMip.m_height
|
, dstMip.m_height
|
||||||
, dstMip.m_depth
|
, dstMip.m_depth
|
||||||
@@ -582,7 +591,8 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
|||||||
bimg::imageGetRawData(*output, side, lod, output->m_data, output->m_size, dstMip);
|
bimg::imageGetRawData(*output, side, lod, output->m_data, output->m_size, dstMip);
|
||||||
dstData = const_cast<uint8_t*>(dstMip.m_data);
|
dstData = const_cast<uint8_t*>(dstMip.m_data);
|
||||||
|
|
||||||
bimg::imageRgba32fToGamma(rgbaDst
|
bimg::imageRgba32fToGamma(
|
||||||
|
rgbaDst
|
||||||
, mip.m_width
|
, mip.m_width
|
||||||
, mip.m_height
|
, mip.m_height
|
||||||
, mip.m_depth
|
, mip.m_depth
|
||||||
@@ -590,7 +600,8 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
|||||||
, rgba32f
|
, rgba32f
|
||||||
);
|
);
|
||||||
|
|
||||||
bimg::imageEncodeFromRgba32f(_allocator
|
bimg::imageEncodeFromRgba32f(
|
||||||
|
_allocator
|
||||||
, dstData
|
, dstData
|
||||||
, rgbaDst
|
, rgbaDst
|
||||||
, dstMip.m_width
|
, dstMip.m_width
|
||||||
@@ -621,7 +632,8 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
|||||||
temp = BX_ALLOC(_allocator, size);
|
temp = BX_ALLOC(_allocator, size);
|
||||||
uint8_t* r8 = (uint8_t*)temp;
|
uint8_t* r8 = (uint8_t*)temp;
|
||||||
|
|
||||||
bimg::imageDecodeToR8(_allocator
|
bimg::imageDecodeToR8(
|
||||||
|
_allocator
|
||||||
, r8
|
, r8
|
||||||
, mip.m_data
|
, mip.m_data
|
||||||
, mip.m_width
|
, mip.m_width
|
||||||
@@ -644,7 +656,8 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
|||||||
|
|
||||||
if (_options.mips) {
|
if (_options.mips) {
|
||||||
const float alphaRef = 0.5f;
|
const float alphaRef = 0.5f;
|
||||||
float coverage = bimg::imageAlphaTestCoverage(bimg::TextureFormat::A8
|
float coverage = bimg::imageAlphaTestCoverage(
|
||||||
|
bimg::TextureFormat::A8
|
||||||
, mip.m_width
|
, mip.m_width
|
||||||
, mip.m_height
|
, mip.m_height
|
||||||
, mip.m_width
|
, mip.m_width
|
||||||
@@ -676,7 +689,8 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
|||||||
);
|
);
|
||||||
|
|
||||||
for (uint8_t lod = 1; lod < numMips && _err->isOk(); ++lod) {
|
for (uint8_t lod = 1; lod < numMips && _err->isOk(); ++lod) {
|
||||||
bimg::imageRgba8Downsample2x2(rgba
|
bimg::imageRgba8Downsample2x2(
|
||||||
|
rgba
|
||||||
, dstMip.m_width
|
, dstMip.m_width
|
||||||
, dstMip.m_height
|
, dstMip.m_height
|
||||||
, dstMip.m_depth
|
, dstMip.m_depth
|
||||||
@@ -690,7 +704,8 @@ bimg::ImageContainer* convert(bx::AllocatorI* _allocator, const void* _inputData
|
|||||||
uint32_t upsample = 1 << lod;
|
uint32_t upsample = 1 << lod;
|
||||||
uint32_t destWidth = dstMip.m_width / 2;
|
uint32_t destWidth = dstMip.m_width / 2;
|
||||||
uint32_t destHeight = dstMip.m_height / 2;
|
uint32_t destHeight = dstMip.m_height / 2;
|
||||||
bimg::imageScaleAlphaToCoverage(bimg::TextureFormat::RGBA8
|
bimg::imageScaleAlphaToCoverage(
|
||||||
|
bimg::TextureFormat::RGBA8
|
||||||
, destWidth
|
, destWidth
|
||||||
, destHeight
|
, destHeight
|
||||||
, destWidth * 4
|
, destWidth * 4
|
||||||
|
|||||||
Reference in New Issue
Block a user