mirror of
https://github.com/overte-org/overte.git
synced 2025-07-28 22:20:25 +02:00
Merge pull request #9647 from samcake/ambient
Fix the filtering problem on color and normals
This commit is contained in:
commit
f4ff5cf746
9 changed files with 39 additions and 21 deletions
|
@ -399,7 +399,7 @@ void ImageReader::run() {
|
||||||
int originalHeight = imageHeight;
|
int originalHeight = imageHeight;
|
||||||
imageWidth = (int)(scaleFactor * (float)imageWidth + 0.5f);
|
imageWidth = (int)(scaleFactor * (float)imageWidth + 0.5f);
|
||||||
imageHeight = (int)(scaleFactor * (float)imageHeight + 0.5f);
|
imageHeight = (int)(scaleFactor * (float)imageHeight + 0.5f);
|
||||||
QImage newImage = image.scaled(QSize(imageWidth, imageHeight), Qt::IgnoreAspectRatio);
|
QImage newImage = image.scaled(QSize(imageWidth, imageHeight), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||||
image.swap(newImage);
|
image.swap(newImage);
|
||||||
qCDebug(modelnetworking) << "Downscale image" << _url
|
qCDebug(modelnetworking) << "Downscale image" << _url
|
||||||
<< "from" << originalWidth << "x" << originalHeight
|
<< "from" << originalWidth << "x" << originalHeight
|
||||||
|
|
|
@ -74,7 +74,7 @@ QImage processSourceImage(const QImage& srcImage, bool cubemap) {
|
||||||
if (targetSize != srcImageSize) {
|
if (targetSize != srcImageSize) {
|
||||||
PROFILE_RANGE(resource_parse, "processSourceImage Rectify");
|
PROFILE_RANGE(resource_parse, "processSourceImage Rectify");
|
||||||
qCDebug(modelLog) << "Resizing texture from " << srcImageSize.x << "x" << srcImageSize.y << " to " << targetSize.x << "x" << targetSize.y;
|
qCDebug(modelLog) << "Resizing texture from " << srcImageSize.x << "x" << srcImageSize.y << " to " << targetSize.x << "x" << targetSize.y;
|
||||||
return srcImage.scaled(fromGlm(targetSize));
|
return srcImage.scaled(fromGlm(targetSize), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||||
}
|
}
|
||||||
|
|
||||||
return srcImage;
|
return srcImage;
|
||||||
|
@ -202,14 +202,19 @@ const QImage& image, bool isLinear, bool doCompress) {
|
||||||
|
|
||||||
#define CPU_MIPMAPS 1
|
#define CPU_MIPMAPS 1
|
||||||
|
|
||||||
void generateMips(gpu::Texture* texture, QImage& image, gpu::Element formatMip) {
|
void generateMips(gpu::Texture* texture, QImage& image, gpu::Element formatMip, bool fastResize) {
|
||||||
#if CPU_MIPMAPS
|
#if CPU_MIPMAPS
|
||||||
PROFILE_RANGE(resource_parse, "generateMips");
|
PROFILE_RANGE(resource_parse, "generateMips");
|
||||||
auto numMips = texture->evalNumMips();
|
auto numMips = texture->evalNumMips();
|
||||||
for (uint16 level = 1; level < numMips; ++level) {
|
for (uint16 level = 1; level < numMips; ++level) {
|
||||||
QSize mipSize(texture->evalMipWidth(level), texture->evalMipHeight(level));
|
QSize mipSize(texture->evalMipWidth(level), texture->evalMipHeight(level));
|
||||||
image = image.scaled(mipSize);
|
if (fastResize) {
|
||||||
texture->assignStoredMip(level, formatMip, image.byteCount(), image.constBits());
|
image = image.scaled(mipSize);
|
||||||
|
texture->assignStoredMip(level, formatMip, image.byteCount(), image.constBits());
|
||||||
|
} else {
|
||||||
|
QImage mipImage = image.scaled(mipSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||||
|
texture->assignStoredMip(level, formatMip, mipImage.byteCount(), mipImage.constBits());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
texture->autoGenerateMips(-1);
|
texture->autoGenerateMips(-1);
|
||||||
|
@ -222,8 +227,8 @@ void generateFaceMips(gpu::Texture* texture, QImage& image, gpu::Element formatM
|
||||||
auto numMips = texture->evalNumMips();
|
auto numMips = texture->evalNumMips();
|
||||||
for (uint16 level = 1; level < numMips; ++level) {
|
for (uint16 level = 1; level < numMips; ++level) {
|
||||||
QSize mipSize(texture->evalMipWidth(level), texture->evalMipHeight(level));
|
QSize mipSize(texture->evalMipWidth(level), texture->evalMipHeight(level));
|
||||||
image = image.scaled(mipSize);
|
QImage mipImage = image.scaled(mipSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||||
texture->assignStoredMipFace(level, formatMip, image.byteCount(), image.constBits(), face);
|
texture->assignStoredMipFace(level, formatMip, mipImage.byteCount(), mipImage.constBits(), face);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
texture->autoGenerateMips(-1);
|
texture->autoGenerateMips(-1);
|
||||||
|
@ -257,7 +262,7 @@ gpu::Texture* TextureUsage::process2DTextureColorFromImage(const QImage& srcImag
|
||||||
theTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
|
theTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
|
||||||
|
|
||||||
if (generateMips) {
|
if (generateMips) {
|
||||||
::generateMips(theTexture, image, formatMip);
|
::generateMips(theTexture, image, formatMip, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,7 +305,7 @@ gpu::Texture* TextureUsage::createNormalTextureFromNormalImage(const QImage& src
|
||||||
theTexture = (gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
|
theTexture = (gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
|
||||||
theTexture->setSource(srcImageName);
|
theTexture->setSource(srcImageName);
|
||||||
theTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
|
theTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
|
||||||
generateMips(theTexture, image, formatMip);
|
generateMips(theTexture, image, formatMip, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return theTexture;
|
return theTexture;
|
||||||
|
@ -386,7 +391,7 @@ gpu::Texture* TextureUsage::createNormalTextureFromBumpImage(const QImage& srcIm
|
||||||
theTexture = (gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
|
theTexture = (gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
|
||||||
theTexture->setSource(srcImageName);
|
theTexture->setSource(srcImageName);
|
||||||
theTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
|
theTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
|
||||||
generateMips(theTexture, image, formatMip);
|
generateMips(theTexture, image, formatMip, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return theTexture;
|
return theTexture;
|
||||||
|
@ -419,7 +424,7 @@ gpu::Texture* TextureUsage::createRoughnessTextureFromImage(const QImage& srcIma
|
||||||
theTexture = (gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
|
theTexture = (gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
|
||||||
theTexture->setSource(srcImageName);
|
theTexture->setSource(srcImageName);
|
||||||
theTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
|
theTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
|
||||||
generateMips(theTexture, image, formatMip);
|
generateMips(theTexture, image, formatMip, true);
|
||||||
|
|
||||||
// FIXME queue for transfer to GPU and block on completion
|
// FIXME queue for transfer to GPU and block on completion
|
||||||
}
|
}
|
||||||
|
@ -458,7 +463,7 @@ gpu::Texture* TextureUsage::createRoughnessTextureFromGlossImage(const QImage& s
|
||||||
theTexture = (gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
|
theTexture = (gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
|
||||||
theTexture->setSource(srcImageName);
|
theTexture->setSource(srcImageName);
|
||||||
theTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
|
theTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
|
||||||
generateMips(theTexture, image, formatMip);
|
generateMips(theTexture, image, formatMip, true);
|
||||||
|
|
||||||
// FIXME queue for transfer to GPU and block on completion
|
// FIXME queue for transfer to GPU and block on completion
|
||||||
}
|
}
|
||||||
|
@ -494,7 +499,7 @@ gpu::Texture* TextureUsage::createMetallicTextureFromImage(const QImage& srcImag
|
||||||
theTexture = (gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
|
theTexture = (gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
|
||||||
theTexture->setSource(srcImageName);
|
theTexture->setSource(srcImageName);
|
||||||
theTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
|
theTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
|
||||||
generateMips(theTexture, image, formatMip);
|
generateMips(theTexture, image, formatMip, true);
|
||||||
|
|
||||||
// FIXME queue for transfer to GPU and block on completion
|
// FIXME queue for transfer to GPU and block on completion
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,8 @@ float fetchRoughnessMap(vec2 uv) {
|
||||||
<@if withNormal@>
|
<@if withNormal@>
|
||||||
uniform sampler2D normalMap;
|
uniform sampler2D normalMap;
|
||||||
vec3 fetchNormalMap(vec2 uv) {
|
vec3 fetchNormalMap(vec2 uv) {
|
||||||
return texture(normalMap, uv).xyz;
|
// unpack normal, swizzle to get into hifi tangent space with Y axis pointing out
|
||||||
|
return normalize(texture(normalMap, uv).xzy -vec3(0.5, 0.5, 0.5));
|
||||||
}
|
}
|
||||||
<@endif@>
|
<@endif@>
|
||||||
|
|
||||||
|
@ -148,11 +149,23 @@ vec3 fetchLightmapMap(vec2 uv) {
|
||||||
vec3 normalizedNormal = normalize(<$interpolatedNormal$>.xyz);
|
vec3 normalizedNormal = normalize(<$interpolatedNormal$>.xyz);
|
||||||
vec3 normalizedTangent = normalize(<$interpolatedTangent$>.xyz);
|
vec3 normalizedTangent = normalize(<$interpolatedTangent$>.xyz);
|
||||||
vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent));
|
vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent));
|
||||||
vec3 localNormal = normalize(<$fetchedNormal$> - vec3(0.5, 0.5, 0.5));
|
vec3 localNormal = <$fetchedNormal$>;
|
||||||
<$normal$> = vec3(normalizedTangent * localNormal.x + normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z);
|
<$normal$> = vec3(normalizedTangent * localNormal.x + normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z);
|
||||||
}
|
}
|
||||||
<@endfunc@>
|
<@endfunc@>
|
||||||
|
|
||||||
|
<@func tangentToViewSpaceLOD(fragPos, fetchedNormal, interpolatedNormal, interpolatedTangent, normal)@>
|
||||||
|
{
|
||||||
|
vec3 normalizedNormal = normalize(<$interpolatedNormal$>.xyz);
|
||||||
|
vec3 normalizedTangent = normalize(<$interpolatedTangent$>.xyz);
|
||||||
|
vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent));
|
||||||
|
// attenuate the normal map divergence from the mesh normal based on distance
|
||||||
|
// THe attenuation range [20,100] meters from the eye is arbitrary for now
|
||||||
|
vec3 localNormal = mix(<$fetchedNormal$>, vec3(0.0, 1.0, 0.0), smoothstep(20, 100, (-<$fragPos$>).z));
|
||||||
|
<$normal$> = vec3(normalizedTangent * localNormal.x + normalizedNormal * localNormal.y + normalizedBitangent * localNormal.z);
|
||||||
|
}
|
||||||
|
<@endfunc@>
|
||||||
|
|
||||||
<@func evalMaterialAlbedo(fetchedAlbedo, materialAlbedo, matKey, albedo)@>
|
<@func evalMaterialAlbedo(fetchedAlbedo, materialAlbedo, matKey, albedo)@>
|
||||||
{
|
{
|
||||||
<$albedo$>.xyz = (((<$matKey$> & ALBEDO_VAL_BIT) != 0) ? <$materialAlbedo$> : vec3(1.0));
|
<$albedo$>.xyz = (((<$matKey$> & ALBEDO_VAL_BIT) != 0) ? <$materialAlbedo$> : vec3(1.0));
|
||||||
|
|
|
@ -47,7 +47,7 @@ void main(void) {
|
||||||
<$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>;
|
<$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>;
|
||||||
|
|
||||||
vec3 viewNormal;
|
vec3 viewNormal;
|
||||||
<$tangentToViewSpace(normalTex, _normal, _tangent, viewNormal)$>
|
<$tangentToViewSpaceLOD(_position, normalTex, _normal, _tangent, viewNormal)$>
|
||||||
|
|
||||||
float scattering = getMaterialScattering(mat);
|
float scattering = getMaterialScattering(mat);
|
||||||
<$evalMaterialScattering(scatteringTex, scattering, matKey, scattering)$>;
|
<$evalMaterialScattering(scatteringTex, scattering, matKey, scattering)$>;
|
||||||
|
|
|
@ -47,7 +47,7 @@ void main(void) {
|
||||||
<$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>;
|
<$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>;
|
||||||
|
|
||||||
vec3 viewNormal;
|
vec3 viewNormal;
|
||||||
<$tangentToViewSpace(normalTex, _normal, _tangent, viewNormal)$>
|
<$tangentToViewSpaceLOD(_position, normalTex, _normal, _tangent, viewNormal)$>
|
||||||
|
|
||||||
float metallic = getMaterialMetallic(mat);
|
float metallic = getMaterialMetallic(mat);
|
||||||
<$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>;
|
<$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>;
|
||||||
|
|
|
@ -34,7 +34,7 @@ void main(void) {
|
||||||
<$fetchMaterialTexturesCoord1(matKey, _texCoord1, _SCRIBE_NULL, lightmapVal)$>
|
<$fetchMaterialTexturesCoord1(matKey, _texCoord1, _SCRIBE_NULL, lightmapVal)$>
|
||||||
|
|
||||||
vec3 viewNormal;
|
vec3 viewNormal;
|
||||||
<$tangentToViewSpace(normalTexel, _normal, _tangent, viewNormal)$>
|
<$tangentToViewSpaceLOD(_position, normalTexel, _normal, _tangent, viewNormal)$>
|
||||||
|
|
||||||
packDeferredFragmentLightmap(
|
packDeferredFragmentLightmap(
|
||||||
normalize(viewNormal.xyz),
|
normalize(viewNormal.xyz),
|
||||||
|
|
|
@ -34,7 +34,7 @@ void main(void) {
|
||||||
<$fetchMaterialTexturesCoord1(matKey, _texCoord1, _SCRIBE_NULL, lightmapVal)$>
|
<$fetchMaterialTexturesCoord1(matKey, _texCoord1, _SCRIBE_NULL, lightmapVal)$>
|
||||||
|
|
||||||
vec3 viewNormal;
|
vec3 viewNormal;
|
||||||
<$tangentToViewSpace(normalTexel, _normal, _tangent, viewNormal)$>
|
<$tangentToViewSpaceLOD(_position, normalTexel, _normal, _tangent, viewNormal)$>
|
||||||
|
|
||||||
packDeferredFragmentLightmap(
|
packDeferredFragmentLightmap(
|
||||||
normalize(viewNormal.xyz),
|
normalize(viewNormal.xyz),
|
||||||
|
|
|
@ -47,7 +47,7 @@ void main(void) {
|
||||||
<$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>;
|
<$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>;
|
||||||
|
|
||||||
vec3 viewNormal;
|
vec3 viewNormal;
|
||||||
<$tangentToViewSpace(normalTex, _normal, _tangent, viewNormal)$>
|
<$tangentToViewSpaceLOD(_position, normalTex, _normal, _tangent, viewNormal)$>
|
||||||
|
|
||||||
float scattering = getMaterialScattering(mat);
|
float scattering = getMaterialScattering(mat);
|
||||||
<$evalMaterialScattering(scatteringTex, scattering, matKey, scattering)$>;
|
<$evalMaterialScattering(scatteringTex, scattering, matKey, scattering)$>;
|
||||||
|
|
|
@ -47,7 +47,7 @@ void main(void) {
|
||||||
<$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>;
|
<$evalMaterialEmissive(emissiveTex, emissive, matKey, emissive)$>;
|
||||||
|
|
||||||
vec3 viewNormal;
|
vec3 viewNormal;
|
||||||
<$tangentToViewSpace(normalTex, _normal, _tangent, viewNormal)$>
|
<$tangentToViewSpaceLOD(_position, normalTex, _normal, _tangent, viewNormal)$>
|
||||||
|
|
||||||
float metallic = getMaterialMetallic(mat);
|
float metallic = getMaterialMetallic(mat);
|
||||||
<$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>;
|
<$evalMaterialMetallic(metallicTex, metallic, matKey, metallic)$>;
|
||||||
|
|
Loading…
Reference in a new issue