Java Code Examples for com.jme3.material.Material#setParam()

The following examples show how to use com.jme3.material.Material#setParam() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MaterialPropertyBuilder.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Apply changes for the material parameter.
 *
 * @param param    the parameter.
 * @param material the material.
 * @param newValue the new value.
 */
@FxThread
protected void applyParam(@NotNull MatParam param, @NotNull Material material, @Nullable Object newValue) {

    if (newValue == null) {
        material.clearParam(param.getName());
    } else {
        material.setParam(param.getName(), param.getVarType(), newValue);
    }
}
 
Example 2
Source File: MaterialDebugAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Material reloadMaterial(Material mat) {
    //clear the entire cache, there might be more clever things to do, like clearing only the matdef, and the associated shaders.
    assetManager.clearCache();

    //creating a dummy mat with the mat def of the mat to reload
    // Force the reloading of the asset, otherwise the new shader code will not be applied.
    Material dummy = new Material(assetManager, mat.getMaterialDef().getAssetName());

    for (MatParam matParam : mat.getParams()) {
        dummy.setParam(matParam.getName(), matParam.getVarType(), matParam.getValue());
    }
    
    dummy.getAdditionalRenderState().set(mat.getAdditionalRenderState());        

    //creating a dummy geom and assigning the dummy material to it
    Geometry dummyGeom = new Geometry("dummyGeom", new Box(1f, 1f, 1f));
    dummyGeom.setMaterial(dummy);

    try {
        //preloading the dummyGeom, this call will compile the shader again
        renderManager.preloadScene(dummyGeom);
    } catch (RendererException e) {
        //compilation error, the shader code will be output to the console
        //the following code will output the error
        //System.err.println(e.getMessage());
        Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.SEVERE, e.getMessage());
        return null;
    }

    Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.INFO, "Material succesfully reloaded");
    //System.out.println("Material succesfully reloaded");
    return dummy;
}
 
Example 3
Source File: SSAOFilter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
    protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
        this.renderManager = renderManager;
        this.viewPort = vp;
        int screenWidth = w;
        int screenHeight = h;
        postRenderPasses = new ArrayList<Pass>();

        normalPass = new Pass();
        normalPass.init(renderManager.getRenderer(), (int) (screenWidth / downSampleFactor), (int) (screenHeight / downSampleFactor), Format.RGBA8, Format.Depth);


        frustumNearFar = new Vector2f();

        float farY = (vp.getCamera().getFrustumTop() / vp.getCamera().getFrustumNear()) * vp.getCamera().getFrustumFar();
        float farX = farY * (screenWidth / (float) screenHeight);
        frustumCorner = new Vector3f(farX, farY, vp.getCamera().getFrustumFar());
        frustumNearFar.x = vp.getCamera().getFrustumNear();
        frustumNearFar.y = vp.getCamera().getFrustumFar();





        //ssao Pass
        ssaoMat = new Material(manager, "Common/MatDefs/SSAO/ssao.j3md");
        ssaoMat.setTexture("Normals", normalPass.getRenderedTexture());
        Texture random = manager.loadTexture("Common/MatDefs/SSAO/Textures/random.png");
        random.setWrap(Texture.WrapMode.Repeat);
        ssaoMat.setTexture("RandomMap", random);

        ssaoPass = new Pass("SSAO pass") {

            @Override
            public boolean requiresDepthAsTexture() {
                return true;
            }
        };

        ssaoPass.init(renderManager.getRenderer(), (int) (screenWidth / downSampleFactor), (int) (screenHeight / downSampleFactor), Format.RGBA8, Format.Depth, 1, ssaoMat);
//        ssaoPass.getRenderedTexture().setMinFilter(Texture.MinFilter.Trilinear);
//        ssaoPass.getRenderedTexture().setMagFilter(Texture.MagFilter.Bilinear);
        postRenderPasses.add(ssaoPass);
        material = new Material(manager, "Common/MatDefs/SSAO/ssaoBlur.j3md");
        material.setTexture("SSAOMap", ssaoPass.getRenderedTexture());

        ssaoMat.setVector3("FrustumCorner", frustumCorner);
        ssaoMat.setFloat("SampleRadius", sampleRadius);
        ssaoMat.setFloat("Intensity", intensity);
        ssaoMat.setFloat("Scale", scale);
        ssaoMat.setFloat("Bias", bias);
        material.setBoolean("UseAo", useAo);
        material.setBoolean("UseOnlyAo", useOnlyAo);
        ssaoMat.setVector2("FrustumNearFar", frustumNearFar);
        material.setVector2("FrustumNearFar", frustumNearFar);
        ssaoMat.setParam("Samples", VarType.Vector2Array, samples);
        ssaoMat.setBoolean("ApproximateNormals", approximateNormals);

        float xScale = 1.0f / w;
        float yScale = 1.0f / h;

        float blurScale = 2f;
        material.setFloat("XScale", blurScale * xScale);
        material.setFloat("YScale", blurScale * yScale);

    }
 
Example 4
Source File: SkeletonControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void controlRenderHardware() {
    offsetMatrices = skeleton.computeSkinningMatrices();
    for (Material m : materials) {
        m.setParam("BoneMatrices", VarType.Matrix4Array, offsetMatrices);
    }
}
 
Example 5
Source File: SSAOFilter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
    this.renderManager = renderManager;
    this.viewPort = vp;
    int screenWidth = w;
    int screenHeight = h;
    postRenderPasses = new ArrayList<Pass>();

    normalPass = new Pass();
    normalPass.init(renderManager.getRenderer(), (int) (screenWidth / downSampleFactor), (int) (screenHeight / downSampleFactor), Format.RGBA8, Format.Depth);


    frustumNearFar = new Vector2f();

    float farY = (vp.getCamera().getFrustumTop() / vp.getCamera().getFrustumNear()) * vp.getCamera().getFrustumFar();
    float farX = farY * ((float) screenWidth / (float) screenHeight);
    frustumCorner = new Vector3f(farX, farY, vp.getCamera().getFrustumFar());
    frustumNearFar.x = vp.getCamera().getFrustumNear();
    frustumNearFar.y = vp.getCamera().getFrustumFar();





    //ssao Pass
    ssaoMat = new Material(manager, "Common/MatDefs/SSAO/ssao.j3md");
    ssaoMat.setTexture("Normals", normalPass.getRenderedTexture());
    Texture random = manager.loadTexture("Common/MatDefs/SSAO/Textures/random.png");
    random.setWrap(Texture.WrapMode.Repeat);
    ssaoMat.setTexture("RandomMap", random);

    ssaoPass = new Pass() {

        @Override
        public boolean requiresDepthAsTexture() {
            return true;
        }
    };

    ssaoPass.init(renderManager.getRenderer(), (int) (screenWidth / downSampleFactor), (int) (screenHeight / downSampleFactor), Format.RGBA8, Format.Depth, 1, ssaoMat);
    ssaoPass.getRenderedTexture().setMinFilter(Texture.MinFilter.Trilinear);
    ssaoPass.getRenderedTexture().setMagFilter(Texture.MagFilter.Bilinear);
    postRenderPasses.add(ssaoPass);
    material = new Material(manager, "Common/MatDefs/SSAO/ssaoBlur.j3md");
    material.setTexture("SSAOMap", ssaoPass.getRenderedTexture());

    ssaoMat.setVector3("FrustumCorner", frustumCorner);
    ssaoMat.setFloat("SampleRadius", sampleRadius);
    ssaoMat.setFloat("Intensity", intensity);
    ssaoMat.setFloat("Scale", scale);
    ssaoMat.setFloat("Bias", bias);
    material.setBoolean("UseAo", useAo);
    material.setBoolean("UseOnlyAo", useOnlyAo);
    ssaoMat.setVector2("FrustumNearFar", frustumNearFar);
    material.setVector2("FrustumNearFar", frustumNearFar);
    ssaoMat.setParam("Samples", VarType.Vector2Array, samples);

    float xScale = 1.0f / w;
    float yScale = 1.0f / h;

    float blurScale = 2f;
    material.setFloat("XScale", blurScale * xScale);
    material.setFloat("YScale", blurScale * yScale);

}