Package com.ardor3d.renderer.state

Examples of com.ardor3d.renderer.state.TextureState


        return box;
    }

    private void setupStates(final Mesh mesh, final String textureName1, final String textureName2, final WrapMode mode) {
        // Add a texture to the mesh.
        final TextureState ts = new TextureState();

        final Texture texture1 = TextureManager.load(textureName1, Texture.MinificationFilter.Trilinear, true);
        texture1.setWrap(mode);
        texture1.setBorderColor(ColorRGBA.RED);
        ts.setTexture(texture1, 0);

        if (textureName2 != null) {
            final Texture texture2 = TextureManager.load(textureName2, Texture.MinificationFilter.Trilinear, true);
            texture2.setApply(ApplyMode.Modulate);
            texture2.setWrap(mode);
            texture2.setBorderColor(ColorRGBA.RED);
            ts.setTexture(texture2, 1);

            mesh.getMeshData().copyTextureCoordinates(0, 1, 1);
        }

        mesh.setRenderState(ts);
View Full Code Here


        blend.setBlendEnabled(true);
        blend.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
        blend.setDestinationFunction(BlendState.DestinationFunction.One);
        explosion.setRenderState(blend);

        final TextureState ts = new TextureState();
        ts.setTexture(TextureManager.load("images/flaresmall.jpg", Texture.MinificationFilter.Trilinear,
                TextureStoreFormat.GuessCompressedFormat, true));
        ts.getTexture().setWrap(WrapMode.BorderClamp);
        ts.setEnabled(true);
        explosion.setRenderState(ts);

        final ZBufferState zstate = new ZBufferState();
        zstate.setWritable(false);
        explosion.setRenderState(zstate);
View Full Code Here

    protected void initExample() {
        _canvas.setTitle("TestExportImport");

        final Texture bg = TextureManager.load("images/ardor3d_white_256.jpg", Texture.MinificationFilter.Trilinear,
                true);
        final TextureState bgts = new TextureState();
        bgts.setTexture(bg);
        bgts.setEnabled(true);

        final TextureState ts = new TextureState();
        final Texture t0 = TextureManager.load("images/ardor3d_white_256.jpg", Texture.MinificationFilter.Trilinear,
                true);
        final Texture t1 = TextureManager.load("images/flaresmall.jpg", Texture.MinificationFilter.Trilinear, true);
        t1.setEnvironmentalMapMode(Texture.EnvironmentalMapMode.SphereMap);
        ts.setTexture(t0, 0);
        ts.setTexture(t1, 1);
        ts.setEnabled(true);

        final Torus torus = new Torus("Torus", 50, 50, 10, 25);
        torus.updateModelBound();
        torus.setRenderState(ts);
View Full Code Here

     */
    private Texture populateTextureState(final Mesh mesh, final Element daeTexture, final Element effect,
            final HashMap<String, Texture> loadedTextures, final MaterialInfo info, String textureSlot) {
        // TODO: Use vert data to determine which texcoords and set to use.
        // final String uvName = daeTexture.getAttributeValue("texcoord");
        TextureState tState = (TextureState) mesh.getLocalRenderState(RenderState.StateType.Texture);
        if (tState == null) {
            tState = new TextureState();
            mesh.setRenderState(tState);
        }

        // Use texture attrib to find correct sampler
        final String textureReference = daeTexture.getAttributeValue("texture");
        if (textureSlot == null) {
            // if we have no texture slot defined (like in the case of an "extra" texture), we'll use the
            // textureReference.
            textureSlot = textureReference;
        }

        /* only add the texture to the state once */
        if (loadedTextures.containsKey(textureReference)) {
            final Texture tex = loadedTextures.get(textureReference);
            if (info != null) {
                info.setTextureSlot(textureSlot, textureReference, tex, null);
            }
            return tex;
        }

        Element node = _colladaDOMUtil.findTargetWithSid(textureReference);
        if (node == null) {
            // Not sure if this is quite right, but spec seems to indicate looking for global id
            node = _colladaDOMUtil.findTargetWithId("#" + textureReference);
        }

        if ("newparam".equals(node.getName())) {
            node = node.getChildren().get(0);
        }

        Element sampler = null;
        Element surface = null;
        Element image = null;

        Texture.MinificationFilter min = Texture.MinificationFilter.BilinearNoMipMaps;
        if ("sampler2D".equals(node.getName())) {
            sampler = node;
            if (sampler.getChild("minfilter") != null) {
                final String minfilter = sampler.getChild("minfilter").getText();
                min = Enum.valueOf(SamplerTypes.MinFilterType.class, minfilter).getArdor3dFilter();
            }
            // Use sampler to get correct surface
            node = _colladaDOMUtil.findTargetWithSid(sampler.getChild("source").getText());
            // node = resolveSid(effect, sampler.getSource());
        }

        if ("newparam".equals(node.getName())) {
            node = node.getChildren().get(0);
        }

        if ("surface".equals(node.getName())) {
            surface = node;
            // image(s) will come from surface.
        } else if ("image".equals(node.getName())) {
            image = node;
        }

        // Ok, a few possibilities here...
        Texture texture = null;
        String fileName = null;
        if (surface == null && image != null) {
            // Only an image found (no sampler). Assume 2d texture. Load.
            fileName = image.getChild("init_from").getText();
            texture = loadTexture2D(fileName, min);
        } else if (surface != null) {
            // We have a surface, pull images from that.
            if ("2D".equals(surface.getAttributeValue("type"))) {
                // look for an init_from with lowest mip and use that. (usually 0)

                // TODO: mip?
                final Element lowest = surface.getChildren("init_from").get(0);
                // Element lowest = null;
                // for (final Element i : (List<Element>) surface.getChildren("init_from")) {
                // if (lowest == null || lowest.getMip() > i.getMip()) {
                // lowest = i;
                // }
                // }

                if (lowest == null) {
                    logger.warning("surface given with no usable init_from: " + surface);
                    return null;
                }

                image = _colladaDOMUtil.findTargetWithId("#" + lowest.getText());
                // image = (DaeImage) root.resolveUrl("#" + lowest.getValue());
                if (image != null) {
                    fileName = image.getChild("init_from").getText();
                    texture = loadTexture2D(fileName, min);
                }

                // TODO: add support for mip map levels other than 0.
            }
            // TODO: add support for the other texture types.
        } else {
            // No surface OR image... warn.
            logger.warning("texture given with no matching <sampler*> or <image> found.");
            if (info != null) {
                info.setTextureSlot(textureSlot, textureReference, null, null);
            }
            return null;
        }

        if (texture != null) {
            if (sampler != null) {
                // Apply params from our sampler.
                applySampler(sampler, texture);
            }

            // Add to texture state.
            tState.setTexture(texture, tState.getNumberOfSetTextures());
            loadedTextures.put(textureReference, texture);
            if (info != null) {
                info.setTextureSlot(textureSlot, textureReference, texture, fileName);
            }
        } else {
View Full Code Here

            tRenderer.setMultipleTargets(true);
            tRenderer.setBackgroundColor(new ColorRGBA(0.0f, 0.0f, 0.0f, 1.0f));
            tRenderer.getCamera().setFrustum(cam.getFrustumNear(), cam.getFrustumFar(), cam.getFrustumLeft(),
                    cam.getFrustumRight(), cam.getFrustumTop(), cam.getFrustumBottom());

            textureState = new TextureState();
            textureState.setEnabled(true);

            setupTextures();

            fullScreenQuad = new Quad("FullScreenQuad", cam.getWidth() / 4, cam.getHeight() / 4);
            fullScreenQuad.setTranslation(cam.getWidth() / 2, cam.getHeight() / 2, 0);
            fullScreenQuad.getSceneHints().setRenderBucketType(RenderBucketType.Ortho);
            fullScreenQuad.getSceneHints().setCullHint(CullHint.Never);
            fullScreenQuad.getSceneHints().setTextureCombineMode(TextureCombineMode.Replace);
            fullScreenQuad.getSceneHints().setLightCombineMode(LightCombineMode.Off);
            final TextureState ts = new TextureState();
            ts.setTexture(textureReflect);
            fullScreenQuad.setRenderState(ts);
            fullScreenQuad.setRenderState(blurShaderVertical);
            fullScreenQuad.updateWorldRenderStates(false);
        }
View Full Code Here

    /**
     * Create setup to use as fallback if fancy water is not supported.
     */
    private void createFallbackData() {
        fallbackTextureState = new TextureState();
        fallbackTextureState.setEnabled(true);

        fallbackTexture = TextureManager.load(fallbackMapTextureString, Texture.MinificationFilter.Trilinear,
                TextureStoreFormat.GuessCompressedFormat, true);
        fallbackTextureState.setTexture(fallbackTexture, 0);
View Full Code Here

            tRenderer.getCamera().setDirection(cam.getDirection());
            tRenderer.getCamera().setUp(cam.getUp());
            tRenderer.getCamera().setLeft(cam.getLeft());

            blend.setEnabled(false);
            final TextureState ts = (TextureState) fullScreenQuad.getWorldRenderState(RenderState.StateType.Texture);

            // see if we should use the current scene to bloom, or only things added to the pass.
            if (useCurrentScene) {
                // grab backbuffer to texture
                if (screenTexture == null) {
                    final DisplaySettings settings = new DisplaySettings(cam.getWidth(), cam.getHeight(), 24, 0, 0, 8,
                            0, 0, false, false);
                    fullTRenderer = TextureRendererFactory.INSTANCE.createTextureRenderer(settings, false, r,
                            ContextManager.getCurrentContext().getCapabilities());
                    screenTexture = new Texture2D();
                    screenTexture.setWrap(Texture.WrapMode.Clamp);
                    screenTexture.setMagnificationFilter(Texture.MagnificationFilter.Bilinear);
                    fullTRenderer.setupTexture(screenTexture);
                }
                fullTRenderer.copyToTexture(screenTexture, 0, 0, cam.getWidth(), cam.getHeight(), 0, 0);
                ts.setTexture(screenTexture, 0);
            } else {
                // Render scene to texture
                tRenderer.render(_spatials, mainTexture, Renderer.BUFFER_COLOR_AND_DEPTH);
                ts.setTexture(mainTexture, 0);
            }

            // Extract intensity
            extractionShader.setUniform("exposurePow", getExposurePow());
            extractionShader.setUniform("exposureCutoff", getExposureCutoff());

            fullScreenQuad.setRenderState(extractionShader);
            fullScreenQuad.updateWorldRenderStates(false);
            // fullScreenQuad.states[RenderState.StateType.GLSLShaderObjects.ordinal()] = extractionShader;
            tRenderer.render(fullScreenQuad, secondTexture, Renderer.BUFFER_NONE);

            if (!useSeparateConvolution) {
                blurShader.setUniform("sampleDist", getBlurSize());
                blurShader.setUniform("blurIntensityMultiplier", getBlurIntensityMultiplier());

                ts.setTexture(secondTexture, 0);
                fullScreenQuad.setRenderState(blurShader);
                fullScreenQuad.updateWorldRenderStates(false);
                // fullScreenQuad.states[RenderState.StateType.GLSLShaderObjects.ordinal()] = blurShader;
                tRenderer.render(fullScreenQuad, mainTexture, Renderer.BUFFER_NONE);

                // Extra blur passes
                for (int i = 1; i < getNrBlurPasses(); i++) {
                    blurShader.setUniform("sampleDist", getBlurSize() - i * getBlurSize() / getNrBlurPasses());
                    if (i % 2 == 1) {
                        ts.setTexture(mainTexture, 0);
                        tRenderer.render(fullScreenQuad, secondTexture, Renderer.BUFFER_NONE);
                    } else {
                        ts.setTexture(secondTexture, 0);
                        tRenderer.render(fullScreenQuad, mainTexture, Renderer.BUFFER_NONE);
                    }
                }
                if (getNrBlurPasses() % 2 == 1) {
                    ts.setTexture(mainTexture, 0);
                } else {
                    ts.setTexture(secondTexture, 0);
                    tRenderer.render(fullScreenQuad, mainTexture, Renderer.BUFFER_NONE);
                    ts.setTexture(mainTexture, 0);
                }
            } else {
                blurShaderVertical.setUniform("blurIntensityMultiplier", getBlurIntensityMultiplier());

                for (int i = 0; i < getNrBlurPasses(); i++) {
                    blurShaderHorizontal
                            .setUniform("sampleDist", getBlurSize() - i * getBlurSize() / getNrBlurPasses());
                    blurShaderVertical.setUniform("sampleDist", getBlurSize() - i * getBlurSize() / getNrBlurPasses());

                    ts.setTexture(secondTexture, 0);
                    fullScreenQuad.setRenderState(blurShaderHorizontal);
                    fullScreenQuad.updateWorldRenderStates(false);
                    // fullScreenQuad.states[RenderState.StateType.GLSLShaderObjects.ordinal()] = blurShaderHorizontal;
                    tRenderer.render(fullScreenQuad, mainTexture, Renderer.BUFFER_NONE);
                    ts.setTexture(mainTexture, 0);
                    fullScreenQuad.setRenderState(blurShaderVertical);
                    fullScreenQuad.updateWorldRenderStates(false);
                    // fullScreenQuad.states[RenderState.StateType.GLSLShaderObjects.ordinal()] = blurShaderVertical;
                    tRenderer.render(fullScreenQuad, secondTexture, Renderer.BUFFER_NONE);
                }
                ts.setTexture(secondTexture, 0);
            }
        }

        // Final blend
        blend.setEnabled(true);
View Full Code Here

        fullScreenQuad.getSceneHints().setCullHint(CullHint.Never);
        fullScreenQuad.getSceneHints().setTextureCombineMode(TextureCombineMode.Replace);
        fullScreenQuad.getSceneHints().setLightCombineMode(LightCombineMode.Off);

        final TextureState ts = new TextureState();
        ts.setEnabled(true);
        fullScreenQuad.setRenderState(ts);

        final BlendState as = new BlendState();
        as.setBlendEnabled(true);
        as.setSourceFunction(BlendState.SourceFunction.One);
View Full Code Here

        setNumOfSplits(numOfSplits);
        _pssmCam = new PSSMCamera();

        _noClip = new ClipState();
        _noClip.setEnabled(false);
        _noTexture = new TextureState();
        _noTexture.setEnabled(false);
        _colorDisabled = new ColorMaskState();
        _colorDisabled.setAll(false);
        _cullFrontFace = new CullState();
        _cullFrontFace.setEnabled(true);
        _cullFrontFace.setCullFace(CullState.Face.Front);
        _noLights = new LightState();
        _noLights.setEnabled(false);

        _shadowOffsetState = new OffsetState();
        _shadowOffsetState.setEnabled(true);
        _shadowOffsetState.setTypeEnabled(OffsetType.Fill, true);
        _shadowOffsetState.setFactor(1.1f);
        _shadowOffsetState.setUnits(4.0f);

        _flat = new ShadingState();
        _flat.setShadingMode(ShadingMode.Flat);

        // When rendering and comparing the shadow map with the current depth, the result will be set to alpha 1 if in
        // shadow and to 0 if not in shadow.
        _discardShadowFragments = new BlendState();
        _discardShadowFragments.setEnabled(true);
        _discardShadowFragments.setBlendEnabled(true);
        _discardShadowFragments.setTestEnabled(true);
        _discardShadowFragments.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
        _discardShadowFragments.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);

        _shadowTextureState = new TextureState();
    }
View Full Code Here

TOP

Related Classes of com.ardor3d.renderer.state.TextureState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.