Target available mip

This commit is contained in:
Brad Davis 2018-03-06 11:20:54 -08:00
parent b7d0260a17
commit f9605cffb1
4 changed files with 30 additions and 16 deletions
libraries

View file

@ -253,6 +253,9 @@ void GL45Texture::releaseBindless() const {
void GL45Texture::recreateBindless() const {
if (isBindless()) {
releaseBindless();
} else {
// Once a texture is about to become bindless, it's base mip level MUST be set to 0
glTextureParameteri(_id, GL_TEXTURE_BASE_LEVEL, 0);
}
_bindless.sampler = SAMPLER_CACHE.getGLSampler(_cachedSampler);
@ -270,16 +273,15 @@ const GL45Texture::Bindless& GL45Texture::getBindless() const {
void GL45Texture::syncSampler() const {
const Sampler& sampler = _gpuObject.getSampler();
bool samplerChanged = _cachedSampler != sampler;
if (samplerChanged) {
_cachedSampler = sampler;
}
if (_cachedSampler == sampler) {
return;
}
_cachedSampler = sampler;
if (isBindless()) {
if (samplerChanged) {
recreateBindless();
}
} else if (samplerChanged) {
recreateBindless();
} else {
const auto& fm = FILTER_MODES[sampler.getFilter()];
glTextureParameteri(_id, GL_TEXTURE_MIN_FILTER, fm.minFilter);
glTextureParameteri(_id, GL_TEXTURE_MAG_FILTER, fm.magFilter);

View file

@ -20,7 +20,17 @@ struct GPUTextureTable {
#define TextureTable(index, name) layout (std140) uniform gpu_resourceTextureTable##index { GPUTextureTable name; }
#define tableTex(name, slot) sampler2D(name._textures[slot].xy)
#define tableTexMinLod(name, slot) float(name._textures[slot].z)
#define tableTexValue(name, slot, uv) \
tableTexValueLod(tableTex(matTex, albedoMap), tableTexMinLod(matTex, albedoMap), uv)
vec4 tableTexValueLod(sampler2D sampler, float minLod, vec2 uv) {
float queryLod = textureQueryLod(sampler, uv).x;
queryLod = max(minLod, queryLod);
return textureLod(sampler, uv, queryLod);
}
#else
#endif

View file

@ -504,6 +504,8 @@ TexturePointer Texture::build(const ktx::KTXDescriptor& descriptor) {
gpuktxKeyValue._usage = Texture::Usage::Builder().withColor().withAlpha().build();
}
auto samplerDesc = gpuktxKeyValue._samplerDesc;
samplerDesc._maxMip = gpu::Sampler::MAX_MIP_LEVEL;
auto texture = create(gpuktxKeyValue._usageType,
type,
texelFormat,
@ -513,7 +515,7 @@ TexturePointer Texture::build(const ktx::KTXDescriptor& descriptor) {
1, // num Samples
header.getNumberOfSlices(),
header.getNumberOfLevels(),
gpuktxKeyValue._samplerDesc);
samplerDesc);
texture->setUsage(gpuktxKeyValue._usage);
// Assing the mips availables

View file

@ -67,42 +67,42 @@ SCATTERING_MAP,
<@if withAlbedo@>
#define albedoMap 1
vec4 fetchAlbedoMap(vec2 uv) {
return texture(tableTex(matTex, albedoMap), uv);
return tableTexValue(matTex, albedoMap, uv);
}
<@endif@>
<@if withRoughness@>
#define roughnessMap 3
float fetchRoughnessMap(vec2 uv) {
return (texture(tableTex(matTex, roughnessMap), uv).r);
return tableTexValue(matTex, roughnessMap, uv).r;
}
<@endif@>
<@if withNormal@>
#define normalMap 4
vec3 fetchNormalMap(vec2 uv) {
return texture(tableTex(matTex, normalMap), uv).xyz;
return tableTexValue(matTex, normalMap, uv).xyz;
}
<@endif@>
<@if withMetallic@>
#define metallicMap 2
float fetchMetallicMap(vec2 uv) {
return (texture(tableTex(matTex, metallicMap), uv).r);
return tableTexValue(matTex, metallicMap, uv).r;
}
<@endif@>
<@if withEmissive@>
#define emissiveMap 0
vec3 fetchEmissiveMap(vec2 uv) {
return texture(tableTex(matTex, emissiveMap), uv).rgb;
return tableTexValue(matTex, emissiveMap, uv).rgb;
}
<@endif@>
<@if withOcclusion@>
#define occlusionMap 5
float fetchOcclusionMap(vec2 uv) {
return texture(tableTex(matTex, occlusionMap), uv).r;
return tableTexValue(matTex, occlusionMap, uv).r;
}
<@endif@>
@ -111,7 +111,7 @@ float fetchOcclusionMap(vec2 uv) {
float fetchScatteringMap(vec2 uv) {
float scattering = texture(tableTex(matTex, scatteringMap), uv).r; // boolean scattering for now
return max(((scattering - 0.1) / 0.9), 0.0);
return texture(tableTex(matTex, scatteringMap), uv).r; // boolean scattering for now
return tableTexValue(matTex, scatteringMap, uv).r; // boolean scattering for now
}
<@endif@>