I've just spent some time preparing input and to show mask for stenciling and efficiency tests. I'll start with description and then show tests results. Praparation of needed sources is also downsampled, so entire solution is scalable (highr proportion of all passses is done on downsampled targets).
Here is result of displaying only offscreen output:
And this is Sobel filter pesenting only alpha
channel (for visibility, a in graphical output set to 1; Inverted value is kept in channel b of output.)
We can see that we got rid of edges that were caused by colour difference (considering only alpha detects only needed places where alpha changed rapidly.
This is very low percentage of picture to display in full resolution - that is good.
In low or none downsample (like 2x2 only intersections with (and being hidden behind) solid onjects cause sharp change of alpha.
(notice that there are no particles behind the square grass-plane).
In picture above we can't see edges between fumes from penguin jet edge and their neighbouring clear space (I've prepared for them extramally smooth fade of alpha).
However, there are a lot of particles of red-blue magic smoke in one place. we see slight edge in place of their biggest density but sobel delta is lower than 1, nearly invisible.
(they start in the same position, so their edges alpha-blend eachother in offscreen target and make more oblique - edges are smooth, but not as much as in fumes from penguin jet).
In higher downsample level, I've provided that pixel size parameter is passed. So to the matrix we always receive neighbouring pixels (not sample from constant proportion). We can understand that in higher downsample, smooth edges becomee less smooth, they generalise higher and more distant areas, the higher is downsample level.
We can see that some particles are this time behind the plane - alsostencil edge pixels are bigger (as distance between pixel middles is higher, the higher is also difference of alpha on edges).
These are links to more, intermediate downsamples.
And this one below is 16x16 pixels downsample. let's see in which pixels there is high difference of alpha in range of 3x3 matrix.
Notice, that I use not simple sobel filter, but one adjusted to detect x, y, mirroredX, mirroredY edges at the sime time (will detect more potential edges).
Descritpion of activated passes in my compositor:
[Edges of alpha channel from off-screen particles only, are printed on background]
-print colour solids to creen after sclearing pass
-calculate depth to offscreen target
-alpha-blend particles to offscreen target
-detect edges and save them to offscreen Sobel target.
alpha blend them to output for debug.
That was nice introduction to following efficiency test results
Observations over few minutes of oscilating FPS (scene is dynamic):
- -offscreen without downsample ([2^0]x[2^0]): from 16 FPS to 29 FPS
-offscreen with 2x2 downsample ([2^1]x[2^1]): from 31 FPS to 51 FPS
-offscreen with 4x4 downsample ([2^2]x[2^2]): from 67 FPS to 111 FPS
-offscreen with 8x8 downsample ([2^3]x[2^3]): from 103 FPS to 135 FPS
-offscreen with 16x16 downsample ([2^4]x[2^4]): from 136 FPS to 152 FPS
We see that solution is scalable.