Search in sources :

Example 1 with Pass

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

the class Material method setTexture.

/**
     * Pass a texture to the material shader.
     *
     * @param name the name of the texture defined in the material definition
     * (j3md) (for example Texture for Lighting.j3md)
     * @param value the Texture object previously loaded by the asset manager
     */
public void setTexture(String name, Texture value) {
    if (value == null) {
        // clear it
        clearParam(name);
        return;
    }
    VarType paramType = null;
    switch(value.getType()) {
        case TwoDimensional:
            paramType = VarType.Texture2D;
            break;
        case TwoDimensionalArray:
            paramType = VarType.TextureArray;
            break;
        case ThreeDimensional:
            paramType = VarType.Texture3D;
            break;
        case CubeMap:
            paramType = VarType.TextureCubeMap;
            break;
        default:
            throw new UnsupportedOperationException("Unknown texture type: " + value.getType());
    }
    setTextureParam(name, paramType, value);
}
Also used : VarType(com.jme3.shader.VarType)

Example 2 with Pass

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

the class WaterFilter method initFilter.

@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
    if (reflectionScene == null) {
        reflectionScene = vp.getScenes().get(0);
        DirectionalLight l = findLight((Node) reflectionScene);
        if (l != null) {
            lightDirection = l.getDirection();
        }
    }
    this.renderManager = renderManager;
    this.viewPort = vp;
    reflectionPass = new Pass();
    reflectionPass.init(renderManager.getRenderer(), reflectionMapSize, reflectionMapSize, Format.RGBA8, Format.Depth);
    reflectionCam = new Camera(reflectionMapSize, reflectionMapSize);
    reflectionView = new ViewPort("reflectionView", reflectionCam);
    reflectionView.setClearFlags(true, true, true);
    reflectionView.attachScene(reflectionScene);
    reflectionView.setOutputFrameBuffer(reflectionPass.getRenderFrameBuffer());
    plane = new Plane(Vector3f.UNIT_Y, new Vector3f(0, waterHeight, 0).dot(Vector3f.UNIT_Y));
    reflectionProcessor = new ReflectionProcessor(reflectionCam, reflectionPass.getRenderFrameBuffer(), plane);
    reflectionProcessor.setReflectionClipPlane(plane);
    reflectionView.addProcessor(reflectionProcessor);
    normalTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/water_normalmap.dds");
    if (foamTexture == null) {
        foamTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/foam.jpg");
    }
    if (causticsTexture == null) {
        causticsTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/caustics.jpg");
    }
    heightTexture = (Texture2D) manager.loadTexture("Common/MatDefs/Water/Textures/heightmap.jpg");
    normalTexture.setWrap(WrapMode.Repeat);
    foamTexture.setWrap(WrapMode.Repeat);
    causticsTexture.setWrap(WrapMode.Repeat);
    heightTexture.setWrap(WrapMode.Repeat);
    material = new Material(manager, "Common/MatDefs/Water/Water.j3md");
    material.setTexture("HeightMap", heightTexture);
    material.setTexture("CausticsMap", causticsTexture);
    material.setTexture("FoamMap", foamTexture);
    material.setTexture("NormalMap", normalTexture);
    material.setTexture("ReflectionMap", reflectionPass.getRenderedTexture());
    material.setFloat("WaterTransparency", waterTransparency);
    material.setFloat("NormalScale", normalScale);
    material.setFloat("R0", refractionConstant);
    material.setFloat("MaxAmplitude", maxAmplitude);
    material.setVector3("LightDir", lightDirection);
    material.setColor("LightColor", lightColor);
    material.setFloat("ShoreHardness", shoreHardness);
    material.setFloat("RefractionStrength", refractionStrength);
    material.setFloat("WaveScale", waveScale);
    material.setVector3("FoamExistence", foamExistence);
    material.setFloat("SunScale", sunScale);
    material.setVector3("ColorExtinction", colorExtinction);
    material.setFloat("Shininess", shininess);
    material.setColor("WaterColor", waterColor);
    material.setColor("DeepWaterColor", deepWaterColor);
    material.setVector2("WindDirection", windDirection);
    material.setFloat("FoamHardness", foamHardness);
    material.setBoolean("UseRipples", useRipples);
    material.setBoolean("UseHQShoreline", useHQShoreline);
    material.setBoolean("UseSpecular", useSpecular);
    material.setBoolean("UseFoam", useFoam);
    material.setBoolean("UseCaustics", useCaustics);
    material.setBoolean("UseRefraction", useRefraction);
    material.setFloat("ReflectionDisplace", reflectionDisplace);
    material.setFloat("FoamIntensity", foamIntensity);
    material.setFloat("UnderWaterFogDistance", underWaterFogDistance);
    material.setFloat("CausticsIntensity", causticsIntensity);
    if (center != null) {
        material.setVector3("Center", center);
        material.setFloat("Radius", radius * radius);
        material.setBoolean("SquareArea", shapeType == AreaShape.Square);
    }
    material.setFloat("WaterHeight", waterHeight);
}
Also used : Pass(com.jme3.post.Filter.Pass) DirectionalLight(com.jme3.light.DirectionalLight) ViewPort(com.jme3.renderer.ViewPort) Material(com.jme3.material.Material) Camera(com.jme3.renderer.Camera)

Example 3 with Pass

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

the class DefaultClient method dispatch.

protected void dispatch(Message m) {
    if (log.isLoggable(Level.FINER)) {
        log.log(Level.FINER, "{0} received:{1}", new Object[] { this, m });
    }
    // interested in and then pass on the rest.
    if (m instanceof ClientRegistrationMessage) {
        ClientRegistrationMessage crm = (ClientRegistrationMessage) m;
        // See if it has a real ID
        if (crm.getId() >= 0) {
            // Then we've gotten our real id
            this.id = (int) crm.getId();
            log.log(Level.FINE, "Connection established, id:{0}.", this.id);
            connecting.countDown();
        //fireConnected();
        } else {
            // Else it's a message letting us know that the 
            // hosted services have been started
            startServices();
            // Delay firing 'connected' until the services have all
            // been started to avoid odd race conditions.  If there is some
            // need to get some kind of event before the services have been
            // started then we should create a new event step.               
            fireConnected();
        }
        return;
    } else if (m instanceof ChannelInfoMessage) {
        // This is an interum step in the connection process and
        // now we need to add a bunch of connections
        configureChannels(((ChannelInfoMessage) m).getId(), ((ChannelInfoMessage) m).getPorts());
        return;
    } else if (m instanceof DisconnectMessage) {
        // Can't do too much else yet
        String reason = ((DisconnectMessage) m).getReason();
        log.log(Level.SEVERE, "Connection terminated, reason:{0}.", reason);
        DisconnectInfo info = new DisconnectInfo();
        info.reason = reason;
        closeConnections(info);
    }
    // thread simultaneously.
    synchronized (this) {
        messageListeners.messageReceived(this, m);
    }
}
Also used : DisconnectMessage(com.jme3.network.message.DisconnectMessage) ChannelInfoMessage(com.jme3.network.message.ChannelInfoMessage) DisconnectInfo(com.jme3.network.ClientStateListener.DisconnectInfo) ClientRegistrationMessage(com.jme3.network.message.ClientRegistrationMessage)

Example 4 with Pass

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

the class DefaultServer method registerClient.

protected void registerClient(KernelAdapter ka, Endpoint p, ClientRegistrationMessage m) {
    Connection addedConnection = null;
    // important enough I won't take chances
    synchronized (this) {
        // Grab the random ID that the client created when creating
        // its two registration messages
        long tempId = m.getId();
        // See if we already have one
        Connection c = connecting.remove(tempId);
        if (c == null) {
            c = new Connection(channels.size());
            log.log(Level.FINE, "Registering client for endpoint, pass 1:{0}.", p);
        } else {
            log.log(Level.FINE, "Refining client registration for endpoint:{0}.", p);
        }
        // Fill in what we now know
        int channel = getChannel(ka);
        c.setChannel(channel, p);
        log.log(Level.FINE, "Setting up channel:{0}", channel);
        // and we will send the connection information
        if (channel == CH_RELIABLE) {
            // over the reliable connection at this point.
            if (!getGameName().equals(m.getGameName()) || getVersion() != m.getVersion()) {
                log.log(Level.FINE, "Kicking client due to name/version mismatch:{0}.", c);
                // Need to kick them off... I may regret doing this from within
                // the sync block but the alternative is more code
                c.close("Server client mismatch, server:" + getGameName() + " v" + getVersion() + "  client:" + m.getGameName() + " v" + m.getVersion());
                return;
            }
            // Else send the extra channel information to the client
            if (!alternatePorts.isEmpty()) {
                ChannelInfoMessage cim = new ChannelInfoMessage(m.getId(), alternatePorts);
                c.send(cim);
            }
        }
        if (c.isComplete()) {
            // Then we are fully connected
            if (connections.put(c.getId(), c) == null) {
                for (Endpoint cp : c.channels) {
                    if (cp == null)
                        continue;
                    endpointConnections.put(cp, c);
                }
                addedConnection = c;
            }
        } else {
            // Need to keep getting channels so we'll keep it in
            // the map
            connecting.put(tempId, c);
        }
    }
    // over synchronizing which is the path to deadlocks
    if (addedConnection != null) {
        log.log(Level.FINE, "Client registered:{0}.", addedConnection);
        // Send the ID back to the client letting it know it's
        // fully connected.
        m = new ClientRegistrationMessage();
        m.setId(addedConnection.getId());
        m.setReliable(true);
        addedConnection.send(m);
        // Now we can notify the listeners about the
        // new connection.
        fireConnectionAdded(addedConnection);
        // Send a second registration message with an invalid ID
        // to let the connection know that it can start its services
        m = new ClientRegistrationMessage();
        m.setId(-1);
        m.setReliable(true);
        addedConnection.send(m);
    }
}
Also used : Endpoint(com.jme3.network.kernel.Endpoint) ChannelInfoMessage(com.jme3.network.message.ChannelInfoMessage) Endpoint(com.jme3.network.kernel.Endpoint) ClientRegistrationMessage(com.jme3.network.message.ClientRegistrationMessage)

Example 5 with Pass

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

the class VertexBuffer method clone.

/**
     * Creates a deep clone of the {@link VertexBuffer}.
     * 
     * @return Deep clone of this buffer
     */
@Override
public VertexBuffer clone() {
    // NOTE: Superclass GLObject automatically creates shallow clone
    // e.g re-use ID.
    VertexBuffer vb = (VertexBuffer) super.clone();
    vb.handleRef = new Object();
    vb.id = -1;
    if (data != null) {
        // Make sure to pass a read-only buffer to clone so that
        // the position information doesn't get clobbered by another
        // reading thread during cloning (and vice versa) since this is
        // a purely read-only operation.
        vb.updateData(BufferUtils.clone(getDataReadOnly()));
    }
    return vb;
}
Also used : NativeObject(com.jme3.util.NativeObject)

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