K.Miao
K.Miao

Reputation: 871

How to Avoid Blending with Background When Enabling Blending

I'm trying to implement what potree does to implement the blended splats. In the this example, when disabling EDL and switch the quality option to Splats in the Appearance folder, it shows the blending effects.

My question is that how it can avoid those points blended with the background. When I enable blending in my own project, the points get blended with my background color and look not good. What's the elegant solution to avoid blending with the background?

EDIT:

You can see the points are getting blended with the white background. I'm using a custom shader to set the alpha value. In this image, the alpha value is 0.5.

image

Upvotes: 1

Views: 684

Answers (1)

Markus
Markus

Reputation: 2222

Potree uses a more complex blending function that requires 3 passes.

  1. Visibility Pass: Renders the depth.
  2. Attribute Pass: Does additive blending, but only for points with that are at most blendDepth units behind the depth buffer.
  3. Shading/Normalization Pass: Normalizes the additive output to go from a bright additive to the smoothly blended look.

enter image description here (edit: taken from http://www.ahornung.net/files/pub/Hornung_PBG05.pdf)

The attribute pass outputs a weighted sum of attribute values into the rgb channel, and a sum of weight into the alpha channel. The weight w for each points depends on the distance to the center. The output of the fragment shader is: gl_FragColor = vec4(w * rgb, w)

enter image description here

The normalization pass is a screen space post processing shader that divides each color in the framebuffer by the weight: gl_FragColor = vec4(weightedSumOfRGBs / sumOfWeights, 1.0)

The final result are smoothely blended points with a transition hardness that depends on the weight function:

enter image description here

Check this thesis for a more detailed explanation (chapter 4.2.2):

https://www.cg.tuwien.ac.at/research/publications/2016/SCHUETZ-2016-POT/SCHUETZ-2016-POT-thesis.pdf

Or this original paper of the algorithm:

http://www.ahornung.net/files/pub/Hornung_PBG05.pdf

Edit:

Also, to avoid seeing through to the backgroud, clear the buffer with a black color and alpha = 0, then render your points with the high quality 3-pass splatting algorithm and in the last step, render the background. The background will only be visible in areas where no points were rendered.

Upvotes: 2

Related Questions