remove RGBM support for skybox and ibl cubemap

This commit is contained in:
Mathias Agopian
2019-06-18 18:33:48 -07:00
committed by Mathias Agopian
parent 99a501f0c3
commit d955e733bf
10 changed files with 12 additions and 86 deletions

View File

@@ -130,7 +130,6 @@ set(MATERIAL_SRCS
src/materials/blur.mat
src/materials/mipmapDepth.mat
src/materials/skybox.mat
src/materials/skyboxRGBM.mat
src/materials/sao.mat
src/materials/ssao.mat
)

View File

@@ -198,13 +198,12 @@ void FEngine::init() {
mDefaultIblTexture = upcast(Texture::Builder()
.width(1).height(1).levels(1)
.format(Texture::InternalFormat::RGBA8)
.rgbm(true)
.sampler(Texture::Sampler::SAMPLER_CUBEMAP)
.build(*this));
static uint32_t pixel = 0;
Texture::PixelBufferDescriptor buffer(
&pixel, 4, // 4 bytes in 1 RGBM pixel
Texture::Format::RGBM, Texture::Type::UBYTE);
&pixel, 4, // 4 bytes in 1 RGB pixel
Texture::Format::RGB, Texture::Type::UBYTE);
Texture::FaceOffsets offsets = {};
mDefaultIblTexture->setImage(*this, 0, std::move(buffer), offsets);
@@ -278,9 +277,7 @@ void FEngine::shutdown() {
cleanupResourceList(mSkyboxes);
// this must be done after Skyboxes and before materials
for (FMaterial const* material : mSkyboxMaterials) {
destroy(material);
}
destroy(mSkyboxMaterial);
cleanupResourceList(mIndexBuffers);
cleanupResourceList(mVertexBuffers);
@@ -429,12 +426,11 @@ void FEngine::flushCommandBuffer(CommandBufferQueue& commandQueue) {
commandQueue.flush();
}
const FMaterial* FEngine::getSkyboxMaterial(bool rgbm) const noexcept {
size_t index = rgbm ? 0 : 1;
FMaterial const* material = mSkyboxMaterials[index];
const FMaterial* FEngine::getSkyboxMaterial() const noexcept {
FMaterial const* material = mSkyboxMaterial;
if (UTILS_UNLIKELY(material == nullptr)) {
material = FSkybox::createMaterial(*const_cast<FEngine*>(this), rgbm);
mSkyboxMaterials[index] = material;
material = FSkybox::createMaterial(*const_cast<FEngine*>(this));
mSkyboxMaterial = material;
}
return material;
}

View File

@@ -110,11 +110,6 @@ IndirectLight* IndirectLight::Builder::build(Engine& engine) {
return nullptr;
}
if (!ASSERT_POSTCONDITION_NON_FATAL( mImpl->mReflectionsMap->isRgbm(),
"reflection map must have RGBM enabled")) {
return nullptr;
}
if (!ASSERT_POSTCONDITION_NON_FATAL(mImpl->mReflectionsMap->getLevels() ==
upcast(mImpl->mReflectionsMap)->getMaxLevelCount(),
"reflection map must have %u mipmap levels",
@@ -122,8 +117,6 @@ IndirectLight* IndirectLight::Builder::build(Engine& engine) {
return nullptr;
}
if (IBL_INTEGRATION == IBL_INTEGRATION_IMPORTANCE_SAMPLING) {
// FIXME: this doesn't work because IBLs are encoded as RGBM with a gamma of 0.5
// this produces mipmap levels that are too dark
mImpl->mReflectionsMap->generateMipmaps(engine);
}
}

View File

@@ -91,7 +91,7 @@ FSkybox::FSkybox(FEngine& engine, const Builder& builder) noexcept
mRenderableManager(engine.getRenderableManager()),
mIntensity(builder->mIntensity) {
FMaterial const* material = engine.getSkyboxMaterial(mSkyboxTexture->isRgbm());
FMaterial const* material = engine.getSkyboxMaterial();
mSkyboxMaterialInstance = material->createInstance();
TextureSampler sampler(TextureSampler::MagFilter::LINEAR, TextureSampler::WrapMode::REPEAT);
@@ -112,14 +112,7 @@ FSkybox::FSkybox(FEngine& engine, const Builder& builder) noexcept
.build(engine, mSkybox);
}
FMaterial const* FSkybox::createMaterial(FEngine& engine, bool rgbm) {
// TODO: Merge the two skybox materials into one.
if (rgbm) {
FMaterial const* material = upcast(Material::Builder().package(
MATERIALS_SKYBOXRGBM_DATA, MATERIALS_SKYBOXRGBM_SIZE).build(engine));
return material;
}
FMaterial const* FSkybox::createMaterial(FEngine& engine) {
FMaterial const* material = upcast(Material::Builder().package(
MATERIALS_SKYBOX_DATA, MATERIALS_SKYBOX_SIZE).build(engine));
return material;

View File

@@ -135,7 +135,7 @@ public:
uint32_t getMaterialId() const noexcept { return mMaterialId++; }
const FMaterial* getDefaultMaterial() const noexcept { return mDefaultMaterial; }
const FMaterial* getSkyboxMaterial(bool rgbm) const noexcept;
const FMaterial* getSkyboxMaterial() const noexcept;
const FIndirectLight* getDefaultIndirectLight() const noexcept { return mDefaultIbl; }
backend::Handle<backend::HwProgram> getPostProcessProgramSlow(PostProcessStage stage) const noexcept;
@@ -339,7 +339,7 @@ private:
Epoch mEngineEpoch;
mutable FMaterial const* mDefaultMaterial = nullptr;
mutable FMaterial const* mSkyboxMaterials[2] = { nullptr, nullptr };
mutable FMaterial const* mSkyboxMaterial = nullptr;
mutable FTexture* mDefaultIblTexture = nullptr;
mutable FIndirectLight* mDefaultIbl = nullptr;

View File

@@ -37,7 +37,7 @@ class FSkybox : public Skybox {
public:
FSkybox(FEngine& engine, const Builder& builder) noexcept;
static FMaterial const* createMaterial(FEngine& engine, bool rgbm);
static FMaterial const* createMaterial(FEngine& engine);
void terminate(FEngine& engine) noexcept;

View File

@@ -1,46 +0,0 @@
material {
name : "Skybox RGBM",
parameters : [
{
type : bool,
name : showSun
},
{
type : samplerCubemap,
name : skybox
}
],
variables : [
eyeDirection
],
vertexDomain : device,
depthWrite : false,
shadingModel : unlit,
variantFilter : [ skinning, shadowReceiver ],
culling: none
}
fragment {
void material(inout MaterialInputs material) {
prepareMaterial(material);
vec3 sky = decodeRGBM(texture(materialParams_skybox, variable_eyeDirection.xyz));
sky *= frameUniforms.iblLuminance;
if (materialParams.showSun && frameUniforms.sun.w >= 0.0f) {
vec3 direction = normalize(variable_eyeDirection.xyz);
vec3 sun = frameUniforms.lightColorIntensity.rgb * frameUniforms.lightColorIntensity.a;
float cosAngle = dot(direction, frameUniforms.lightDirection);
float x = (cosAngle - frameUniforms.sun.x) * frameUniforms.sun.z;
float gradient = pow(1.0 - saturate(x), frameUniforms.sun.w);
sky += sun * gradient;
}
material.baseColor = vec4(sky, 1.0);
}
}
vertex {
void materialVertex(inout MaterialVertexInputs material) {
float3 p = getPosition().xyz;
float3 unprojected = mulMat4x4Float3(getViewFromClipMatrix(), p).xyz;
material.eyeDirection.xyz = mulMat3x3Float3(getWorldFromViewMatrix(), unprojected);
}
}

View File

@@ -55,9 +55,6 @@ constexpr size_t CONFIG_MAX_LIGHT_INDEX = CONFIG_MAX_LIGHT_COUNT - 1;
// We store 64 bytes per bone.
constexpr size_t CONFIG_MAX_BONE_COUNT = 256;
// TODO This should be injected by the engine as a define of the shader.
static constexpr bool CONFIG_IBL_RGBM = true;
} // namespace filament
#endif // TNT_FILAMENT_driver/EngineEnums.h

View File

@@ -236,8 +236,6 @@ const std::string ShaderGenerator::createFragmentProgram(filament::backend::Shad
utils::io::sstream fs;
cg.generateProlog(fs, ShaderType::FRAGMENT, material.hasExternalSamplers);
cg.generateDefine(fs, "IBL_USE_RGBM", filament::CONFIG_IBL_RGBM);
// this should probably be a code generation option
cg.generateDefine(fs, "USE_MULTIPLE_SCATTERING_COMPENSATION", true);

View File

@@ -26,11 +26,7 @@
//------------------------------------------------------------------------------
vec3 decodeDataForIBL(const vec4 data) {
#if defined(IBL_USE_RGBM)
return decodeRGBM(data);
#else
return data.rgb;
#endif
}
//------------------------------------------------------------------------------