RenderKit / ospray

An Open, Scalable, Portable, Ray Tracing Based Rendering Engine for High-Fidelity Visualization
http://ospray.org
Apache License 2.0
997 stars 182 forks source link

Background alpha not present in framebuffer output #394

Closed paulmelis closed 4 years ago

paulmelis commented 4 years ago
#include <ospray/ospray_cpp.h>

using namespace ospcommon::math;
using namespace ospray::cpp;

const int W = 32;
const int H = 32;

int main(int argc, const char *argv[])
{
    ospInit(&argc, argv);

    World world;
    world.commit();

    Renderer renderer("scivis");
    renderer.setParam("bgColor", vec4f(1.0f, 1.0f, 1.0f, 0.5f));
    renderer.commit();

    Camera camera("perspective");
    camera.setParam("aspect", 1.0f*W/H);
    camera.commit();

    FrameBuffer fb(vec2i(W,H), OSP_FB_SRGBA, OSP_FB_COLOR);
    fb.clear();

    fb.renderFrame(renderer, camera, world).wait();

    uint8_t *pixels = (uint8_t *)fb.map(OSP_FB_COLOR);

    for (int i = 0; i < W; i++)
        printf("%02d %02d %02d %02d\n", pixels[4*i+0], pixels[4*i+1], pixels[4*i+2], pixels[4*i+3]);

    fb.unmap(pixels);    
}

paulm@cmstorm 09:26:~/concepts/ospray-python/utes./t_bgcolor_alpha
255 255 255 254
255 255 255 254
255 255 255 254
255 255 255 254
255 255 255 254
255 255 255 254
255 255 255 254
...

The alpha value of bgColor doesn't seem to have any effect?

johguenther commented 4 years ago

Is now fixed in release-2.0.x.

paulmelis commented 4 years ago

Check!

paulmelis commented 4 years ago

Hmmm, found something weird. See this test:

The output image contains the correct opacity=1 (but see #393) for the white background, but the red geometry has opacity=0.5. The image here in the github issue doesn't show alpha in meaningful way, unfortunately:

opacity

I would expect all pixels to have the full opaqueness of the background color, regardless of the geometry opacity. To get an image with the actual opaqueness of the geometry I would normally use background (1,1,1,0).

Also, if you enable vertex.color in the test and disable the material, the per-vertex colors will have opacity 0.1, but this doesn't show in the rendered image. All pixels have opacity 1.0.

Finally, using the usual renderer.setParam("backgroundColor", 1.0f) has the new behaviour of setting the opacity to 0. Perhaps because the float gets cast first to a vec3f(1,1,1) followed by widening to vec4(1,1,1,0)?

johguenther commented 4 years ago

SciVis currently does not support (recursive) transparency of surfaces: another object behind the red quad would also be not visible (as is the background). We will fix this in v2.1.

Use of opacity of vertex.color will come in v2.0.1.

Re the last point: this is exactly what happens, and this is intended (default of backgroudColor is transparent/black) and was introduced in v1.3 (6d7a7634b2).