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

The following examples show how to use com.jme3.material.Material#setVector2() . 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: TestLightingFog.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {

    ColorRGBA skyColor = new ColorRGBA(0.5f, 0.6f, 0.7f, 0.0f);

    flyCam.setMoveSpeed(20);
    viewPort.setBackgroundColor(skyColor.mult(0.9f));

    DirectionalLight directionalLight = new DirectionalLight(new Vector3f(-1, -1, -1).normalizeLocal());
    rootNode.addLight(directionalLight);

    material = new Material(assetManager, Materials.LIGHTING);
    material.setBoolean("UseFog", true);
    material.setColor("FogColor", skyColor);
    material.setVector2("LinearFog", linear);

    int distance = -3;

    for (int i = 0; i < 100; i++) {
        Geometry geometry = new Geometry("Sphere", new Sphere(32, 32, 2));
        geometry.setMaterial(material);

        geometry.setLocalTranslation((FastMath.nextRandomFloat() - 0.5f) * 45, 0, i * distance);
        rootNode.attachChild(geometry);
    }

    inputManager.addMapping("Linear",  new KeyTrigger(KeyInput.KEY_1));
    inputManager.addMapping("Exponential",  new KeyTrigger(KeyInput.KEY_2));
    inputManager.addMapping("ExponentialSquared",  new KeyTrigger(KeyInput.KEY_3));
    inputManager.addListener(this, "Linear", "Exponential", "ExponentialSquared");
}
 
Example 2
Source File: CartoonSSAO.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) {
    this.renderManager = renderManager;
    this.viewPort = vp;

    int screenWidth = Math.round(w / downsample);
    int screenHeight = Math.round(h / downsample);

    normalPass = new Pass();
    normalPass.init(renderManager.getRenderer(), screenWidth, screenHeight, 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
    material = new Material(manager, "Common/MatDefs/VR/CartoonSSAO.j3md");
    material.setTexture("Normals", normalPass.getRenderedTexture());        

    material.setVector3("FrustumCorner", frustumCorner);
    material.setVector2("FrustumNearFar", frustumNearFar);
    material.setFloat("Distance", applyDistance);
    if( useOutline == false ) material.setBoolean("disableOutline", true);
    if( instancedRendering ) material.setBoolean("useInstancing", true);
}
 
Example 3
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 4
Source File: DirectionalLightShadowRendererVR.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void setMaterialParameters(Material material) {
    material.setColor("Splits", splits);
    material.setVector3("LightDir", light.getDirection());
    if (fadeInfo != null) {
        material.setVector2("FadeInfo", fadeInfo);
    }
}
 
Example 5
Source File: HDRRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Material createLumShader(int srcW, int srcH, int bufW, int bufH, int mode,
                            int iters, Texture tex){
    Material mat = new Material(manager, "Common/MatDefs/Hdr/LogLum.j3md");
    
    Vector2f blockSize = new Vector2f(1f / bufW, 1f / bufH);
    Vector2f pixelSize = new Vector2f(1f / srcW, 1f / srcH);
    Vector2f blocks = new Vector2f();
    float numPixels = Float.POSITIVE_INFINITY;
    if (iters != -1){
        do {
            pixelSize.multLocal(2);
            blocks.set(blockSize.x / pixelSize.x,
                       blockSize.y / pixelSize.y);
            numPixels = blocks.x * blocks.y;
        } while (numPixels > iters);
    }else{
        blocks.set(blockSize.x / pixelSize.x,
                   blockSize.y / pixelSize.y);
        numPixels = blocks.x * blocks.y;
    }

    mat.setBoolean("Blocks", true);
    if (mode == LUMMODE_ENCODE_LUM)
        mat.setBoolean("EncodeLum", true);
    else if (mode == LUMMODE_DECODE_LUM)
        mat.setBoolean("DecodeLum", true);

    mat.setTexture("Texture", tex);
    mat.setVector2("BlockSize", blockSize);
    mat.setVector2("PixelSize", pixelSize);
    mat.setFloat("NumPixels", numPixels);

    return mat;
}
 
Example 6
Source File: DirectionalLightShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void setMaterialParameters(Material material) {
    material.setColor("Splits", splits);
    material.setVector3("LightDir", light == null ? new Vector3f() : light.getDirection());
    if (fadeInfo != null) {
        material.setVector2("FadeInfo", fadeInfo);
    }
}
 
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: HDRRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Material createLumShader(int srcW, int srcH, int bufW, int bufH, int mode,
                            int iters, Texture tex){
    Material mat = new Material(manager, "Common/MatDefs/Hdr/LogLum.j3md");
    
    Vector2f blockSize = new Vector2f(1f / bufW, 1f / bufH);
    Vector2f pixelSize = new Vector2f(1f / srcW, 1f / srcH);
    Vector2f blocks = new Vector2f();
    float numPixels = Float.POSITIVE_INFINITY;
    if (iters != -1){
        do {
            pixelSize.multLocal(2);
            blocks.set(blockSize.x / pixelSize.x,
                       blockSize.y / pixelSize.y);
            numPixels = blocks.x * blocks.y;
        } while (numPixels > iters);
    }else{
        blocks.set(blockSize.x / pixelSize.x,
                   blockSize.y / pixelSize.y);
        numPixels = blocks.x * blocks.y;
    }
    System.out.println(numPixels);

    mat.setBoolean("Blocks", true);
    if (mode == LUMMODE_ENCODE_LUM)
        mat.setBoolean("EncodeLum", true);
    else if (mode == LUMMODE_DECODE_LUM)
        mat.setBoolean("DecodeLum", true);

    mat.setTexture("Texture", tex);
    mat.setVector2("BlockSize", blockSize);
    mat.setVector2("PixelSize", pixelSize);
    mat.setFloat("NumPixels", numPixels);

    return mat;
}
 
Example 9
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 10
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);

}