Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable ImageSmoothing in javaFX 3D

I'm rendering cubes in JavaFX 3D for a voxel-based game. I'm trying to texture the cubes with a diffuseMap, however due to the textures being 32x32 the image is being considerably blurred. Is there a way to turn this off?

//render materials
Image tileSet = new Image("Graphics/tileSet2.png", 0, 0, false, false, false);

tileMaterial = new PhongMaterial();
tileMaterial.setDiffuseMap(tileSet);

As you can see in the code above, I've tried turning off blurring and mipmapping, but it doesn't change anything. I did however try resizing the image to be 1024x1024 and it worked, but it had a more significant drain on performance, and you could still see gaps around the edges of each texture.

like image 614
SplashyPond Avatar asked Jan 18 '26 03:01

SplashyPond


1 Answers

If and when PR #1281 is merged into JavaFX, you would be able to accomplish it like this:

TextureData data = (new TextureData.Builder())
     .minFilterType(TextureData.MinMagFilterType.NEAREST_POINT)
     .magFilterType(TextureData.MinMagFilterType.NEAREST_POINT)
     .build();

// Exposing the NG material may not be necessary if API changes are made
NGPhongMaterial ngTileMaterial = MaterialHelper.getNGMaterial(tileMaterial);
ngTileMaterial.setDiffuseTextureData(data);

In this case, NEAREST_POINT refers to nearest-neighbor interpolation. This would preserve the integrity of pixel boundaries when scaling your textures.

Until then, I would recommend a mature multimedia library like LWJGL or anything providing fairly direct bindings for OpenGL/Vulkan.

like image 150
Wasabi Thumbs Avatar answered Jan 20 '26 19:01

Wasabi Thumbs