Page MenuHome

Show Background Image Beneath Transparent Objects (Cycles only)
ClosedPublic

Authored by Jeroen Bakker (jbakker) on Aug 8 2019, 12:53 PM.

Details

Summary

Camera background images were not shown beneath transparent objects.
This patch performs an alpha under for background images for cycles.

In order to see the difference the Film transparency needs to be turned on.

Note that workbench and EEVEE still needs to be adapted as they don't
write the alpha value in the viewport.

This image shows the old behavior (left) vs the new behavior (right)

Side note. This implementation is already an improvement of the current behavior, what users are requesting. (Show background images underneath cycles viewport rendering.) It is clear that this patch still needs to be extended to workbench and eevee. For now that should be marked as a known limitation.

Diff Detail

Repository
rB Blender
Branch
T65988 (branched from master)
Build Status
Buildable 5032
Build 5032: arc lint + arc unit

Event Timeline

Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Aug 8 2019, 12:58 PM
Jeroen Bakker (jbakker) planned changes to this revision.Aug 8 2019, 1:38 PM
  • alpha channel of source image is ignored. Add a shader that does premultiply the colors with the alpha

Use Alpha premul for camera images

Jeroen Bakker (jbakker) retitled this revision from Show Background Image Beneath Transparent Objects to [WIP] Show Background Image Beneath Transparent Objects.Aug 8 2019, 2:05 PM
Jeroen Bakker (jbakker) planned changes to this revision.Aug 9 2019, 10:22 AM

Move the drawing of the checkerboard to object_mode.

Postpone rendering of checkerboard for better compositing

Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)Aug 9 2019, 11:32 AM

Removed unused code

@Jeroen Bakker (jbakker) what is the current status of this patch? Trying to see if it may fit in 2.81 (it seems a bit late for that though to be honest).

Part of the issues has been resolved inside as in it works better than it currently does. It works with cycles, but only with a single background image. EEVEE and Workbench still needs to be adapted as they do not support alpha film in the viewport. Supporting multiple background is a OIT question. The non transparent part needs to be rendered front to back. and the transparent part needs to be rendered back to front for better result. The draw engines are a bit in between and can intervene.

IMO it is solvable to 95% of what we want.

Draw order for alpha under pass

Finalized for cycles

Jeroen Bakker (jbakker) retitled this revision from [WIP] Show Background Image Beneath Transparent Objects to Show Background Image Beneath Transparent Objects.Sep 19 2019, 2:07 PM
Jeroen Bakker (jbakker) edited the summary of this revision. (Show Details)
Jeroen Bakker (jbakker) retitled this revision from Show Background Image Beneath Transparent Objects to Show Background Image Beneath Transparent Objects (Cycles only).
source/blender/draw/modes/object_mode.c
1266

Nitpicking, but this is float promotion, and some compilers will throw annoying warnings at us ;)

- depth = 0.000001;
+ depth = 0.000001f;
1272
- depth = 0.999999;
+ depth = 0.999999f;

Personally I would initialize float depth = 0.000001f, and here do depth = 1.0f - depth.

Jeroen Bakker (jbakker) marked 2 inline comments as done.Wed, Sep 25, 4:05 PM
Clément Foucault (fclem) requested changes to this revision.Wed, Oct 2, 6:14 PM

That said, I don't think the 2 pass approach is necessary. Is there any reason behind it? if any, it should at least be mentioned somewhere in a comment.

source/blender/draw/modes/object_mode.c
1281

I'm really not a big fan of this. Another approach would be to cycle through the CameraBGImage backwards in another loop.

It won't cost anything and it makes things more clean IMO. One loop for foreground and one for background images.

1456

Why not use :

DRWState state = DRW_STATE_WRITE_COLOR;
psl->camera_images_back = DRW_pass_create("Camera Images Back",
                                          state | DRW_STATE_BLEND_ALPHA_UNDER_PREMUL);
psl->camera_images_front = DRW_pass_create("Camera Images Front",
                                           state | DRW_STATE_BLEND_ALPHA_PREMUL);

This simplify a lot of thing. No need for double pass drawing, no need for depth biasing.

This revision now requires changes to proceed.Wed, Oct 2, 6:14 PM

Removed the reverse add in draw manager

Jeroen Bakker (jbakker) marked an inline comment as done.Fri, Oct 4, 1:01 PM
This revision is now accepted and ready to land.Fri, Oct 4, 4:35 PM