Search in sources :

Example 26 with Filter

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

the class AudioNode method read.

@Override
public void read(JmeImporter im) throws IOException {
    super.read(im);
    InputCapsule ic = im.getCapsule(this);
    // to "audio_key" in case Spatial's key will be written as "key".
    if (ic.getSavableVersion(AudioNode.class) == 0) {
        audioKey = (AudioKey) ic.readSavable("key", null);
    } else {
        audioKey = (AudioKey) ic.readSavable("audio_key", null);
    }
    loop = ic.readBoolean("looping", false);
    volume = ic.readFloat("volume", 1);
    pitch = ic.readFloat("pitch", 1);
    timeOffset = ic.readFloat("time_offset", 0);
    dryFilter = (Filter) ic.readSavable("dry_filter", null);
    velocity = (Vector3f) ic.readSavable("velocity", null);
    reverbEnabled = ic.readBoolean("reverb_enabled", false);
    reverbFilter = (Filter) ic.readSavable("reverb_filter", null);
    maxDistance = ic.readFloat("max_distance", 20);
    refDistance = ic.readFloat("ref_distance", 10);
    directional = ic.readBoolean("directional", false);
    direction = (Vector3f) ic.readSavable("direction", null);
    innerAngle = ic.readFloat("inner_angle", 360);
    outerAngle = ic.readFloat("outer_angle", 360);
    positional = ic.readBoolean("positional", false);
    velocityFromTranslation = ic.readBoolean("velocity_from_translation", false);
    if (audioKey != null) {
        try {
            data = im.getAssetManager().loadAsset(audioKey);
        } catch (AssetNotFoundException ex) {
            Logger.getLogger(AudioNode.class.getName()).log(Level.FINE, "Cannot locate {0} for audio node {1}", new Object[] { audioKey, key });
            data = PlaceholderAssets.getPlaceholderAudio();
        }
    }
}
Also used : InputCapsule(com.jme3.export.InputCapsule) AssetNotFoundException(com.jme3.asset.AssetNotFoundException)

Example 27 with Filter

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

the class FilterPostProcessor method initFilter.

/**
     * init the given filter
     * @param filter
     * @param vp 
     */
private void initFilter(Filter filter, ViewPort vp) {
    filter.setProcessor(this);
    if (filter.isRequiresDepthTexture()) {
        if (!computeDepth && renderFrameBuffer != null) {
            depthTexture = new Texture2D(width, height, Format.Depth24);
            renderFrameBuffer.setDepthTexture(depthTexture);
        }
        computeDepth = true;
        filter.init(assetManager, renderManager, vp, width, height);
        filter.setDepthTexture(depthTexture);
    } else {
        filter.init(assetManager, renderManager, vp, width, height);
    }
}
Also used : Texture2D(com.jme3.texture.Texture2D)

Example 28 with Filter

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

the class FilterPostProcessor method initialize.

public void initialize(RenderManager rm, ViewPort vp) {
    renderManager = rm;
    renderer = rm.getRenderer();
    viewPort = vp;
    fsQuad = new Picture("filter full screen quad");
    fsQuad.setWidth(1);
    fsQuad.setHeight(1);
    if (fbFormat == Format.RGB111110F && !renderer.getCaps().contains(Caps.PackedFloatTexture)) {
        fbFormat = Format.RGB8;
    }
    Camera cam = vp.getCamera();
    //save view port diensions
    left = cam.getViewPortLeft();
    right = cam.getViewPortRight();
    top = cam.getViewPortTop();
    bottom = cam.getViewPortBottom();
    originalWidth = cam.getWidth();
    originalHeight = cam.getHeight();
    //first call to reshape
    reshape(vp, cam.getWidth(), cam.getHeight());
}
Also used : Picture(com.jme3.ui.Picture)

Example 29 with Filter

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

the class Material method render.

/**
     * Called by {@link RenderManager} to render the geometry by
     * using this material.
     * <p>
     * The material is rendered as follows:
     * <ul>
     * <li>Determine which technique to use to render the material -
     * either what the user selected via
     * {@link #selectTechnique(java.lang.String, com.jme3.renderer.RenderManager)
     * Material.selectTechnique()},
     * or the first default technique that the renderer supports
     * (based on the technique's {@link TechniqueDef#getRequiredCaps() requested rendering capabilities})<ul>
     * <li>If the technique has been changed since the last frame, then it is notified via
     * {@link Technique#makeCurrent(com.jme3.asset.AssetManager, boolean, java.util.EnumSet)
     * Technique.makeCurrent()}.
     * If the technique wants to use a shader to render the model, it should load it at this part -
     * the shader should have all the proper defines as declared in the technique definition,
     * including those that are bound to material parameters.
     * The technique can re-use the shader from the last frame if
     * no changes to the defines occurred.</li></ul>
     * <li>Set the {@link RenderState} to use for rendering. The render states are
     * applied in this order (later RenderStates override earlier RenderStates):<ol>
     * <li>{@link TechniqueDef#getRenderState() Technique Definition's RenderState}
     * - i.e. specific renderstate that is required for the shader.</li>
     * <li>{@link #getAdditionalRenderState() Material Instance Additional RenderState}
     * - i.e. ad-hoc renderstate set per model</li>
     * <li>{@link RenderManager#getForcedRenderState() RenderManager's Forced RenderState}
     * - i.e. renderstate requested by a {@link com.jme3.post.SceneProcessor} or
     * post-processing filter.</li></ol>
     * <li>If the technique {@link TechniqueDef#isUsingShaders() uses a shader}, then the uniforms of the shader must be updated.<ul>
     * <li>Uniforms bound to material parameters are updated based on the current material parameter values.</li>
     * <li>Uniforms bound to world parameters are updated from the RenderManager.
     * Internally {@link UniformBindingManager} is used for this task.</li>
     * <li>Uniforms bound to textures will cause the texture to be uploaded as necessary.
     * The uniform is set to the texture unit where the texture is bound.</li></ul>
     * <li>If the technique uses a shader, the model is then rendered according
     * to the lighting mode specified on the technique definition.<ul>
     * <li>{@link LightMode#SinglePass single pass light mode} fills the shader's light uniform arrays
     * with the first 4 lights and renders the model once.</li>
     * <li>{@link LightMode#MultiPass multi pass light mode} light mode renders the model multiple times,
     * for the first light it is rendered opaque, on subsequent lights it is
     * rendered with {@link BlendMode#AlphaAdditive alpha-additive} blending and depth writing disabled.</li>
     * </ul>
     * <li>For techniques that do not use shaders,
     * fixed function OpenGL is used to render the model (see {@link GL1Renderer} interface):<ul>
     * <li>OpenGL state ({@link FixedFuncBinding}) that is bound to material parameters is updated. </li>
     * <li>The texture set on the material is uploaded and bound.
     * Currently only 1 texture is supported for fixed function techniques.</li>
     * <li>If the technique uses lighting, then OpenGL lighting state is updated
     * based on the light list on the geometry, otherwise OpenGL lighting is disabled.</li>
     * <li>The mesh is uploaded and rendered.</li>
     * </ul>
     * </ul>
     *
     * @param geometry The geometry to render
     * @param lights Presorted and filtered light list to use for rendering
     * @param renderManager The render manager requesting the rendering
     */
public void render(Geometry geometry, LightList lights, RenderManager renderManager) {
    if (technique == null) {
        selectTechnique(TechniqueDef.DEFAULT_TECHNIQUE_NAME, renderManager);
    }
    TechniqueDef techniqueDef = technique.getDef();
    Renderer renderer = renderManager.getRenderer();
    EnumSet<Caps> rendererCaps = renderer.getCaps();
    if (techniqueDef.isNoRender()) {
        return;
    }
    // Apply render state
    updateRenderState(renderManager, renderer, techniqueDef);
    // Get world overrides
    SafeArrayList<MatParamOverride> overrides = geometry.getWorldMatParamOverrides();
    // Select shader to use
    Shader shader = technique.makeCurrent(renderManager, overrides, renderManager.getForcedMatParams(), lights, rendererCaps);
    // Begin tracking which uniforms were changed by material.
    clearUniformsSetByCurrent(shader);
    // Set uniform bindings
    renderManager.updateUniformBindings(shader);
    // Set material parameters
    int unit = updateShaderMaterialParameters(renderer, shader, overrides, renderManager.getForcedMatParams());
    // Clear any uniforms not changed by material.
    resetUniformsNotSetByCurrent(shader);
    // Delegate rendering to the technique
    technique.render(renderManager, shader, geometry, lights, unit);
}
Also used : Renderer(com.jme3.renderer.Renderer) Shader(com.jme3.shader.Shader) Caps(com.jme3.renderer.Caps)

Example 30 with Filter

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

the class RenderManager method renderGeometry.

/**
     * Renders the given geometry.
     * <p>
     * First the proper world matrix is set, if 
     * the geometry's {@link Geometry#setIgnoreTransform(boolean) ignore transform}
     * feature is enabled, the identity world matrix is used, otherwise, the 
     * geometry's {@link Geometry#getWorldMatrix() world transform matrix} is used. 
     * <p>
     * Once the world matrix is applied, the proper material is chosen for rendering.
     * If a {@link #setForcedMaterial(com.jme3.material.Material) forced material} is
     * set on this RenderManager, then it is used for rendering the geometry,
     * otherwise, the {@link Geometry#getMaterial() geometry's material} is used.
     * <p>
     * If a {@link #setForcedTechnique(java.lang.String) forced technique} is
     * set on this RenderManager, then it is selected automatically
     * on the geometry's material and is used for rendering. Otherwise, one
     * of the {@link MaterialDef#getDefaultTechniques() default techniques} is
     * used.
     * <p>
     * If a {@link #setForcedRenderState(com.jme3.material.RenderState) forced
     * render state} is set on this RenderManager, then it is used
     * for rendering the material, and the material's own render state is ignored.
     * Otherwise, the material's render state is used as intended.
     * 
     * @param geom The geometry to render
       * 
     * @see Technique
     * @see RenderState
     * @see Material#selectTechnique(java.lang.String, com.jme3.renderer.RenderManager) 
     * @see Material#render(com.jme3.scene.Geometry, com.jme3.renderer.RenderManager) 
     */
public void renderGeometry(Geometry geom) {
    if (geom.isIgnoreTransform()) {
        setWorldMatrix(Matrix4f.IDENTITY);
    } else {
        setWorldMatrix(geom.getWorldMatrix());
    }
    // Perform light filtering if we have a light filter.
    LightList lightList = geom.getWorldLightList();
    if (lightFilter != null) {
        filteredLightList.clear();
        lightFilter.filterLights(geom, filteredLightList);
        lightList = filteredLightList;
    }
    Material material = geom.getMaterial();
    //else the geom is not rendered
    if (forcedTechnique != null) {
        MaterialDef matDef = material.getMaterialDef();
        if (matDef.getTechniqueDefs(forcedTechnique) != null) {
            Technique activeTechnique = material.getActiveTechnique();
            String previousTechniqueName = activeTechnique != null ? activeTechnique.getDef().getName() : TechniqueDef.DEFAULT_TECHNIQUE_NAME;
            geom.getMaterial().selectTechnique(forcedTechnique, this);
            //saving forcedRenderState for future calls
            RenderState tmpRs = forcedRenderState;
            if (geom.getMaterial().getActiveTechnique().getDef().getForcedRenderState() != null) {
                //forcing forced technique renderState
                forcedRenderState = geom.getMaterial().getActiveTechnique().getDef().getForcedRenderState();
            }
            // use geometry's material
            material.render(geom, lightList, this);
            material.selectTechnique(previousTechniqueName, this);
            //restoring forcedRenderState
            forcedRenderState = tmpRs;
        //Reverted this part from revision 6197
        //If forcedTechnique does not exists, and forcedMaterial is not set, the geom MUST NOT be rendered
        } else if (forcedMaterial != null) {
            // use forced material
            forcedMaterial.render(geom, lightList, this);
        }
    } else if (forcedMaterial != null) {
        // use forced material
        forcedMaterial.render(geom, lightList, this);
    } else {
        material.render(geom, lightList, this);
    }
}
Also used : RenderState(com.jme3.material.RenderState) LightList(com.jme3.light.LightList) Material(com.jme3.material.Material) Technique(com.jme3.material.Technique) MaterialDef(com.jme3.material.MaterialDef)

Aggregations

Node (com.jme3.scene.Node)10 Vector3f (com.jme3.math.Vector3f)7 FilterPostProcessor (com.jme3.post.FilterPostProcessor)7 Spatial (com.jme3.scene.Spatial)7 Texture2D (com.jme3.texture.Texture2D)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 SSAOFilter (com.jme3.post.ssao.SSAOFilter)5 DirectionalLight (com.jme3.light.DirectionalLight)4 Material (com.jme3.material.Material)4 Quaternion (com.jme3.math.Quaternion)4 Filter (com.jme3.post.Filter)4 AudioNode (com.jme3.audio.AudioNode)3 KeyTrigger (com.jme3.input.controls.KeyTrigger)3 ColorRGBA (com.jme3.math.ColorRGBA)3 FogFilter (com.jme3.post.filters.FogFilter)3 DirectionalLightShadowFilter (com.jme3.shadow.DirectionalLightShadowFilter)3 Texture (com.jme3.texture.Texture)3 TextureKey (com.jme3.asset.TextureKey)2 LowPassFilter (com.jme3.audio.LowPassFilter)2