5
$\begingroup$

I would like to produce fuzzy random points (sprites like) in a 3D view. Applying a Blur command doesn't do the trick since the view is then frozen and we couldn't rotate the view anymore, and I don't want to blur the frame box too.

Here's a MWE to play with (currently, I'm using some transparency to blur slightly the particles, but the effect isn't that good!) :

particles := RandomReal[{-1, 1}, {1000, 3}]

graph := Graphics3D[{RGBColor[{0.5, 0.4, 1.0, 0.4}], PointSize -> 0.006, Point[particles]}]

Show[graph,
    PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}},
    Boxed -> True,
    Ticks -> None,
    Background -> Black,
    ImageSize -> {700, 700},
    SphericalRegion -> True,
    Method -> {"RotationControl" -> "Globe"}
]

So the question is simple: Is there a way to get fuzzy dots/points without applying a Blur command to the whole thing, in a way that the view could still be rotated? Ideally, the solution (if any) should be applicable to an old version of Mathematica (I'm still using Mma 7.0, until I upgrade the whole computer!).

Maybe the solution is to use a sprite PNG image for each particle, but then that small picture should stay oriented front to the viewer, whatever what he do with the view. I doubt that this would work well for an output that draws several thousands of particles, and it may be way too long to program just to get fuzzy dots in a manipulate box.

EDIT:. The fuzzy sprite-like particles I would like to get are looking like this:

A single particle, without any specific color:

enter image description here

Several particles, each one using the same disk blob (or sprite), but using different colors and sizes:

enter image description here

$\endgroup$
11
  • 1
    $\begingroup$ Is there any image that could help explain what you want more specifically? $\endgroup$
    – rhermans
    Commented Jul 28, 2022 at 16:42
  • $\begingroup$ @rhermans, I simply want to add a blurry/fuzzy aspect to the particles in the manipulate box. You could check the picture I gave in my question here (which is related): mathematica.stackexchange.com/questions/271261/… $\endgroup$
    – Cham
    Commented Jul 28, 2022 at 16:44
  • 1
    $\begingroup$ "simply" is a dangerous word. For myself, I don't understand what you want. Do you want some transparency? some texture? a non-circular shape? a hierarchy of point sizes? a different distribution (although you accepted an answer to that other question, so that doesn't seem likely)? $\endgroup$
    – lericr
    Commented Jul 28, 2022 at 20:15
  • $\begingroup$ @lericr, I’m asking for the simplest in your list: all particles should have an identical blurry round shape. No texture! No special shape (all round disk on screen like a big dot), no variable size! The texture is made by the whole distribution. I’m just looking for fuzzy individual dots, nothing fancy. The fuzzy dots should have some transparency, yes... $\endgroup$
    – Cham
    Commented Jul 28, 2022 at 20:52
  • 1
    $\begingroup$ @MichaelE2, yes. Fuzzy sprites should be faster than spheres. And small spheres are useless to me anyway. $\endgroup$
    – Cham
    Commented Jul 29, 2022 at 1:37

1 Answer 1

5
$\begingroup$

As OP already suggested, an image sprite based approach could be a solution, except a special rendering option "3DRenderingMethod" -> "BSPTreeOrDepthBuffer" is needed in order to give a correct result. (Note however this solution doesn't really work in 13.1, at least the Windows version, due to unsettled z-fighting.)

$Version
(* 13.0.1 for Microsoft Windows (64-bit) (January 28, 2022) *)

spriteAlpha = With[{r = 20}
      , GaussianMatrix[{r, r/3}] // Rescale // Chop // Image
    ]

sprite alpha mask

The sprites can be inserted in Graphics3D using Inset (or if multiple copies of the same sprite is needed, we could use one Inset coupled with a Translate[g, {pos1, pos2, ...}]):

graph = Module[{n = 100}
  , MapThread[
          Function[{col, pos, size, maxOpacity}
               , ConstantImage[col, ImageDimensions@spriteAlpha, ImageSize -> size] //
               SetAlphaChannel[#, maxOpacity spriteAlpha] & //
               Inset[#, pos] &
           ], {
          RandomColor[LABColor[.7, _, _], n]
          , RandomPoint[Ball[{0, 0, 0}, 1], n]
          , RandomInteger[{10, 50}, n]
          , RandomReal[{.3, 1}, n]
      }] //
 Graphics3D[#
    , PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}
    , SphericalRegion -> True, RotationAction -> "Clip"
    , ImageSize -> 200] & //
 Style[#, RenderingOptions -> {
     (*"DepthPeelingLayers" -> 64,*)
     "3DRenderingMethod" -> "BSPTreeOrDepthBuffer"
     }] &
]

3D graphic with fuzzy sprites

It looks like this approach performs good enough on my computer. At least n = 1000 doesn't really slow down the 3D interaction. "DepthPeelingLayers" could use a larger value than the default 8 in case of really lots of sprites.

GIFs to demonstrate the 3D graphic is really transparent, also the performance on Windows:

interactive 3D graphic with fuzzy sprites demo for n=1000

$\endgroup$
3
  • $\begingroup$ Very nice solution here, how to fix the z-fighting? With n=300 when I resize the graphic it freezes the FE... $\endgroup$
    – user5601
    Commented Aug 9, 2022 at 20:17
  • $\begingroup$ @user5601 Hi there, I added a GIF to demonstrate the performance on my laptop when n=1000. I suspect it varies dramatically from OS to OS. I don't have access to Mathematica with GUI on Mac or Linux, but I do know on Windows the FrontEnd uses DirectX to accelerate 3D graphic rendering, which could provide huge performance boost. $\endgroup$
    – Silvia
    Commented Aug 11, 2022 at 7:03
  • $\begingroup$ As for the z-fighting issue, I assume you meant for 13.1? I don't know if fiddling with RenderingOptions could give result as good as the ones I saw in 13.0.1. It could be a side effect of updates of the FrontEnd in 13.1. Actually I will report that to WRI as a bug. $\endgroup$
    – Silvia
    Commented Aug 11, 2022 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.