Bloom can now have a dirt texture applied

This commit is contained in:
Mathias Agopian
2020-02-13 20:51:43 -08:00
committed by Mathias Agopian
parent a4e4021950
commit 8bbf0ce9ef
14 changed files with 170 additions and 45 deletions
+34
View File
@@ -46,6 +46,8 @@
#include "Cube.h"
#include "NativeWindowHelper.h"
#include <stb_image.h>
#include "generated/resources/resources.h"
using namespace filament;
@@ -137,6 +139,7 @@ void FilamentApp::run(const Config& config, SetupCallback setupCallback,
window->mDepthView->getView()->setClearColor({0, 0, 0, 1});
}
loadDirt(config);
loadIBL(config);
if (mIBL != nullptr) {
mIBL->getSkybox()->setLayerMask(0x7, 0x4);
@@ -452,6 +455,37 @@ void FilamentApp::loadIBL(const Config& config) {
}
}
void FilamentApp::loadDirt(const Config& config) {
if (!config.dirt.empty()) {
Path dirtPath(config.dirt);
if (!dirtPath.exists()) {
std::cerr << "The specified dirt file does not exist: " << dirtPath << std::endl;
return;
}
if (!dirtPath.isFile()) {
std::cerr << "The specified dirt path is not a file: " << dirtPath << std::endl;
return;
}
int w, h, n;
unsigned char* data = stbi_load(dirtPath.getAbsolutePath().c_str(), &w, &h, &n, 3);
assert(n == 3);
mDirt = Texture::Builder()
.width(w)
.height(h)
.format(Texture::InternalFormat::RGB8)
.build(*mEngine);
mDirt->setImage(*mEngine, 0, { data, size_t(w * h * 3),
Texture::Format::RGB, Texture::Type::UBYTE,
(Texture::PixelBufferDescriptor::Callback)&stbi_image_free });
}
}
void FilamentApp::initSDL() {
ASSERT_POSTCONDITION(SDL_Init(SDL_INIT_EVENTS) == 0, "SDL_Init Failure");
}