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

The following examples show how to use com.jme3.material.Material#clearParam() . 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: TextureLayerSettings.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@JmeThread
private void updateTexture(@Nullable final Texture texture, @NotNull final String paramName,
                           @NotNull final Geometry geometry) {

    final Material material = geometry.getMaterial();
    final MatParam matParam = material.getParam(paramName);
    if (matParam == null && texture == null) {
        return;
    }

    if (texture == null) {
        material.clearParam(matParam.getName());
    } else {
        material.setTexture(paramName, texture);
    }
}
 
Example 2
Source File: AbstractShadowRendererVR.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void clearMatParams(){
    for (Material mat : matCache) {
     
        //clearing only necessary params, the others may be set by other 
        //renderers 
        //Note that j start at 1 because other shadow renderers will have 
        //at least 1 shadow map and will set it on each frame anyway.
        for (int j = 1; j < nbShadowMaps; j++) {
            mat.clearParam(lightViewStringCache[j]);
        }
        for (int j = 1; j < nbShadowMaps; j++) {
            mat.clearParam(shadowMapStringCache[j]);
        }
        mat.clearParam("FadeInfo");
        clearMaterialParameters(mat);
    }        
    //No need to clear the postShadowMat params as the instance is locale to each renderer       
}
 
Example 3
Source File: TranslucentBucketFilter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void initFilter(AssetManager manager, RenderManager rm, ViewPort vp, int w, int h) {
    this.renderManager = rm;
    this.viewPort = vp;
    material = new Material(manager, "Common/MatDefs/Post/Overlay.j3md");
    material.setColor("Color", ColorRGBA.White);
    Texture2D tex = processor.getFilterTexture();
    material.setTexture("Texture", tex);
    if (tex.getImage().getMultiSamples() > 1) {
        material.setInt("NumSamples", tex.getImage().getMultiSamples());
    } else {
        material.clearParam("NumSamples");
    }
    renderManager.setHandleTranslucentBucket(false);
    if (enabledSoftParticles && depthTexture != null) {
        initSoftParticles(vp, true);
    }
}
 
Example 4
Source File: AbstractShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void clearMatParams(){
    for (Material mat : matCache) {
     
        //clearing only necessary params, the others may be set by other 
        //renderers 
        //Note that j start at 1 because other shadow renderers will have 
        //at least 1 shadow map and will set it on each frame anyway.
        for (int j = 1; j < nbShadowMaps; j++) {
            mat.clearParam(lightViewStringCache[j]);
        }
        for (int j = 1; j < nbShadowMaps; j++) {
            mat.clearParam(shadowMapStringCache[j]);
        }
        mat.clearParam("FadeInfo");
        clearMaterialParameters(mat);
    }        
    //No need to clear the postShadowMat params as the instance is locale to each renderer       
}
 
Example 5
Source File: TranslucentBucketFilter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected void initFilter(AssetManager manager, RenderManager rm, ViewPort vp, int w, int h) {
    this.renderManager = rm;
    this.viewPort = vp;
    material = new Material(manager, "Common/MatDefs/Post/Overlay.j3md");
    material.setColor("Color", ColorRGBA.White);
    Texture2D tex = processor.getFilterTexture();
    material.setTexture("Texture", tex);
    if (tex.getImage().getMultiSamples() > 1) {
        material.setInt("NumSamples", tex.getImage().getMultiSamples());
    } else {
        material.clearParam("NumSamples");
    }
    renderManager.setHandleTranslucentBucket(false);
    if (enabledSoftParticles && depthTexture != null) {
        initSoftParticles(vp, true);
    }
}
 
Example 6
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 7
Source File: SkeletonControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void switchToSoftware() {
    for (Material m : materials) {
        if (m.getParam("NumberOfBones") != null) {
            m.clearParam("NumberOfBones");
        }
    }
    for (Mesh mesh : targets) {
        if (mesh.isAnimated()) {
            mesh.prepareForAnim(true);
        }
    }
}
 
Example 8
Source File: DirectionalLightShadowRendererVR.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected void clearMaterialParameters(Material material) {
    material.clearParam("Splits");
    material.clearParam("FadeInfo");
    material.clearParam("LightDir");
}
 
Example 9
Source File: FilterPostProcessor.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * iterate through the filter list and renders filters
 * @param r
 * @param sceneFb 
 */
private void renderFilterChain(Renderer r, FrameBuffer sceneFb) {
    Texture2D tex = filterTexture;
    FrameBuffer buff = sceneFb;
    boolean msDepth = depthTexture != null && depthTexture.getImage().getMultiSamples() > 1;
    for (int i = 0; i < filters.size(); i++) {
        Filter filter = filters.get(i);
        if (prof != null) prof.spStep(SpStep.ProcPostFrame, FPP, filter.getName());
        if (filter.isEnabled()) {
            if (filter.getPostRenderPasses() != null) {
                for (Iterator<Filter.Pass> it1 = filter.getPostRenderPasses().iterator(); it1.hasNext();) {
                    Filter.Pass pass = it1.next();
                    if (prof != null) prof.spStep(SpStep.ProcPostFrame, FPP, filter.getName(), pass.toString());
                    pass.beforeRender();
                    if (pass.requiresSceneAsTexture()) {
                        pass.getPassMaterial().setTexture("Texture", tex);
                        if (tex.getImage().getMultiSamples() > 1) {
                            pass.getPassMaterial().setInt("NumSamples", tex.getImage().getMultiSamples());
                        } else {
                            pass.getPassMaterial().clearParam("NumSamples");

                        }
                    }
                    if (pass.requiresDepthAsTexture()) {
                        pass.getPassMaterial().setTexture("DepthTexture", depthTexture);
                        if (msDepth) {
                            pass.getPassMaterial().setInt("NumSamplesDepth", depthTexture.getImage().getMultiSamples());
                        } else {
                            pass.getPassMaterial().clearParam("NumSamplesDepth");
                        }
                    }
                    renderProcessing(r, pass.getRenderFrameBuffer(), pass.getPassMaterial());
                }
            }
            if (prof != null) prof.spStep(SpStep.ProcPostFrame, FPP, filter.getName(), "postFrame");
            filter.postFrame(renderManager, viewPort, buff, sceneFb);

            Material mat = filter.getMaterial();
            if (msDepth && filter.isRequiresDepthTexture()) {
                mat.setInt("NumSamplesDepth", depthTexture.getImage().getMultiSamples());
            }

            if (filter.isRequiresSceneTexture()) {
                mat.setTexture("Texture", tex);
                if (tex.getImage().getMultiSamples() > 1) {
                    mat.setInt("NumSamples", tex.getImage().getMultiSamples());
                } else {
                    mat.clearParam("NumSamples");
                }
            }
            
            boolean wantsBilinear = filter.isRequiresBilinear();
            if (wantsBilinear) {
                tex.setMagFilter(Texture.MagFilter.Bilinear);
                tex.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
            }

            buff = outputBuffer;
            if (i != lastFilterIndex) {
                buff = filter.getRenderFrameBuffer();
                tex = filter.getRenderedTexture();

            }
            if (prof != null) prof.spStep(SpStep.ProcPostFrame, FPP, filter.getName(), "render");
            renderProcessing(r, buff, mat);
            if (prof != null) prof.spStep(SpStep.ProcPostFrame, FPP, filter.getName(), "postFilter");
            filter.postFilter(r, buff);
            
            if (wantsBilinear) {
                tex.setMagFilter(Texture.MagFilter.Nearest);
                tex.setMinFilter(Texture.MinFilter.NearestNoMipMaps);
            }
        }
    }
}
 
Example 10
Source File: DirectionalLightShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected void clearMaterialParameters(Material material) {
    material.clearParam("Splits");
    material.clearParam("FadeInfo");
    material.clearParam("LightDir");
}
 
Example 11
Source File: PointLightShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected void clearMaterialParameters(Material material) {
    material.clearParam("LightPos");        
}
 
Example 12
Source File: SpotLightShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected void clearMaterialParameters(Material material) {
    material.clearParam("LightPos");
    material.clearParam("LightDir");
}
 
Example 13
Source File: FilterPostProcessor.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * iterate through the filter list and renders filters
 * @param r
 * @param sceneFb 
 */
private void renderFilterChain(Renderer r, FrameBuffer sceneFb) {
    Texture2D tex = filterTexture;
    FrameBuffer buff = sceneFb;
    boolean msDepth = depthTexture != null && depthTexture.getImage().getMultiSamples() > 1;
    for (int i = 0; i < filters.size(); i++) {
        Filter filter = filters.get(i);
        if (filter.isEnabled()) {
            if (filter.getPostRenderPasses() != null) {
                for (Iterator<Filter.Pass> it1 = filter.getPostRenderPasses().iterator(); it1.hasNext();) {
                    Filter.Pass pass = it1.next();
                    pass.beforeRender();
                    if (pass.requiresSceneAsTexture()) {
                        pass.getPassMaterial().setTexture("Texture", tex);
                        if (tex.getImage().getMultiSamples() > 1) {
                            pass.getPassMaterial().setInt("NumSamples", tex.getImage().getMultiSamples());
                        } else {
                            pass.getPassMaterial().clearParam("NumSamples");

                        }
                    }
                    if (pass.requiresDepthAsTexture()) {
                        pass.getPassMaterial().setTexture("DepthTexture", depthTexture);
                        if (msDepth) {
                            pass.getPassMaterial().setInt("NumSamplesDepth", depthTexture.getImage().getMultiSamples());
                        } else {
                            pass.getPassMaterial().clearParam("NumSamplesDepth");
                        }
                    }
                    renderProcessing(r, pass.getRenderFrameBuffer(), pass.getPassMaterial());
                }
            }

            filter.postFrame(renderManager, viewPort, buff, sceneFb);

            Material mat = filter.getMaterial();
            if (msDepth && filter.isRequiresDepthTexture()) {
                mat.setInt("NumSamplesDepth", depthTexture.getImage().getMultiSamples());
            }

            if (filter.isRequiresSceneTexture()) {
                mat.setTexture("Texture", tex);
                if (tex.getImage().getMultiSamples() > 1) {
                    mat.setInt("NumSamples", tex.getImage().getMultiSamples());
                } else {
                    mat.clearParam("NumSamples");
                }
            }

            buff = outputBuffer;
            if (i != lastFilterIndex) {
                buff = filter.getRenderFrameBuffer();
                tex = filter.getRenderedTexture();

            }
            renderProcessing(r, buff, mat);
        }
    }
}