Search in sources :

Example 46 with RenderManager

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

the class Technique method makeCurrent.

/**
     * Called by the material to determine which shader to use for rendering.
     * 
     * The {@link TechniqueDefLogic} is used to determine the shader to use
     * based on the {@link LightMode}.
     * 
     * @param renderManager The render manager for which the shader is to be selected.
     * @param rendererCaps The renderer capabilities which the shader should support.
     * @return A compatible shader.
     */
Shader makeCurrent(RenderManager renderManager, SafeArrayList<MatParamOverride> worldOverrides, SafeArrayList<MatParamOverride> forcedOverrides, LightList lights, EnumSet<Caps> rendererCaps) {
    TechniqueDefLogic logic = def.getLogic();
    AssetManager assetManager = owner.getMaterialDef().getAssetManager();
    dynamicDefines.clear();
    dynamicDefines.setAll(paramDefines);
    if (worldOverrides != null) {
        applyOverrides(dynamicDefines, worldOverrides);
    }
    if (forcedOverrides != null) {
        applyOverrides(dynamicDefines, forcedOverrides);
    }
    return logic.makeCurrent(assetManager, renderManager, rendererCaps, lights, dynamicDefines);
}
Also used : AssetManager(com.jme3.asset.AssetManager) TechniqueDefLogic(com.jme3.material.logic.TechniqueDefLogic)

Example 47 with RenderManager

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

the class Technique method render.

/**
     * Render the technique according to its {@link TechniqueDefLogic}.
     * 
     * @param renderManager The render manager to perform the rendering against.
     * @param shader The shader that was selected in 
     * {@link #makeCurrent(com.jme3.renderer.RenderManager, java.util.EnumSet)}.
     * @param geometry The geometry to render
     * @param lights Lights which influence the geometry.
     */
void render(RenderManager renderManager, Shader shader, Geometry geometry, LightList lights, int lastTexUnit) {
    TechniqueDefLogic logic = def.getLogic();
    logic.render(renderManager, shader, geometry, lights, lastTexUnit);
}
Also used : TechniqueDefLogic(com.jme3.material.logic.TechniqueDefLogic)

Example 48 with RenderManager

use of com.jme3.renderer.RenderManager 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)

Example 49 with RenderManager

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

the class TranslucentBucketFilter method makeSoftParticleEmitter.

private void makeSoftParticleEmitter(Spatial scene, boolean enabled) {
    if (scene instanceof Node) {
        Node n = (Node) scene;
        for (Spatial child : n.getChildren()) {
            makeSoftParticleEmitter(child, enabled);
        }
    }
    if (scene instanceof ParticleEmitter) {
        ParticleEmitter emitter = (ParticleEmitter) scene;
        if (enabled) {
            enabledSoftParticles = enabled;
            emitter.getMaterial().selectTechnique("SoftParticles", renderManager);
            if (processor.getNumSamples() > 1) {
                emitter.getMaterial().setInt("NumSamplesDepth", processor.getNumSamples());
            }
            emitter.getMaterial().setTexture("DepthTexture", processor.getDepthTexture());
            emitter.setQueueBucket(RenderQueue.Bucket.Translucent);
            logger.log(Level.FINE, "Made particle Emitter {0} soft.", emitter.getName());
        } else {
            emitter.getMaterial().clearParam("DepthTexture");
            emitter.getMaterial().selectTechnique("Default", renderManager);
            // emitter.setQueueBucket(RenderQueue.Bucket.Transparent);
            logger.log(Level.FINE, "Particle Emitter {0} is not soft anymore.", emitter.getName());
        }
    }
}
Also used : ParticleEmitter(com.jme3.effect.ParticleEmitter) Spatial(com.jme3.scene.Spatial) Node(com.jme3.scene.Node)

Example 50 with RenderManager

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

the class SSAOFilter method initFilter.

@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("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);
}
Also used : Pass(com.jme3.post.Filter.Pass) Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture)

Aggregations

Material (com.jme3.material.Material)25 Camera (com.jme3.renderer.Camera)15 Renderer (com.jme3.renderer.Renderer)11 Vector3f (com.jme3.math.Vector3f)8 Texture2D (com.jme3.texture.Texture2D)5 DirectionalLight (com.jme3.light.DirectionalLight)4 Geometry (com.jme3.scene.Geometry)4 Picture (com.jme3.ui.Picture)4 TempVars (com.jme3.util.TempVars)4 Light (com.jme3.light.Light)3 PointLight (com.jme3.light.PointLight)3 SpotLight (com.jme3.light.SpotLight)3 Pass (com.jme3.post.Filter.Pass)3 RenderManager (com.jme3.renderer.RenderManager)3 Spatial (com.jme3.scene.Spatial)3 Shader (com.jme3.shader.Shader)3 FrameBuffer (com.jme3.texture.FrameBuffer)3 Texture (com.jme3.texture.Texture)3 Test (org.junit.Test)3 Technique (com.jme3.material.Technique)2