I am creating a side-to-side scrolling 2D game with a number of environment layers and am having problems getting one of the layers to be semi-transparent to create a sort of distance haze effect. The layers I have include (from back to front):
- Stars –Sphere MeshFilter, Mesh Renderer, Sprites/Default Shader
- Mountains - Mesh Filter (procedurally generated), Mesh Renderer, Sprites/Default Shader
- Haze – Plane Mesh Filter, Mesh Renderer, custom material
- Landscape - Mesh Filter (procedurally generated), Mesh Renderer, Sprites/Default Shader
I am trying to set up the Haze layer with some transparency as a simple, or not so simple as it turns out, distance haze effect. Using a standard shader on the material the layer either does or does not render at all depending on the alpha value, but is not transparent, i.e. if it renders then it blocks the stars/mountains completely. I can get a transparent looking effect if I use the Skybox/Panoramic shader although the mountains are still rendered in front of the Haze layer even though they are physically behind it in the z-dimension.
I have read a page on how to fix transparent rendering problems here: https://answers.unity.com/questions/609021/how-to-fix-transparent-rendering-problem.html and tried using a Standard shader with Rendering Mode set to cutout, but get the same problem that the Haze layer is either solid or invisible.
I am a total noob when it comes to this stuff so am just groping in the dark changing options to see what happens. I don’t know enough about the suggestions on the ”how to fix transparent rendering problems” page to understand how to implement the solutions or if they will work for me. I’ve read lots of other pages, but am none the wiser.
Can anyone give me any suggestions about how I might fix this problem so that my Haze layer is rendered semi-transparently in front of the stars/mountains? If I haven’t provided enough information here then let me know (not sure what is relevant/isn’t!)
Just for completeness, I have tried another approach by making the mountains transparent (which works fine… so not sure why the Haze layer doesn’t!) and using a script to selectively disable my stars if they are behind the mountains using a raycast, however this is not 100% accurate and can lead to parallax errors where the stars are something visible behind the semi-transparent mountains. It seemed like it would be easier just to have a semi-transparent plane in from of the mountains that tracked the camera, but can’t work out what I am doing wrong.
ps apologies for the bad paragraph spacing, but I can’t get the line breaks to work for some reason. :s
pps I fixed the paragraph spacing using basic html.