Reputation: 871
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.
Upvotes: 1
Views: 684
Reputation: 2222
Potree uses a more complex blending function that requires 3 passes.
(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)
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:
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