Search in sources :

Example 6 with Pass

use of com.jme3.post.Filter.Pass in project jmonkeyengine by jMonkeyEngine.

the class FilterPostProcessor method renderFilterChain.

/**
     * 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);
            }
        }
    }
}
Also used : Texture2D(com.jme3.texture.Texture2D) Material(com.jme3.material.Material) FrameBuffer(com.jme3.texture.FrameBuffer)

Example 7 with Pass

use of com.jme3.post.Filter.Pass in project jmonkeyengine by jMonkeyEngine.

the class SceneLoader method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes attribs) throws SAXException {
    if (qName.equals("scene")) {
        if (elementStack.size() != 0) {
            throw new SAXException("dotScene parse error: 'scene' element must be the root XML element");
        }
        String version = attribs.getValue("formatVersion");
        if (version == null || (!version.equals("1.0.0") && !version.equals("1.0.1"))) {
            logger.log(Level.WARNING, "Unrecognized version number" + " in dotScene file: {0}", version);
        }
    } else if (qName.equals("nodes")) {
        if (root != null) {
            throw new SAXException("dotScene parse error: nodes element was specified twice");
        }
        if (sceneName == null) {
            root = new com.jme3.scene.Node("OgreDotScene" + (++sceneIdx));
        } else {
            root = new com.jme3.scene.Node(sceneName + "-scene_node");
        }
        node = root;
    } else if (qName.equals("externals")) {
        checkTopNode("scene");
    } else if (qName.equals("item")) {
        checkTopNode("externals");
    } else if (qName.equals("file")) {
        checkTopNode("item");
    // NOTE: This part of the file is ignored, it is parsed
    // by SceneMaterialLoader in the first pass.
    } else if (qName.equals("node")) {
        String curElement = elementStack.peek();
        if (!curElement.equals("node") && !curElement.equals("nodes")) {
            throw new SAXException("dotScene parse error: " + "node element can only appear under 'node' or 'nodes'");
        }
        parseNode(attribs);
    } else if (qName.equals("property")) {
        if (node != null) {
            String type = attribs.getValue("type");
            String name = attribs.getValue("name");
            String data = attribs.getValue("data");
            if (type.equals("BOOL")) {
                node.setUserData(name, Boolean.parseBoolean(data) || data.equals("1"));
            } else if (type.equals("FLOAT")) {
                node.setUserData(name, Float.parseFloat(data));
            } else if (type.equals("STRING")) {
                node.setUserData(name, data);
            } else if (type.equals("INT")) {
                node.setUserData(name, Integer.parseInt(data));
            }
        }
    } else if (qName.equals("entity")) {
        checkTopNode("node");
        parseEntity(attribs);
    } else if (qName.equals("camera")) {
        checkTopNode("node");
        parseCamera(attribs);
    } else if (qName.equals("clipping")) {
        checkTopNode("camera");
        parseCameraClipping(attribs);
    } else if (qName.equals("position")) {
        if (elementStack.peek().equals("node")) {
            node.setLocalTranslation(SAXUtil.parseVector3(attribs));
        } else if (elementStack.peek().equals("camera")) {
            cameraNode.setLocalTranslation(SAXUtil.parseVector3(attribs));
        }
    } else if (qName.equals("quaternion") || qName.equals("rotation")) {
        node.setLocalRotation(parseQuat(attribs));
    } else if (qName.equals("scale")) {
        node.setLocalScale(SAXUtil.parseVector3(attribs));
    } else if (qName.equals("light")) {
        parseLight(attribs);
    } else if (qName.equals("colourDiffuse") || qName.equals("colorDiffuse")) {
        if (elementStack.peek().equals("light")) {
            if (light != null) {
                light.setColor(parseColor(attribs));
            }
        } else {
            checkTopNode("environment");
        }
    } else if (qName.equals("colourAmbient") || qName.equals("colorAmbient")) {
        if (elementStack.peek().equals("environment")) {
            ColorRGBA color = parseColor(attribs);
            if (!color.equals(ColorRGBA.Black) && !color.equals(ColorRGBA.BlackNoAlpha)) {
                // Lets add an ambient light to the scene.
                AmbientLight al = new AmbientLight();
                al.setColor(color);
                root.addLight(al);
            }
        }
    } else if (qName.equals("normal") || qName.equals("direction")) {
        checkTopNode("light");
        parseLightNormal(attribs);
    } else if (qName.equals("lightAttenuation")) {
        parseLightAttenuation(attribs);
    } else if (qName.equals("spotLightRange") || qName.equals("lightRange")) {
        parseLightSpotLightRange(attribs);
    }
    elementStack.push(qName);
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) LightNode(com.jme3.scene.LightNode) CameraNode(com.jme3.scene.CameraNode) AmbientLight(com.jme3.light.AmbientLight) SAXException(org.xml.sax.SAXException)

Example 8 with Pass

use of com.jme3.post.Filter.Pass in project jmonkeyengine by jMonkeyEngine.

the class AbstractShadowRendererVR method postFrame.

public void postFrame(FrameBuffer out) {
    if (skipPostPass) {
        return;
    }
    if (debug) {
        displayShadowMap(renderManager.getRenderer());
    }
    getReceivers(lightReceivers);
    if (lightReceivers.size() != 0) {
        //setting params to recieving geometry list
        setMatParams(lightReceivers);
        Camera cam = viewPort.getCamera();
        //some materials in the scene does not have a post shadow technique so we're using the fall back material
        if (needsfallBackMaterial) {
            renderManager.setForcedMaterial(postshadowMat);
        }
        //forcing the post shadow technique and render state
        renderManager.setForcedTechnique(postTechniqueName);
        //rendering the post shadow pass
        viewPort.getQueue().renderShadowQueue(lightReceivers, renderManager, cam, false);
        //resetting renderManager settings
        renderManager.setForcedTechnique(null);
        renderManager.setForcedMaterial(null);
        renderManager.setCamera(cam, false);
        //clearing the params in case there are some other shadow renderers
        clearMatParams();
    }
}
Also used : Camera(com.jme3.renderer.Camera)

Example 9 with Pass

use of com.jme3.post.Filter.Pass in project jmonkeyengine by jMonkeyEngine.

the class TestOgg method simpleUpdate.

@Override
public void simpleUpdate(float tpf) {
    if (audioSource.getStatus() != AudioSource.Status.Playing) {
        audioRenderer.deleteAudioData(audioSource.getAudioData());
        System.out.println("Playing with low pass filter");
        audioSource = new AudioNode(assetManager, "Sound/Effects/Foot steps.ogg", DataType.Buffer);
        audioSource.setDryFilter(new LowPassFilter(1f, .1f));
        audioSource.setVolume(3);
        audioSource.play();
    }
}
Also used : LowPassFilter(com.jme3.audio.LowPassFilter) AudioNode(com.jme3.audio.AudioNode)

Example 10 with Pass

use of com.jme3.post.Filter.Pass in project jmonkeyengine by jMonkeyEngine.

the class SinglePassAndImageBasedLightingLogic method updateLightListUniforms.

/**
     * Uploads the lights in the light list as two uniform arrays.<br/><br/> *
     * <p>
     * <code>uniform vec4 g_LightColor[numLights];</code><br/> //
     * g_LightColor.rgb is the diffuse/specular color of the light.<br/> //
     * g_Lightcolor.a is the type of light, 0 = Directional, 1 = Point, <br/> //
     * 2 = Spot. <br/> <br/>
     * <code>uniform vec4 g_LightPosition[numLights];</code><br/> //
     * g_LightPosition.xyz is the position of the light (for point lights)<br/>
     * // or the direction of the light (for directional lights).<br/> //
     * g_LightPosition.w is the inverse radius (1/r) of the light (for
     * attenuation) <br/> </p>
     */
protected int updateLightListUniforms(Shader shader, Geometry g, LightList lightList, int numLights, RenderManager rm, int startIndex, int lastTexUnit) {
    if (numLights == 0) {
        // this shader does not do lighting, ignore.
        return 0;
    }
    Uniform lightData = shader.getUniform("g_LightData");
    //8 lights * max 3
    lightData.setVector4Length(numLights * 3);
    Uniform ambientColor = shader.getUniform("g_AmbientLightColor");
    Uniform lightProbeData = shader.getUniform("g_LightProbeData");
    lightProbeData.setVector4Length(1);
    Uniform lightProbeIrrMap = shader.getUniform("g_IrradianceMap");
    Uniform lightProbePemMap = shader.getUniform("g_PrefEnvMap");
    lightProbe = null;
    if (startIndex != 0) {
        // apply additive blending for 2nd and future passes
        rm.getRenderer().applyRenderState(ADDITIVE_LIGHT);
        ambientColor.setValue(VarType.Vector4, ColorRGBA.Black);
    } else {
        lightProbe = extractIndirectLights(lightList, true);
        ambientColor.setValue(VarType.Vector4, ambientLightColor);
    }
    //If there is a lightProbe in the list we force it's render on the first pass
    if (lightProbe != null) {
        BoundingSphere s = (BoundingSphere) lightProbe.getBounds();
        lightProbeData.setVector4InArray(lightProbe.getPosition().x, lightProbe.getPosition().y, lightProbe.getPosition().z, 1f / s.getRadius(), 0);
        //assigning new texture indexes
        int irrUnit = lastTexUnit++;
        int pemUnit = lastTexUnit++;
        rm.getRenderer().setTexture(irrUnit, lightProbe.getIrradianceMap());
        lightProbeIrrMap.setValue(VarType.Int, irrUnit);
        rm.getRenderer().setTexture(pemUnit, lightProbe.getPrefilteredEnvMap());
        lightProbePemMap.setValue(VarType.Int, pemUnit);
    } else {
        //Disable IBL for this pass
        lightProbeData.setVector4InArray(0, 0, 0, -1, 0);
    }
    int lightDataIndex = 0;
    TempVars vars = TempVars.get();
    Vector4f tmpVec = vars.vect4f1;
    int curIndex;
    int endIndex = numLights + startIndex;
    for (curIndex = startIndex; curIndex < endIndex && curIndex < lightList.size(); curIndex++) {
        Light l = lightList.get(curIndex);
        if (l.getType() == Light.Type.Ambient) {
            endIndex++;
            continue;
        }
        ColorRGBA color = l.getColor();
        if (l.getType() != Light.Type.Probe) {
            lightData.setVector4InArray(color.getRed(), color.getGreen(), color.getBlue(), l.getType().getId(), lightDataIndex);
            lightDataIndex++;
        }
        switch(l.getType()) {
            case Directional:
                DirectionalLight dl = (DirectionalLight) l;
                Vector3f dir = dl.getDirection();
                //Data directly sent in view space to avoid a matrix mult for each pixel
                tmpVec.set(dir.getX(), dir.getY(), dir.getZ(), 0.0f);
                lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), -1, lightDataIndex);
                lightDataIndex++;
                //PADDING
                lightData.setVector4InArray(0, 0, 0, 0, lightDataIndex);
                lightDataIndex++;
                break;
            case Point:
                PointLight pl = (PointLight) l;
                Vector3f pos = pl.getPosition();
                float invRadius = pl.getInvRadius();
                tmpVec.set(pos.getX(), pos.getY(), pos.getZ(), 1.0f);
                lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRadius, lightDataIndex);
                lightDataIndex++;
                //PADDING
                lightData.setVector4InArray(0, 0, 0, 0, lightDataIndex);
                lightDataIndex++;
                break;
            case Spot:
                SpotLight sl = (SpotLight) l;
                Vector3f pos2 = sl.getPosition();
                Vector3f dir2 = sl.getDirection();
                float invRange = sl.getInvSpotRange();
                float spotAngleCos = sl.getPackedAngleCos();
                tmpVec.set(pos2.getX(), pos2.getY(), pos2.getZ(), 1.0f);
                lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRange, lightDataIndex);
                lightDataIndex++;
                tmpVec.set(dir2.getX(), dir2.getY(), dir2.getZ(), 0.0f);
                lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), spotAngleCos, lightDataIndex);
                lightDataIndex++;
                break;
            default:
                throw new UnsupportedOperationException("Unknown type of light: " + l.getType());
        }
    }
    vars.release();
    //Padding of unsued buffer space
    while (lightDataIndex < numLights * 3) {
        lightData.setVector4InArray(0f, 0f, 0f, 0f, lightDataIndex);
        lightDataIndex++;
    }
    return curIndex;
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) TempVars(com.jme3.util.TempVars)

Aggregations

Material (com.jme3.material.Material)11 Vector3f (com.jme3.math.Vector3f)6 Camera (com.jme3.renderer.Camera)4 Geometry (com.jme3.scene.Geometry)4 Pass (com.jme3.post.Filter.Pass)3 Node (com.jme3.scene.Node)3 AmbientLight (com.jme3.light.AmbientLight)2 DirectionalLight (com.jme3.light.DirectionalLight)2 PointLight (com.jme3.light.PointLight)2 ColorRGBA (com.jme3.math.ColorRGBA)2 Quaternion (com.jme3.math.Quaternion)2 Vector2f (com.jme3.math.Vector2f)2 ChannelInfoMessage (com.jme3.network.message.ChannelInfoMessage)2 ClientRegistrationMessage (com.jme3.network.message.ClientRegistrationMessage)2 Renderer (com.jme3.renderer.Renderer)2 LightNode (com.jme3.scene.LightNode)2 Spatial (com.jme3.scene.Spatial)2 FrameBuffer (com.jme3.texture.FrameBuffer)2 Texture2D (com.jme3.texture.Texture2D)2 NativeObject (com.jme3.util.NativeObject)2