This tool allows developers to easily run filters and effects on multi-image, assembled mesh or 3D objects. See a demonstration here.
2D skeleton animation tools like Spine 2D are fantastic for creating 2D artwork in games. They allow for smooth animations while reducing the amount of assets required for each object. A drawback of these assets is that they are comprised of multiple images. Any effects that are applied to the asset are applied to the individual images and not the assembled mesh that you see on screen.
Let's take a look at an example of when this becomes an issue. Say you want to apply an outline effect. We start with following images
which are assembled into the following mesh at runtime
when we attach a simple outline shader we get the following
not only is there some clipping issues based on the bounds of our sample images but you can see that each individual piece is outlined. What we want is this
A common technique to solve this problem is to use a multi camera setup that captures the assembled mesh and renders it to a texture.
This can be a lot to manage though. Entity Post-Processor 2D seeks to automate the setup and management of this multi camera solution for you.
- Create a new layer named
EntityPostProcessor
. You should treat this as a reserved layer and never directly add anything to it - Remove this new layer your main camera Culling Mask.
- Select the Main Camera from your Scene Hierarchy
- Open the Culling Mask drop down in the camera component in the Inspector
- Select EntityPostProcessor to remove it from the Culling Mask
- Right click on the scene Hierarchy and select EntityPostProcessor2D->Controller
- Attach any 2D assets you want to display to the child object EntityRenderSource of your new EntityController gameObject. (note: you can replace this RenderSouce object with your own gameObject instead of making it a child object. Just be sure to attach an EntityRenderSource component to your object)
- Position the EntityRenderSource relative to the parent EntityController however you want.
- Set the
Sorting Layer
andOrder In Layer
that you want your EntityRenderSource to appear on. - Check
Show Camera Rect
is checked - You should see a blue square around the asset(s) you used in your render source. This represents the area that will be captured by the post processing camera. The goal is to make this as small possible without your asset(s) going outside this blue box.
- You can change this capture size by changing the
Render Texture Size
Width and Height. - You can also change how your asset is positioned within the camera with
Source Capture Offset
- Play around with
Render Texture Size
andSource Capture Offset
until you've found the best fit. Also remember, this has to account for animations.
- Right click on the scene Hierarchy and select EntityPostProcessor2D->PostProcessor
- Drag this object into your Project hierarchy and delete it from the scene
- Assign this
EntityPostProcessor
prefab to thePostProcessor
field of the EntityController component you previously created
Note: A single EntityPostProcessor prefab can be used by many/all of your EntityController objects. Each EntityController will always create an its own instance of the EntityPostProcessor though.
At this point when you run your scene your new EntityController shold be displayed as if nothings changed. If you look at the EntityController the EntityRenderSouce should have be replaced with a Render Texture.
Any scripts attached to your EntityPostProcessor can apply post-processing effects to your entity using the OnRenderImage
function. See the docs for more details.
To see a few sample effects you can attach EntityPostProcessor2D/Examples/Scripts/EntityEffects
scripts to your EntityPostProcessor prefab
My asset(s) appears cut off
Enable Show Capture Rect
and then change the values of Source Capture Offset
until the character fits within the blue box. Increase the Render Texture Size
if needed.
A character appears twice on the screen
Make sure that your main camera and other cameras have the EntityPostProcessor
layer removed the Culling Mask
.
How do I refence the EntityRenderSource from the EntityController and vice versa?
Both components keep a reference to the other. If you have a attach a script MyEntity
to your entity and a script MyRenderSource
to your render source
MyEntity
using EntityPostProcessor;
public class MyEntity : MonoBehaviour
{
MyRenderSource renderSource;
void Start () {
renderSource = GetComponent<EntityController>().renderSource.GetComponent<MyRenderSource>();
}
}
MyRenderSource
using EntityPostProcessor;
public class MyRenderSource : MonoBehaviour
{
MyEntity entity;
void Start () {
entity = GetComponent<EntityRenderSource>().controller.GetComponent<MyEntity>();
}
}
I can't get 3rd party effects libraries like 2DxFX to work with this tool.
This tool renders your assets to a MeshRenderer
+ MeshFilter "Quad"
and a lot of these effects expect a SpriteRenderer
. So although they might not work out of the box it might be possible to modify them to work.
With 2DxFX a lot effects simply require a search and replace on SpriteRenderer
for MeshRenderer
on the effect script file. Once you've done this attach the script to the EntityRenderOutput
child object of your EntityController