com.jme3.material.RenderState Java Examples

The following examples show how to use com.jme3.material.RenderState. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractSceneEditor3DPart.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Create collision plane.
 */
@FromAnyThread
private void createCollisionPlane() {

    final AssetManager assetManager = EditorUtil.getAssetManager();

    final Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    final RenderState renderState = material.getAdditionalRenderState();
    renderState.setFaceCullMode(RenderState.FaceCullMode.Off);
    renderState.setWireframe(true);

    final float size = 20000;

    final Geometry geometry = new Geometry("plane", new Quad(size, size));
    geometry.setMaterial(material);
    geometry.setLocalTranslation(-size / 2, -size / 2, 0);

    collisionPlane = new Node();
    collisionPlane.attachChild(geometry);
}
 
Example #2
Source File: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private int convertBlendEquationAlpha(RenderState.BlendEquationAlpha blendEquationAlpha) {
    //Note: InheritColor mode should already be handled, that is why it does not belong the switch case.
    switch (blendEquationAlpha) {
        case Add:
            return GL2.GL_FUNC_ADD;
        case Subtract:
            return GL2.GL_FUNC_SUBTRACT;
        case ReverseSubtract:
            return GL2.GL_FUNC_REVERSE_SUBTRACT;
        case Min:
            return GL2.GL_MIN;
        case Max:
            return GL2.GL_MAX;
        default:
            throw new UnsupportedOperationException("Unrecognized alpha blend operation: " + blendEquationAlpha);
    }
}
 
Example #3
Source File: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private int convertBlendEquation(RenderState.BlendEquation blendEquation) {
    switch (blendEquation) {
        case Add:
            return GL2.GL_FUNC_ADD;
        case Subtract:
            return GL2.GL_FUNC_SUBTRACT;
        case ReverseSubtract:
            return GL2.GL_FUNC_REVERSE_SUBTRACT;
        case Min:
            return GL2.GL_MIN;
        case Max:
            return GL2.GL_MAX;
        default:
            throw new UnsupportedOperationException("Unrecognized blend operation: " + blendEquation);
    }
}
 
Example #4
Source File: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void blendFuncSeparate(RenderState.BlendFunc sfactorRGB, RenderState.BlendFunc dfactorRGB,
        RenderState.BlendFunc sfactorAlpha, RenderState.BlendFunc dfactorAlpha) {
    if (sfactorRGB != context.sfactorRGB
            || dfactorRGB != context.dfactorRGB
            || sfactorAlpha != context.sfactorAlpha
            || dfactorAlpha != context.dfactorAlpha) {

        gl.glBlendFuncSeparate(
                convertBlendFunc(sfactorRGB),
                convertBlendFunc(dfactorRGB),
                convertBlendFunc(sfactorAlpha),
                convertBlendFunc(dfactorAlpha));
        context.sfactorRGB = sfactorRGB;
        context.dfactorRGB = dfactorRGB;
        context.sfactorAlpha = sfactorAlpha;
        context.dfactorAlpha = dfactorAlpha;
    }
}
 
Example #5
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void updateDisplayList(Mesh mesh) {
    if (mesh.getId() != -1) {
        // delete list first
        gl.glDeleteLists(mesh.getId(), mesh.getId());
        mesh.setId(-1);
    }

    // create new display list
    // first set state to NULL
    applyRenderState(RenderState.NULL);

    // disable lighting
    setLighting(null);

    int id = gl.glGenLists(1);
    mesh.setId(id);
    gl.glNewList(id, gl.GL_COMPILE);
    renderMeshDefault(mesh, 0, 1);
    gl.glEndList();
}
 
Example #6
Source File: TestBlendEquations.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Adds a "transparent" quad to the scene, that limits the color values of the scene behind the object.<br/>
 * This effect can be good seen on bright areas of the scene (e.g. areas with specular lighting effects).
 */
private void createRightQuad() {
    Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    material.setColor("Color", new ColorRGBA(0.4f, 0.4f, 0.4f, 1f));

    // Min( Source , Destination)
    material.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Custom);
    material.getAdditionalRenderState().setBlendEquation(RenderState.BlendEquation.Min);
    material.getAdditionalRenderState().setBlendEquationAlpha(RenderState.BlendEquationAlpha.Min);

    // In OpenGL no blend factors are used, when using the blend equations Min or Max!
    //material.getAdditionalRenderState().setCustomBlendFactors(
    //        RenderState.BlendFunc.One, RenderState.BlendFunc.One,
    //        RenderState.BlendFunc.One, RenderState.BlendFunc.One);

    rightQuad = new Geometry("RightQuad", new Quad(1f, 1f));
    rightQuad.setMaterial(material);
    rightQuad.setQueueBucket(RenderQueue.Bucket.Transparent);
    rootNode.attachChild(rightQuad);
}
 
Example #7
Source File: TestBlendEquations.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Adds a "transparent" quad to the scene, that shows an inverse blue value sight of the scene behind.
 */
private void createLeftQuad() {
    Material material = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

    // This color creates a blue value image. The effect will have a strength of 80% (set by the alpha value).
    material.setColor("Color", new ColorRGBA(0f, 0f, 1f, 0.8f));

    // Result.RGB = Source.A * Source.RGB - Source.A * Destination.RGB
    // Result.A   = Destination.A
    material.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Custom);
    material.getAdditionalRenderState().setBlendEquation(RenderState.BlendEquation.Subtract);
    material.getAdditionalRenderState().setBlendEquationAlpha(RenderState.BlendEquationAlpha.Add);
    material.getAdditionalRenderState().setCustomBlendFactors(
            RenderState.BlendFunc.Src_Alpha, RenderState.BlendFunc.Src_Alpha,
            RenderState.BlendFunc.Zero, RenderState.BlendFunc.One);

    leftQuad = new Geometry("LeftQuad", new Quad(1f, 1f));
    leftQuad.setMaterial(material);
    leftQuad.setQueueBucket(RenderQueue.Bucket.Transparent);
    rootNode.attachChild(leftQuad);
}
 
Example #8
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void updateDisplayList(Mesh mesh) {
    GL gl = GLContext.getCurrentGL();
    if (mesh.getId() != -1) {
        // delete list first
        gl.getGL2().glDeleteLists(mesh.getId(), mesh.getId());
        mesh.setId(-1);
    }

    // create new display list
    // first set state to NULL
    applyRenderState(RenderState.NULL);

    // disable lighting
    setLighting(null);

    int id = gl.getGL2().glGenLists(1);
    mesh.setId(id);
    gl.getGL2().glNewList(id, GL2.GL_COMPILE);
    renderMeshDefault(mesh, 0, 1);
    gl.getGL2().glEndList();
}
 
Example #9
Source File: RenderDeviceJme.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private RenderState.BlendMode convertBlend(BlendMode blendMode) {
    if (blendMode == null) {
        return RenderState.BlendMode.Off;
    } else
        switch (blendMode) {
            case BLEND:
                return RenderState.BlendMode.Alpha;
            case MULIPLY:
                return RenderState.BlendMode.Alpha;
            default:
                throw new UnsupportedOperationException();
    }
}
 
Example #10
Source File: JmeBatchRenderBackend.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private RenderState.BlendMode convertBlend(final BlendMode blendMode) {
    if (blendMode == null) {
        return RenderState.BlendMode.Off;
    } else {
        switch (blendMode) {
            case BLEND:
                return RenderState.BlendMode.Alpha;
            case MULIPLY:
                return RenderState.BlendMode.Alpha;
            default:
                throw new UnsupportedOperationException();
        }
    }
}
 
Example #11
Source File: TestIssue1125.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Configure materials during startup.
 */
private void configureMaterials() {
    quadMaterial = new Material(assetManager,
            "Common/MatDefs/Misc/Unshaded.j3md");
    quadMaterial.setColor("Color", ColorRGBA.Green.clone());
    RenderState ars = quadMaterial.getAdditionalRenderState();
    ars.setWireframe(true);
}
 
Example #12
Source File: JoglRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void initialize() {
    logger.log(Level.INFO, "Vendor: {0}", gl.glGetString(gl.GL_VENDOR));
    logger.log(Level.INFO, "Renderer: {0}", gl.glGetString(gl.GL_RENDERER));
    logger.log(Level.INFO, "Version: {0}", gl.glGetString(gl.GL_VERSION));

    applyRenderState(RenderState.DEFAULT);

    powerOf2 = gl.isExtensionAvailable("GL_ARB_texture_non_power_of_two");
    hardwareMips = gl.isExtensionAvailable("GL_SGIS_generate_mipmap");
    vbo = gl.isExtensionAvailable("GL_ARB_vertex_buffer_object");
}
 
Example #13
Source File: J3mdTechniqueDefWriter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void writeRenderState(RenderState rs, OutputStreamWriter out) throws IOException {
    RenderState defRs = RenderState.DEFAULT;
    if(rs.getBlendMode() != defRs.getBlendMode()) {
        writeRenderStateAttribute(out, "Blend", rs.getBlendMode().name());
    }
    if(rs.isWireframe() != defRs.isWireframe()) {
        writeRenderStateAttribute(out, "Wireframe", rs.isWireframe()?"On":"Off");
    }
    if(rs.getFaceCullMode() != defRs.getFaceCullMode()) {
        writeRenderStateAttribute(out, "FaceCull", rs.getFaceCullMode().name());
    }
    if(rs.isDepthWrite() != defRs.isDepthWrite()) {
        writeRenderStateAttribute(out, "DepthWrite", rs.isDepthWrite()?"On":"Off");
    }
    if(rs.isDepthTest() != defRs.isDepthTest()) {
        writeRenderStateAttribute(out, "DepthTest",  rs.isDepthTest()?"On":"Off");
    }
    if(rs.getBlendEquation() != defRs.getBlendEquation()) {
        writeRenderStateAttribute(out, "BlendEquation", rs.getBlendEquation().name());
    }
    if(rs.getBlendEquationAlpha() != defRs.getBlendEquationAlpha()) {
        writeRenderStateAttribute(out, "BlendEquationAlpha", rs.getBlendEquationAlpha().name());
    }
    if(rs.getPolyOffsetFactor() != defRs.getPolyOffsetFactor() || rs.getPolyOffsetUnits() != defRs.getPolyOffsetUnits()) {
        writeRenderStateAttribute(out, "PolyOffset", rs.getPolyOffsetFactor() + " " + rs.getPolyOffsetUnits());
    }
    if(rs.isColorWrite() != defRs.isColorWrite()) {
        writeRenderStateAttribute(out, "ColorWrite",  rs.isColorWrite()?"On":"Off");
    }
    if(rs.getDepthFunc() != defRs.getDepthFunc()) {
        writeRenderStateAttribute(out, "DepthFunc", rs.getDepthFunc().name());
    }
    if(rs.getLineWidth() != defRs.getLineWidth()) {
        writeRenderStateAttribute(out, "LineWidth", Float.toString(rs.getLineWidth()));
    }
}
 
Example #14
Source File: RenderDeviceJme.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void renderFont(RenderFont font, String str, int x, int y, Color color, float sizeX, float sizeY) {        
        if (str.length() == 0)
            return;

        if (font instanceof RenderFontNull)
            return;

        RenderFontJme jmeFont = (RenderFontJme) font;
        
        String key = font+str+color.getColorString();
        BitmapText text = textCacheLastFrame.get(key);
        if (text == null) {
            text = jmeFont.createText();
            text.setText(str);
            text.updateLogicalState(0);
        }
        textCacheCurrentFrame.put(key, text);

        niftyMat.setColor("Color", convertColor(color, tempColor));
        niftyMat.setBoolean("UseTex", true);
        niftyMat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
//        niftyMat.getAdditionalRenderState().setBlendMode(convertBlend());
        text.setMaterial(niftyMat);

        float width = text.getLineWidth();
        float height = text.getLineHeight();

        float x0 = x + 0.5f * width  * (1f - sizeX);
        float y0 = y + 0.5f * height * (1f - sizeY);

        tempMat.loadIdentity();
        tempMat.setTranslation(x0, getHeight() - y0, 0);
        tempMat.setScale(sizeX, sizeY, 0);

        rm.setWorldMatrix(tempMat);
        text.render(rm);
        
//        System.out.println("renderFont");
    }
 
Example #15
Source File: RenderDeviceJme.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private RenderState.BlendMode convertBlend(){
    if (blendMode == null)
        return RenderState.BlendMode.Off;
    else if (blendMode == BlendMode.BLEND)
        return RenderState.BlendMode.Alpha;
    else if (blendMode == BlendMode.MULIPLY)
        return RenderState.BlendMode.Modulate;
    else
        throw new UnsupportedOperationException();
}
 
Example #16
Source File: PreDepthProcessor.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public PreDepthProcessor(AssetManager assetManager){
    this.assetManager = assetManager;
    preDepth = new Material(assetManager, "Common/MatDefs/Shadow/PreShadow.j3md");
    preDepth.getAdditionalRenderState().setPolyOffset(0, 0);
    preDepth.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Back);

    forcedRS = new RenderState();
    forcedRS.setDepthTest(true);
    forcedRS.setDepthWrite(false);
}
 
Example #17
Source File: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void blendFunc(RenderState.BlendFunc sfactor, RenderState.BlendFunc dfactor) {
    if (sfactor != context.sfactorRGB
            || dfactor != context.dfactorRGB
            || sfactor != context.sfactorAlpha
            || dfactor != context.dfactorAlpha) {

        gl.glBlendFunc(
                convertBlendFunc(sfactor),
                convertBlendFunc(dfactor));
        context.sfactorRGB = sfactor;
        context.dfactorRGB = dfactor;
        context.sfactorAlpha = sfactor;
        context.dfactorAlpha = dfactor;
    }
}
 
Example #18
Source File: ArmatureDebugger.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void initialize(AssetManager assetManager, Camera camera) {

        armatureNode.setCamera(camera);

        Material matJoints = new Material(assetManager, "Common/MatDefs/Misc/Billboard.j3md");
        Texture t = assetManager.loadTexture("Common/Textures/dot.png");
        matJoints.setTexture("Texture", t);
        matJoints.getAdditionalRenderState().setDepthTest(false);
        matJoints.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
        joints.setQueueBucket(RenderQueue.Bucket.Translucent);
        joints.setMaterial(matJoints);

        Material matWires = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        matWires.setBoolean("VertexColor", true);
        matWires.getAdditionalRenderState().setLineWidth(1f);
        wires.setMaterial(matWires);

        Material matOutline = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        matOutline.setBoolean("VertexColor", true);
        matOutline.getAdditionalRenderState().setLineWidth(1f);
        outlines.setMaterial(matOutline);

        Material matOutline2 = new Material(assetManager, "Common/MatDefs/Misc/DashedLine.j3md");
        matOutline2.getAdditionalRenderState().setLineWidth(1);
        outlines.getChild(1).setMaterial(matOutline2);

        Material matWires2 = new Material(assetManager, "Common/MatDefs/Misc/DashedLine.j3md");
        matWires2.getAdditionalRenderState().setLineWidth(1);
        wires.getChild(1).setMaterial(matWires2);

    }
 
Example #19
Source File: PreDepthProcessor.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public PreDepthProcessor(AssetManager assetManager){
    this.assetManager = assetManager;
    preDepth = new Material(assetManager, "Common/MatDefs/Shadow/PreShadow.j3md");
    preDepth.getAdditionalRenderState().setPolyOffset(0, 0);
    preDepth.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Back);

    forcedRS = new RenderState();
    forcedRS.setDepthTest(true);
    forcedRS.setDepthWrite(false);
}
 
Example #20
Source File: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void blendEquationSeparate(RenderState.BlendEquation blendEquation, RenderState.BlendEquationAlpha blendEquationAlpha) {
    if (blendEquation != context.blendEquation || blendEquationAlpha != context.blendEquationAlpha) {
        int glBlendEquation = convertBlendEquation(blendEquation);
        int glBlendEquationAlpha = blendEquationAlpha == RenderState.BlendEquationAlpha.InheritColor
                ? glBlendEquation
                : convertBlendEquationAlpha(blendEquationAlpha);
        gl.glBlendEquationSeparate(glBlendEquation, glBlendEquationAlpha);
        context.blendEquation = blendEquation;
        context.blendEquationAlpha = blendEquationAlpha;
    }
}
 
Example #21
Source File: GLRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void changeBlendMode(RenderState.BlendMode blendMode) {
    if (blendMode != context.blendMode) {
        if (blendMode == RenderState.BlendMode.Off) {
            gl.glDisable(GL.GL_BLEND);
        } else if (context.blendMode == RenderState.BlendMode.Off) {
            gl.glEnable(GL.GL_BLEND);
        }

        context.blendMode = blendMode;
    }
}
 
Example #22
Source File: NullRenderer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void applyRenderState(RenderState state) {
}
 
Example #23
Source File: RenderContext.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Reset the RenderContext to default GL state
 */
public void reset(){
    cullMode = RenderState.FaceCullMode.Off;
    depthTestEnabled = false;
    alphaTestEnabled = false;
    depthWriteEnabled = false;
    colorWriteEnabled = false;
    clipRectEnabled = false;
    polyOffsetEnabled = false;
    polyOffsetFactor = 0;
    polyOffsetUnits = 0;
    normalizeEnabled = false;
    matrixMode = -1;
    pointSize = 1;
    blendMode = RenderState.BlendMode.Off;
    wireframe = false;
    boundShaderProgram = 0;
    boundFBO = 0;
    boundRB = 0;
    boundDrawBuf = -1; 
    boundReadBuf = -1;
    boundElementArrayVBO = 0;
    boundVertexArray = 0;
    boundArrayVBO = 0;
    numTexturesSet = 0;
    for (int i = 0; i < boundTextures.length; i++)
        boundTextures[i] = null;

    textureIndexList.reset();
    boundTextureUnit = 0;
    for (int i = 0; i < boundAttribs.length; i++)
        boundAttribs[i] = null;

    attribIndexList.reset();
    
    stencilTest = false;
    frontStencilStencilFailOperation = RenderState.StencilOperation.Keep;
    frontStencilDepthFailOperation = RenderState.StencilOperation.Keep;
    frontStencilDepthPassOperation = RenderState.StencilOperation.Keep;
    backStencilStencilFailOperation = RenderState.StencilOperation.Keep;
    backStencilDepthFailOperation = RenderState.StencilOperation.Keep;
    backStencilDepthPassOperation = RenderState.StencilOperation.Keep;
    frontStencilFunction = RenderState.TestFunction.Always;
    backStencilFunction = RenderState.TestFunction.Always;
    
    ambient = diffuse = specular = color = null;
    shininess = 0;
    useVertexColor = false;
}
 
Example #24
Source File: RenderContext.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void init() {
    cullMode = RenderState.FaceCullMode.Off;
    depthTestEnabled = false;
    depthWriteEnabled = true;
    colorWriteEnabled = true;
    clipRectEnabled = false;
    polyOffsetEnabled = false;
    polyOffsetFactor = 0;
    polyOffsetUnits = 0;
    pointSize = 1;
    lineWidth = 1;
    blendMode = RenderState.BlendMode.Off;
    blendEquation = RenderState.BlendEquation.Add;
    blendEquationAlpha = RenderState.BlendEquationAlpha.InheritColor;
    sfactorRGB = RenderState.BlendFunc.One;
    dfactorRGB = RenderState.BlendFunc.One;
    sfactorAlpha = RenderState.BlendFunc.One;
    dfactorAlpha = RenderState.BlendFunc.One;
    wireframe = false;

    boundShaderProgram = 0;
    boundShader = null;
    boundFBO = 0;
    boundFB = null;
    boundRB = 0;
    boundDrawBuf = -1;
    boundReadBuf = -1;
    boundElementArrayVBO = 0;
    boundVertexArray = 0;
    boundArrayVBO = 0;
    boundPixelPackPBO = 0;
    numTexturesSet = 0;
    boundTextureUnit = 0;
    stencilTest = false;

    frontStencilStencilFailOperation = RenderState.StencilOperation.Keep;
    frontStencilDepthFailOperation = RenderState.StencilOperation.Keep;
    frontStencilDepthPassOperation = RenderState.StencilOperation.Keep;
    backStencilStencilFailOperation = RenderState.StencilOperation.Keep;
    backStencilDepthFailOperation = RenderState.StencilOperation.Keep;
    backStencilDepthPassOperation = RenderState.StencilOperation.Keep;
    frontStencilFunction = RenderState.TestFunction.Always;
    backStencilFunction = RenderState.TestFunction.Always;

    depthFunc = RenderState.TestFunction.Less;
    alphaFunc = RenderState.TestFunction.Greater;
    cullMode = RenderState.FaceCullMode.Off;

    clearColor.set(0, 0, 0, 0);
}
 
Example #25
Source File: DetailedProfilerState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected void initialize(Application app) {
    Material mat = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", new ColorRGBA(0, 0, 0, 0.5f));
    mat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
    Geometry darkenStats = new Geometry("StatsDarken", new Quad(PANEL_WIDTH, app.getCamera().getHeight()));
    darkenStats.setMaterial(mat);
    darkenStats.setLocalTranslation(0, -app.getCamera().getHeight(), -1);

    ui.attachChild(darkenStats);
    ui.setLocalTranslation(app.getCamera().getWidth() - PANEL_WIDTH, app.getCamera().getHeight(), 0);
    font = app.getAssetManager().loadFont("Interface/Fonts/Console.fnt");
    bigFont = app.getAssetManager().loadFont("Interface/Fonts/Default.fnt");
    prof.setRenderer(app.getRenderer());
    rootLine = new StatLineView("Frame");
    rootLine.attachTo(ui);

    BitmapText frameLabel = new BitmapText(bigFont);
    frameLabel.setText("Total Frame Time: ");
    ui.attachChild(frameLabel);
    frameLabel.setLocalTranslation(new Vector3f(PANEL_WIDTH / 2 - bigFont.getLineWidth(frameLabel.getText()), -PADDING, 0));

    BitmapText cpuLabel = new BitmapText(bigFont);
    cpuLabel.setText("CPU");
    ui.attachChild(cpuLabel);
    cpuLabel.setLocalTranslation(PANEL_WIDTH / 4 - bigFont.getLineWidth(cpuLabel.getText()) / 2, -PADDING - 30, 0);

    BitmapText gpuLabel = new BitmapText(bigFont);
    gpuLabel.setText("GPU");
    ui.attachChild(gpuLabel);
    gpuLabel.setLocalTranslation(3 * PANEL_WIDTH / 4 - bigFont.getLineWidth(gpuLabel.getText()) / 2, -PADDING - 30, 0);

    frameTimeValue = new BitmapText(bigFont);
    frameCpuTimeValue = new BitmapText(bigFont);
    frameGpuTimeValue = new BitmapText(bigFont);

    selectedField = new BitmapText(font);
    selectedField.setText("Selected: ");
    selectedField.setLocalTranslation(PANEL_WIDTH / 2, -PADDING - 75, 0);
    selectedField.setColor(ColorRGBA.Yellow);


    ui.attachChild(frameTimeValue);
    ui.attachChild(frameCpuTimeValue);
    ui.attachChild(frameGpuTimeValue);
    ui.attachChild(selectedField);

    hideInsignificantField = new BitmapText(font);
    hideInsignificantField.setText("O " + INSIGNIFICANT);
    hideInsignificantField.setLocalTranslation(PADDING, -PADDING - 75, 0);
    ui.attachChild(hideInsignificantField);

    final InputManager inputManager = app.getInputManager();
    if (inputManager != null) {
        inputManager.addMapping(TOGGLE_KEY, new KeyTrigger(KeyInput.KEY_F6));
        inputManager.addMapping(CLICK_KEY, new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
        inputManager.addListener(inputListener, TOGGLE_KEY, CLICK_KEY);
    }
}
 
Example #26
Source File: AbstractShadowRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
protected void initForcedRenderState() {
    forcedRenderState.setFaceCullMode(RenderState.FaceCullMode.Front);
    forcedRenderState.setColorWrite(false);
    forcedRenderState.setDepthWrite(true);
    forcedRenderState.setDepthTest(true);
}
 
Example #27
Source File: NullRenderer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void applyRenderState(RenderState state) {
}
 
Example #28
Source File: ParticlePerformer.java    From OpenRTS with MIT License 4 votes vote down vote up
private void createEmitter(ParticleActor actor){
	ParticleEmitter emitter = new ParticleEmitter("", ParticleMesh.Type.Triangle, actor.maxCount);
	Material m = actorDrawer.getParticleMat(actor.spritePath);

	if(!actor.add) {
		m.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
	}
	emitter.setMaterial(m);
	emitter.setParticlesPerSec(actor.perSecond);
	emitter.setImagesX(actor.nbRow);
	emitter.setImagesY(actor.nbCol);

	emitter.setStartColor(TranslateUtil.toColorRGBA(actor.startColor));
	emitter.setEndColor(TranslateUtil.toColorRGBA(actor.endColor));

	emitter.setStartSize((float)actor.startSize);
	emitter.setEndSize((float)actor.endSize);
	if(actor.gravity) {
		emitter.setGravity(0, 0, 4);
	} else {
		emitter.setGravity(0, 0, 0);
	}

	emitter.setLowLife((float)actor.minLife);
	emitter.setHighLife((float)actor.maxLife);
	emitter.setRotateSpeed((float)actor.rotationSpeed);

	if(actor.startVariation != 0) {
		emitter.setShape(new EmitterSphereShape(Vector3f.ZERO, (float)actor.startVariation));
	}

	if(actor.facing == ParticleActor.Facing.Horizontal) {
		emitter.setFaceNormal(Vector3f.UNIT_Z);
	}
	if(actor.velocity != 0) {
		emitter.setFacingVelocity(true);
	}
	emitter.setQueueBucket(Bucket.Transparent);
	actorDrawer.mainNode.attachChild(emitter);
	actor.getViewElements().particleEmitter = emitter;
}
 
Example #29
Source File: AbstractSceneEditor3DPart.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
@FromAnyThread
private @NotNull Node createGrid() {

    final Node gridNode = new Node("GridNode");

    final ColorRGBA gridColor = new ColorRGBA(0.4f, 0.4f, 0.4f, 0.5f);
    final ColorRGBA xColor = new ColorRGBA(1.0f, 0.1f, 0.1f, 0.5f);
    final ColorRGBA zColor = new ColorRGBA(0.1f, 1.0f, 0.1f, 0.5f);

    final Material gridMaterial = createColorMaterial(gridColor);
    gridMaterial.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);

    final Material xMaterial = createColorMaterial(xColor);
    xMaterial.getAdditionalRenderState().setLineWidth(5);

    final Material zMaterial = createColorMaterial(zColor);
    zMaterial.getAdditionalRenderState().setLineWidth(5);

    final int gridSize = getGridSize();

    final Geometry grid = new Geometry("grid", new Grid(gridSize, gridSize, 1.0f));
    grid.setMaterial(gridMaterial);
    grid.setQueueBucket(RenderQueue.Bucket.Transparent);
    grid.setShadowMode(RenderQueue.ShadowMode.Off);
    grid.setCullHint(Spatial.CullHint.Never);
    grid.setLocalTranslation(gridSize / 2 * -1, 0, gridSize / 2 * -1);

    final Quad quad = new Quad(gridSize, gridSize);
    final Geometry gridCollision = new Geometry("collision", quad);
    gridCollision.setMaterial(createColorMaterial(gridColor));
    gridCollision.setQueueBucket(RenderQueue.Bucket.Transparent);
    gridCollision.setShadowMode(RenderQueue.ShadowMode.Off);
    gridCollision.setCullHint(Spatial.CullHint.Always);
    gridCollision.setLocalTranslation(gridSize / 2 * -1, 0, gridSize / 2 * -1);
    gridCollision.setLocalRotation(new Quaternion().fromAngles(AngleUtils.degreeToRadians(90), 0, 0));

    gridNode.attachChild(grid);
    gridNode.attachChild(gridCollision);

    // Red line for X axis
    final Line xAxis = new Line(new Vector3f(-gridSize / 2, 0f, 0f), new Vector3f(gridSize / 2 - 1, 0f, 0f));

    final Geometry gxAxis = new Geometry("XAxis", xAxis);
    gxAxis.setModelBound(new BoundingBox());
    gxAxis.setShadowMode(RenderQueue.ShadowMode.Off);
    gxAxis.setCullHint(Spatial.CullHint.Never);
    gxAxis.setMaterial(xMaterial);

    gridNode.attachChild(gxAxis);

    // Blue line for Z axis
    final Line zAxis = new Line(new Vector3f(0f, 0f, -gridSize / 2), new Vector3f(0f, 0f, gridSize / 2 - 1));

    final Geometry gzAxis = new Geometry("ZAxis", zAxis);
    gzAxis.setModelBound(new BoundingBox());
    gzAxis.setShadowMode(RenderQueue.ShadowMode.Off);
    gzAxis.setCullHint(Spatial.CullHint.Never);
    gzAxis.setMaterial(zMaterial);

    gridNode.attachChild(gzAxis);

    return gridNode;
}
 
Example #30
Source File: MaterialSettingsPropertyBuilder.java    From jmonkeybuilder with Apache License 2.0 4 votes vote down vote up
@Override
@FxThread
protected @Nullable List<EditableProperty<?, ?>> getProperties(@NotNull final Object object) {

    if (!(object instanceof MaterialSettings) || object instanceof RootMaterialSettings) {
        return null;
    }

    final MaterialSettings settings = (MaterialSettings) object;
    final Material material = settings.getMaterial();

    if(object instanceof RenderSettings) {

        final RenderState renderState = material.getAdditionalRenderState();

        final List<EditableProperty<?, ?>> result = new ArrayList<>();
        result.add(new SimpleProperty<>(BOOLEAN, Messages.MATERIAL_RENDER_STATE_COLOR_WRITE, settings,
                sett -> renderState.isColorWrite(),
                (sett, property) -> renderState.setColorWrite(property)));
        result.add(new SimpleProperty<>(BOOLEAN, Messages.MATERIAL_RENDER_STATE_DEPTH_WRITE, settings,
                sett -> renderState.isDepthWrite(),
                (sett, property) -> renderState.setDepthWrite(property)));
        result.add(new SimpleProperty<>(BOOLEAN, Messages.MATERIAL_RENDER_STATE_DEPTH_TEST, settings,
                sett -> renderState.isDepthTest(),
                (sett, property) -> renderState.setDepthTest(property)));
        result.add(new SimpleProperty<>(BOOLEAN, Messages.MATERIAL_RENDER_STATE_WIREFRAME, settings,
                sett -> renderState.isWireframe(),
                (sett, property) -> renderState.setWireframe(property)));
        result.add(new SimpleProperty<>(ENUM, Messages.MATERIAL_RENDER_STATE_FACE_CULL_MODE, settings,
                sett -> renderState.getFaceCullMode(),
                (sett, property) -> renderState.setFaceCullMode(property)));
        result.add(new SimpleProperty<>(ENUM, Messages.MATERIAL_RENDER_STATE_BLEND_MODE, settings,
                sett -> renderState.getBlendMode(),
                (sett, property) -> renderState.setBlendMode(property)));
        result.add(new SimpleProperty<>(ENUM, Messages.MATERIAL_RENDER_STATE_BLEND_EQUATION, settings,
                sett -> renderState.getBlendEquation(),
                (sett, property) -> renderState.setBlendEquation(property)));
        result.add(new SimpleProperty<>(ENUM, Messages.MATERIAL_RENDER_STATE_BLEND_EQUATION_ALPHA, settings,
                sett -> renderState.getBlendEquationAlpha(),
                (sett, property) -> renderState.setBlendEquationAlpha(property)));
        result.add(new SimpleProperty<>(FLOAT,  Messages.MATERIAL_RENDER_STATE_POLY_OFFSET_FACTOR, 0.1F, settings,
                sett -> renderState.getPolyOffsetFactor(),
                (sett, property) -> renderState.setPolyOffset(property, renderState.getPolyOffsetUnits())));
        result.add(new SimpleProperty<>(FLOAT,  Messages.MATERIAL_RENDER_STATE_POLY_OFFSET_UNITS, 0.1F, settings,
                sett -> renderState.getPolyOffsetUnits(),
                (sett, property) -> renderState.setPolyOffset(renderState.getPolyOffsetFactor(), property)));

        return result;
    }

    final MaterialDef materialDef = material.getMaterialDef();

    return materialDef.getMaterialParams()
            .stream()
            .filter(param -> filter(param, object))
            .sorted(MAT_PARAM_NAME_COMPARATOR)
            .map(param -> convert(param, material, settings))
            .filter(Objects::nonNull)
            .collect(Collectors.toList());
}