mirror of
https://github.com/overte-org/overte.git
synced 2025-04-14 07:47:30 +02:00
cleaning up macos warnings, separating Metallic maps from the default, gamma corrected gray textures
This commit is contained in:
commit
96fb9c4466
22 changed files with 118 additions and 104 deletions
|
@ -31,8 +31,7 @@ Column {
|
||||||
"Albedo",
|
"Albedo",
|
||||||
"Normal",
|
"Normal",
|
||||||
"Roughness",
|
"Roughness",
|
||||||
"Metallic",
|
"Metallic",
|
||||||
"Fresnel",
|
|
||||||
"Emissive",
|
"Emissive",
|
||||||
"Occlusion",
|
"Occlusion",
|
||||||
"Lightmap",
|
"Lightmap",
|
||||||
|
|
|
@ -3818,18 +3818,10 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup the current Zone Entity lighting and skybox
|
// Setup the current Zone Entity lighting
|
||||||
{
|
{
|
||||||
// FIXME: Use a zone setting to determine the ambient light mode
|
auto stage = DependencyManager::get<SceneScriptingInterface>()->getSkyStage();
|
||||||
DependencyManager::get<DeferredLightingEffect>()->setAmbientLightMode(-1);
|
DependencyManager::get<DeferredLightingEffect>()->setGlobalLight(stage->getSunLight(), stage->getSkybox()->getCubemap());
|
||||||
auto skyStage = DependencyManager::get<SceneScriptingInterface>()->getSkyStage();
|
|
||||||
DependencyManager::get<DeferredLightingEffect>()->setGlobalLight(skyStage->getSunLight()->getDirection(), skyStage->getSunLight()->getColor(), skyStage->getSunLight()->getIntensity(), skyStage->getSunLight()->getAmbientIntensity());
|
|
||||||
|
|
||||||
auto skybox = model::SkyboxPointer();
|
|
||||||
if (skyStage->getBackgroundMode() == model::SunSkyStage::SKY_BOX) {
|
|
||||||
skybox = skyStage->getSkybox();
|
|
||||||
}
|
|
||||||
DependencyManager::get<DeferredLightingEffect>()->setGlobalSkybox(skybox);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -140,7 +140,8 @@ void EntityTreeRenderer::update() {
|
||||||
// even if we haven't changed positions, if we previously attempted to set the skybox, but
|
// even if we haven't changed positions, if we previously attempted to set the skybox, but
|
||||||
// have a pending download of the skybox texture, then we should attempt to reapply to
|
// have a pending download of the skybox texture, then we should attempt to reapply to
|
||||||
// get the correct texture.
|
// get the correct texture.
|
||||||
if (_pendingSkyboxTexture && _skyboxTexture && _skyboxTexture->isLoaded()) {
|
if ((_pendingSkyboxTexture && _skyboxTexture && _skyboxTexture->isLoaded()) ||
|
||||||
|
(_pendingAmbientTexture && _ambientTexture && _ambientTexture->isLoaded())) {
|
||||||
applyZonePropertiesToScene(_bestZone);
|
applyZonePropertiesToScene(_bestZone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,6 +254,7 @@ void EntityTreeRenderer::forceRecheckEntities() {
|
||||||
|
|
||||||
|
|
||||||
void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityItem> zone) {
|
void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityItem> zone) {
|
||||||
|
auto textureCache = DependencyManager::get<TextureCache>();
|
||||||
auto scene = DependencyManager::get<SceneScriptingInterface>();
|
auto scene = DependencyManager::get<SceneScriptingInterface>();
|
||||||
auto sceneStage = scene->getStage();
|
auto sceneStage = scene->getStage();
|
||||||
auto skyStage = scene->getSkyStage();
|
auto skyStage = scene->getSkyStage();
|
||||||
|
@ -264,7 +266,11 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
|
||||||
_pendingSkyboxTexture = false;
|
_pendingSkyboxTexture = false;
|
||||||
_skyboxTexture.clear();
|
_skyboxTexture.clear();
|
||||||
|
|
||||||
|
_pendingAmbientTexture = false;
|
||||||
|
_ambientTexture.clear();
|
||||||
|
|
||||||
if (_hasPreviousZone) {
|
if (_hasPreviousZone) {
|
||||||
|
sceneKeyLight->resetAmbientSphere();
|
||||||
sceneKeyLight->setColor(_previousKeyLightColor);
|
sceneKeyLight->setColor(_previousKeyLightColor);
|
||||||
sceneKeyLight->setIntensity(_previousKeyLightIntensity);
|
sceneKeyLight->setIntensity(_previousKeyLightIntensity);
|
||||||
sceneKeyLight->setAmbientIntensity(_previousKeyLightAmbientIntensity);
|
sceneKeyLight->setAmbientIntensity(_previousKeyLightAmbientIntensity);
|
||||||
|
@ -274,6 +280,7 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
|
||||||
_previousStageAltitude);
|
_previousStageAltitude);
|
||||||
sceneTime->setHour(_previousStageHour);
|
sceneTime->setHour(_previousStageHour);
|
||||||
sceneTime->setDay(_previousStageDay);
|
sceneTime->setDay(_previousStageDay);
|
||||||
|
|
||||||
_hasPreviousZone = false;
|
_hasPreviousZone = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,6 +313,23 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
|
||||||
sceneTime->setHour(zone->getStageProperties().calculateHour());
|
sceneTime->setHour(zone->getStageProperties().calculateHour());
|
||||||
sceneTime->setDay(zone->getStageProperties().calculateDay());
|
sceneTime->setDay(zone->getStageProperties().calculateDay());
|
||||||
|
|
||||||
|
bool isAmbientTextureSet = false;
|
||||||
|
if (zone->getKeyLightProperties().getAmbientURL().isEmpty()) {
|
||||||
|
_pendingAmbientTexture = false;
|
||||||
|
_ambientTexture.clear();
|
||||||
|
} else {
|
||||||
|
_ambientTexture = textureCache->getTexture(zone->getKeyLightProperties().getAmbientURL(), CUBE_TEXTURE);
|
||||||
|
if (_ambientTexture->getGPUTexture()) {
|
||||||
|
_pendingAmbientTexture = false;
|
||||||
|
if (_ambientTexture->getGPUTexture()->getIrradiance()) {
|
||||||
|
sceneKeyLight->setAmbientSphere(_ambientTexture->getGPUTexture()->getIrradiance());
|
||||||
|
isAmbientTextureSet = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_pendingAmbientTexture = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (zone->getBackgroundMode()) {
|
switch (zone->getBackgroundMode()) {
|
||||||
case BACKGROUND_MODE_SKYBOX: {
|
case BACKGROUND_MODE_SKYBOX: {
|
||||||
auto skybox = std::dynamic_pointer_cast<ProceduralSkybox>(skyStage->getSkybox());
|
auto skybox = std::dynamic_pointer_cast<ProceduralSkybox>(skyStage->getSkybox());
|
||||||
|
@ -326,12 +350,16 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
|
||||||
_skyboxTexture.clear();
|
_skyboxTexture.clear();
|
||||||
} else {
|
} else {
|
||||||
// Update the Texture of the Skybox with the one pointed by this zone
|
// Update the Texture of the Skybox with the one pointed by this zone
|
||||||
auto textureCache = DependencyManager::get<TextureCache>();
|
|
||||||
_skyboxTexture = textureCache->getTexture(zone->getSkyboxProperties().getURL(), CUBE_TEXTURE);
|
_skyboxTexture = textureCache->getTexture(zone->getSkyboxProperties().getURL(), CUBE_TEXTURE);
|
||||||
|
|
||||||
if (_skyboxTexture->getGPUTexture()) {
|
if (_skyboxTexture->getGPUTexture()) {
|
||||||
skybox->setCubemap(_skyboxTexture->getGPUTexture());
|
auto texture = _skyboxTexture->getGPUTexture();
|
||||||
|
skybox->setCubemap(texture);
|
||||||
_pendingSkyboxTexture = false;
|
_pendingSkyboxTexture = false;
|
||||||
|
if (!isAmbientTextureSet && texture->getIrradiance()) {
|
||||||
|
sceneKeyLight->setAmbientSphere(texture->getIrradiance());
|
||||||
|
isAmbientTextureSet = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
_pendingSkyboxTexture = true;
|
_pendingSkyboxTexture = true;
|
||||||
}
|
}
|
||||||
|
@ -348,6 +376,10 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
|
||||||
_skyboxTexture.clear();
|
_skyboxTexture.clear();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isAmbientTextureSet) {
|
||||||
|
sceneKeyLight->resetAmbientSphere();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const FBXGeometry* EntityTreeRenderer::getGeometryForEntity(EntityItemPointer entityItem) {
|
const FBXGeometry* EntityTreeRenderer::getGeometryForEntity(EntityItemPointer entityItem) {
|
||||||
|
|
|
@ -146,6 +146,9 @@ private:
|
||||||
bool _pendingSkyboxTexture { false };
|
bool _pendingSkyboxTexture { false };
|
||||||
NetworkTexturePointer _skyboxTexture;
|
NetworkTexturePointer _skyboxTexture;
|
||||||
|
|
||||||
|
bool _pendingAmbientTexture { false };
|
||||||
|
NetworkTexturePointer _ambientTexture;
|
||||||
|
|
||||||
bool _wantScripts;
|
bool _wantScripts;
|
||||||
ScriptEngine* _entitiesScriptEngine;
|
ScriptEngine* _entitiesScriptEngine;
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ void KeyLightPropertyGroup::copyToScriptValue(const EntityPropertyFlags& desired
|
||||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_KEYLIGHT_INTENSITY, KeyLight, keyLight, Intensity, intensity);
|
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_KEYLIGHT_INTENSITY, KeyLight, keyLight, Intensity, intensity);
|
||||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_KEYLIGHT_AMBIENT_INTENSITY, KeyLight, keyLight, AmbientIntensity, ambientIntensity);
|
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_KEYLIGHT_AMBIENT_INTENSITY, KeyLight, keyLight, AmbientIntensity, ambientIntensity);
|
||||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_KEYLIGHT_DIRECTION, KeyLight, keyLight, Direction, direction);
|
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_KEYLIGHT_DIRECTION, KeyLight, keyLight, Direction, direction);
|
||||||
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_KEYLIGHT_AMBIENT_URL, KeyLight, keyLight, AmbientURL, ambientUrl);
|
COPY_GROUP_PROPERTY_TO_QSCRIPTVALUE(PROP_KEYLIGHT_AMBIENT_URL, KeyLight, keyLight, AmbientURL, ambientURL);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -131,11 +131,10 @@ class FBXMaterial {
|
||||||
public:
|
public:
|
||||||
FBXMaterial() {};
|
FBXMaterial() {};
|
||||||
FBXMaterial(const glm::vec3& diffuseColor, const glm::vec3& specularColor, const glm::vec3& emissiveColor,
|
FBXMaterial(const glm::vec3& diffuseColor, const glm::vec3& specularColor, const glm::vec3& emissiveColor,
|
||||||
const glm::vec2& emissiveParams, float shininess, float opacity) :
|
float shininess, float opacity) :
|
||||||
diffuseColor(diffuseColor),
|
diffuseColor(diffuseColor),
|
||||||
specularColor(specularColor),
|
specularColor(specularColor),
|
||||||
emissiveColor(emissiveColor),
|
emissiveColor(emissiveColor),
|
||||||
lightmapParams(emissiveParams),
|
|
||||||
shininess(shininess),
|
shininess(shininess),
|
||||||
opacity(opacity) {}
|
opacity(opacity) {}
|
||||||
|
|
||||||
|
|
|
@ -185,8 +185,6 @@ void FBXReader::consolidateFBXMaterials() {
|
||||||
} else {
|
} else {
|
||||||
material._material->setRoughness(model::Material::shininessToRoughness(material.shininess));
|
material._material->setRoughness(model::Material::shininessToRoughness(material.shininess));
|
||||||
float metallic = std::max(material.specularColor.x, std::max(material.specularColor.y, material.specularColor.z));
|
float metallic = std::max(material.specularColor.x, std::max(material.specularColor.y, material.specularColor.z));
|
||||||
// FIXME: Do not use the Specular Factor yet as some FBX models have it set to 0
|
|
||||||
// metallic *= material.specularFactor;
|
|
||||||
material._material->setMetallic(metallic);
|
material._material->setMetallic(metallic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -558,7 +558,6 @@ FBXGeometry* OBJReader::readOBJ(QByteArray& model, const QVariantHash& mapping,
|
||||||
geometry.materials[materialID] = FBXMaterial(objMaterial.diffuseColor,
|
geometry.materials[materialID] = FBXMaterial(objMaterial.diffuseColor,
|
||||||
objMaterial.specularColor,
|
objMaterial.specularColor,
|
||||||
glm::vec3(0.0f),
|
glm::vec3(0.0f),
|
||||||
glm::vec2(0.0f, 1.0f),
|
|
||||||
objMaterial.shininess,
|
objMaterial.shininess,
|
||||||
objMaterial.opacity);
|
objMaterial.opacity);
|
||||||
FBXMaterial& fbxMaterial = geometry.materials[materialID];
|
FBXMaterial& fbxMaterial = geometry.materials[materialID];
|
||||||
|
|
|
@ -145,6 +145,8 @@ public:
|
||||||
switch(dstFormat.getSemantic()) {
|
switch(dstFormat.getSemantic()) {
|
||||||
case gpu::RGB:
|
case gpu::RGB:
|
||||||
case gpu::RGBA:
|
case gpu::RGBA:
|
||||||
|
case gpu::SRGB:
|
||||||
|
case gpu::SRGBA:
|
||||||
texel.internalFormat = GL_RED;
|
texel.internalFormat = GL_RED;
|
||||||
switch (dstFormat.getType()) {
|
switch (dstFormat.getType()) {
|
||||||
case gpu::UINT32: {
|
case gpu::UINT32: {
|
||||||
|
@ -196,7 +198,11 @@ public:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case gpu::NUINT8: {
|
case gpu::NUINT8: {
|
||||||
texel.internalFormat = GL_R8;
|
if ((dstFormat.getSemantic() == gpu::SRGB || dstFormat.getSemantic() == gpu::SRGBA)) {
|
||||||
|
texel.internalFormat = GL_SLUMINANCE8;
|
||||||
|
} else {
|
||||||
|
texel.internalFormat = GL_R8;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case gpu::NINT8: {
|
case gpu::NINT8: {
|
||||||
|
@ -209,6 +215,7 @@ public:
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case gpu::DEPTH:
|
case gpu::DEPTH:
|
||||||
texel.format = GL_DEPTH_COMPONENT; // It's depth component to load it
|
texel.format = GL_DEPTH_COMPONENT; // It's depth component to load it
|
||||||
texel.internalFormat = GL_DEPTH_COMPONENT;
|
texel.internalFormat = GL_DEPTH_COMPONENT;
|
||||||
|
|
|
@ -363,7 +363,7 @@ static NetworkMaterial* buildNetworkMaterial(NetworkGeometry* geometry, const FB
|
||||||
material._material->setTextureMap(model::MaterialKey::METALLIC_MAP, metallicMap);
|
material._material->setTextureMap(model::MaterialKey::METALLIC_MAP, metallicMap);
|
||||||
}
|
}
|
||||||
if (!material.roughnessTexture.filename.isEmpty()) {
|
if (!material.roughnessTexture.filename.isEmpty()) {
|
||||||
material.roughnessTexture.isGlossmap;
|
// FIXME: COnvert from gloss to roughness if material.roughnessTexture.isGlossmap;
|
||||||
networkMaterial->roughnessTexture = textureCache->getTexture(textureBaseUrl.resolved(QUrl(material.roughnessTexture.filename)), ROUGHNESS_TEXTURE, material.roughnessTexture.content);
|
networkMaterial->roughnessTexture = textureCache->getTexture(textureBaseUrl.resolved(QUrl(material.roughnessTexture.filename)), ROUGHNESS_TEXTURE, material.roughnessTexture.content);
|
||||||
networkMaterial->roughnessTextureName = material.roughnessTexture.name;
|
networkMaterial->roughnessTextureName = material.roughnessTexture.name;
|
||||||
|
|
||||||
|
|
|
@ -216,12 +216,15 @@ NetworkTexture::TextureLoaderFunc NetworkTexture::getTextureLoader() const {
|
||||||
return TextureLoaderFunc(model::TextureUsage::createRoughnessTextureFromImage);
|
return TextureLoaderFunc(model::TextureUsage::createRoughnessTextureFromImage);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case SPECULAR_TEXTURE: {
|
||||||
|
return TextureLoaderFunc(model::TextureUsage::createMetallicTextureFromImage);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case CUSTOM_TEXTURE: {
|
case CUSTOM_TEXTURE: {
|
||||||
return _textureLoader;
|
return _textureLoader;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DEFAULT_TEXTURE:
|
case DEFAULT_TEXTURE:
|
||||||
case SPECULAR_TEXTURE:
|
|
||||||
case EMISSIVE_TEXTURE:
|
case EMISSIVE_TEXTURE:
|
||||||
default: {
|
default: {
|
||||||
return TextureLoaderFunc(model::TextureUsage::create2DTextureFromImage);
|
return TextureLoaderFunc(model::TextureUsage::create2DTextureFromImage);
|
||||||
|
|
|
@ -202,14 +202,13 @@ void SunSkyStage::setSunModelEnable(bool isEnabled) {
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SunSkyStage::setSunColor(const Vec3& color) {
|
void SunSkyStage::setSunAmbientSphere(const gpu::SHPointer& sphere) {
|
||||||
_sunLight->setColor(color);
|
if (sphere) {
|
||||||
}
|
_sunLight->setAmbientSphere(*sphere);
|
||||||
void SunSkyStage::setSunIntensity(float intensity) {
|
} else {
|
||||||
_sunLight->setIntensity(intensity);
|
const gpu::SphericalHarmonics::Preset DEFAULT_AMBIENT_SPHERE = gpu::SphericalHarmonics::OLD_TOWN_SQUARE;
|
||||||
}
|
_sunLight->setAmbientSpherePreset(DEFAULT_AMBIENT_SPHERE);
|
||||||
void SunSkyStage::setSunAmbientIntensity(float intensity) {
|
}
|
||||||
_sunLight->setAmbientIntensity(intensity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SunSkyStage::setSunDirection(const Vec3& direction) {
|
void SunSkyStage::setSunDirection(const Vec3& direction) {
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#ifndef hifi_model_Stage_h
|
#ifndef hifi_model_Stage_h
|
||||||
#define hifi_model_Stage_h
|
#define hifi_model_Stage_h
|
||||||
|
|
||||||
#include "gpu/Pipeline.h"
|
#include <gpu/Pipeline.h>
|
||||||
|
|
||||||
#include "Light.h"
|
#include "Light.h"
|
||||||
#include "Skybox.h"
|
#include "Skybox.h"
|
||||||
|
@ -143,12 +143,13 @@ public:
|
||||||
bool isSunModelEnabled() const { return _sunModelEnable; }
|
bool isSunModelEnabled() const { return _sunModelEnable; }
|
||||||
|
|
||||||
// Sun properties
|
// Sun properties
|
||||||
void setSunColor(const Vec3& color);
|
void setSunColor(const Vec3& color) { _sunLight->setColor(color); }
|
||||||
const Vec3& getSunColor() const { return getSunLight()->getColor(); }
|
const Vec3& getSunColor() const { return getSunLight()->getColor(); }
|
||||||
void setSunIntensity(float intensity);
|
void setSunIntensity(float intensity) { _sunLight->setIntensity(intensity); }
|
||||||
float getSunIntensity() const { return getSunLight()->getIntensity(); }
|
float getSunIntensity() const { return getSunLight()->getIntensity(); }
|
||||||
void setSunAmbientIntensity(float intensity);
|
void setSunAmbientIntensity(float intensity) { _sunLight->setAmbientIntensity(intensity); }
|
||||||
float getSunAmbientIntensity() const { return getSunLight()->getAmbientIntensity(); }
|
float getSunAmbientIntensity() const { return getSunLight()->getAmbientIntensity(); }
|
||||||
|
void setSunAmbientSphere(const gpu::SHPointer& sphere);
|
||||||
|
|
||||||
// The sun direction is expressed in the world space
|
// The sun direction is expressed in the world space
|
||||||
void setSunDirection(const Vec3& direction);
|
void setSunDirection(const Vec3& direction);
|
||||||
|
|
|
@ -264,27 +264,38 @@ gpu::Texture* TextureUsage::createRoughnessTextureFromImage(const QImage& srcIma
|
||||||
|
|
||||||
image = image.convertToFormat(QImage::Format_Grayscale8);
|
image = image.convertToFormat(QImage::Format_Grayscale8);
|
||||||
|
|
||||||
/* gpu::Texture* theTexture = nullptr;
|
gpu::Texture* theTexture = nullptr;
|
||||||
if ((image.width() > 0) && (image.height() > 0)) {
|
if ((image.width() > 0) && (image.height() > 0)) {
|
||||||
|
|
||||||
// Actual alpha channel?
|
gpu::Element formatGPU = gpu::Element(gpu::SCALAR, gpu::NUINT8, gpu::RGB);
|
||||||
for (int y = 0; y < image.height(); ++y) {
|
gpu::Element formatMip = gpu::Element(gpu::SCALAR, gpu::NUINT8, gpu::RGB);
|
||||||
QRgb* data = reinterpret_cast<QRgb*>(image.scanLine(y));
|
|
||||||
for (int x = 0; x < image.width(); ++x) {
|
theTexture = (gpu::Texture::create2D(formatGPU, image.width(), image.height(), gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
|
||||||
data[x]auto alpha = q(data[x]);
|
theTexture->assignStoredMip(0, formatMip, image.byteCount(), image.constBits());
|
||||||
if (alpha != 255) {
|
theTexture->autoGenerateMips(-1);
|
||||||
validAlpha = true;
|
|
||||||
break;
|
// FIXME queue for transfer to GPU and block on completion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return theTexture;
|
||||||
|
}
|
||||||
|
|
||||||
|
gpu::Texture* TextureUsage::createMetallicTextureFromImage(const QImage& srcImage, const std::string& srcImageName) {
|
||||||
|
QImage image = srcImage;
|
||||||
|
if (!image.hasAlphaChannel()) {
|
||||||
|
if (image.format() != QImage::Format_RGB888) {
|
||||||
|
image = image.convertToFormat(QImage::Format_RGB888);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (image.format() != QImage::Format_ARGB32) {
|
||||||
|
image = image.convertToFormat(QImage::Format_ARGB32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
|
image = image.convertToFormat(QImage::Format_Grayscale8);
|
||||||
|
|
||||||
gpu::Texture* theTexture = nullptr;
|
gpu::Texture* theTexture = nullptr;
|
||||||
if ((image.width() > 0) && (image.height() > 0)) {
|
if ((image.width() > 0) && (image.height() > 0)) {
|
||||||
// bool isLinearRGB = true; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE);
|
|
||||||
bool isLinearRGB = false; //(_type == NORMAL_TEXTURE) || (_type == EMISSIVE_TEXTURE);
|
|
||||||
|
|
||||||
gpu::Element formatGPU = gpu::Element(gpu::SCALAR, gpu::NUINT8, gpu::RGB);
|
gpu::Element formatGPU = gpu::Element(gpu::SCALAR, gpu::NUINT8, gpu::RGB);
|
||||||
gpu::Element formatMip = gpu::Element(gpu::SCALAR, gpu::NUINT8, gpu::RGB);
|
gpu::Element formatMip = gpu::Element(gpu::SCALAR, gpu::NUINT8, gpu::RGB);
|
||||||
|
|
|
@ -35,6 +35,7 @@ public:
|
||||||
static gpu::Texture* createNormalTextureFromNormalImage(const QImage& image, const std::string& srcImageName);
|
static gpu::Texture* createNormalTextureFromNormalImage(const QImage& image, const std::string& srcImageName);
|
||||||
static gpu::Texture* createNormalTextureFromBumpImage(const QImage& image, const std::string& srcImageName);
|
static gpu::Texture* createNormalTextureFromBumpImage(const QImage& image, const std::string& srcImageName);
|
||||||
static gpu::Texture* createRoughnessTextureFromImage(const QImage& image, const std::string& srcImageName);
|
static gpu::Texture* createRoughnessTextureFromImage(const QImage& image, const std::string& srcImageName);
|
||||||
|
static gpu::Texture* createMetallicTextureFromImage(const QImage& image, const std::string& srcImageName);
|
||||||
static gpu::Texture* createCubeTextureFromImage(const QImage& image, const std::string& srcImageName);
|
static gpu::Texture* createCubeTextureFromImage(const QImage& image, const std::string& srcImageName);
|
||||||
static gpu::Texture* createLightmapTextureFromImage(const QImage& image, const std::string& srcImageName);
|
static gpu::Texture* createLightmapTextureFromImage(const QImage& image, const std::string& srcImageName);
|
||||||
|
|
||||||
|
|
|
@ -60,29 +60,23 @@ static const std::string DEFAULT_ALBEDO_SHADER {
|
||||||
" }"
|
" }"
|
||||||
};
|
};
|
||||||
|
|
||||||
static const std::string DEFAULT_FRESNEL_SHADER{
|
|
||||||
"vec4 getFragmentColor() {"
|
|
||||||
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
|
|
||||||
" return vec4(pow(frag.specular, vec3(1.0 / 2.2)), 1.0);"
|
|
||||||
" }"
|
|
||||||
};
|
|
||||||
|
|
||||||
static const std::string DEFAULT_METALLIC_SHADER {
|
static const std::string DEFAULT_METALLIC_SHADER {
|
||||||
"vec4 getFragmentColor() {"
|
"vec4 getFragmentColor() {"
|
||||||
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
|
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
|
||||||
" return vec4(vec3(frag.metallic), 1.0);"
|
" return vec4(vec3(pow(frag.metallic, 1.0 / 2.2)), 1.0);"
|
||||||
" }"
|
" }"
|
||||||
};
|
};
|
||||||
|
|
||||||
static const std::string DEFAULT_ROUGHNESS_SHADER {
|
static const std::string DEFAULT_ROUGHNESS_SHADER {
|
||||||
"vec4 getFragmentColor() {"
|
"vec4 getFragmentColor() {"
|
||||||
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
|
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
|
||||||
" return vec4(vec3(frag.roughness), 1.0);"
|
" return vec4(vec3(pow(frag.roughness, 1.0 / 2.2)), 1.0);"
|
||||||
" }"
|
" }"
|
||||||
};
|
};
|
||||||
static const std::string DEFAULT_NORMAL_SHADER {
|
static const std::string DEFAULT_NORMAL_SHADER {
|
||||||
"vec4 getFragmentColor() {"
|
"vec4 getFragmentColor() {"
|
||||||
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
|
" DeferredFragment frag = unpackDeferredFragmentNoPosition(uv);"
|
||||||
" return vec4(normalize(frag.normal), 1.0);"
|
" return vec4(vec3(0.5) + (frag.normal * 0.5), 1.0);"
|
||||||
" }"
|
" }"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -180,8 +174,6 @@ std::string DebugDeferredBuffer::getShaderSourceCode(Mode mode, std::string cust
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case AlbedoMode:
|
case AlbedoMode:
|
||||||
return DEFAULT_ALBEDO_SHADER;
|
return DEFAULT_ALBEDO_SHADER;
|
||||||
case FresnelMode:
|
|
||||||
return DEFAULT_FRESNEL_SHADER;
|
|
||||||
case MetallicMode:
|
case MetallicMode:
|
||||||
return DEFAULT_METALLIC_SHADER;
|
return DEFAULT_METALLIC_SHADER;
|
||||||
case RoughnessMode:
|
case RoughnessMode:
|
||||||
|
|
|
@ -52,7 +52,6 @@ protected:
|
||||||
NormalMode,
|
NormalMode,
|
||||||
RoughnessMode,
|
RoughnessMode,
|
||||||
MetallicMode,
|
MetallicMode,
|
||||||
FresnelMode,
|
|
||||||
EmissiveMode,
|
EmissiveMode,
|
||||||
OcclusionMode,
|
OcclusionMode,
|
||||||
LightmapMode,
|
LightmapMode,
|
||||||
|
|
|
@ -312,15 +312,13 @@ void DeferredLightingEffect::render(const render::RenderContextPointer& renderCo
|
||||||
|
|
||||||
// First Global directional light and ambient pass
|
// First Global directional light and ambient pass
|
||||||
{
|
{
|
||||||
bool useSkyboxCubemap = (_skybox) && (_skybox->getCubemap());
|
|
||||||
|
|
||||||
auto& program = _shadowMapEnabled ? _directionalLightShadow : _directionalLight;
|
auto& program = _shadowMapEnabled ? _directionalLightShadow : _directionalLight;
|
||||||
LightLocationsPtr locations = _shadowMapEnabled ? _directionalLightShadowLocations : _directionalLightLocations;
|
LightLocationsPtr locations = _shadowMapEnabled ? _directionalLightShadowLocations : _directionalLightLocations;
|
||||||
|
|
||||||
// Setup the global directional pass pipeline
|
// Setup the global directional pass pipeline
|
||||||
{
|
{
|
||||||
if (_shadowMapEnabled) {
|
if (_shadowMapEnabled) {
|
||||||
if (useSkyboxCubemap) {
|
if (_skyboxTexture) {
|
||||||
program = _directionalSkyboxLightShadow;
|
program = _directionalSkyboxLightShadow;
|
||||||
locations = _directionalSkyboxLightShadowLocations;
|
locations = _directionalSkyboxLightShadowLocations;
|
||||||
} else if (_ambientLightMode > -1) {
|
} else if (_ambientLightMode > -1) {
|
||||||
|
@ -328,7 +326,7 @@ void DeferredLightingEffect::render(const render::RenderContextPointer& renderCo
|
||||||
locations = _directionalAmbientSphereLightShadowLocations;
|
locations = _directionalAmbientSphereLightShadowLocations;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (useSkyboxCubemap) {
|
if (_skyboxTexture) {
|
||||||
program = _directionalSkyboxLight;
|
program = _directionalSkyboxLight;
|
||||||
locations = _directionalSkyboxLightLocations;
|
locations = _directionalSkyboxLightLocations;
|
||||||
} else if (_ambientLightMode > -1) {
|
} else if (_ambientLightMode > -1) {
|
||||||
|
@ -356,7 +354,7 @@ void DeferredLightingEffect::render(const render::RenderContextPointer& renderCo
|
||||||
geometryCache->renderQuad(batch, topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, color);
|
geometryCache->renderQuad(batch, topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useSkyboxCubemap) {
|
if (_skyboxTexture) {
|
||||||
batch.setResourceTexture(SKYBOX_MAP_UNIT, nullptr);
|
batch.setResourceTexture(SKYBOX_MAP_UNIT, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -501,9 +499,8 @@ void DeferredLightingEffect::setupKeyLightBatch(gpu::Batch& batch, int lightBuff
|
||||||
batch.setUniformBuffer(lightBufferUnit, globalLight->getSchemaBuffer());
|
batch.setUniformBuffer(lightBufferUnit, globalLight->getSchemaBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool useSkyboxCubemap = (_skybox) && (_skybox->getCubemap());
|
if (_skyboxTexture && (skyboxCubemapUnit >= 0)) {
|
||||||
if (useSkyboxCubemap && (skyboxCubemapUnit >= 0)) {
|
batch.setResourceTexture(skyboxCubemapUnit, _skyboxTexture);
|
||||||
batch.setResourceTexture(skyboxCubemapUnit, _skybox->getCubemap());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -562,32 +559,9 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeferredLightingEffect::setAmbientLightMode(int preset) {
|
void DeferredLightingEffect::setGlobalLight(const model::LightPointer& light, const gpu::TexturePointer& skyboxTexture) {
|
||||||
if ((preset >= 0) && (preset < gpu::SphericalHarmonics::NUM_PRESET)) {
|
_allocatedLights.front() = light;
|
||||||
_ambientLightMode = preset;
|
_skyboxTexture = skyboxTexture;
|
||||||
auto light = _allocatedLights.front();
|
|
||||||
light->setAmbientSpherePreset(gpu::SphericalHarmonics::Preset(preset % gpu::SphericalHarmonics::NUM_PRESET));
|
|
||||||
} else {
|
|
||||||
// force to preset 0
|
|
||||||
setAmbientLightMode(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeferredLightingEffect::setGlobalLight(const glm::vec3& direction, const glm::vec3& color, float intensity, float ambientIntensity) {
|
|
||||||
auto light = _allocatedLights.front();
|
|
||||||
light->setDirection(direction);
|
|
||||||
light->setColor(color);
|
|
||||||
light->setIntensity(intensity);
|
|
||||||
light->setAmbientIntensity(ambientIntensity);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DeferredLightingEffect::setGlobalSkybox(const model::SkyboxPointer& skybox) {
|
|
||||||
_skybox = skybox;
|
|
||||||
auto light = _allocatedLights.front();
|
|
||||||
|
|
||||||
if (_skybox && _skybox->getCubemap() && _skybox->getCubemap()->isDefined() && _skybox->getCubemap()->getIrradiance()) {
|
|
||||||
light->setAmbientSphere( (*_skybox->getCubemap()->getIrradiance()) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
model::MeshPointer DeferredLightingEffect::getSpotLightMesh() {
|
model::MeshPointer DeferredLightingEffect::getSpotLightMesh() {
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
#include <NumericalConstants.h>
|
#include <NumericalConstants.h>
|
||||||
|
|
||||||
#include "model/Light.h"
|
#include "model/Light.h"
|
||||||
#include "model/Stage.h"
|
|
||||||
#include "model/Geometry.h"
|
#include "model/Geometry.h"
|
||||||
|
|
||||||
#include "render/Context.h"
|
#include "render/Context.h"
|
||||||
|
@ -49,9 +48,7 @@ public:
|
||||||
void setupKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int skyboxCubemapUnit);
|
void setupKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int skyboxCubemapUnit);
|
||||||
|
|
||||||
// update global lighting
|
// update global lighting
|
||||||
void setAmbientLightMode(int preset);
|
void setGlobalLight(const model::LightPointer& light, const gpu::TexturePointer& skyboxTexture);
|
||||||
void setGlobalLight(const glm::vec3& direction, const glm::vec3& color, float intensity, float ambientIntensity);
|
|
||||||
void setGlobalSkybox(const model::SkyboxPointer& skybox);
|
|
||||||
|
|
||||||
const LightStage& getLightStage() { return _lightStage; }
|
const LightStage& getLightStage() { return _lightStage; }
|
||||||
void setShadowMapEnabled(bool enable) { _shadowMapEnabled = enable; };
|
void setShadowMapEnabled(bool enable) { _shadowMapEnabled = enable; };
|
||||||
|
@ -99,7 +96,7 @@ private:
|
||||||
std::vector<int> _spotLights;
|
std::vector<int> _spotLights;
|
||||||
|
|
||||||
int _ambientLightMode = 0;
|
int _ambientLightMode = 0;
|
||||||
model::SkyboxPointer _skybox;
|
gpu::TexturePointer _skyboxTexture;
|
||||||
|
|
||||||
// Class describing the uniform buffer with all the parameters common to the deferred shaders
|
// Class describing the uniform buffer with all the parameters common to the deferred shaders
|
||||||
class DeferredTransform {
|
class DeferredTransform {
|
||||||
|
|
|
@ -23,7 +23,7 @@ vec4 fetchAlbedoMap(vec2 uv) {
|
||||||
<@if withRoughness@>
|
<@if withRoughness@>
|
||||||
uniform sampler2D roughnessMap;
|
uniform sampler2D roughnessMap;
|
||||||
float fetchRoughnessMap(vec2 uv) {
|
float fetchRoughnessMap(vec2 uv) {
|
||||||
return texture(roughnessMap, uv).r;
|
return pow(texture(roughnessMap, uv).r, 2.2);
|
||||||
}
|
}
|
||||||
<@endif@>
|
<@endif@>
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ vec3 fetchNormalMap(vec2 uv) {
|
||||||
<@if withMetallic@>
|
<@if withMetallic@>
|
||||||
uniform sampler2D specularMap;
|
uniform sampler2D specularMap;
|
||||||
float fetchMetallicMap(vec2 uv) {
|
float fetchMetallicMap(vec2 uv) {
|
||||||
return texture(specularMap, uv).r;
|
return pow(texture(specularMap, uv).r, 2.2);
|
||||||
}
|
}
|
||||||
<@endif@>
|
<@endif@>
|
||||||
|
|
||||||
|
|
|
@ -77,6 +77,10 @@ void SceneScripting::KeyLight::setAmbientIntensity(float intensity) {
|
||||||
_skyStage->setSunAmbientIntensity(intensity);
|
_skyStage->setSunAmbientIntensity(intensity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SceneScripting::KeyLight::setAmbientSphere(const gpu::SHPointer& sphere) {
|
||||||
|
_skyStage->setSunAmbientSphere(sphere);
|
||||||
|
}
|
||||||
|
|
||||||
glm::vec3 SceneScripting::KeyLight::getDirection() const {
|
glm::vec3 SceneScripting::KeyLight::getDirection() const {
|
||||||
return _skyStage->getSunDirection();
|
return _skyStage->getSunDirection();
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,6 +81,10 @@ namespace SceneScripting {
|
||||||
// setDirection is only effective if stage Sun model is disabled
|
// setDirection is only effective if stage Sun model is disabled
|
||||||
void setDirection(const glm::vec3& direction);
|
void setDirection(const glm::vec3& direction);
|
||||||
|
|
||||||
|
// AmbientTexture is unscriptable - it must be set through the zone entity
|
||||||
|
void setAmbientSphere(const gpu::SHPointer& sphere);
|
||||||
|
void resetAmbientSphere() { setAmbientSphere(nullptr); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
model::SunSkyStagePointer _skyStage;
|
model::SunSkyStagePointer _skyStage;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue