-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
When importing models from blender into JME, I constantly get this warning:
The texture Diffuse Color has linear color space, but the material parameter DiffuseMap specifies no color space requirement, this may lead to unexpected behavior.
Check if the image was not set to another material parameter with a linear color space, or that you did not set the ColorSpace to Linear using texture.getImage.setColorSpace().
See multiple forum posts about this issue:
This is the check that logs the warning:
if (paramDef.getColorSpace() == null && value.getName() != null && value.getImage().getColorSpace() == ColorSpace.Linear) {
logger.log(Level.WARNING,
"The texture {0} has linear color space, but the material "
+ "parameter {2} specifies no color space requirement, this may "
+ "lead to unexpected behavior.\nCheck if the image "
+ "was not set to another material parameter with a linear "
+ "color space, or that you did not set the ColorSpace to "
+ "Linear using texture.getImage.setColorSpace().",
new Object[]{value.getName(), value.getImage().getColorSpace().name(), name});The warning is only logged when a linear colorspace is set on the image and the MatParam doesn't have a colorspace.
I looked a bit around the jme3-blender code and found I this:
in the file TextureBlenderAWT:146
Image result = depth > 1 ? new Image(Format.RGBA8, width, height, depth, dataArray, ColorSpace.Linear) : new Image(Format.RGBA8, width, height, dataArray.get(0), ColorSpace.Linear);The colorspace of the new created image is always set to ColorSpace.Linear although the original colorspace of the image was ColorSpace.sRGB. When I adapt this line, and set the colorspace to the colorspace of the original image, the warning vanishes. The Image has now colorspace ColorSpace.sRGB and the MatParam still has colorspace null. But the warning is only logged when the colorspace of the images is Linear.
Looking further down the code, because the colorspace is not set on the MatParam, I noticed that in the Material class in jme3-core the colorspace is never set on the MatParam when a texture is specified:
com.jme3.material.Material:540:
public void setTextureParam(String name, VarType type, Texture value) {
if (value == null) {
throw new IllegalArgumentException();
}
checkSetParam(type, name);
MatParamTexture val = getTextureParam(name);
if (val == null) {
checkTextureParamColorSpace(name, value);
paramValues.put(name, new MatParamTexture(type, name, value, null));
} else {
val.setTextureValue(value);
}
if (technique != null) {
technique.notifyParamChanged(name, type, value);
}
// need to recompute sort ID
sortingId = -1;
}The colorSpace is set to null (new MatParamTexture(type, name, value, null)), although the value (Texture) has a ColorSpace value.
I don't know any of the history of this, so maybe this is on purpose.
My questions:
- Can I add a PR that sets the colorspace in the TextureBlenderAWT class, so the warning disappears? Maybe I'm wrong and the warning is indeed valid as the newly created texture is in Linear colorspace and the problem is somewhere else.
- Is there a reason why the colorspace is not set on the MatParam in the material? If not, should I also adapt this in the PR?