Occlusion Effect

2DDL Documentation

If you are designing a game and have to reveal characters, scenario or enemies in progressive way, this method is exact for you. Let’s go to use some textures included in 2DDL package to build a dungeon scene and set up the occlusion effect.

1) Create a empty scene and add “dungeon_screen” texture located in 2DLightAssets/Textures, set position to cero (0,0,0), called it “Bacground0″


2) Duplicate “Background0″. To the clone apply this changes :

  • Name: “Background1″
  • Position  = (0,0,1).
  • SpriteMaterial color =  yellow  (like image)


  • Set to layer “Background”, create if isn’t exist

3) Need build the colliders of walls. take it easy… this step is a delicate process and you’ll  must consider how do it. Remember split huge concave colliders into many small convex. See Concave Colliders: the pacman case.

4) For my comfort, I decided to create a parent GO and add in all the mini colliders that composing the scene.

Screen Shot 2015-04-14 at 18.39.08

5) Now that we have set the walls, add a 2DLight. Check if all is working OK. Look how the light fill all empty space up to hit against the walls.

Screen Shot 2015-04-14 at 18.43.58

6) Now located and add this little guy Screen Shot 2015-04-14 at 18.55.46 to the scene, set within “HiddenObjs” Layer, and cloned it many times.

7) distribute randomly in the scene.

8) Ok the Scene is ready. Now we’re focused in occlusion effect.
Set 2DLight Material property to :DepthMaskMaterial . You’ll find out inside 2DLightAssets/Materials
Note that now the light doesn’t shine, instead , penetrates the entire scene in Z direction.

Screen Shot 2015-04-14 at 19.07.42

Let me explain a little theory of occlusion effect.
DepthRenderMaterial has a shader that allows any mesh of an object to create a kind of depth giving the feeling of a hole in the shape of it. i.e. that everything is located, behind 2DLight, in this case, isn’t rendered (z> 0).
But if , we only show some elements which is of interest for us behind the light, we can create a sense of hidden, but when the light touch, discovers completely.
We need two cameras in theory, but if we need render a background, we’ll need a third for the skybox. In total we will use 3 cameras.

Don’t be afraid to add multiple cameras to your project, had a insignificant impact on performance against productivity of your design.

9) Set up the CAMERAS:

Camera0: will render everything except hiddenObjs


  • Position = (0,0,-10)
  • Clear Flags: Depth Only
  • Culling mask: Only deactive HiddenObjs Layer
  • Depth = 0


Camera1: will render only hiddenObjs


  • Position = (0,0,-10)
  • Clear Flags: Depth Only
  • Culling mask: Only check HiddenObjs Layer
  • Depth = -1


Camera2: will render only background Layer & skybox


  • Position = (0,0,-10)
  • Clear Flags: Skybox
  • Culling mask: Only check Background Layer
  • Depth = -2


which renders each camera …


10) The final result is a occlusion effect, and all cameras working together.


NOTE: If you have issues to construct this scene, remember that is included in 2DDL package like as “4. Occlusion”.