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

The following examples show how to use com.jme3.material.Material#setInt() . 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: 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 2
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 3
Source File: DDSPreview.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public DDSPreview(ProjectAssetManager assetManager) {
    this.assetManager = assetManager;

    Quad quadMesh = new Quad(4.5f, 4.5f);
    Quad quadMesh3D = new Quad(4.5f, 4.5f);
    quadMesh3D.scaleTextureCoordinates(new Vector2f(4, 4));
    quad = new Geometry("previewQuad", quadMesh);
    quad.setLocalTranslation(new Vector3f(-2.25f, -2.25f, 0));
    quad3D = new Geometry("previewQuad", quadMesh3D);
    quad3D.setLocalTranslation(new Vector3f(-2.25f, -2.25f, 0));
    material3D = new Material(assetManager, "com/jme3/gde/core/properties/preview/tex3DThumb.j3md");
    material3D.setFloat("InvDepth", 1f / 16f);
    material3D.setInt("Rows", 4);
    material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    SceneApplication.getApplication().addSceneListener(this);
}
 
Example 4
Source File: TestTexture3DLoading.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);
    flyCam.setEnabled(false);


    Quad q = new Quad(10, 10);

    Geometry geom = new Geometry("Quad", q);
    Material material = new Material(assetManager, "jme3test/texture/tex3DThumb.j3md");
    TextureKey key = new TextureKey("Textures/3D/flame.dds");
    key.setGenerateMips(true);
    key.setTextureTypeHint(Texture.Type.ThreeDimensional);

    Texture t = assetManager.loadTexture(key);

    int rows = 4;//4 * 4

    q.scaleTextureCoordinates(new Vector2f(rows, rows));

    //The image only have 8 pictures and we have 16 thumbs, the data will be interpolated by the GPU
    material.setFloat("InvDepth", 1f / 16f);
    material.setInt("Rows", rows);
    material.setTexture("Texture", t);
    geom.setMaterial(material);

    rootNode.attachChild(geom);

    cam.setLocation(new Vector3f(4.7444625f, 5.160054f, 13.1939f));
}
 
Example 5
Source File: AbstractShadowRendererVR.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setMatParams(GeometryList l) {
    //iteration throught all the geometries of the list to gather the materials

    buildMatCache(l);

    //iterating through the mat cache and setting the parameters
    for (Material mat : matCache) {

        mat.setFloat("ShadowMapSize", shadowMapSize);

        for (int j = 0; j < nbShadowMaps; j++) {
            mat.setMatrix4(lightViewStringCache[j], lightViewProjectionsMatrices[j]);
        }
        for (int j = 0; j < nbShadowMaps; j++) {
            mat.setTexture(shadowMapStringCache[j], shadowMaps[j]);
        }
        mat.setBoolean("HardwareShadows", shadowCompareMode == CompareMode.Hardware);
        mat.setInt("FilterMode", edgeFilteringMode.getMaterialParamValue());
        mat.setFloat("PCFEdge", edgesThickness);
        mat.setFloat("ShadowIntensity", shadowIntensity);
        mat.setBoolean("BackfaceShadows", renderBackFacesShadows);

        if (fadeInfo != null) {
           mat.setVector2("FadeInfo", fadeInfo);
        }

        setMaterialParameters(mat);
    }

    //At least one material of the receiving geoms does not support the post shadow techniques
    //so we fall back to the forced material solution (transparent shadows won't be supported for these objects)
    if (needsfallBackMaterial) {
        setPostShadowParams();
    }

}
 
Example 6
Source File: PosterizationFilter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
    material = new Material(manager, "Common/MatDefs/Post/Posterization.j3md");
    material.setInt("NumColors", numColors);
    material.setFloat("Gamma", gamma);
    material.setFloat("Strength", strength);
}
 
Example 7
Source File: AbstractShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setMatParams(GeometryList l) {
    //iteration throught all the geometries of the list to gather the materials

    buildMatCache(l);

    //iterating through the mat cache and setting the parameters
    for (Material mat : matCache) {

        mat.setFloat("ShadowMapSize", shadowMapSize);

        for (int j = 0; j < nbShadowMaps; j++) {
            mat.setMatrix4(lightViewStringCache[j], lightViewProjectionsMatrices[j]);
        }

        for (int j = 0; j < nbShadowMaps; j++) {
            mat.setTexture(shadowMapStringCache[j], shadowMaps[j]);
        }

        mat.setBoolean("HardwareShadows", shadowCompareMode == CompareMode.Hardware);
        mat.setInt("FilterMode", edgeFilteringMode.getMaterialParamValue());
        mat.setFloat("PCFEdge", edgesThickness);
        mat.setFloat("ShadowIntensity", shadowIntensity);
        mat.setBoolean("BackfaceShadows", renderBackFacesShadows);

        if (fadeInfo != null) {
           mat.setVector2("FadeInfo", fadeInfo);
        }

        setMaterialParameters(mat);
    }

    //At least one material of the receiving geoms does not support the post shadow techniques
    //so we fall back to the forced material solution (transparent shadows won't be supported for these objects)
    if (needsfallBackMaterial) {
        setPostShadowParams();
    }

}
 
Example 8
Source File: TestTexture3DLoading.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);
    flyCam.setEnabled(false);


    Quad q = new Quad(10, 10);

    Geometry geom = new Geometry("Quad", q);
    Material material = new Material(assetManager, "jme3test/texture/tex3DThumb.j3md");
    TextureKey key = new TextureKey("Textures/3D/flame.dds");
    key.setGenerateMips(true);
    key.setAsTexture3D(true);

    Texture t = assetManager.loadTexture(key);

    int rows = 4;//4 * 4

    q.scaleTextureCoordinates(new Vector2f(rows, rows));

    //The image only have 8 pictures and we have 16 thumbs, the data will be interpolated by the GPU
    material.setFloat("InvDepth", 1f / 16f);
    material.setInt("Rows", rows);
    material.setTexture("Texture", t);
    geom.setMaterial(material);

    rootNode.attachChild(geom);

    cam.setLocation(new Vector3f(4.7444625f, 5.160054f, 13.1939f));
}
 
Example 9
Source File: SkeletonControl.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void switchToHardware() {
    // Next full 10 bones (e.g. 30 on 24 bones)
    int numBones = ((skeleton.getBoneCount() / 10) + 1) * 10;
    for (Material m : materials) {
        m.setInt("NumberOfBones", numBones);
    }
    for (Mesh mesh : targets) {
        if (mesh.isAnimated()) {
            mesh.prepareForAnim(false);
        }
    }
}
 
Example 10
Source File: PosterizationFilter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
    material = new Material(manager, "Common/MatDefs/Post/Posterization.j3md");
    material.setInt("NumColors", numColors);
    material.setFloat("Gamma", gamma);
    material.setFloat("Strength", strength);
}
 
Example 11
Source File: TestTessellationShader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
    tessellationMaterial = new Material(getAssetManager(), "Materials/Tess/SimpleTess.j3md");
    tessellationMaterial.setInt("TessellationFactor", tessFactor);
    tessellationMaterial.getAdditionalRenderState().setWireframe(true);
    Quad quad = new Quad(10, 10);
    quad.clearBuffer(VertexBuffer.Type.Index);
    quad.setBuffer(VertexBuffer.Type.Index, 4, BufferUtils.createIntBuffer(0, 1, 2, 3));
    quad.setMode(Mesh.Mode.Patch);
    quad.setPatchVertexCount(4);
    Geometry geometry = new Geometry("tessTest", quad);
    geometry.setMaterial(tessellationMaterial);
    rootNode.attachChild(geometry);

    getInputManager().addMapping("TessUp", new KeyTrigger(KeyInput.KEY_O));
    getInputManager().addMapping("TessDo", new KeyTrigger(KeyInput.KEY_L));
    getInputManager().addListener(new AnalogListener() {
        @Override
        public void onAnalog(String name, float value, float tpf) {
            if(name.equals("TessUp")){
                tessFactor++;
                enqueue(new Callable<Boolean>() {
                    @Override
                    public Boolean call() throws Exception {
                        tessellationMaterial.setInt("TessellationFactor",tessFactor);
                        return true;
                    }
                });
            }
            if(name.equals("TessDo")){
                tessFactor--;
                enqueue(new Callable<Boolean>() {
                    @Override
                    public Boolean call() throws Exception {
                        tessellationMaterial.setInt("TessellationFactor",tessFactor);
                        return true;
                    }
                });
            }
        }
    },"TessUp","TessDo");
}
 
Example 12
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 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);
        }
    }
}