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

MaterialDebugAppState is not reloading the changed shader instead reloads the old one #843

Closed
b00nation opened this issue Mar 11, 2018 · 3 comments
Labels
defect Something that is supposed to work, but doesn't. Less severe than a "bug"
Milestone

Comments

@b00nation
Copy link
Contributor

If a shader-file has changed the application recognizes correctly the change, but the reload of the material actually reloads the old shader code instead of loading the new code. This is caused by the TechniqueDefault deep in the MaterialDefiniton.

@Nehon
Copy link
Contributor

Nehon commented Mar 11, 2018

Could you provide a test case please

@b00nation
Copy link
Contributor Author

b00nation commented Mar 11, 2018

@Nehon, sure, here you go:

Issue840.zip

In the fragment shader change the line:

gl_FragColor = vec4(1.0);//comment me
//gl_FragColor = vec4(1.0,0.0,0.0,1.0);//uncomment me

to

//gl_FragColor = vec4(1.0);//comment me
gl_FragColor = vec4(1.0,0.0,0.0,1.0);//uncomment me

otherwise, take a custom MaterialDefinition register a shader and change that one:

package mygame;

import com.jme3.app.FlyCamAppState;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.util.MaterialDebugAppState;

public class Main extends SimpleApplication {

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

    @Override
    public void simpleInitApp() {
        Box b = new Box(1, 1, 1);
        Geometry geom = new Geometry("Box", b);

        Material mat = new Material(assetManager, "MatDefs/Unshaded.j3md");
        geom.setMaterial(mat);
        MaterialDebugAppState materialDebugAppState = new MaterialDebugAppState();
        stateManager.attach(materialDebugAppState);
        rootNode.attachChild(geom);
        materialDebugAppState.registerBinding("MatDefs/Unshaded.frag", geom);
        stateManager.detach(stateManager.getState(FlyCamAppState.class));
    }

}

fragment-shader:
assets\MatDefs\Unshaded.frag

void main(){
    gl_FragColor = vec4(1.0);//comment me
    //gl_FragColor = vec4(1.0,0.0,0.0,1.0);//uncomment me
}

vertex-shader:
assets\MatDefs\Unshaded.vert

#import "Common/ShaderLib/GLSLCompat.glsllib"
#import "Common/ShaderLib/Skinning.glsllib"
#import "Common/ShaderLib/Instancing.glsllib"

attribute vec3 inPosition;

void main(){

    vec4 modelSpacePos = vec4(inPosition, 1.0);


    gl_Position = TransformWorldViewProjection(modelSpacePos);

}

MaterialDefinition:
assets\MatDefs\Unshaded.j3md

MaterialDef Unshaded {

    MaterialParameters {
    }

    Technique {
        VertexShader GLSL150:   MatDefs/Unshaded.vert
        FragmentShader GLSL150: MatDefs/Unshaded.frag

        WorldParameters {
            WorldViewProjectionMatrix
            WorldMatrix   
            ViewProjectionMatrix
            ViewMatrix
        }

        Defines {
        }
    }

}

@Nehon
Copy link
Contributor

Nehon commented Apr 25, 2018

fixed in #840
Thanks a lot

@Nehon Nehon closed this as completed Apr 25, 2018
@stephengold stephengold added this to the v3.2.2 milestone Dec 16, 2018
@stephengold stephengold added the defect Something that is supposed to work, but doesn't. Less severe than a "bug" label Dec 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect Something that is supposed to work, but doesn't. Less severe than a "bug"
Projects
None yet
Development

No branches or pull requests

3 participants