jMonkeyEngine / jMonkeyEngine/jmonkeyengine

TextureAtlas class for PBR / custom materials

Open
#1,263 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
4.3k
Forks
1.2k
Avg merge
4d 7h
Merged PRs (30d)
14

Description

recently @yaRnMcDonuts had issues to use TextureAtlas generator for his PBR models.

not sure if issue or feature.

but:
Geometry geom = TextureAtlas.makeAtlasBatch(scene, assetManager, 2048);

within TextureAtlass class, it refer only for Lightning.j3md material.

i would suggest do one of below options:

  • create TextureAtlasMaterialMerger interface, and provide 2 classes TextureAtlasPBRMerger and TextureAtlasLightningMerger

  • create TextureAtlasLightning and TextureAtlasPBR(but it might have dupplicated code, so its bad)

  • create "in-code" if/else conditions to check material of element (but here it will break if one model is PBR and second is Lightning material type)

  • create "in-code" additional if/else conditions, but also add new variable in initialization like:
    TextureAtlas.makeAtlasBatch(scene, assetManager, 2048, TextureAtlas.MATERIAL_PBR);
    to allow set what materials should be gathered.

  • like above, but: TextureAtlas.makeAtlasBatch(scene, assetManager, 2048, materialToPutTexturesAndReadType);
    what i mean with last param is that TextureAtlas would put just textures into new user created material. This should throw exception if batching geometry have different material type.

imo last option sounds best. - reasons:

  • because each geometry also have float/vector/etc material data, not just textures, we might "get averate values" but anyway i think best would be if user would provide material with defined values and TextureAtlas would just update its textures and apply for all geometries. current class do it ugly way by just setting mat.setFloat("Shininess", 16.0f); that might not be expected by user anyway.
    Last option also allow "custom material" batching.

below is Lightning.j3md related code:

    public boolean addGeometry(Geometry geometry) {
        Texture diffuse = getMaterialTexture(geometry, "DiffuseMap");
        Texture normal = getMaterialTexture(geometry, "NormalMap");
        Texture specular = getMaterialTexture(geometry, "SpecularMap");
        if (diffuse == null) {
            diffuse = getMaterialTexture(geometry, "ColorMap");

        }
        if (diffuse != null && diffuse.getKey() != null) {
            String keyName = diffuse.getKey().toString();
            if (!addTexture(diffuse, "DiffuseMap")) {
                return false;
            } else {
                if (normal != null && normal.getKey() != null) {
                    addTexture(normal, "NormalMap", keyName);
                }
                if (specular != null && specular.getKey() != null) {
                    addTexture(specular, "SpecularMap", keyName);
                }
            }
            return true;
        }
        return true;
    }

and:

        Material mat = new Material(mgr, "Common/MatDefs/Light/Lighting.j3md");
        Texture diffuseMap = atlas.getAtlasTexture("DiffuseMap");
        Texture normalMap = atlas.getAtlasTexture("NormalMap");
        Texture specularMap = atlas.getAtlasTexture("SpecularMap");
        if (diffuseMap != null) {
            mat.setTexture("DiffuseMap", diffuseMap);
        }
        if (normalMap != null) {
            mat.setTexture("NormalMap", normalMap);
        }
        if (specularMap != null) {
            mat.setTexture("SpecularMap", specularMap);
        }
        mat.setFloat("Shininess", 16.0f);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the TextureAtlas class, especially makeAtlasBatch and addGeometry, and compare its material creation with Common/MatDefs/Light/Lighting.j3md. Clarify the material-merging design and verify that batching can support PBR or custom materials without silently imposing Lighting.j3md values such as Shininess.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
computer-graphics, game-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.