Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blender import warning #1106

Closed
rvandoosselaer opened this issue Jun 2, 2019 · 0 comments

Comments

@rvandoosselaer
Copy link
Contributor

commented Jun 2, 2019

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?

rvandoosselaer added a commit to rvandoosselaer/jmonkeyengine that referenced this issue Jun 3, 2019

stephengold added a commit that referenced this issue Jun 26, 2019

@stephengold stephengold added this to the v3.2.4 milestone Jul 7, 2019

stephengold added a commit that referenced this issue Jul 10, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.