Effekseer Native for JME (wip)

I have a couple of graphical issues when using it on my game. On the left, I’ve removed the FilterPostProcessor.

  1. on top, there is a weird interaction with my shader (a transparent part is now greenish)
  2. on the bottom (but also on the top) a transparency issue.

The code:

import com.jme.effekseer.EffekseerEmitterControl;
import com.jme.effekseer.EffekseerPostRenderer;
import com.jme.effekseer.driver.EffekseerEmissionDriverGeneric;
import com.jme.effekseer.driver.fun.impl.EffekseerGenericSpawner;
import com.jme.effekseer.driver.fun.impl.EffekseerPointFollowingSpatialShape;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.material.RenderState;
import com.jme3.post.FilterPostProcessor;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Quad;
import com.jme3.system.AppSettings;

import static com.pesegato.MonkeySheet.MSGlobals.MS_HEIGHT;
import static com.pesegato.MonkeySheet.MSGlobals.MS_WIDTH;

public class HelloJME3_2 extends SimpleApplication{

    public static void main(String[] args) {
        HelloJME3_2 app=new HelloJME3_2();
        app.setShowSettings(false);
        AppSettings settings=new AppSettings(true);
        settings.setRenderer(AppSettings.LWJGL_OPENGL32);
        app.setSettings(settings);
        app.start(); // start the game
    }

    @Override
    public void simpleInitApp() {

        Geometry bg = new Geometry("monkeybg", new Quad(200, 200));
        Material glowM = new Material(assetManager, "MatDefs/SimoGlow.j3md");
        glowM.setTexture("Threshold", assetManager.loadTexture("Textures/gradient-up.png"));
        glowM.setTexture("ColorMap", assetManager.loadTexture("Textures/grade-a.png"));
        glowM.setTexture("ColorMap2", assetManager.loadTexture("Textures/grade-a.png"));
        glowM.setBoolean("ShowThreshold", true);
        glowM.setFloat("Level",0.5f);
        glowM.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
        bg.setMaterial(glowM);

        bg.setLocalTranslation(0,300,0);
        guiNode.attachChild(bg);

        // Add a filter post processor to your viewPort
        FilterPostProcessor fpp=new FilterPostProcessor(getAssetManager());
        getGuiViewPort().addProcessor(fpp);

        // Add Effekseer Renderer
        fpp.addFilter(new EffekseerPostRenderer(getAssetManager()));

        // Load an effect
        EffekseerEmitterControl effekt=(EffekseerEmitterControl)assetManager.loadAsset("Effekts/prova.efkefc");
        effekt.setDriver(
                new EffekseerEmissionDriverGeneric()
                        .shape(new EffekseerPointFollowingSpatialShape())
                        .spawner(new EffekseerGenericSpawner().loop(true).maxInstances(1))
        );

        // Attach to a spatial
        Node n=new Node();
        n.addControl(effekt);
        n.setLocalTranslation(cam.getWidth() / 2,cam.getHeight() / 2,0);
        n.setLocalScale(50f);

        guiNode.attachChild(n);
    }
}

Material:

MaterialDef Anim {

    MaterialParameters {
        Texture2D ColorMap
        Texture2D ColorMap2
        Texture2D Threshold -LINEAR
        Float Level
        Boolean ShowThreshold
        Float SizeX : 1
        Float SizeY : 1
        Float Position
        Float FlipHorizontal
        Float HitTime
        Color GlowColor
        Float AlphaValue
    }

    Technique {
        VertexShader GLSL100:   MatDefs/Threshold.vert
        FragmentShader GLSL100: MatDefs/SimoGlow.frag

        WorldParameters {
            WorldViewProjectionMatrix
        }

        Defines {
            HAS_GLOWCOLOR : GlowColor
        }
    }
    Technique Glow {

        VertexShader GLSL100:   Common/MatDefs/Misc/Unshaded.vert
        FragmentShader GLSL100: Common/MatDefs/Light/Glow.frag

        WorldParameters {
            WorldViewProjectionMatrix
            ViewProjectionMatrix
            ViewMatrix
        }

        Defines {
            NEED_TEXCOORD1
            HAS_GLOWMAP : GlowMap
            HAS_GLOWCOLOR : GlowColor
            NUM_BONES : NumberOfBones
	    INSTANCING : UseInstancing
        }
    }
}

Shader:


uniform mat4 g_WorldViewProjectionMatrix;
uniform float m_SizeX;
uniform float m_SizeY;
uniform float m_Position;

attribute vec3 inPosition;
attribute vec2 inTexCoord;

varying vec2 texCoord;

void main(){
    texCoord.x = inTexCoord.x;
    texCoord.y = inTexCoord.y;
    gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
}

Shader

uniform sampler2D m_ColorMap;
uniform sampler2D m_ColorMap2;
uniform sampler2D m_Threshold;
float threshold;
float alpha;
uniform float m_Level;
uniform bool m_ShowThreshold;
varying vec2 texCoord;

void main(){

    threshold = texture2D(m_Threshold, texCoord).r;
    if (threshold < m_Level)
        if (m_ShowThreshold == false)
            discard;
        else
            if (m_Level - threshold <0.1) {
                alpha = max(texture2D(m_ColorMap, texCoord).a, texture2D(m_ColorMap2, texCoord).a);
                alpha = alpha * abs(m_Level - threshold - 0.1) * 10.0;
                gl_FragColor = vec4(1.0, abs(m_Level - threshold - 0.1) * 10.0, 1.0, alpha);
            }
            else
                discard;
    else
        if (threshold - m_Level <0.1) {
            alpha = max(texture2D(m_ColorMap, texCoord).a, texture2D(m_ColorMap2, texCoord).a);
            alpha = alpha * abs(threshold - m_Level - 0.1) * 10.0;
            gl_FragColor = vec4(1.0, abs(m_Level - threshold - 0.1) * 10.0, 1.0, alpha);
        }
        else
            discard;
}


I updated the library to use the current effekseer master.
Now it also supports background distortions and better soft particles.
Upgrade infos here: jme-effekseerNative/UPGRADE.md at master · riccardobl/jme-effekseerNative · GitHub

The FPS Demo was updated acordingly to use the new version.

2 Likes

Hi

Any news on Android support?

I don’t currently do android development, but afaik the effekseer runtime supports android.

This is the repo for the bindings used by this library, i guess the main step would be to get this to build for android, the rest should probably be fine

1 Like