Skip to content

Commit

Permalink
Update usage infos
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl authored Oct 14, 2020
1 parent 6fc548a commit 6a95855
Showing 1 changed file with 59 additions and 16 deletions.
75 changes: 59 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,28 @@ repositories {
maven { url "https://dl.bintray.com/riccardo/effekseer" }
}
dependencies {
implementation 'com.github.riccardobl:jme-effekseerNative:-SNAPSHOT'
implementation 'com.github.riccardobl:jme-effekseerNative:-SNAPSHOT'
}
```


## Usage
## Usage - Managed Rendering
```java
// Add a filter post processor to your viewPort
FilterPostProcessor fpp=new FilterPostProcessor(assetManager);
viewPort.addProcessor(fpp);
// optional:
// if the FilterPostProcessor is created, EffekseerRenderer will attach itself as a filter
// otherwise it will be attached as a scene processor.
// Note: if a FilterPostProcessor is used in the viewport, EffekseerRenderer must be called before
// attaching any other filter, becoming defacto the first filter to be attached to the FilterPostProcessor
// FilterPostProcessor fpp=new FilterPostProcessor(assetManager);
// viewPort.addProcessor(fpp);

// Add Effekseer Renderer
fpp.addFilter(new EffekseerPostRenderer(assetManager));
EffekseerRenderer effekseerRenderer=EffekseerRenderer.addToViewPort(stateManager, viewPort, assetManager, settings.isGammaCorrection());

// Load an effect
EffekseerEmitterControl effekt=(EffekseerEmitterControl)assetManager.loadAsset("effekts/Pierre/Lightning.efkefc");
EffekseerEmitterControl effekt=new EffekseerEmitterControl(assetManager,"effekts/Pierre/Lightning.efkefc");

// Set a driver (optional)
effekt.setDriver(
Expand All @@ -54,7 +59,6 @@ effekt.setDriver(
Node n=new Node();
n.addControl(effekt);


rootNode.attachChild(n);

```
Expand All @@ -63,22 +67,61 @@ rootNode.attachChild(n);
This is intended to be used on custom render pipelines or offscreen rendering
```java
// Init Effekseer
Effekseer.init(assetManager);

// Select the scene to render (only child of root will be renderer). root=null to render all.
Effekseer.beginScene(root);
boolean isSRGB=true;
Effekseer.init(assetManager,isSRGB);

// Update the logic
// Update logic: This needs to be called in your update loop (once per frame)
Effekseer.update( tpf);

// --- Render scene 1
// Select the scene to render
Effekseer.beginRender(root1);

// Render
Effekseer.render(
Renderer, /* The opengl renderer */
Camera, /* The scene camera */
FrameBuffer, /* The render target */
Texture2D, /* The depth texture of the current scene (for soft particles, null to disable soft particles) */
Float, /* Particles hardness (for soft particles) */
Float, /* Particles contrast (for soft particles) */
Boolean /* True if rendering on 2d Target */
);

// End the render
Effekseer.endRender();

// --- Render scene 2
// Select the scene to render
Effekseer.beginRender(root2);

// Render
// sceneDepth is the depth of the current scene - used for soft particles
Effekseer.render(Renderer renderer,Camera cam,FrameBuffer renderTarget,Texture sceneDepth);
Effekseer.render(
Renderer, /* The opengl renderer */
Camera, /* The scene camera */
FrameBuffer, /* The render target */
Texture2D, /* The depth texture of the current scene (for soft particles, null to disable soft particles) */
Float, /* Particles hardness (for soft particles) */
Float, /* Particles contrast (for soft particles) */
Boolean /* True if rendering on 2d Target */
);

// End the scene, reset states
Effekseer.endScene();
// End the render
Effekseer.endRender();

```

Note: opengl cannot read and write on the same target, this means that depth that comes from the same target framebuffer has to be copied.
The following helper utility can be used to do it in a reasonably fast way (it used glBlitFramebuffer and a pool of cached framebuffers internally):
```java
Texture copiedDepth=EffekseerUtils.copyDepthFromFrameBuffer(
RenderManager, /* the render manager */
FrameBuffer, /* source */
int, /* width */
int /* height */
);
```

### Limitations
- There is an issue with depth sorting when using *Managed Rendering* to render inside the SimpleApplication's guiViewPort: the particles will always be rendered on top. Finding a generic workaround for this issue is pretty complex due to the way the engine handles the guiViewPort. A possible solution is to use *Advanced Usage - Manual Rendering* to render a special root node containing only "gui particles" on top of the main framebuffer using an appropriate Camera.

0 comments on commit 6a95855

Please sign in to comment.