Search code examples
javajavafxtextnodes

prevent node blur in javafx


this is a rather simple question but ive found no answer to it so far . Inside my code i need a text node to be extremly close to the camera(its a 3d engine), needing to be very small so it fits in the screen, while keeping a recognizable form/shape of text.

whenever i move it closer towards the camera the resolution gets lower and lower untill there is nothing left, ive tried setting the smoothness to false preventing antialiasing, but it didnt work .Aswell i even tried setting the font smoothing type which didnt seem to effect anything.

I tried putting it in panes and groups and moving it closer using the parent or changing to size so im not directly changing the size of the text with the distance/scale.

"amount" is the parent of the 'place1amount' node which is the text needing to be a higher resolution, the child is 'place1amount' and the text is '0'. The text will be changed frequently to suit its job, so converting it into a imageview would be too slow and resource comsuming.

If there a way to higher the resoultion, set the pixel size within a node or keep the resoultion when changing the size it would help

it would be very appricited if you could help by pointing out the answer, thanks

        place1amount.setTranslateZ(1);
        place1amount.setSmooth(false);
        place1amount.setFontSmoothingType(FontSmoothingType.LCD);
        place1amount.setLineSpacing(10);
        place1amount.setFont(Font.font("Arial", FontWeight.BOLD, 12));

         amount.setScaleX(1);
         amount.setScaleY(1);
         amount.setTranslateZ(100);
         amount.setTranslateY(40);
         amount.setTranslateX(0);

Problem: The text node placed close to the camera loses resolution and becomes unreadable.

Current outcome: When moving the text node closer to the camera, the resolution decreases, making the text illegible.

Desired Outcome: I want to keep the text node close to the camera while maintaining a high resolution and legibility. I have tried adjusting settings like smoothness and font smoothing type, but it hasn't solved the issue. Is there a way to increase the resolution or maintain it when changing the size of the text node? Any help would be appreciated. Thank you.


Solution

  • 3D scenes usually have different cameras and lighting than 2D scenes.

    It seems you want a heads-up display (HUD), rendered in 2D with a ParallelCamera on top of a 3D scene with a PerspectiveCamera. To achieve this, create two SubScenes in a StackPane. Place your 2D scene for the HUD using a default 2D parallel camera on top, and a 3D scene using a 3D perspective camera in the background.

    Asker notes in comments:

    After implementing the subscenes and adding the overlay node to it my code worked.


    On font smoothing

    This section is not directly related to the answer and is included because the user mentioned trying the font smoothing feature in the question.

    Usually specifying anything other than the default GRAY font smoothing option is unnecessary.

    LCD smoothing:

    Specifies sub-pixel LCD text, which utilises characteristics of digital LCD display panels to achieve increased pixel resolution.

    Specifying LCD font smoothing instead of GRAY smoothing generally won't make sense in a 3D scene with a perspective camera. The text elements displayed in 3D are unlikely to line up with the pixel placements on a 2D LCD panel.

    Whereas GRAY is:

    the default gray scale smoothing, which is most suitable for graphics and animation uses.

    This seems to match the usage in most 3D applications more closely. So using the default GRAY smoothing in a 3D scene seems most appropriate.

    For a 2D scene, you can experiment in your environment with GRAY and LCD font smoothing settings to see which you prefer. You may not notice much, if any, difference between the two. LCD smoothing requires the appropriate hardware and a good eye (perhaps a magnifying glass on high resolution LCD panels) to spot. LCD font smoothing is an optional feature of the platform. The setting is treated as a hint for font rendering that can be ignored on some platforms.