mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 06:44:06 +02:00
Merge pull request #4798 from samcake/blue
Add the loading of cube map and the rendering of skybox but broken
This commit is contained in:
commit
47630e9a0e
16 changed files with 175 additions and 61 deletions
|
@ -25,6 +25,7 @@
|
|||
#include <PerfStat.h>
|
||||
#include <SceneScriptingInterface.h>
|
||||
#include <ScriptEngine.h>
|
||||
#include <TextureCache.h>
|
||||
|
||||
#include "EntityTreeRenderer.h"
|
||||
|
||||
|
@ -455,7 +456,9 @@ void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode,
|
|||
if (_bestZone->getSkyboxProperties().getURL().isEmpty()) {
|
||||
stage->getSkybox()->clearCubemap();
|
||||
} else {
|
||||
stage->getSkybox()->clearCubemap(); // NOTE: this should be changed to do something to set the cubemap
|
||||
// Update the Texture of the Skybox with the one pointed by this zone
|
||||
auto cubeMap = DependencyManager::get<TextureCache>()->getTexture(_bestZone->getSkyboxProperties().getURL(), CUBE_TEXTURE);
|
||||
stage->getSkybox()->setCubemap(cubeMap->getGPUTexture());
|
||||
}
|
||||
stage->setBackgroundMode(model::SunSkyStage::SKY_BOX);
|
||||
}
|
||||
|
|
|
@ -479,6 +479,7 @@ void GLBackend::getCurrentGLState(State::Data& state) {
|
|||
void GLBackend::syncPipelineStateCache() {
|
||||
State::Data state;
|
||||
|
||||
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
|
||||
getCurrentGLState(state);
|
||||
State::Signature signature = State::evalSignature(state);
|
||||
|
||||
|
|
|
@ -373,7 +373,6 @@ GLBackend::GLTexture* GLBackend::syncGPUObject(const Texture& texture) {
|
|||
GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
||||
GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z };
|
||||
|
||||
if (needUpdate) {
|
||||
if (texture.isStoredMipAvailable(0)) {
|
||||
Texture::PixelsPointer mip = texture.accessStoredMip(0);
|
||||
|
|
|
@ -68,11 +68,11 @@ public:
|
|||
uint8 _maxMip = MAX_MIP_LEVEL;
|
||||
|
||||
Desc() {}
|
||||
Desc(const Filter filter) : _filter(filter) {}
|
||||
Desc(const Filter filter, const WrapMode wrap = WRAP_REPEAT) : _filter(filter), _wrapModeU(wrap), _wrapModeV(wrap), _wrapModeW(wrap) {}
|
||||
};
|
||||
|
||||
Sampler() {}
|
||||
Sampler(const Filter filter) : _desc(filter) {}
|
||||
Sampler(const Filter filter, const WrapMode wrap = WRAP_REPEAT) : _desc(filter, wrap) {}
|
||||
Sampler(const Desc& desc) : _desc(desc) {}
|
||||
~Sampler() {}
|
||||
|
||||
|
|
|
@ -92,15 +92,3 @@ void Material::setTextureView(MapChannel channel, const gpu::TextureView& view)
|
|||
_textureMap[channel] = view;
|
||||
}
|
||||
|
||||
// TextureStorage
|
||||
TextureStorage::TextureStorage(const QUrl& url) : gpu::Texture::Storage(), _url(url) {
|
||||
init();
|
||||
}
|
||||
|
||||
TextureStorage::~TextureStorage() {
|
||||
}
|
||||
|
||||
void TextureStorage::init() {
|
||||
_gpuTexture = TexturePointer(Texture::createFromStorage(this));
|
||||
}
|
||||
|
||||
|
|
|
@ -23,27 +23,6 @@
|
|||
|
||||
namespace model {
|
||||
|
||||
typedef glm::vec3 Color;
|
||||
|
||||
// TextureStorage is a specialized version of the gpu::Texture::Storage
|
||||
// It adds the URL and the notion that it owns the gpu::Texture
|
||||
class TextureStorage : public gpu::Texture::Storage {
|
||||
public:
|
||||
TextureStorage(const QUrl& url);
|
||||
~TextureStorage();
|
||||
|
||||
const QUrl& getUrl() const { return _url; }
|
||||
const gpu::TexturePointer& getGPUTexture() const { return _gpuTexture; }
|
||||
|
||||
protected:
|
||||
gpu::TexturePointer _gpuTexture;
|
||||
QUrl _url;
|
||||
void init();
|
||||
};
|
||||
typedef std::shared_ptr< TextureStorage > TextureStoragePointer;
|
||||
|
||||
|
||||
|
||||
class Material {
|
||||
public:
|
||||
typedef gpu::BufferView UniformBufferView;
|
||||
|
@ -62,6 +41,7 @@ public:
|
|||
NUM_MAPS,
|
||||
};
|
||||
typedef std::map<MapChannel, TextureView> TextureMap;
|
||||
typedef std::bitset<NUM_MAPS> MapFlags;
|
||||
|
||||
enum FlagBit {
|
||||
DIFFUSE_BIT = 0,
|
||||
|
|
|
@ -21,6 +21,7 @@ using namespace model;
|
|||
|
||||
Skybox::Skybox() {
|
||||
|
||||
/* // PLease create a default engineer skybox
|
||||
_cubemap.reset( gpu::Texture::createCube(gpu::Element::COLOR_RGBA_32, 1));
|
||||
unsigned char texels[] = {
|
||||
255, 0, 0, 255,
|
||||
|
@ -30,7 +31,7 @@ Skybox::Skybox() {
|
|||
0, 255, 0, 255,
|
||||
255, 0, 255, 255,
|
||||
};
|
||||
_cubemap->assignStoredMip(0, gpu::Element::COLOR_RGBA_32, sizeof(texels), texels);
|
||||
_cubemap->assignStoredMip(0, gpu::Element::COLOR_RGBA_32, sizeof(texels), texels);*/
|
||||
}
|
||||
|
||||
void Skybox::setColor(const Color& color) {
|
||||
|
@ -47,7 +48,7 @@ void Skybox::clearCubemap() {
|
|||
|
||||
void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Skybox& skybox) {
|
||||
|
||||
if (skybox.getCubemap()) {
|
||||
if (skybox.getCubemap() && skybox.getCubemap()->isDefined()) {
|
||||
static gpu::PipelinePointer thePipeline;
|
||||
static gpu::BufferPointer theBuffer;
|
||||
static gpu::Stream::FormatPointer theFormat;
|
||||
|
|
|
@ -18,7 +18,8 @@ varying vec3 color;
|
|||
|
||||
|
||||
void main(void) {
|
||||
vec4 texel = textureCube(cubeMap, normalize(normal));
|
||||
gl_FragData[0] = texel;
|
||||
// gl_FragData[0] = vec4(normal, 1.0);
|
||||
vec3 coord = normalize(normal);
|
||||
vec4 texel = textureCube(cubeMap, coord);
|
||||
// gl_FragData[0] = vec4(texel.xyz * color, texel.w);
|
||||
gl_FragData[0] = vec4(texel.xyz, 1.0);
|
||||
}
|
||||
|
|
|
@ -190,7 +190,8 @@ const float NUM_HOURS_PER_DAY = 24.0f;
|
|||
const float NUM_HOURS_PER_HALF_DAY = NUM_HOURS_PER_DAY * 0.5f;
|
||||
|
||||
SunSkyStage::SunSkyStage() :
|
||||
_sunLight(new Light())
|
||||
_sunLight(new Light()),
|
||||
_skybox(new Skybox())
|
||||
{
|
||||
_sunLight->setType(Light::SUN);
|
||||
|
||||
|
@ -290,6 +291,19 @@ void SunSkyStage::updateGraphicsObject() const {
|
|||
_sunLight->setPosition(Vec3(0.0f, originAlt, 0.0f));
|
||||
}
|
||||
|
||||
// Background
|
||||
switch (getBackgroundMode()) {
|
||||
case NO_BACKGROUND: {
|
||||
break;
|
||||
}
|
||||
case SKY_DOME: {
|
||||
break;
|
||||
}
|
||||
case SKY_BOX: {
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
static int firstTime = 0;
|
||||
if (firstTime == 0) {
|
||||
firstTime++;
|
||||
|
|
|
@ -223,11 +223,11 @@ public:
|
|||
const SkyboxPointer& getSkybox() const { valid(); return _skybox; }
|
||||
|
||||
protected:
|
||||
BackgroundMode _backgroundMode = SKY_DOME;
|
||||
BackgroundMode _backgroundMode = SKY_BOX;
|
||||
|
||||
LightPointer _sunLight;
|
||||
AtmospherePointer _atmosphere;
|
||||
SkyboxPointer _skybox;
|
||||
mutable SkyboxPointer _skybox;
|
||||
|
||||
gpu::PipelinePointer _skyPipeline;
|
||||
|
||||
|
|
28
libraries/model/src/model/TextureStorage.cpp
Executable file
28
libraries/model/src/model/TextureStorage.cpp
Executable file
|
@ -0,0 +1,28 @@
|
|||
//
|
||||
// TextureStorage.cpp
|
||||
// libraries/model/src/model
|
||||
//
|
||||
// Created by Sam Gateau on 5/6/2015.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
#include "TextureStorage.h"
|
||||
|
||||
using namespace model;
|
||||
using namespace gpu;
|
||||
|
||||
// TextureStorage
|
||||
TextureStorage::TextureStorage() : Texture::Storage(),
|
||||
_gpuTexture(Texture::createFromStorage(this))
|
||||
{}
|
||||
|
||||
TextureStorage::~TextureStorage() {
|
||||
}
|
||||
|
||||
void TextureStorage::reset(const QUrl& url, const TextureUsage& usage) {
|
||||
_url = url;
|
||||
_usage = usage;
|
||||
}
|
||||
|
56
libraries/model/src/model/TextureStorage.h
Executable file
56
libraries/model/src/model/TextureStorage.h
Executable file
|
@ -0,0 +1,56 @@
|
|||
//
|
||||
// TextureStorage.h
|
||||
// libraries/model/src/model
|
||||
//
|
||||
// Created by Sam Gateau on 5/6/2015.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
#ifndef hifi_model_TextureStorage_h
|
||||
#define hifi_model_TextureStorage_h
|
||||
|
||||
#include "gpu/Texture.h"
|
||||
|
||||
#include "Material.h"
|
||||
|
||||
#include <qurl.h>
|
||||
|
||||
namespace model {
|
||||
|
||||
typedef glm::vec3 Color;
|
||||
|
||||
class TextureUsage {
|
||||
public:
|
||||
gpu::Texture::Type _type{ gpu::Texture::TEX_2D };
|
||||
Material::MapFlags _materialUsage{ Material::DIFFUSE_MAP };
|
||||
|
||||
int _environmentUsage = 0;
|
||||
};
|
||||
|
||||
// TextureStorage is a specialized version of the gpu::Texture::Storage
|
||||
// It provides the mechanism to create a texture from a Url and the intended usage
|
||||
// that guides the internal format used
|
||||
class TextureStorage : public gpu::Texture::Storage {
|
||||
public:
|
||||
TextureStorage();
|
||||
~TextureStorage();
|
||||
|
||||
const QUrl& getUrl() const { return _url; }
|
||||
const gpu::Texture::Type getType() const { return _usage._type; }
|
||||
const gpu::TexturePointer& getGPUTexture() const { return _gpuTexture; }
|
||||
|
||||
void reset(const QUrl& url, const TextureUsage& usage);
|
||||
|
||||
protected:
|
||||
gpu::TexturePointer _gpuTexture;
|
||||
TextureUsage _usage;
|
||||
QUrl _url;
|
||||
};
|
||||
typedef std::shared_ptr< TextureStorage > TextureStoragePointer;
|
||||
|
||||
};
|
||||
|
||||
#endif // hifi_model_TextureStorage_h
|
||||
|
|
@ -417,17 +417,23 @@ void ImageReader::run() {
|
|||
return;
|
||||
}
|
||||
|
||||
// enforce a fixed maximum area (1024 * 2048)
|
||||
const int MAXIMUM_AREA_SIZE = 2097152;
|
||||
int imageArea = image.width() * image.height();
|
||||
if (imageArea > MAXIMUM_AREA_SIZE) {
|
||||
float scaleRatio = sqrtf((float)MAXIMUM_AREA_SIZE) / sqrtf((float)imageArea);
|
||||
int resizeWidth = static_cast<int>(std::floor(scaleRatio * static_cast<float>(image.width())));
|
||||
int resizeHeight = static_cast<int>(std::floor(scaleRatio * static_cast<float>(image.height())));
|
||||
qCDebug(renderutils) << "Image greater than maximum size:" << _url << image.width() << image.height() <<
|
||||
" scaled to:" << resizeWidth << resizeHeight;
|
||||
image = image.scaled(resizeWidth, resizeHeight, Qt::IgnoreAspectRatio);
|
||||
imageArea = image.width() * image.height();
|
||||
auto ntex = dynamic_cast<NetworkTexture*>(&*texture);
|
||||
if (ntex && (ntex->getType() == CUBE_TEXTURE)) {
|
||||
qCDebug(renderutils) << "Cube map size:" << _url << image.width() << image.height();
|
||||
} else {
|
||||
|
||||
// enforce a fixed maximum area (1024 * 2048)
|
||||
const int MAXIMUM_AREA_SIZE = 2097152;
|
||||
if (imageArea > MAXIMUM_AREA_SIZE) {
|
||||
float scaleRatio = sqrtf((float)MAXIMUM_AREA_SIZE) / sqrtf((float)imageArea);
|
||||
int resizeWidth = static_cast<int>(std::floor(scaleRatio * static_cast<float>(image.width())));
|
||||
int resizeHeight = static_cast<int>(std::floor(scaleRatio * static_cast<float>(image.height())));
|
||||
qCDebug(renderutils) << "Image greater than maximum size:" << _url << image.width() << image.height() <<
|
||||
" scaled to:" << resizeWidth << resizeHeight;
|
||||
image = image.scaled(resizeWidth, resizeHeight, Qt::IgnoreAspectRatio);
|
||||
imageArea = image.width() * image.height();
|
||||
}
|
||||
}
|
||||
|
||||
const int EIGHT_BIT_MAXIMUM = 255;
|
||||
|
@ -507,6 +513,7 @@ void NetworkTexture::setImage(const QImage& image, bool translucent, const QColo
|
|||
imageLoaded(image);
|
||||
|
||||
if ((_width > 0) && (_height > 0)) {
|
||||
|
||||
bool isLinearRGB = true; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE);
|
||||
|
||||
gpu::Element formatGPU = gpu::Element(gpu::VEC3, gpu::UINT8, (isLinearRGB ? gpu::RGB : gpu::SRGB));
|
||||
|
@ -515,9 +522,18 @@ void NetworkTexture::setImage(const QImage& image, bool translucent, const QColo
|
|||
formatGPU = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::RGBA : gpu::SRGBA));
|
||||
formatMip = gpu::Element(gpu::VEC4, gpu::UINT8, (isLinearRGB ? gpu::BGRA : gpu::SBGRA));
|
||||
}
|
||||
_gpuTexture = gpu::TexturePointer(gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
|
||||
_gpuTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
|
||||
_gpuTexture->autoGenerateMips(-1);
|
||||
|
||||
if (_type == CUBE_TEXTURE) {
|
||||
if (_height >= (6 * _width)) {
|
||||
_gpuTexture = gpu::TexturePointer(gpu::Texture::createCube(formatGPU, image.width(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR, gpu::Sampler::WRAP_CLAMP)));
|
||||
_gpuTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
|
||||
_gpuTexture->autoGenerateMips(-1);
|
||||
}
|
||||
} else {
|
||||
_gpuTexture = gpu::TexturePointer(gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
|
||||
_gpuTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
|
||||
_gpuTexture->autoGenerateMips(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ class NetworkTexture;
|
|||
|
||||
typedef QSharedPointer<NetworkTexture> NetworkTexturePointer;
|
||||
|
||||
enum TextureType { DEFAULT_TEXTURE, NORMAL_TEXTURE, SPECULAR_TEXTURE, EMISSIVE_TEXTURE, SPLAT_TEXTURE };
|
||||
enum TextureType { DEFAULT_TEXTURE, NORMAL_TEXTURE, SPECULAR_TEXTURE, EMISSIVE_TEXTURE, SPLAT_TEXTURE, CUBE_TEXTURE };
|
||||
|
||||
/// Stores cached textures, including render-to-texture targets.
|
||||
class TextureCache : public ResourceCache, public Dependency {
|
||||
|
@ -164,7 +164,7 @@ public:
|
|||
int getOriginalHeight() const { return _originalHeight; }
|
||||
int getWidth() const { return _width; }
|
||||
int getHeight() const { return _height; }
|
||||
|
||||
TextureType getType() const { return _type; }
|
||||
protected:
|
||||
|
||||
virtual void downloadFinished(QNetworkReply* reply);
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
|
||||
#include "SceneScriptingInterface.h"
|
||||
|
||||
#include "SceneScriptingInterface.h"
|
||||
|
||||
|
||||
void SceneScriptingInterface::setStageOrientation(const glm::quat& orientation) {
|
||||
_skyStage->setOriginOrientation(orientation);
|
||||
}
|
||||
|
@ -86,6 +89,29 @@ bool SceneScriptingInterface::isStageSunModelEnabled() const {
|
|||
return _skyStage->isSunModelEnabled();
|
||||
}
|
||||
|
||||
void SceneScriptingInterface::setBackgroundMode(const QString& mode) {
|
||||
if (mode == QString("inherit")) {
|
||||
_skyStage->setBackgroundMode(model::SunSkyStage::NO_BACKGROUND);
|
||||
} else if (mode == QString("atmosphere")) {
|
||||
_skyStage->setBackgroundMode(model::SunSkyStage::SKY_DOME);
|
||||
} else if (mode == QString("skybox")) {
|
||||
_skyStage->setBackgroundMode(model::SunSkyStage::SKY_BOX);
|
||||
}
|
||||
}
|
||||
|
||||
QString SceneScriptingInterface::getBackgroundMode() const {
|
||||
switch (_skyStage->getBackgroundMode()) {
|
||||
case model::SunSkyStage::NO_BACKGROUND:
|
||||
return QString("inherit");
|
||||
case model::SunSkyStage::SKY_DOME:
|
||||
return QString("atmosphere");
|
||||
case model::SunSkyStage::SKY_BOX:
|
||||
return QString("skybox");
|
||||
default:
|
||||
return QString("inherit");
|
||||
};
|
||||
}
|
||||
|
||||
model::SunSkyStagePointer SceneScriptingInterface::getSkyStage() const {
|
||||
return _skyStage;
|
||||
}
|
||||
|
|
|
@ -57,7 +57,8 @@ public:
|
|||
Q_INVOKABLE glm::vec3 getKeyLightDirection() const;
|
||||
|
||||
|
||||
|
||||
Q_INVOKABLE void setBackgroundMode(const QString& mode);
|
||||
Q_INVOKABLE QString getBackgroundMode() const;
|
||||
|
||||
model::SunSkyStagePointer getSkyStage() const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue