jME3 Special Effects Overview
jME3 supports several types of special effects: Post-Processor Filters, SceneProcessors, and Particle Emitters (also known as particle systems). This list contains screenshots and links to sample code that demonstrates how to add the effect to a scene.
Sample Code
-
There is one
com.jme3.effect.ParticleEmitter
class for all Particle Systems. -
There is one
com.jme3.post.FilterPostProcessor
class and severalcom.jme3.post.filters.
(all Filters haveFilter
in their names). -
There are several
SceneProcessor
classes in various packages, including e.g.com.jme3.shadow.
andcom.jme3.water.
(SceneProcessor haveProcessor
orRenderer
in their names).
Particle Emitter
public class MyGame extends SimpleApplication {
public void simpleInitApp() {
ParticleEmitter pm = new ParticleEmitter("my particle effect", Type.Triangle, 60);
Material pmMat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
pmMat.setTexture("Texture", assetManager.loadTexture("Effects/spark.png"));
pm.setMaterial(pmMat);
pm.setImagesX(1);
pm.setImagesY(1);
rootNode.attachChild(pm); // attach one or more emitters to any node
}
}
Scene Processor
public class MyGame extends SimpleApplication {
private BasicShadowRenderer bsr;
public void simpleInitApp() {
bsr = new BasicShadowRenderer(assetManager, 1024);
bsr.setDirection(new Vector3f(.3f, -0.5f, -0.5f));
viewPort.addProcessor(bsr); // add one or more sceneprocessor to viewport
}
...
}
Post-Processor Filter
public class MyGame extends SimpleApplication {
private FilterPostProcessor fpp; // one FilterPostProcessor per app
private SomeFilter sf; // one or more Filters per app
public void simpleInitApp() {
fpp = new FilterPostProcessor(assetManager);
viewPort.addProcessor(fpp); // add one FilterPostProcessor to viewPort
sf = new SomeFilter();
fpp.addFilter(sf); // add one or more Filters to FilterPostProcessor
}
...
}
Water
The jMonkeyEngine “SeaMonkey WaterFilter” simulates ocean waves, foam, including cool underwater caustics.
Use the SimpleWaterProcessor (SceneProcessor) for small, limited bodies of water, such as puddles, drinking troughs, pools, fountains.
See also:
-
Rendering Water as Post-Process Effect announcement with video.
-
TestSceneWater.java – SimpleWaterProcessor. (SceneProcessor)
-
TestSimpleWater.java – SimpleWaterProcessor. (SceneProcessor)
-
TestPostWater.java – WaterFilter.
-
TestPostWaterLake.java – WaterFilter.
Environment Effects
Fog
-
TestFog.java – FogFilter.
Light Scattering
-
TestLightScattering.java – LightScatteringFilter.
Vegetation
-
Contribution: Grass System
-
Contribution: Trees (WIP)
Light and Shadows
Light
-
TestSimpleLighting.java – DirectionalLight, PointLight.
-
TestLightRadius.java – DirectionalLight, PointLight.
-
TestManyLights.java – .j3o scene.
-
More details: Light and Shadow
Shadow
-
TestSSAO.java, TestSSAO2.java – SSAOFilter, also known as Screen-Space Ambient Occlusion shadows (SSOA).
-
TestTransparentSSAO.java – SSAOFilter, also known as Screen-Space Ambient Occlusion shadows (SSOA), plus transparency.
-
More details: Light and Shadow
Special: Glass, Metal, Dissolve, Toon
Toon Effect
-
TestCartoonEdge.java – CartoonEdgeFilter.
-
TestTransparentCartoonEdge.java – CartoonEdgeFilter.
Fade in / Fade out
-
Fade – FadeFilter
User Contributed
-
LightBlow Shader – blend material texture maps.
-
FakeParticleBlow Shader – jet, fire effect.
-
ToonBlow Shader – Toon Shading, toon edges.
-
Dissolve Shader – Scifi teleportation/dissolve effect.
-
MatCap Shader – Gold, metals, glass, toons…!
-
Glass Shader – Glass.
-
Force Shield Shader – Scifi impact-on-force-field effect.
-
SimpleSprite Shader – Animated textures.
-
SimpleSpriteParticle Shader – Sprite library.
-
MovingTexture Shader – Animated cloud/mist texture.
-
SoftParticles Shader – Fire, clouds, smoke etc.
-
Displace Shader – Deformation effect: Ripple, wave, pulse, swell!
Thanks for your awesome contributions! Keep them coming!
Particle Emitters: Explosions, Fire, Smoke
Particle emitter effects are highly configurable and can have any texture. They can simulate smoke, dust, leaves, meteors, snowflakes, mosquitoes, fire, explosions, clusters, embers, sparks…
-
TestExplosionEffect.java – debris, flame, flash, shockwave, smoke, sparks.
-
TestPointSprite.java – cluster of points.
-
TestMovingParticle.java – dust, smoke.
Creating your own Filters
Here is an extract taken from @nehon in the forum thread (http://hub.jmonkeyengine.org/forum/topic/how-exactly-do-filters-work/)
The methods are called in this order (pretty much the same flow as processors): - initFilter() is called once when the FilterPostProcessor is initialized or when the filter is added to the processor and this one as already been initialized.
for each frame the methods are called in that sequence : - preFrame() occurs before anything happens - postQueue() occurs once the queues have been populated (there is one queue per bucket and 2 additional queues for the shadows, casters and receivers). Note that geometries in the queues are the one in the view frustum. - postFrame occurs once the main frame has been rendered (the back buffer)
Those methods are optional in a filter, they are only there if you want to hook in the rendering process.
The material variable is here for convenience. You have a getMaterial method that returns the material that’s gonna be used to render the full screen quad. It just happened that in every implementation I had a material attribute in all my sub-classes, so I just put it back in the abstract class. Most of the time getMaterial returns this attribute.
Forced-technique can be any technique really, they are more related with the material system than to the filters but anyway. When you use a forced technique the renderer tries to select it on the material of each geometry, if the technique does not exists for the material the geometry is not rendered. You assume well about the SSAO filer, the normal of the scene are rendered to a texture in a pre pass.
Passes : these are filters in filters in a way. First they are a convenient way to initialize a FrameBuffer and the associated textures it needs, then you can use them for what ever you want. For example, a Pass can be (as in the SSAO filter) an extra render of the scene with a forced technique, and you have to handle the render yourself in the postQueue method. It can be a post pass to do after the main filter has been rendered to screen (for example an additional blur pass used in SSAO again). You have a list of passes called postRenderPass in the Filter abstract class. If you add a pass to this list, it’ll be automatically rendered by the FilterPostProcessor during the filter chain.
The bloom Filter does an intensive use of passes.
Filters in a nutshell.
See also: