Fix display of 3D texture slices when linear sampling

* When displaying mip 0 of a texture at less than 100% zoom we linear sampling,
  but we don't want to linear sample across slices. Adding a half pixel offset
  in z ensures we sample precisely on the slice itself.
This commit is contained in:
baldurk
2021-01-20 17:15:34 +00:00
parent 309a08373b
commit 20d8ae2dcf
13 changed files with 541 additions and 50 deletions
+3 -3
View File
@@ -104,7 +104,7 @@ uvec4 SampleTextureUInt4(int type, vec2 pos, float slice, int mipLevel, int samp
}
else // if (type == RESTYPE_TEX3D)
{
col = texelFetch(texUInt3D, ivec3(pos * texRes.xy, slice + 0.001f), mipLevel);
col = texelFetch(texUInt3D, ivec3(pos * texRes.xy, slice), mipLevel);
}
return col;
@@ -195,7 +195,7 @@ ivec4 SampleTextureSInt4(int type, vec2 pos, float slice, int mipLevel, int samp
}
else // if (type == RESTYPE_TEX3D)
{
col = texelFetch(texSInt3D, ivec3(pos * texRes.xy, slice + 0.001f), mipLevel);
col = texelFetch(texSInt3D, ivec3(pos * texRes.xy, slice), mipLevel);
}
return col;
@@ -377,7 +377,7 @@ vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int samp
}
else if(type == RESTYPE_TEX3D)
{
col = textureLod(tex3D, vec3(pos, (slice + 0.001f) / texRes.z), float(mipLevel));
col = textureLod(tex3D, vec3(pos, slice / texRes.z), float(mipLevel));
}
else if(type == RESTYPE_TEXCUBE)
{
+3 -3
View File
@@ -109,7 +109,7 @@ uvec4 SampleTextureUInt4(int type, vec2 pos, float slice, int mipLevel, int samp
}
else // if (type == RESTYPE_TEX3D)
{
col = texelFetch(texUInt3D, ivec3(pos * texRes.xy, slice + 0.001f), mipLevel);
col = texelFetch(texUInt3D, ivec3(pos * texRes.xy, slice), mipLevel);
}
return col;
@@ -196,7 +196,7 @@ ivec4 SampleTextureSInt4(int type, vec2 pos, float slice, int mipLevel, int samp
}
else // if (type == RESTYPE_TEX3D)
{
col = texelFetch(texSInt3D, ivec3(pos * texRes.xy, slice + 0.001f), mipLevel);
col = texelFetch(texSInt3D, ivec3(pos * texRes.xy, slice), mipLevel);
}
return col;
@@ -376,7 +376,7 @@ vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int samp
}
else if(type == RESTYPE_TEX3D)
{
col = textureLod(tex3D, vec3(pos, (slice + 0.001f) / texRes.z), float(mipLevel));
col = textureLod(tex3D, vec3(pos, slice / texRes.z), float(mipLevel));
}
else if(type == RESTYPE_TEXCUBE)
{
+3 -3
View File
@@ -65,7 +65,7 @@ vec4 SampleTextureFloat4(int type, vec2 pos, float slice, int mipLevel, int samp
}
else if(type == RESTYPE_TEX3D)
{
col = textureLod(tex3D, vec3(pos, (slice + 0.001f) / texRes.z), float(mipLevel));
col = textureLod(tex3D, vec3(pos, slice / texRes.z), float(mipLevel));
}
else if(type == RESTYPE_TEX2DMS)
{
@@ -196,7 +196,7 @@ uvec4 SampleTextureUInt4(int type, vec2 pos, float slice, int mipLevel, int samp
}
else if(type == RESTYPE_TEX3D)
{
col = texelFetch(texUInt3D, ivec3(pos * texRes.xy, slice + 0.001f), mipLevel);
col = texelFetch(texUInt3D, ivec3(pos * texRes.xy, slice), mipLevel);
}
else if(type == RESTYPE_TEX2DMS)
{
@@ -251,7 +251,7 @@ ivec4 SampleTextureSInt4(int type, vec2 pos, float slice, int mipLevel, int samp
}
else if(type == RESTYPE_TEX3D)
{
col = texelFetch(texSInt3D, ivec3(pos * texRes.xy, slice + 0.001f), mipLevel);
col = texelFetch(texSInt3D, ivec3(pos * texRes.xy, slice), mipLevel);
}
else if(type == RESTYPE_TEX2DMS)
{
+4 -5
View File
@@ -56,7 +56,7 @@ uint4 SampleTextureUInt4(uint type, float2 uv, float slice, float mip, int sampl
if(type == RESTYPE_TEX1D)
col = texDisplayUIntTex1DArray.Load(int3(uv.x * texRes.x, slice, mip));
else if(type == RESTYPE_TEX3D)
col = texDisplayUIntTex3D.Load(int4(uv.xy * texRes.xy, slice + 0.001f, mip));
col = texDisplayUIntTex3D.Load(int4(uv.xy * texRes.xy, slice, mip));
else if(type == RESTYPE_TEX2D)
col = texDisplayUIntTex2DArray.Load(int4(uv.xy * texRes.xy, slice, mip));
else if(type == RESTYPE_TEX2D_MS)
@@ -76,7 +76,7 @@ int4 SampleTextureInt4(uint type, float2 uv, float slice, float mip, int sample,
if(type == RESTYPE_TEX1D)
col = texDisplayIntTex1DArray.Load(int3(uv.x * texRes.x, slice, mip));
else if(type == RESTYPE_TEX3D)
col = texDisplayIntTex3D.Load(int4(uv.xy * texRes.xy, slice + 0.001f, mip));
col = texDisplayIntTex3D.Load(int4(uv.xy * texRes.xy, slice, mip));
else if(type == RESTYPE_TEX2D)
col = texDisplayIntTex2DArray.Load(int4(uv.xy * texRes.xy, slice, mip));
else if(type == RESTYPE_TEX2D_MS)
@@ -117,10 +117,9 @@ float4 SampleTextureFloat4(uint type, bool linearSample, float2 uv, float slice,
else if(type == RESTYPE_TEX3D)
{
if(linearSample)
col = texDisplayTex3D.SampleLevel(linearSampler, float3(uv.xy, (slice + 0.001f) / texRes.z),
mip);
col = texDisplayTex3D.SampleLevel(linearSampler, float3(uv.xy, slice / texRes.z), mip);
else
col = texDisplayTex3D.Load(int4(uv.xy * texRes.xy, slice + 0.001f, mip));
col = texDisplayTex3D.Load(int4(uv.xy * texRes.xy, slice, mip));
}
else if(type == RESTYPE_DEPTH)
{