add version to texmeta.json files, fallback to original file if version has changed for skyboxes

This commit is contained in:
SamGondelman 2019-05-21 15:30:28 -07:00
parent fa7a998cca
commit 4eeff52746
6 changed files with 27 additions and 10 deletions

View file

@ -26,13 +26,6 @@ layout(location=0) in vec3 _normal;
layout(location=0) out vec4 _fragColor;
void main(void) {
vec3 coord = normalize(_normal);
vec3 color = skybox.color.rgb;
// blend is only set if there is a cubemap
float check = float(skybox.color.a > 0.0);
color = mix(color, texture(cubeMap, coord).rgb, check);
color *= mix(vec3(1.0), skybox.color.rgb, check * float(skybox.color.a < 1.0));
_fragColor = vec4(color, 0.0);
vec3 skyboxColor = texture(cubeMap, normalize(_normal)).rgb;
_fragColor = vec4(mix(skybox.color.rgb, skyboxColor, skybox.color.a), 1.0);
}

View file

@ -690,6 +690,8 @@ void convertImageToLDRTexture(gpu::Texture* texture, Image&& image, BackendTarge
compressionOptions.setFormat(nvtt::Format_BC4);
} else if (mipFormat == gpu::Element::COLOR_COMPRESSED_BCX_XY) {
compressionOptions.setFormat(nvtt::Format_BC5);
} else if (mipFormat == gpu::Element::COLOR_COMPRESSED_BCX_HDR_RGB) {
compressionOptions.setFormat(nvtt::Format_BC6);
} else if (mipFormat == gpu::Element::COLOR_COMPRESSED_BCX_SRGBA_HIGH) {
alphaMode = nvtt::AlphaMode_Transparency;
compressionOptions.setFormat(nvtt::Format_BC7);

View file

@ -16,6 +16,7 @@
#include <QJsonObject>
const QString TEXTURE_META_EXTENSION = ".texmeta.json";
const uint16_t KTX_VERSION = 1;
bool TextureMeta::deserialize(const QByteArray& data, TextureMeta* meta) {
QJsonParseError error;
@ -46,6 +47,9 @@ bool TextureMeta::deserialize(const QByteArray& data, TextureMeta* meta) {
}
}
}
if (root.contains("version")) {
meta->version = root["version"].toInt();
}
return true;
}
@ -62,6 +66,7 @@ QByteArray TextureMeta::serialize() {
root["original"] = original.toString();
root["uncompressed"] = uncompressed.toString();
root["compressed"] = compressed;
root["version"] = KTX_VERSION;
doc.setObject(root);
return doc.toJson();

View file

@ -19,6 +19,7 @@
#include "khronos/KHR.h"
extern const QString TEXTURE_META_EXTENSION;
extern const uint16_t KTX_VERSION;
namespace std {
template<> struct hash<khronos::gl::texture::InternalFormat> {
@ -37,6 +38,7 @@ struct TextureMeta {
QUrl original;
QUrl uncompressed;
std::unordered_map<khronos::gl::texture::InternalFormat, QUrl> availableTextureTypes;
uint16_t version { 0 };
};

View file

@ -1065,6 +1065,21 @@ void NetworkTexture::loadMetaContent(const QByteArray& content) {
return;
}
// Version 0 ktx skyboxes and ambient maps don't work on AMD anymore, so we fallback to the original texture
if (meta.version == 0 && _type == image::TextureUsage::Type::SKY_TEXTURE ||
_type == image::TextureUsage::Type::AMBIENT_TEXTURE && !meta.original.isEmpty()) {
_currentlyLoadingResourceType = ResourceType::ORIGINAL;
_activeUrl = _activeUrl.resolved(meta.original);
auto textureCache = DependencyManager::get<TextureCache>();
auto self = _self.lock();
if (!self) {
return;
}
QMetaObject::invokeMethod(this, "attemptRequest", Qt::QueuedConnection);
return;
}
auto& backend = DependencyManager::get<TextureCache>()->getGPUContext()->getBackend();
for (auto pair : meta.availableTextureTypes) {
gpu::Element elFormat;

View file

@ -42,5 +42,5 @@ void main(void) {
color = max(color, vec3(0));
// Procedural Shaders are expected to be Gamma corrected so let's bring back the RGB in linear space for the rest of the pipeline
color = pow(color, vec3(2.2));
_fragColor = vec4(color, 0.0);
_fragColor = vec4(color, 1.0);
}