Skip to content

Commit a7c0b4c

Browse files
upstream from ditt : fix normalmap format delivery issue
normalmaps are usually encoded in [0,255] UNORM then decoded via 2x-1 therefore there's no way to express a 0.0, meaning 127 got interpreted as (0.003,-0.003,1.0), added an epsilon to produce 0 len normals.
1 parent dcc8363 commit a7c0b4c

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

include/nbl/asset/filters/CCopyImageFilter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class CCopyImageFilter : public CImageFilter<CCopyImageFilter>, public CMatchedS
4949
return false;
5050

5151
return getFormatClass(state->inImage->getCreationParameters().format)==getFormatClass(state->outImage->getCreationParameters().format);
52-
return true;
5352
}
5453

5554
template<class ExecutionPolicy>

include/nbl/asset/filters/CNormalMapToDerivativeFilter.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,22 @@ namespace nbl::asset
2222
*/
2323
struct NormalMapToDerivativeMapSwizzle
2424
{
25+
// since most normalmaps are supplied in RG8_UNORM
26+
double zeroEpsilon = 1.0/255.0;
27+
2528
template<typename InT, typename OutT>
2629
void operator()(const InT* in, OutT* out) const
2730
{
2831
const auto* _in = reinterpret_cast<const std::conditional_t<std::is_void_v<InT>,uint64_t,InT>*>(in);
2932
auto* _out = reinterpret_cast<std::conditional_t<std::is_void_v<OutT>,uint64_t,OutT>*>(out);
3033
const auto xDecode = _in[0]*2.f-1.f;
3134
const auto yDecode = _in[1]*2.f-1.f;
35+
// TODO: a template parameter to decide if Z is in [0,1] or [-1,1]
3236
const auto zDecode = _in[2]*2.f-1.f;
33-
_out[0] = -xDecode/zDecode;
37+
// because normalmaps are supplied in UNORM formats, there's no true zero
38+
_out[0] = core::abs(xDecode)>zeroEpsilon ? (-xDecode/zDecode):0.f;
3439
// scanlines go from top down, so Y component is in reverse
35-
_out[1] = yDecode/zDecode;
40+
_out[1] = core::abs(yDecode)>zeroEpsilon ? (yDecode/zDecode):0.f;
3641
}
3742
};
3843

include/nbl/asset/utils/CDerivativeMapCreator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef __NBL_I_DERIVATIVE_MAP_CREATOR_H_INCLUDED__
2-
#define __NBL_I_DERIVATIVE_MAP_CREATOR_H_INCLUDED__
1+
#ifndef _NBL_I_DERIVATIVE_MAP_CREATOR_H_INCLUDED_
2+
#define _NBL_I_DERIVATIVE_MAP_CREATOR_H_INCLUDED_
33

44
#include "nbl/asset/ICPUImage.h"
55
#include "nbl/asset/ICPUImageView.h"

0 commit comments

Comments
 (0)