mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 20:08:56 +02:00
Update generateIrradiance to take a BackendTarget
This commit is contained in:
parent
26e69de81e
commit
6be0c43fca
6 changed files with 70 additions and 71 deletions
|
@ -149,9 +149,9 @@ void TextureBaker::processTexture() {
|
||||||
|
|
||||||
// Compressed KTX
|
// Compressed KTX
|
||||||
if (_compressionEnabled) {
|
if (_compressionEnabled) {
|
||||||
constexpr std::array<image::BackendTarget, 2> BACKEND_TARGETS {{
|
constexpr std::array<gpu::BackendTarget, 2> BACKEND_TARGETS {{
|
||||||
image::BackendTarget::GL45,
|
gpu::BackendTarget::GL45,
|
||||||
image::BackendTarget::GLES32
|
gpu::BackendTarget::GLES32
|
||||||
}};
|
}};
|
||||||
for (auto target : BACKEND_TARGETS) {
|
for (auto target : BACKEND_TARGETS) {
|
||||||
auto processedTexture = image::processImage(buffer, _textureURL.toString().toStdString(),
|
auto processedTexture = image::processImage(buffer, _textureURL.toString().toStdString(),
|
||||||
|
@ -198,7 +198,7 @@ void TextureBaker::processTexture() {
|
||||||
if (_textureType == image::TextureUsage::Type::CUBE_TEXTURE) {
|
if (_textureType == image::TextureUsage::Type::CUBE_TEXTURE) {
|
||||||
buffer->reset();
|
buffer->reset();
|
||||||
auto processedTexture = image::processImage(std::move(buffer), _textureURL.toString().toStdString(),
|
auto processedTexture = image::processImage(std::move(buffer), _textureURL.toString().toStdString(),
|
||||||
ABSOLUTE_MAX_TEXTURE_NUM_PIXELS, _textureType, false, image::BackendTarget::GL45, _abortProcessing);
|
ABSOLUTE_MAX_TEXTURE_NUM_PIXELS, _textureType, false, gpu::BackendTarget::GL45, _abortProcessing);
|
||||||
if (!processedTexture) {
|
if (!processedTexture) {
|
||||||
handleError("Could not process texture " + _textureURL.toString());
|
handleError("Could not process texture " + _textureURL.toString());
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -510,7 +510,7 @@ void Texture::setSampler(const Sampler& sampler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Texture::generateIrradiance() {
|
bool Texture::generateIrradiance(gpu::BackendTarget target) {
|
||||||
if (getType() != TEX_CUBE) {
|
if (getType() != TEX_CUBE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -521,7 +521,7 @@ bool Texture::generateIrradiance() {
|
||||||
_irradiance = std::make_shared<SphericalHarmonics>();
|
_irradiance = std::make_shared<SphericalHarmonics>();
|
||||||
}
|
}
|
||||||
|
|
||||||
_irradiance->evalFromTexture(*this);
|
_irradiance->evalFromTexture(*this, target);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -684,7 +684,7 @@ void sphericalHarmonicsEvaluateDirection(float * result, int order, const glm::
|
||||||
result[8] = P_2_2 * ((double)dir.x * (double)dir.x - (double)dir.y * (double)dir.y);
|
result[8] = P_2_2 * ((double)dir.x * (double)dir.x - (double)dir.y * (double)dir.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sphericalHarmonicsFromTexture(const gpu::Texture& cubeTexture, std::vector<glm::vec3> & output, const uint order) {
|
bool sphericalHarmonicsFromTexture(const gpu::Texture& cubeTexture, std::vector<glm::vec3> & output, const uint order, gpu::BackendTarget target) {
|
||||||
int width = cubeTexture.getWidth();
|
int width = cubeTexture.getWidth();
|
||||||
if(width != cubeTexture.getHeight()) {
|
if(width != cubeTexture.getHeight()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -692,22 +692,6 @@ bool sphericalHarmonicsFromTexture(const gpu::Texture& cubeTexture, std::vector<
|
||||||
|
|
||||||
PROFILE_RANGE(render_gpu, "sphericalHarmonicsFromTexture");
|
PROFILE_RANGE(render_gpu, "sphericalHarmonicsFromTexture");
|
||||||
|
|
||||||
#ifndef USE_GLES
|
|
||||||
auto mipFormat = cubeTexture.getStoredMipFormat();
|
|
||||||
std::function<glm::vec3(uint32)> unpackFunc;
|
|
||||||
switch (mipFormat.getSemantic()) {
|
|
||||||
case gpu::R11G11B10:
|
|
||||||
unpackFunc = glm::unpackF2x11_1x10;
|
|
||||||
break;
|
|
||||||
case gpu::RGB9E5:
|
|
||||||
unpackFunc = glm::unpackF3x9_E1x5;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const uint sqOrder = order*order;
|
const uint sqOrder = order*order;
|
||||||
|
|
||||||
// allocate memory for calculations
|
// allocate memory for calculations
|
||||||
|
@ -741,11 +725,7 @@ bool sphericalHarmonicsFromTexture(const gpu::Texture& cubeTexture, std::vector<
|
||||||
for(int face=0; face < gpu::Texture::NUM_CUBE_FACES; face++) {
|
for(int face=0; face < gpu::Texture::NUM_CUBE_FACES; face++) {
|
||||||
PROFILE_RANGE(render_gpu, "ProcessFace");
|
PROFILE_RANGE(render_gpu, "ProcessFace");
|
||||||
|
|
||||||
#ifndef USE_GLES
|
|
||||||
auto data = reinterpret_cast<const uint32*>( cubeTexture.accessStoredMipFace(0, face)->readData() );
|
|
||||||
#else
|
|
||||||
auto data = cubeTexture.accessStoredMipFace(0, face)->readData();
|
auto data = cubeTexture.accessStoredMipFace(0, face)->readData();
|
||||||
#endif
|
|
||||||
if (data == nullptr) {
|
if (data == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -827,20 +807,40 @@ bool sphericalHarmonicsFromTexture(const gpu::Texture& cubeTexture, std::vector<
|
||||||
|
|
||||||
// get color from texture
|
// get color from texture
|
||||||
glm::vec3 color{ 0.0f, 0.0f, 0.0f };
|
glm::vec3 color{ 0.0f, 0.0f, 0.0f };
|
||||||
for (int i = 0; i < stride; ++i) {
|
|
||||||
for (int j = 0; j < stride; ++j) {
|
if (target != gpu::BackendTarget::GLES32) {
|
||||||
#ifndef USE_GLES
|
auto mipFormat = cubeTexture.getStoredMipFormat();
|
||||||
int k = (int)(x + i - halfStride + (y + j - halfStride) * width);
|
std::function<glm::vec3(uint32)> unpackFunc;
|
||||||
color += unpackFunc(data[k]);
|
switch (mipFormat.getSemantic()) {
|
||||||
#else
|
case gpu::R11G11B10:
|
||||||
const int NUM_COMPONENTS_PER_PIXEL = 4;
|
unpackFunc = glm::unpackF2x11_1x10;
|
||||||
int k = NUM_COMPONENTS_PER_PIXEL * (int)(x + i - halfStride + (y + j - halfStride) * width);
|
break;
|
||||||
// BGRA -> RGBA
|
case gpu::RGB9E5:
|
||||||
color += glm::pow(glm::vec3(data[k + 2], data[k + 1], data[k]) / 255.0f, glm::vec3(2.2f));
|
unpackFunc = glm::unpackF3x9_E1x5;
|
||||||
#endif
|
break;
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
auto data32 = reinterpret_cast<const uint32*>(data);
|
||||||
|
for (int i = 0; i < stride; ++i) {
|
||||||
|
for (int j = 0; j < stride; ++j) {
|
||||||
|
int k = (int)(x + i - halfStride + (y + j - halfStride) * width);
|
||||||
|
color += unpackFunc(data32[k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// BGRA -> RGBA
|
||||||
|
const int NUM_COMPONENTS_PER_PIXEL = 4;
|
||||||
|
for (int i = 0; i < stride; ++i) {
|
||||||
|
for (int j = 0; j < stride; ++j) {
|
||||||
|
int k = NUM_COMPONENTS_PER_PIXEL * (int)(x + i - halfStride + (y + j - halfStride) * width);
|
||||||
|
color += glm::pow(glm::vec3(data[k + 2], data[k + 1], data[k]) / 255.0f, glm::vec3(2.2f));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// scale color and add to previously accumulated coefficients
|
// scale color and add to previously accumulated coefficients
|
||||||
// red
|
// red
|
||||||
sphericalHarmonicsScale(shBuffB.data(), order, shBuff.data(), color.r * fDiffSolid);
|
sphericalHarmonicsScale(shBuffB.data(), order, shBuff.data(), color.r * fDiffSolid);
|
||||||
|
@ -869,10 +869,10 @@ bool sphericalHarmonicsFromTexture(const gpu::Texture& cubeTexture, std::vector<
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SphericalHarmonics::evalFromTexture(const Texture& texture) {
|
void SphericalHarmonics::evalFromTexture(const Texture& texture, gpu::BackendTarget target) {
|
||||||
if (texture.isDefined()) {
|
if (texture.isDefined()) {
|
||||||
std::vector< glm::vec3 > coefs;
|
std::vector< glm::vec3 > coefs;
|
||||||
sphericalHarmonicsFromTexture(texture, coefs, 3);
|
sphericalHarmonicsFromTexture(texture, coefs, 3, target);
|
||||||
|
|
||||||
L00 = coefs[0];
|
L00 = coefs[0];
|
||||||
L1m1 = coefs[1];
|
L1m1 = coefs[1];
|
||||||
|
|
|
@ -43,6 +43,11 @@ namespace khronos { namespace gl { namespace texture {
|
||||||
|
|
||||||
namespace gpu {
|
namespace gpu {
|
||||||
|
|
||||||
|
enum class BackendTarget {
|
||||||
|
GL41,
|
||||||
|
GL45,
|
||||||
|
GLES32
|
||||||
|
};
|
||||||
|
|
||||||
const std::string SOURCE_HASH_KEY { "hifi.sourceHash" };
|
const std::string SOURCE_HASH_KEY { "hifi.sourceHash" };
|
||||||
|
|
||||||
|
@ -82,7 +87,7 @@ public:
|
||||||
|
|
||||||
void assignPreset(int p);
|
void assignPreset(int p);
|
||||||
|
|
||||||
void evalFromTexture(const Texture& texture);
|
void evalFromTexture(const Texture& texture, gpu::BackendTarget target);
|
||||||
};
|
};
|
||||||
typedef std::shared_ptr< SphericalHarmonics > SHPointer;
|
typedef std::shared_ptr< SphericalHarmonics > SHPointer;
|
||||||
|
|
||||||
|
@ -541,7 +546,7 @@ public:
|
||||||
Usage getUsage() const { return _usage; }
|
Usage getUsage() const { return _usage; }
|
||||||
|
|
||||||
// For Cube Texture, it's possible to generate the irradiance spherical harmonics and make them availalbe with the texture
|
// For Cube Texture, it's possible to generate the irradiance spherical harmonics and make them availalbe with the texture
|
||||||
bool generateIrradiance();
|
bool generateIrradiance(gpu::BackendTarget target);
|
||||||
const SHPointer& getIrradiance(uint16 slice = 0) const { return _irradiance; }
|
const SHPointer& getIrradiance(uint16 slice = 0) const { return _irradiance; }
|
||||||
void overrideIrradiance(SHPointer irradiance) { _irradiance = irradiance; }
|
void overrideIrradiance(SHPointer irradiance) { _irradiance = irradiance; }
|
||||||
bool isIrradianceValid() const { return _isIrradianceValid; }
|
bool isIrradianceValid() const { return _isIrradianceValid; }
|
||||||
|
|
|
@ -1392,7 +1392,7 @@ gpu::TexturePointer TextureUsage::processCubeTextureColorFromImage(QImage&& srcI
|
||||||
irradianceTexture->assignStoredMipFace(0, face, faces[face].byteCount(), faces[face].constBits());
|
irradianceTexture->assignStoredMipFace(0, face, faces[face].byteCount(), faces[face].constBits());
|
||||||
}
|
}
|
||||||
|
|
||||||
irradianceTexture->generateIrradiance();
|
irradianceTexture->generateIrradiance(target);
|
||||||
|
|
||||||
auto irradiance = irradianceTexture->getIrradiance();
|
auto irradiance = irradianceTexture->getIrradiance();
|
||||||
theTexture->overrideIrradiance(irradiance);
|
theTexture->overrideIrradiance(irradiance);
|
||||||
|
|
|
@ -21,12 +21,6 @@ class QImage;
|
||||||
|
|
||||||
namespace image {
|
namespace image {
|
||||||
|
|
||||||
enum class BackendTarget {
|
|
||||||
GL41,
|
|
||||||
GL45,
|
|
||||||
GLES32
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace TextureUsage {
|
namespace TextureUsage {
|
||||||
|
|
||||||
enum Type {
|
enum Type {
|
||||||
|
@ -47,41 +41,41 @@ enum Type {
|
||||||
UNUSED_TEXTURE
|
UNUSED_TEXTURE
|
||||||
};
|
};
|
||||||
|
|
||||||
using TextureLoader = std::function<gpu::TexturePointer(QImage&&, const std::string&, bool, BackendTarget, const std::atomic<bool>&)>;
|
using TextureLoader = std::function<gpu::TexturePointer(QImage&&, const std::string&, bool, gpu::BackendTarget, const std::atomic<bool>&)>;
|
||||||
TextureLoader getTextureLoaderForType(Type type, const QVariantMap& options = QVariantMap());
|
TextureLoader getTextureLoaderForType(Type type, const QVariantMap& options = QVariantMap());
|
||||||
|
|
||||||
gpu::TexturePointer create2DTextureFromImage(QImage&& image, const std::string& srcImageName,
|
gpu::TexturePointer create2DTextureFromImage(QImage&& image, const std::string& srcImageName,
|
||||||
bool compress, BackendTarget target, const std::atomic<bool>& abortProcessing);
|
bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing);
|
||||||
gpu::TexturePointer createStrict2DTextureFromImage(QImage&& image, const std::string& srcImageName,
|
gpu::TexturePointer createStrict2DTextureFromImage(QImage&& image, const std::string& srcImageName,
|
||||||
bool compress, BackendTarget target, const std::atomic<bool>& abortProcessing);
|
bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing);
|
||||||
gpu::TexturePointer createAlbedoTextureFromImage(QImage&& image, const std::string& srcImageName,
|
gpu::TexturePointer createAlbedoTextureFromImage(QImage&& image, const std::string& srcImageName,
|
||||||
bool compress, BackendTarget target, const std::atomic<bool>& abortProcessing);
|
bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing);
|
||||||
gpu::TexturePointer createEmissiveTextureFromImage(QImage&& image, const std::string& srcImageName,
|
gpu::TexturePointer createEmissiveTextureFromImage(QImage&& image, const std::string& srcImageName,
|
||||||
bool compress, BackendTarget target, const std::atomic<bool>& abortProcessing);
|
bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing);
|
||||||
gpu::TexturePointer createNormalTextureFromNormalImage(QImage&& image, const std::string& srcImageName,
|
gpu::TexturePointer createNormalTextureFromNormalImage(QImage&& image, const std::string& srcImageName,
|
||||||
bool compress, BackendTarget target, const std::atomic<bool>& abortProcessing);
|
bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing);
|
||||||
gpu::TexturePointer createNormalTextureFromBumpImage(QImage&& image, const std::string& srcImageName,
|
gpu::TexturePointer createNormalTextureFromBumpImage(QImage&& image, const std::string& srcImageName,
|
||||||
bool compress, BackendTarget target, const std::atomic<bool>& abortProcessing);
|
bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing);
|
||||||
gpu::TexturePointer createRoughnessTextureFromImage(QImage&& image, const std::string& srcImageName,
|
gpu::TexturePointer createRoughnessTextureFromImage(QImage&& image, const std::string& srcImageName,
|
||||||
bool compress, BackendTarget target, const std::atomic<bool>& abortProcessing);
|
bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing);
|
||||||
gpu::TexturePointer createRoughnessTextureFromGlossImage(QImage&& image, const std::string& srcImageName,
|
gpu::TexturePointer createRoughnessTextureFromGlossImage(QImage&& image, const std::string& srcImageName,
|
||||||
bool compress, BackendTarget target, const std::atomic<bool>& abortProcessing);
|
bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing);
|
||||||
gpu::TexturePointer createMetallicTextureFromImage(QImage&& image, const std::string& srcImageName,
|
gpu::TexturePointer createMetallicTextureFromImage(QImage&& image, const std::string& srcImageName,
|
||||||
bool compress, BackendTarget target, const std::atomic<bool>& abortProcessing);
|
bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing);
|
||||||
gpu::TexturePointer createCubeTextureFromImage(QImage&& image, const std::string& srcImageName,
|
gpu::TexturePointer createCubeTextureFromImage(QImage&& image, const std::string& srcImageName,
|
||||||
bool compress, BackendTarget target, const std::atomic<bool>& abortProcessing);
|
bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing);
|
||||||
gpu::TexturePointer createCubeTextureFromImageWithoutIrradiance(QImage&& image, const std::string& srcImageName,
|
gpu::TexturePointer createCubeTextureFromImageWithoutIrradiance(QImage&& image, const std::string& srcImageName,
|
||||||
bool compress, BackendTarget target, const std::atomic<bool>& abortProcessing);
|
bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing);
|
||||||
gpu::TexturePointer createLightmapTextureFromImage(QImage&& image, const std::string& srcImageName,
|
gpu::TexturePointer createLightmapTextureFromImage(QImage&& image, const std::string& srcImageName,
|
||||||
bool compress, BackendTarget target, const std::atomic<bool>& abortProcessing);
|
bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing);
|
||||||
gpu::TexturePointer process2DTextureColorFromImage(QImage&& srcImage, const std::string& srcImageName, bool compress,
|
gpu::TexturePointer process2DTextureColorFromImage(QImage&& srcImage, const std::string& srcImageName, bool compress,
|
||||||
BackendTarget target, bool isStrict, const std::atomic<bool>& abortProcessing);
|
gpu::BackendTarget target, bool isStrict, const std::atomic<bool>& abortProcessing);
|
||||||
gpu::TexturePointer process2DTextureNormalMapFromImage(QImage&& srcImage, const std::string& srcImageName, bool compress,
|
gpu::TexturePointer process2DTextureNormalMapFromImage(QImage&& srcImage, const std::string& srcImageName, bool compress,
|
||||||
BackendTarget target, bool isBumpMap, const std::atomic<bool>& abortProcessing);
|
gpu::BackendTarget target, bool isBumpMap, const std::atomic<bool>& abortProcessing);
|
||||||
gpu::TexturePointer process2DTextureGrayscaleFromImage(QImage&& srcImage, const std::string& srcImageName, bool compress,
|
gpu::TexturePointer process2DTextureGrayscaleFromImage(QImage&& srcImage, const std::string& srcImageName, bool compress,
|
||||||
BackendTarget target, bool isInvertedPixels, const std::atomic<bool>& abortProcessing);
|
gpu::BackendTarget target, bool isInvertedPixels, const std::atomic<bool>& abortProcessing);
|
||||||
gpu::TexturePointer processCubeTextureColorFromImage(QImage&& srcImage, const std::string& srcImageName, bool compress,
|
gpu::TexturePointer processCubeTextureColorFromImage(QImage&& srcImage, const std::string& srcImageName, bool compress,
|
||||||
BackendTarget target, bool generateIrradiance, const std::atomic<bool>& abortProcessing);
|
gpu::BackendTarget target, bool generateIrradiance, const std::atomic<bool>& abortProcessing);
|
||||||
|
|
||||||
} // namespace TextureUsage
|
} // namespace TextureUsage
|
||||||
|
|
||||||
|
@ -89,7 +83,7 @@ const QStringList getSupportedFormats();
|
||||||
|
|
||||||
gpu::TexturePointer processImage(std::shared_ptr<QIODevice> content, const std::string& url,
|
gpu::TexturePointer processImage(std::shared_ptr<QIODevice> content, const std::string& url,
|
||||||
int maxNumPixels, TextureUsage::Type textureType,
|
int maxNumPixels, TextureUsage::Type textureType,
|
||||||
bool compress, BackendTarget target, const std::atomic<bool>& abortProcessing = false);
|
bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing = false);
|
||||||
|
|
||||||
} // namespace image
|
} // namespace image
|
||||||
|
|
||||||
|
|
|
@ -280,9 +280,9 @@ gpu::TexturePointer TextureCache::getImageTexture(const QString& path, image::Te
|
||||||
}
|
}
|
||||||
auto loader = image::TextureUsage::getTextureLoaderForType(type, options);
|
auto loader = image::TextureUsage::getTextureLoaderForType(type, options);
|
||||||
#ifdef USE_GLES
|
#ifdef USE_GLES
|
||||||
image::BackendTarget target = image::BackendTarget::GLES32;
|
gpu::BackendTarget target = gpu::BackendTarget::GLES32;
|
||||||
#else
|
#else
|
||||||
image::BackendTarget target = image::BackendTarget::GL45;
|
gpu::BackendTarget target = gpu::BackendTarget::GL45;
|
||||||
#endif
|
#endif
|
||||||
return gpu::TexturePointer(loader(std::move(image), path.toStdString(), false, target, false));
|
return gpu::TexturePointer(loader(std::move(image), path.toStdString(), false, target, false));
|
||||||
}
|
}
|
||||||
|
@ -1172,9 +1172,9 @@ void ImageReader::read() {
|
||||||
constexpr bool shouldCompress = false;
|
constexpr bool shouldCompress = false;
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_GLES
|
#ifdef USE_GLES
|
||||||
image::BackendTarget target = image::BackendTarget::GLES32;
|
gpu::BackendTarget target = gpu::BackendTarget::GLES32;
|
||||||
#else
|
#else
|
||||||
image::BackendTarget target = image::BackendTarget::GL45;
|
gpu::BackendTarget target = gpu::BackendTarget::GL45;
|
||||||
#endif
|
#endif
|
||||||
texture = image::processImage(std::move(buffer), _url.toString().toStdString(), _maxNumPixels, networkTexture->getTextureType(), shouldCompress, target);
|
texture = image::processImage(std::move(buffer), _url.toString().toStdString(), _maxNumPixels, networkTexture->getTextureType(), shouldCompress, target);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue