- Home /
Make shadows disappear
I have a GPS in my fps game that follows the player and help him to locate enemies faster and explore the enviroment. It's a camera with lots of "customization". I want to change the camera so it CANNOT SEE SHADOWS. Is there a way to do it? Tag something or change layers? Via script? I don't have any idea.
Answer by rocket350 · Jul 23, 2016 at 04:09 PM
There is a bit of a hackish solution, but it works (tested).
Attach a script called HideShadows.cs with this code to a camera:
using UnityEngine;
public class HideShadows: MonoBehaviour {
float storedShadowDistance;
void OnPreRender() {
storedShadowDistance = QualitySettings.shadowDistance;
QualitySettings.shadowDistance = 0;
}
void OnPostRender() {
QualitySettings.shadowDistance = storedShadowDistance;
}
}
The functions OnPreRender() and OnPostRender() are called by Unity on all scripts attached to a GameObject with a Camera component before and after the camera renders it's view to the screen.
In OnPrerender() this script sets the shadowdistance to 0 after storing the "real" shadow distance in a variable.
When the camera renders, it doesn't render any shadows due to shadowdistance being 0.
In OnPostRender() the script restores the shadowdistance setting, making the other cameras render shadows as normal.
Cheers!