Devlog #1 See Through Leaves

Final result, palm leaf is semi-transparent around the player and close to camera using custom shader

Player can’t see obstacles

In current version of the game there are passages of the game play where some palms is going in front of camera and the player is unable to see obstacles and can therefore be hit in the game. This is very frustrating and so I started to look hot to implement some feature that will fix this issue and improve game play.

As I am still new to challenges like this therefore I have started researching what is possible and how this can be implemented.

Design

Easy solution is to detect game objects using raycast that are between camera and player in the scene and for those change their material to be transparent. Detection itself can be done on CPU by executing raycast from player towards camera and if this script will hit some object. Then verify if they are from chosen layer (e. g. vegetation) and then apply material changes to them. This solution has some disadvantages that I dont like:

  • Raycast towards camera needs to run often and can take some CPU time
  • Ray can hit lot of child objects we need to traverse them to filter right one
  • For each we need to loop and change material to transparent
  • need to track same procedure to return back solid material

Second option is to create custom post-processing stack and using stencil buffer clear area on the leafs where the player is. I was not happy about his option as with this option you are wiping exact pixels where the player is and not something more.

Third option that is described here was to make custom transparent shader for leaves that will change pixels to transparent based on distance to camera. As close as they are to the camera more transparent they will be.

Last option is to combine first (ray cast) with third option (special shader) to gain some more performance. So we can do raycast towards camera every other frame and if detect obstacle for them change material to transparent one. This option can be handy if we dont wanted to have too much transparent objects in the scene if they are not needed (far from camera) because transparent rendering is costly comparing to opaque object detection.