Skip to content

Commit 9ce4b8e

Browse files
VT simplification 1
1 parent d91717e commit 9ce4b8e

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

include/nbl/builtin/glsl/virtual_texturing/impl_functions.glsl

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,21 +112,36 @@ vec4 nbl_glsl_vTextureGrad_impl(in uint formatID, in vec3 virtualUV, in mat2 dOr
112112
#else
113113
LoD *= 0.5;
114114
#endif
115+
LoD += 5.f;
115116
// WARNING: LoD_high will round up when LoD negative, its not a floor
116117
int LoD_high = int(LoD);
117118

118-
// are we performing minification
119-
bool positiveLoD = LoD>0.0;
120-
// magnification samples LoD 0, else clip to max representable in VT
121-
int clippedLoD = positiveLoD ? min(LoD_high,int(originalMaxFullMip)-1):0; // originalMaxFullMip is always -1 in case of no miplevel taking at least 1 full page
122-
clippedLoD = originalMaxFullMip<1u ? 0 : clippedLoD;
119+
bool haveToDoTrilinear = false; // have to do trilinear only if doing minification AND larger than 1x1 footprint
120+
int levelInTail = 0;
121+
int clippedLoD = 0;
122+
if (LoD>0.f) // are we performing minification
123+
{
124+
const bool bbbb = LoD_high>=originalMaxFullMip;
125+
// clip to max representable in VT, originalMaxFullMip is always -1 in case of no miplevel taking at least 1 full page
126+
clippedLoD = bbbb ? (int(max(originalMaxFullMip,1u))-1):LoD_high;
123127

124-
// if minification is being performaed then get tail position
125-
int levelInTail = LoD_high-clippedLoD;
126-
// have to do trilinear only if doing minification AND larger than 1x1 footprint
127-
bool haveToDoTrilinear = levelInTail<int(_NBL_VT_IMPL_PAGE_SZ_LOG2) && positiveLoD;
128-
levelInTail = haveToDoTrilinear ? levelInTail:(positiveLoD ? int(_NBL_VT_IMPL_PAGE_SZ_LOG2):0);
129-
levelInTail += originalMaxFullMip<1u ? 1 : 0;
128+
if (bbbb)
129+
{
130+
// if minification is being performaed then get tail position
131+
levelInTail = LoD_high-clippedLoD;
132+
// have to do trilinear only if doing minification AND larger than 1x1 footprint
133+
haveToDoTrilinear = LoD_high-clippedLoD<int(_NBL_VT_IMPL_PAGE_SZ_LOG2);
134+
levelInTail = haveToDoTrilinear ? levelInTail:int(_NBL_VT_IMPL_PAGE_SZ_LOG2);
135+
levelInTail += originalMaxFullMip!=0u ? 0:1;
136+
}
137+
else
138+
{
139+
levelInTail += originalMaxFullMip!=0u ? 0:1;
140+
haveToDoTrilinear = true;
141+
}
142+
}
143+
else
144+
levelInTail = originalMaxFullMip!=0u ? 0:1;
130145

131146
// get the higher resolution mip-map level
132147
vec3 hiPhysCoord = nbl_glsl_vTexture_helper(formatID,virtualUV,clippedLoD,levelInTail);

0 commit comments

Comments
 (0)