Search in sources :

Example 16 with Renderer

use of com.jme3.renderer.Renderer in project jmonkeyengine by jMonkeyEngine.

the class Material method preload.

/**
     * Preloads this material for the given render manager.
     * <p>
     * Preloading the material can ensure that when the material is first
     * used for rendering, there won't be any delay since the material has
     * been already been setup for rendering.
     *
     * @param renderManager The render manager to preload for
     */
public void preload(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;
    }
    Shader shader = technique.makeCurrent(renderManager, null, null, null, rendererCaps);
    updateShaderMaterialParameters(renderer, shader, null, null);
    renderManager.getRenderer().setShader(shader);
}
Also used : Renderer(com.jme3.renderer.Renderer) Shader(com.jme3.shader.Shader) Caps(com.jme3.renderer.Caps)

Example 17 with Renderer

use of com.jme3.renderer.Renderer in project jmonkeyengine by jMonkeyEngine.

the class Material method applyOverrides.

private int applyOverrides(Renderer renderer, Shader shader, SafeArrayList<MatParamOverride> overrides, int unit) {
    for (MatParamOverride override : overrides.getArray()) {
        VarType type = override.getVarType();
        MatParam paramDef = def.getMaterialParam(override.getName());
        if (paramDef == null || paramDef.getVarType() != type || !override.isEnabled()) {
            continue;
        }
        Uniform uniform = shader.getUniform(override.getPrefixedName());
        if (override.getValue() != null) {
            if (type.isTextureType()) {
                renderer.setTexture(unit, (Texture) override.getValue());
                uniform.setValue(VarType.Int, unit);
                unit++;
            } else {
                uniform.setValue(type, override.getValue());
            }
        } else {
            uniform.clearValue();
        }
    }
    return unit;
}
Also used : Uniform(com.jme3.shader.Uniform) VarType(com.jme3.shader.VarType)

Example 18 with Renderer

use of com.jme3.renderer.Renderer in project jmonkeyengine by jMonkeyEngine.

the class Material method updateShaderMaterialParameters.

private int updateShaderMaterialParameters(Renderer renderer, Shader shader, SafeArrayList<MatParamOverride> worldOverrides, SafeArrayList<MatParamOverride> forcedOverrides) {
    int unit = 0;
    if (worldOverrides != null) {
        unit = applyOverrides(renderer, shader, worldOverrides, unit);
    }
    if (forcedOverrides != null) {
        unit = applyOverrides(renderer, shader, forcedOverrides, unit);
    }
    for (int i = 0; i < paramValues.size(); i++) {
        MatParam param = paramValues.getValue(i);
        VarType type = param.getVarType();
        Uniform uniform = shader.getUniform(param.getPrefixedName());
        if (uniform.isSetByCurrentMaterial()) {
            continue;
        }
        if (type.isTextureType()) {
            renderer.setTexture(unit, (Texture) param.getValue());
            uniform.setValue(VarType.Int, unit);
            unit++;
        } else {
            uniform.setValue(type, param.getValue());
        }
    }
    //TODO HACKY HACK remove this when texture unit is handled by the uniform.
    return unit;
}
Also used : Uniform(com.jme3.shader.Uniform) VarType(com.jme3.shader.VarType)

Example 19 with Renderer

use of com.jme3.renderer.Renderer 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 20 with Renderer

use of com.jme3.renderer.Renderer in project jmonkeyengine by jMonkeyEngine.

the class HDRRenderer method initialize.

public void initialize(RenderManager rm, ViewPort vp) {
    if (!enabled)
        return;
    renderer = rm.getRenderer();
    renderManager = rm;
    viewPort = vp;
    // loadInitial()
    fsQuad = new Picture("HDR Fullscreen Quad");
    Format lumFmt = Format.RGB8;
    scene64FB = new FrameBuffer(64, 64, 1);
    scene64 = new Texture2D(64, 64, lumFmt);
    scene64FB.setColorTexture(scene64);
    scene64.setMagFilter(fbMagFilter);
    scene64.setMinFilter(fbMinFilter);
    scene8FB = new FrameBuffer(8, 8, 1);
    scene8 = new Texture2D(8, 8, lumFmt);
    scene8FB.setColorTexture(scene8);
    scene8.setMagFilter(fbMagFilter);
    scene8.setMinFilter(fbMinFilter);
    scene1FB[0] = new FrameBuffer(1, 1, 1);
    scene1[0] = new Texture2D(1, 1, lumFmt);
    scene1FB[0].setColorTexture(scene1[0]);
    scene1FB[1] = new FrameBuffer(1, 1, 1);
    scene1[1] = new Texture2D(1, 1, lumFmt);
    scene1FB[1].setColorTexture(scene1[1]);
    // prepare tonemap shader
    tone = new Material(manager, "Common/MatDefs/Hdr/ToneMap.j3md");
    tone.setFloat("A", 0.18f);
    tone.setFloat("White", 100);
    // load();
    int w = vp.getCamera().getWidth();
    int h = vp.getCamera().getHeight();
    reshape(vp, w, h);
}
Also used : Texture2D(com.jme3.texture.Texture2D) Format(com.jme3.texture.Image.Format) Picture(com.jme3.ui.Picture) Material(com.jme3.material.Material) FrameBuffer(com.jme3.texture.FrameBuffer)

Aggregations

Renderer (com.jme3.renderer.Renderer)17 Camera (com.jme3.renderer.Camera)7 Vector3f (com.jme3.math.Vector3f)5 Material (com.jme3.material.Material)4 SceneProcessor (com.jme3.post.SceneProcessor)3 RendererException (com.jme3.renderer.RendererException)3 GLExt (com.jme3.renderer.opengl.GLExt)3 GLFbo (com.jme3.renderer.opengl.GLFbo)3 GLRenderer (com.jme3.renderer.opengl.GLRenderer)3 Uniform (com.jme3.shader.Uniform)3 CartoonSSAO (com.jme3.post.CartoonSSAO)2 Filter (com.jme3.post.Filter)2 FilterPostProcessor (com.jme3.post.FilterPostProcessor)2 HDRRenderer (com.jme3.post.HDRRenderer)2 FogFilter (com.jme3.post.filters.FogFilter)2 TranslucentBucketFilter (com.jme3.post.filters.TranslucentBucketFilter)2 SSAOFilter (com.jme3.post.ssao.SSAOFilter)2 Caps (com.jme3.renderer.Caps)2 RenderManager (com.jme3.renderer.RenderManager)2 LwjglGL (com.jme3.renderer.lwjgl.LwjglGL)2