Search in sources :

Example 16 with Shader

use of com.jme3.shader.Shader in project jmonkeyengine by jMonkeyEngine.

the class TechniqueDef method setShaderFile.

/**
     * Sets the shaders that this technique definition will use.
     *
     * @param shaderNames EnumMap containing all shader names for this stage
     * @param shaderLanguages EnumMap containing all shader languages for this stage
     */
public void setShaderFile(EnumMap<Shader.ShaderType, String> shaderNames, EnumMap<Shader.ShaderType, String> shaderLanguages) {
    requiredCaps.clear();
    weight = 0;
    for (Shader.ShaderType shaderType : shaderNames.keySet()) {
        String language = shaderLanguages.get(shaderType);
        String shaderFile = shaderNames.get(shaderType);
        this.shaderLanguages.put(shaderType, language);
        this.shaderNames.put(shaderType, shaderFile);
        Caps cap = Caps.valueOf(language);
        requiredCaps.add(cap);
        weight = Math.max(weight, cap.ordinal());
        if (shaderType.equals(Shader.ShaderType.Geometry)) {
            requiredCaps.add(Caps.GeometryShader);
        } else if (shaderType.equals(Shader.ShaderType.TessellationControl)) {
            requiredCaps.add(Caps.TesselationShader);
        }
    }
}
Also used : ShaderType(com.jme3.shader.Shader.ShaderType) Caps(com.jme3.renderer.Caps)

Example 17 with Shader

use of com.jme3.shader.Shader in project jmonkeyengine by jMonkeyEngine.

the class TechniqueDef method setShaderFile.

/**
     * Sets the shaders that this technique definition will use.
     *
     * @param vertexShader The name of the vertex shader
     * @param fragmentShader The name of the fragment shader
     * @param vertLanguage The vertex shader language
     * @param fragLanguage The fragment shader language
     */
public void setShaderFile(String vertexShader, String fragmentShader, String vertLanguage, String fragLanguage) {
    this.shaderLanguages.put(Shader.ShaderType.Vertex, vertLanguage);
    this.shaderNames.put(Shader.ShaderType.Vertex, vertexShader);
    this.shaderLanguages.put(Shader.ShaderType.Fragment, fragLanguage);
    this.shaderNames.put(Shader.ShaderType.Fragment, fragmentShader);
    requiredCaps.clear();
    Caps vertCap = Caps.valueOf(vertLanguage);
    requiredCaps.add(vertCap);
    Caps fragCap = Caps.valueOf(fragLanguage);
    requiredCaps.add(fragCap);
    weight = Math.max(vertCap.ordinal(), fragCap.ordinal());
}
Also used : Caps(com.jme3.renderer.Caps)

Example 18 with Shader

use of com.jme3.shader.Shader 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)

Example 19 with Shader

use of com.jme3.shader.Shader in project jmonkeyengine by jMonkeyEngine.

the class GLRenderer method setVertexAttrib.

public void setVertexAttrib(VertexBuffer vb, VertexBuffer idb) {
    if (vb.getBufferType() == VertexBuffer.Type.Index) {
        throw new IllegalArgumentException("Index buffers not allowed to be set to vertex attrib");
    }
    if (context.boundShaderProgram <= 0) {
        throw new IllegalStateException("Cannot render mesh without shader bound");
    }
    Attribute attrib = context.boundShader.getAttribute(vb.getBufferType());
    int loc = attrib.getLocation();
    if (loc == -1) {
        // not defined
        return;
    }
    if (loc == -2) {
        loc = gl.glGetAttribLocation(context.boundShaderProgram, "in" + vb.getBufferType().name());
        // the internal name of the enum (Position).
        if (loc < 0) {
            attrib.setLocation(-1);
            // not available in shader.
            return;
        } else {
            attrib.setLocation(loc);
        }
    }
    if (vb.isInstanced()) {
        if (!caps.contains(Caps.MeshInstancing)) {
            throw new RendererException("Instancing is required, " + "but not supported by the " + "graphics hardware");
        }
    }
    int slotsRequired = 1;
    if (vb.getNumComponents() > 4) {
        if (vb.getNumComponents() % 4 != 0) {
            throw new RendererException("Number of components in multi-slot " + "buffers must be divisible by 4");
        }
        slotsRequired = vb.getNumComponents() / 4;
    }
    if (vb.isUpdateNeeded() && idb == null) {
        updateBufferData(vb);
    }
    VertexBuffer[] attribs = context.boundAttribs;
    for (int i = 0; i < slotsRequired; i++) {
        if (!context.attribIndexList.moveToNew(loc + i)) {
            gl.glEnableVertexAttribArray(loc + i);
        }
    }
    if (attribs[loc] != vb) {
        // NOTE: Use id from interleaved buffer if specified
        int bufId = idb != null ? idb.getId() : vb.getId();
        assert bufId != -1;
        if (context.boundArrayVBO != bufId) {
            gl.glBindBuffer(GL.GL_ARRAY_BUFFER, bufId);
            context.boundArrayVBO = bufId;
        //statistics.onVertexBufferUse(vb, true);
        } else {
        //statistics.onVertexBufferUse(vb, false);
        }
        if (slotsRequired == 1) {
            gl.glVertexAttribPointer(loc, vb.getNumComponents(), convertFormat(vb.getFormat()), vb.isNormalized(), vb.getStride(), vb.getOffset());
        } else {
            for (int i = 0; i < slotsRequired; i++) {
                // The pointer maps the next 4 floats in the slot.
                // E.g.
                // P1: XXXX____________XXXX____________
                // P2: ____XXXX____________XXXX________
                // P3: ________XXXX____________XXXX____
                // P4: ____________XXXX____________XXXX
                // stride = 4 bytes in float * 4 floats in slot * num slots
                // offset = 4 bytes in float * 4 floats in slot * slot index
                gl.glVertexAttribPointer(loc + i, 4, convertFormat(vb.getFormat()), vb.isNormalized(), 4 * 4 * slotsRequired, 4 * 4 * i);
            }
        }
        for (int i = 0; i < slotsRequired; i++) {
            int slot = loc + i;
            if (vb.isInstanced() && (attribs[slot] == null || !attribs[slot].isInstanced())) {
                // non-instanced -> instanced
                glext.glVertexAttribDivisorARB(slot, vb.getInstanceSpan());
            } else if (!vb.isInstanced() && attribs[slot] != null && attribs[slot].isInstanced()) {
                // instanced -> non-instanced
                glext.glVertexAttribDivisorARB(slot, 0);
            }
            attribs[slot] = vb;
        }
    }
}
Also used : Attribute(com.jme3.shader.Attribute) VertexBuffer(com.jme3.scene.VertexBuffer)

Example 20 with Shader

use of com.jme3.shader.Shader in project jmonkeyengine by jMonkeyEngine.

the class OpaqueComparator method compare.

@Override
public int compare(Geometry o1, Geometry o2) {
    Material m1 = o1.getMaterial();
    Material m2 = o2.getMaterial();
    int compareResult = Integer.compare(m1.getSortId(), m2.getSortId());
    if (compareResult == 0) {
        // use the same shader.
        // sort front-to-back then.
        float d1 = distanceToCam(o1);
        float d2 = distanceToCam(o2);
        if (d1 == d2)
            return 0;
        else if (d1 < d2)
            return -1;
        else
            return 1;
    } else {
        return compareResult;
    }
}
Also used : Material(com.jme3.material.Material)

Aggregations

Uniform (com.jme3.shader.Uniform)8 Renderer (com.jme3.renderer.Renderer)6 Caps (com.jme3.renderer.Caps)5 DirectionalLight (com.jme3.light.DirectionalLight)4 PointLight (com.jme3.light.PointLight)4 SpotLight (com.jme3.light.SpotLight)4 Material (com.jme3.material.Material)4 Vector3f (com.jme3.math.Vector3f)4 Shader (com.jme3.shader.Shader)4 IOException (java.io.IOException)4 ShaderNodeDefinitionKey (com.jme3.asset.ShaderNodeDefinitionKey)3 Light (com.jme3.light.Light)3 ColorRGBA (com.jme3.math.ColorRGBA)3 ShaderType (com.jme3.shader.Shader.ShaderType)3 VarType (com.jme3.shader.VarType)3 TempVars (com.jme3.util.TempVars)3 Statement (com.jme3.util.blockparser.Statement)3 AssetLoadException (com.jme3.asset.AssetLoadException)2 AssetNotFoundException (com.jme3.asset.AssetNotFoundException)2 MatParam (com.jme3.material.MatParam)2