google/filament

How to configure screen space reflection effect?

MrZhuGitHub opened this issue · 5 comments

I want to achieve the following screen space reflection effect, but after configuring the setScreenSpaceReflectionsOptions() API as shown in the example, it didn’t produce the expected result. Has Filament implemented this feature yet? If so, how should I configure it?

    app.material = Material::Builder().package(RESOURCES_AIDEFAULTMAT_DATA, 
                                                 RESOURCES_AIDEFAULTMAT_SIZE).build(*engine);
    auto mi = app.materialInstance = app.material->createInstance();
    mi->setParameter("baseColor", RgbType::LINEAR, math::float3{0.6, 1.0, 0.2});
    mi->setParameter("metallic", 0.5f);
    mi->setParameter("roughness", 0.0f);
    mi->setParameter("reflectance", 0.5f);
   ..............

    filament::View::ScreenSpaceReflectionsOptions options;

    options.thickness = 0.1f;   
    options.bias = 0.01f;   
    options.maxDistance = 3.0f;  
    options.stride = 2.0f;  
    options.enabled = true;

    view->setScreenSpaceReflectionsOptions(options);

Image

Can you be more precise about what didn't work?

Can you be more precise about what didn't work?

Below First image is what I expect, but result is second image. My question is why there is no screen space reflection, although I have enable ScreenSpaceReflectionsOptions by View::setScreenSpaceReflectionsOptions(options) API. So is it due to incorrect material binding, lighting configuration, or other reasons?

Image

Image

The following is the specific code implementation:
.................
app.material = Material::Builder().package(RESOURCES_AIDEFAULTMAT_DATA, RESOURCES_AIDEFAULTMAT_SIZE).build(*engine);

    auto mi = app.material->createInstance();
    mi->setParameter("baseColor", RgbType::LINEAR, math::float3{0.75, 0.23, 0.5});
    mi->setParameter("metallic", 0.0f);
    mi->setParameter("roughness", 0.0f);
    mi->setParameter("reflectance", 1.0f);
    mi->setCullingMode(filament::Material::CullingMode::FRONT, filament::Material::CullingMode::NONE);

    RenderableManager::Builder(1)
        .boundingBox({ {0, 0, 0}, {2*cubeSize, 2*cubeSize, 2*cubeSize} })
        .geometry(0, RenderableManager::PrimitiveType::TRIANGLES, cubeVb, cubeIb, 0, 36)
        .material(0, mi)
        .receiveShadows(true)
        .castShadows(true)
        .build(*engine, app.cubeEntity);

  scene->addEntity(app.cubeEntity);  

  auto mi_1  = app.material->createInstance();
  mi_1  ->setParameter("baseColor", RgbType::LINEAR, math::float3{0.9, 0.9, 0.9});
  mi_1  ->setParameter("metallic", 1.0f);
  mi_1  ->setParameter("roughness", 0.2f);
  mi_1  ->setParameter("reflectance", 1.0f);

RenderableManager::Builder(1)
    .boundingBox({{ 0, 0, 0 }, { 200, 0.01, 200 }})
    .material(0, mi)
    .geometry(0, RenderableManager::PrimitiveType::TRIANGLES, vertexBuffer, indexBuffer, 0, 6)
    .receiveShadows(true)
    .castShadows(false)
    .build(*engine, app.planarEntity);

scene->addEntity(app.planarEntity);

    app.light = utils::EntityManager::get().create();
    LightManager::Builder(LightManager::Type::DIRECTIONAL)
            .color(Color::toLinear<ACCURATE>({0.98f, 0.92f, 0.89f}))
            .intensity(110000)
            .direction({0.5, -0.8, 0.7})
            .castShadows(true)
            .build(*engine, app.light);
    scene->addEntity(app.light);

    filament::View::ScreenSpaceReflectionsOptions options;
    options.enabled = true;
    view->setScreenSpaceReflectionsOptions(options);
 
    auto mIndirectLight = IndirectLight::Builder()
        .reflections(mTexture)
        .intensity(10000.0f)
        .build(*app.engine);
    app.scene->setIndirectLight(mIndirectLight);

    view->setScene(scene);
    ...........

Your plane must enable SSR as well, see https://google.github.io/filament/Materials.html#materialdefinitions/materialblock/lighting:reflections

Thank you very much for providing assistance. Configuring “reflections : screenspace” does indeed make screen space reflection effective. I have another question, FPS would decreased significantly, when open screen space reflection. Does the filament adapt Hierarchical-Z (Hi-Z) algorithm to optimize?

Besides, will filament support Stochastic Screen Space Reflections in the future.

Image

We're not doing these optimizations yet. And SSR work is generally not high priority at this point.