Skip to content

Conversation

@rvandoosselaer
Copy link
Contributor

when the image object has a ColorSpace value we pass it on, else we leave it at the default value.

@stephengold stephengold merged commit adb88dc into jMonkeyEngine:master Jun 26, 2019
@stephengold
Copy link
Member

stephengold commented Jun 26, 2019

I had hoped for some review by a more senior monkey, but you seem to know what you're doing.

@rvandoosselaer
Copy link
Contributor Author

rvandoosselaer commented Jun 26, 2019

I did a few tests with my own models and some free one’s I found online. I didn’t encounter any errors or strange behaviour, it seems to work.
However if people do find issues with it, I’ll be happy to revert the change or look for a solution.

@riccardobl
Copy link
Member

riccardobl commented Jun 26, 2019

Ok, sorry i didn't see this (it might be a good idea for the future to use an actual title for PRs, because when you start having several "Fix ISSUE NUMBER" it's easy to miss some).

My question is, what will happen if i have a matdef that defines a -LINEAR param, but the image is sRGB? Will this pr break the linearization by forcing the mat param to become sRGB ?

@rvandoosselaer
Copy link
Contributor Author

rvandoosselaer commented Jun 26, 2019

Ok, sorry i didn't see this (it might be a good idea for the future to use an actual title for PRs, because when you start having several "Fix ISSUE NUMBER" it's easy to miss some).

My question is, what will happen if i have a matdef that defines a -LINEAR param, but the image is sRGB? Will this pr break the linearization by forcing the mat param to become sRGB ?

Hi @riccardobl, I wasn't aware of the -LINEAR option in a material definition file.
I just tested it, and if you specify -LINEAR in the materialDef, the colorspace will be set to linear.

This is my test case:
Gamma correction is enabled, the texture in the material is an sRGB one, the colorspace in the materialDef is set to '-LINEAR':
Screenshot 2019-06-26 at 21 00 46
I also added a log statement printing out the colorspace of the material that is set on the model:
From the log:
Colorspace: Linear

Same test as above, but without the -LINEAR flag:
Screenshot 2019-06-26 at 21 02 57
log:
Colorspace: sRGB

The first image is clearly gamma corrected (too bright) because of the colorspace, so all should still be working as expected.

Part of the relevant texture used:
Screenshot 2019-06-26 at 21 08 50

@riccardobl
Copy link
Member

Can you share the code?

@rvandoosselaer
Copy link
Contributor Author

rvandoosselaer commented Jun 26, 2019

test:

TestMaterialLinearColorspace.java

public class TestMaterialLinearColorspace extends SimpleApplication {

    public static void main(String[] args) {
        new TestMaterialLinearColorspace().start();
    }

    @Override
    public void simpleInitApp() {
        AmbientLight ambientLight = new AmbientLight(ColorRGBA.White.mult(0.2f));
        DirectionalLight directionalLight = new DirectionalLight(new Vector3f(-0.2f, -1, -0.2f).normalizeLocal(), ColorRGBA.White);

        Spatial model = assetManager.loadModel("staff-0.j3o");
        Material material = assetManager.loadMaterial("colorspace-test.j3m");
        model.depthFirstTraversal(new SceneGraphVisitorAdapter() {
            @Override
            public void visit(Geometry geom) {
                geom.setMaterial(material);
                System.out.println("Colorspace: " + material.getTextureParam("DiffuseMap").getColorSpace());
            }
        });

        rootNode.addLight(ambientLight);
        rootNode.addLight(directionalLight);
        rootNode.attachChild(model);
    }
}

colorspace-test.j3m:

Material colorsapace-test : Common/MatDefs/Light/Lighting.j3md {
    MaterialParameters {
        Shininess: 0
        UseMaterialColors: true
        DiffuseMap: Flip texture.png
        Ambient: 1.0 1.0 1.0 1.0
        Diffuse: 1.0 1.0 1.0 1.0
        Specular: 0.0 0.0 0.0 1.0
    }
}

When running the testcase, I adapted this line in Lighting.j3md:31:

// Diffuse map
Texture2D DiffuseMap

to:

// Diffuse map
Texture2D DiffuseMap -LINEAR

If you want I can create a proper testcase for it, and put it in the jme3-examples module.

@riccardobl
Copy link
Member

Oh ok, i see. I was mislead by the fact that both Materials and MatDefs keep a list of MatParamTexture. But the material will always look at the matdef list to see if it needs to switch the colorspace.

@rvandoosselaer
Copy link
Contributor Author

rvandoosselaer commented Jun 26, 2019

Oh ok, i see. I was mislead by the fact that both Materials and MatDefs keep a list of MatParamTexture. But the material will always look at the matdef list to see if it needs to switch the colorspace.

Yep, indeed. You can always overwrite it if needed. This should only set the colorspace to the colorspace of the texture instead of defaulting to null.

@stephengold stephengold added this to the v3.2.4 milestone Jul 7, 2019
stephengold pushed a commit that referenced this pull request Jul 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants