Working beta pipeline

This commit is contained in:
Olivier Prat 2019-03-28 16:44:22 +01:00
parent 2397d5919f
commit cef9e454d5
8 changed files with 82 additions and 46 deletions

View file

@ -501,7 +501,7 @@ void CubeMap::generateGGXSamples(GGXSamples& data, float roughness, const int re
} }
void CubeMap::convolveForGGX(CubeMap& output, const std::atomic<bool>& abortProcessing) const { void CubeMap::convolveForGGX(CubeMap& output, const std::atomic<bool>& abortProcessing) const {
// This should match fragment.glsl values, too // This should match the value in the getMipLevelFromRoughness function (LightAmbient.slh)
static const float ROUGHNESS_1_MIP_RESOLUTION = 1.5f; static const float ROUGHNESS_1_MIP_RESOLUTION = 1.5f;
static const size_t MAX_SAMPLE_COUNT = 4000; static const size_t MAX_SAMPLE_COUNT = 4000;

View file

@ -105,9 +105,9 @@ TextureUsage::TextureLoader TextureUsage::getTextureLoaderForType(Type type, con
return image::TextureUsage::createCubeTextureFromImage; return image::TextureUsage::createCubeTextureFromImage;
case AMBIENT_TEXTURE: case AMBIENT_TEXTURE:
if (options.value("generateIrradiance", true).toBool()) { if (options.value("generateIrradiance", true).toBool()) {
return image::TextureUsage::createCubeTextureAndIrradianceFromImage; return image::TextureUsage::createAmbientCubeTextureAndIrradianceFromImage;
} else { } else {
return image::TextureUsage::createCubeTextureFromImage; return image::TextureUsage::createAmbientCubeTextureFromImage;
} }
case BUMP_TEXTURE: case BUMP_TEXTURE:
return image::TextureUsage::createNormalTextureFromBumpImage; return image::TextureUsage::createNormalTextureFromBumpImage;
@ -188,12 +188,12 @@ gpu::TexturePointer TextureUsage::createCubeTextureFromImage(QImage&& srcImage,
return processCubeTextureColorFromImage(std::move(srcImage), srcImageName, compress, target, CUBE_DEFAULT, abortProcessing); return processCubeTextureColorFromImage(std::move(srcImage), srcImageName, compress, target, CUBE_DEFAULT, abortProcessing);
} }
gpu::TexturePointer TextureUsage::createGGXConvolvedCubeTextureFromImage(QImage&& image, const std::string& srcImageName, gpu::TexturePointer TextureUsage::createAmbientCubeTextureFromImage(QImage&& image, const std::string& srcImageName,
bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing) { bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing) {
return processCubeTextureColorFromImage(std::move(image), srcImageName, compress, target, CUBE_GGX_CONVOLVE, abortProcessing); return processCubeTextureColorFromImage(std::move(image), srcImageName, compress, target, CUBE_GGX_CONVOLVE, abortProcessing);
} }
gpu::TexturePointer TextureUsage::createGGXConvolvedCubeTextureAndIrradianceFromImage(QImage&& image, const std::string& srcImageName, gpu::TexturePointer TextureUsage::createAmbientCubeTextureAndIrradianceFromImage(QImage&& image, const std::string& srcImageName,
bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing) { bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing) {
return processCubeTextureColorFromImage(std::move(image), srcImageName, compress, target, CUBE_GENERATE_IRRADIANCE | CUBE_GGX_CONVOLVE, abortProcessing); return processCubeTextureColorFromImage(std::move(image), srcImageName, compress, target, CUBE_GENERATE_IRRADIANCE | CUBE_GGX_CONVOLVE, abortProcessing);
} }

View file

@ -78,10 +78,10 @@ gpu::TexturePointer createCubeTextureFromImage(QImage&& image, const std::string
bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing); bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing);
gpu::TexturePointer createCubeTextureAndIrradianceFromImage(QImage&& image, const std::string& srcImageName, gpu::TexturePointer createCubeTextureAndIrradianceFromImage(QImage&& image, const std::string& srcImageName,
bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing); bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing);
gpu::TexturePointer createGGXConvolvedCubeTextureFromImage(QImage&& image, const std::string& srcImageName, gpu::TexturePointer createAmbientCubeTextureFromImage(QImage&& image, const std::string& srcImageName,
bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing); bool compress, gpu::BackendTarget target, const std::atomic<bool>& abortProcessing);
gpu::TexturePointer createGGXConvolvedCubeTextureAndIrradianceFromImage(QImage&& image, const std::string& srcImageName, gpu::TexturePointer createAmbientCubeTextureAndIrradianceFromImage(QImage&& image, const std::string& srcImageName,
bool compress, gpu::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, gpu::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,

View file

@ -642,8 +642,6 @@ void RenderDeferred::run(const RenderContextPointer& renderContext, const Inputs
config->setGPUBatchRunTime(_gpuTimer->getGPUAverage(), _gpuTimer->getBatchAverage()); config->setGPUBatchRunTime(_gpuTimer->getGPUAverage(), _gpuTimer->getBatchAverage());
} }
void DefaultLightingSetup::run(const RenderContextPointer& renderContext) { void DefaultLightingSetup::run(const RenderContextPointer& renderContext) {
if (!_defaultLight || !_defaultBackground) { if (!_defaultLight || !_defaultBackground) {
@ -655,21 +653,21 @@ void DefaultLightingSetup::run(const RenderContextPointer& renderContext) {
defaultSkyboxURL, image::TextureUsage::SKY_TEXTURE); defaultSkyboxURL, image::TextureUsage::SKY_TEXTURE);
} }
if (!_defaultSkyboxAmbientTexture) { if (!_defaultAmbientNetworkTexture) {
PROFILE_RANGE(render, "Process Default Ambient map"); PROFILE_RANGE(render, "Process Default Ambient map");
_defaultSkyboxAmbientTexture = DependencyManager::get<TextureCache>()->getTexture( _defaultAmbientNetworkTexture = DependencyManager::get<TextureCache>()->getTexture(
defaultSkyboxURL, image::TextureUsage::AMBIENT_TEXTURE); defaultSkyboxURL, image::TextureUsage::AMBIENT_TEXTURE);
} }
if (_defaultSkyboxNetworkTexture && _defaultSkyboxNetworkTexture->isLoaded() && _defaultSkyboxNetworkTexture->getGPUTexture()) { if (_defaultSkyboxNetworkTexture && _defaultSkyboxNetworkTexture->isLoaded() && _defaultSkyboxNetworkTexture->getGPUTexture()) {
_defaultSkybox->setCubemap(_defaultSkyboxAmbientTexture); _defaultSkybox->setCubemap(_defaultSkyboxNetworkTexture->getGPUTexture());
} else { } else {
// Don't do anything until the skybox has loaded // Don't do anything until the skybox has loaded
return; return;
} }
if (_defaultSkyboxAmbientTexture && _defaultSkyboxAmbientTexture->isLoaded() && _defaultSkyboxAmbientTexture->getGPUTexture()) { if (_defaultAmbientNetworkTexture && _defaultAmbientNetworkTexture->isLoaded() && _defaultAmbientNetworkTexture->getGPUTexture()) {
_defaultSkyboxAmbientTexture = _defaultSkyboxAmbientTexture->getGPUTexture(); _defaultAmbientTexture = _defaultAmbientNetworkTexture->getGPUTexture();
} else { } else {
// Don't do anything until the ambient box has been loaded // Don't do anything until the ambient box has been loaded
return; return;
@ -688,8 +686,8 @@ void DefaultLightingSetup::run(const RenderContextPointer& renderContext) {
lp->setAmbientSpherePreset(gpu::SphericalHarmonics::Preset::OLD_TOWN_SQUARE); lp->setAmbientSpherePreset(gpu::SphericalHarmonics::Preset::OLD_TOWN_SQUARE);
lp->setAmbientIntensity(0.5f); lp->setAmbientIntensity(0.5f);
lp->setAmbientMap(_defaultSkyboxAmbientTexture); lp->setAmbientMap(_defaultAmbientTexture);
auto irradianceSH = _defaultSkyboxAmbientTexture->getIrradiance(); auto irradianceSH = _defaultAmbientTexture->getIrradiance();
if (irradianceSH) { if (irradianceSH) {
lp->setAmbientSphere((*irradianceSH)); lp->setAmbientSphere((*irradianceSH));
} }

View file

@ -212,7 +212,8 @@ protected:
HazeStage::Index _defaultHazeID{ HazeStage::INVALID_INDEX }; HazeStage::Index _defaultHazeID{ HazeStage::INVALID_INDEX };
graphics::SkyboxPointer _defaultSkybox { new ProceduralSkybox() }; graphics::SkyboxPointer _defaultSkybox { new ProceduralSkybox() };
NetworkTexturePointer _defaultSkyboxNetworkTexture; NetworkTexturePointer _defaultSkyboxNetworkTexture;
gpu::TexturePointer _defaultSkyboxAmbientTexture; NetworkTexturePointer _defaultAmbientNetworkTexture;
gpu::TexturePointer _defaultAmbientTexture;
}; };
#endif // hifi_DeferredLightingEffect_h #endif // hifi_DeferredLightingEffect_h

View file

@ -36,6 +36,13 @@ vec3 fresnelSchlickAmbient(vec3 fresnelColor, float ndotd, float gloss) {
<$declareSkyboxMap()$> <$declareSkyboxMap()$>
<@endif@> <@endif@>
float getMipLevelFromRoughness(float roughness, float lodCount) {
// This should match the value in the CubeMap::convolveForGGX method (CubeMap.cpp)
float ROUGHNESS_1_MIP_RESOLUTION = 1.5;
float deltaLod = lodCount - ROUGHNESS_1_MIP_RESOLUTION;
return (sqrt(6.0*roughness+0.25)-0.5)*deltaLod*0.5;
}
vec3 evalAmbientSpecularIrradiance(LightAmbient ambient, SurfaceData surface, vec3 lightDir) { vec3 evalAmbientSpecularIrradiance(LightAmbient ambient, SurfaceData surface, vec3 lightDir) {
vec3 specularLight; vec3 specularLight;
<@if supportIfAmbientMapElseAmbientSphere@> <@if supportIfAmbientMapElseAmbientSphere@>
@ -43,10 +50,10 @@ vec3 evalAmbientSpecularIrradiance(LightAmbient ambient, SurfaceData surface, ve
<@endif@> <@endif@>
<@if supportAmbientMap@> <@if supportAmbientMap@>
{ {
float levels = getLightAmbientMapNumMips(ambient); float levelCount = getLightAmbientMapNumMips(ambient);
float m = 12.0 / (1.0+11.0*surface.roughness); float lod = getMipLevelFromRoughness(surface.roughness, levelCount);
float lod = levels - m;
lod = max(lod, 0.0); lod = max(lod, 0.0);
specularLight = evalSkyboxLight(lightDir, lod).xyz; specularLight = evalSkyboxLight(lightDir, lod).xyz;
} }
<@endif@> <@endif@>

View file

@ -17,6 +17,7 @@
#include <QtWidgets/QLineEdit> #include <QtWidgets/QLineEdit>
#include <QtWidgets/QMessageBox> #include <QtWidgets/QMessageBox>
#include <QtWidgets/QPushButton> #include <QtWidgets/QPushButton>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QStackedWidget> #include <QtWidgets/QStackedWidget>
#include <QtCore/QDir> #include <QtCore/QDir>
@ -61,6 +62,15 @@ void SkyboxBakeWidget::setupUI() {
// start a new row for next component // start a new row for next component
++rowIndex; ++rowIndex;
// setup a section to enable Ambient map baking
_ambientMapBox = new QCheckBox("Bake ambient map(s)");
_ambientMapBox->setChecked(false);
gridLayout->addWidget(_ambientMapBox, rowIndex, 1);
// start a new row for next component
++rowIndex;
// setup a section to choose the output directory // setup a section to choose the output directory
QLabel* outputDirectoryLabel = new QLabel("Output Directory"); QLabel* outputDirectoryLabel = new QLabel("Output Directory");
@ -176,51 +186,67 @@ void SkyboxBakeWidget::bakeButtonClicked() {
// if the URL doesn't have a scheme, assume it is a local file // if the URL doesn't have a scheme, assume it is a local file
if (skyboxToBakeURL.scheme() != "http" && skyboxToBakeURL.scheme() != "https" && skyboxToBakeURL.scheme() != "ftp") { if (skyboxToBakeURL.scheme() != "http" && skyboxToBakeURL.scheme() != "https" && skyboxToBakeURL.scheme() != "ftp") {
skyboxToBakeURL.setScheme("file"); skyboxToBakeURL = QUrl::fromLocalFile(fileURLString);
} }
// everything seems to be in place, kick off a bake for this skybox now // everything seems to be in place, kick off a bake for this skybox now
auto baker = std::unique_ptr<TextureBaker> { addBaker(new TextureBaker(skyboxToBakeURL, image::TextureUsage::SKY_TEXTURE, outputDirectory.absolutePath()),
new TextureBaker(skyboxToBakeURL, image::TextureUsage::SKY_TEXTURE, outputDirectory.absolutePath()) outputDirectory);
};
// move the baker to a worker thread if (_ambientMapBox->isChecked()) {
baker->moveToThread(Oven::instance().getNextWorkerThread()); QString ambientMapBaseFilename;
QString urlPath = skyboxToBakeURL.path();
auto urlParts = urlPath.split('.');
// invoke the bake method on the baker thread urlParts.front() += "-ambient";
QMetaObject::invokeMethod(baker.get(), "bake"); ambientMapBaseFilename = QUrl(urlParts.front()).fileName();
// make sure we hear about the results of this baker when it is done // we need to bake the corresponding ambient map too
connect(baker.get(), &TextureBaker::finished, this, &SkyboxBakeWidget::handleFinishedBaker); addBaker(new TextureBaker(skyboxToBakeURL, image::TextureUsage::AMBIENT_TEXTURE, outputDirectory.absolutePath(), QString(), ambientMapBaseFilename),
outputDirectory);
// add a pending row to the results window to show that this bake is in process }
auto resultsWindow = OvenGUIApplication::instance()->getMainWindow()->showResultsWindow();
auto resultsRow = resultsWindow->addPendingResultRow(skyboxToBakeURL.fileName(), outputDirectory);
// keep a unique_ptr to this baker
// and remember the row that represents it in the results table
_bakers.emplace_back(std::move(baker), resultsRow);
} }
} }
void SkyboxBakeWidget::addBaker(TextureBaker* baker, const QDir& outputDirectory) {
auto textureBaker = std::unique_ptr<TextureBaker>{ baker };
// move the textureBaker to a worker thread
textureBaker->moveToThread(Oven::instance().getNextWorkerThread());
// invoke the bake method on the textureBaker thread
QMetaObject::invokeMethod(textureBaker.get(), "bake");
// make sure we hear about the results of this textureBaker when it is done
connect(textureBaker.get(), &TextureBaker::finished, this, &SkyboxBakeWidget::handleFinishedBaker);
// add a pending row to the results window to show that this bake is in process
auto resultsWindow = OvenGUIApplication::instance()->getMainWindow()->showResultsWindow();
auto resultsRow = resultsWindow->addPendingResultRow(baker->getBaseFilename(), outputDirectory);
// keep a unique_ptr to this textureBaker
// and remember the row that represents it in the results table
_bakers.emplace_back(std::move(textureBaker), resultsRow);
}
void SkyboxBakeWidget::handleFinishedBaker() { void SkyboxBakeWidget::handleFinishedBaker() {
if (auto baker = qobject_cast<TextureBaker*>(sender())) { if (auto textureBaker = qobject_cast<TextureBaker*>(sender())) {
// add the results of this bake to the results window // add the results of this bake to the results window
auto it = std::find_if(_bakers.begin(), _bakers.end(), [baker](const BakerRowPair& value) { auto it = std::find_if(_bakers.begin(), _bakers.end(), [textureBaker](const BakerRowPair& value) {
return value.first.get() == baker; return value.first.get() == textureBaker;
}); });
if (it != _bakers.end()) { if (it != _bakers.end()) {
auto resultRow = it->second; auto resultRow = it->second;
auto resultsWindow = OvenGUIApplication::instance()->getMainWindow()->showResultsWindow(); auto resultsWindow = OvenGUIApplication::instance()->getMainWindow()->showResultsWindow();
if (baker->hasErrors()) { if (textureBaker->hasErrors()) {
resultsWindow->changeStatusForRow(resultRow, baker->getErrors().join("\n")); resultsWindow->changeStatusForRow(resultRow, textureBaker->getErrors().join("\n"));
} else { } else {
resultsWindow->changeStatusForRow(resultRow, "Success"); resultsWindow->changeStatusForRow(resultRow, "Success");
} }
// drop our strong pointer to the baker now that we are done with it // drop our strong pointer to the textureBaker now that we are done with it
_bakers.erase(it); _bakers.erase(it);
} }
} }

View file

@ -21,6 +21,7 @@
#include "BakeWidget.h" #include "BakeWidget.h"
class QLineEdit; class QLineEdit;
class QCheckBox;
class SkyboxBakeWidget : public BakeWidget { class SkyboxBakeWidget : public BakeWidget {
Q_OBJECT Q_OBJECT
@ -42,9 +43,12 @@ private:
QLineEdit* _selectionLineEdit; QLineEdit* _selectionLineEdit;
QLineEdit* _outputDirLineEdit; QLineEdit* _outputDirLineEdit;
QCheckBox* _ambientMapBox;
Setting::Handle<QString> _exportDirectory; Setting::Handle<QString> _exportDirectory;
Setting::Handle<QString> _selectionStartDirectory; Setting::Handle<QString> _selectionStartDirectory;
void addBaker(TextureBaker* baker, const QDir& outputDir);
}; };
#endif // hifi_SkyboxBakeWidget_h #endif // hifi_SkyboxBakeWidget_h