-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
J3MLoader always set generate mips flag to true regardless of whether it is required by MinFilter or not.
jmonkeyengine/jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java
Line 279 in befa930
| textureKey.setGenerateMips(true); |
for example, NearestNoMipMaps and BilinearNoMipMaps do not require mips.
jmonkeyengine/jme3-core/src/main/java/com/jme3/texture/Texture.java
Lines 87 to 102 in ac8c101
| /** | |
| * Nearest neighbor interpolation is the fastest and crudest filtering | |
| * method - it simply uses the color of the texel closest to the pixel | |
| * center for the pixel color. While fast, this results in aliasing and | |
| * shimmering during minification. (GL equivalent: GL_NEAREST) | |
| */ | |
| NearestNoMipMaps(false), | |
| /** | |
| * In this method the four nearest texels to the pixel center are | |
| * sampled (at texture level 0), and their colors are combined by | |
| * weighted averages. Though smoother, without mipmaps it suffers the | |
| * same aliasing and shimmering problems as nearest | |
| * NearestNeighborNoMipMaps. (GL equivalent: GL_LINEAR) | |
| */ | |
| BilinearNoMipMaps(false), |
Shouldn't it check MinFilter and generate mips only if it is required?
Because of that, J3MLoader is broken, I noticed if I set the min filter to BilinearNoMipMaps on texture and export the material to a j3m file in the code then if I load it at runtime the min filter is set to Trilinear. It will work fine if I set it to something other than BilinearNoMipMaps.
That is because BilinearNoMipMaps is not written to the j3m file as it is the default min filter in the Texture class and is supposed to be used when nothing is specified for the min filter in the j3m file:
| private MinFilter minificationFilter = MinFilter.BilinearNoMipMaps; |
Lines 142 to 150 in ceb3564
| //Min and Mag filter | |
| Texture.MinFilter def = Texture.MinFilter.BilinearNoMipMaps; | |
| if (tex.getImage().hasMipmaps() || (key != null && key.isGenerateMips())) { | |
| def = Texture.MinFilter.Trilinear; | |
| } | |
| if (tex.getMinFilter() != def) { | |
| ret.append("Min").append(tex.getMinFilter().name()).append(" "); | |
| } | |
but it does not work as expected because J3MLoader will set the mips generation flag to true and this causes TextureProcessor to change the min filter to Trilinear on texture when loaded with asset manager:
jmonkeyengine/jme3-core/src/main/java/com/jme3/texture/TextureProcessor.java
Lines 64 to 68 in ceb3564
| // enable mipmaps if image has them | |
| // or generate them if requested by user | |
| if (img.hasMipmaps() || texKey.isGenerateMips()) { | |
| tex.setMinFilter(Texture.MinFilter.Trilinear); | |
| } |
If someone manually adds the BilinearNoMipMaps inside j3m file then it will work fine and will not get changed to Trilinear after loading but the generate mips flag will still be set to true.
Solution:
Those can be fixed by checking this inside the min filter and setting the flag only if it is required.
We would need to override the applyToTextureKey method :
@Override
public void applyToTextureKey(final String option, final TextureKey textureKey) {
Texture.MinFilter minFilter = Texture.MinFilter.valueOf(option);
textureKey.setGenerateMips(minFilter.usesMipMapLevels());
}
inside
jmonkeyengine/jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java
Lines 860 to 868 in befa930
| /** | |
| * Applies a {@link com.jme3.texture.Texture.MinFilter} to the texture. | |
| */ | |
| Min { | |
| @Override | |
| public void applyToTexture(final String option, final Texture texture) { | |
| texture.setMinFilter(Texture.MinFilter.valueOf(option)); | |
| } | |
| }, |
forum post:
https://hub.jmonkeyengine.org/t/j3mloader-always-generates-mips-ignoring-minfilter-bug/46296