- Home /
Most efficient way to darken the screen?
I want to do a simple dark backdrop of the screen. For example, if the pause menu of the game is gonna appear, I want to darken the screen and then show the pause menu. I understand that there are multiple ways of doing this, and I know how to do the ways I am aware of (such as (1) using camera effects, (2) using a black GUITexture in front of the camera and managing its alpha channel, and (3) playing with the lighting of the scene).
My game is completely light-free, so option (3) is out. Which one ((1) or (2), or any other method I have not mentioned) is the most efficient for a mobile platform like iOS? I'm concerned about all that alpha blending on every pixel of the screen.
Any thoughts? Thanks in advance!
Cheers!
Answer by Meltdown · Jul 25, 2012 at 07:46 PM
Instantiating a black GUITexture or even a textured 1x1 plane in front of the rest of the menu is pretty efficient. Although for a pause menu I wouldn't be too worried about performance.
You could even have two cameras, one for your game, one for your pause menu, and only render those respective layers on each camera, so you simply disable one camera, and enable the other.
Thanks for the quick reply! :) Can you elaborate a bit more on the 1x1 plane idea?
There is a create plane script here from his most esteemed Sir $$anonymous$$ichael Garforth.. http://unifycommunity.com/wiki/index.php?title=CreatePlane
Basically the default Unity plane has an excessive amount of polygons, this lets you create a 1x1 plane mesh to use in Unity for your plains where you don't need the detail.
You can put it on its own layer, with its own camera, and wrap it all up into a prefab.
Thanks for the tip! Is it more efficient to have it on its own layer/camera? What would be the benefits over just using it on my UI camera or main camera?
also on the UnifyCommunity 'site, there are lots of useful scripts, some being GUITexture Faders :
From our very own Eric : http://unifycommunity.com/wiki/index.php?title=Fade
and : http://unifycommunity.com/wiki/index.php?title=FadeIn
one more : http://unifycommunity.com/wiki/index.php?title=FadeInOut
Answer by Mortoc · Jul 25, 2012 at 07:52 PM
The most efficient way would be to use option 2 (GUITexture with alpha across the screen) for a single frame, setting the camera to not clear out the display buffer and then disable rendering of everything else in the scene. If you need the pause menu to be interactive, you would copy the screen to a render texture and use that texture as the background instead (this would require Unity Pro).
This is most likely overkill, just putting a simple GUITexture over the screen should run just fine.
I do have Unity Pro. But I have never used RenderTextures. I have some reading to do. Thanks for the help!
I wouldn't suggest using Render Textures for this. a) because it requires PRO and b.) Using two cameras on two different layers is more diverse, and you can wrap up each screen and camera in a prefab quite easily and make good re-use of it.
Answer by chantey · Aug 19, 2018 at 10:12 AM
I found using an Image on a canvas stretched across the screen was quite an easy way to do this.