Skip to content

Instantly share code, notes, and snippets.

@zsoi
Last active July 20, 2017 09:22
Show Gist options
  • Save zsoi/1dd7fd1d2192654feacf850f23086e83 to your computer and use it in GitHub Desktop.
Save zsoi/1dd7fd1d2192654feacf850f23086e83 to your computer and use it in GitHub Desktop.
Unity3D Behaviours for changing LodBias and ShadowCasting for individual cameras. Add scripts to chosen cameras and modify the LodBias / ShadowCasting method as you require. Serves well to have e.g. reflection cameras draw with less quality.
namespace Game.Camera
{
using UnityEngine;
/// <summary>
/// Applies a custom LOD bias factor to rendering when attached to a camera
/// </summary>
[RequireComponent(typeof(Camera))]
class CustomLodBias : MonoBehaviour
{
public float LodBiasFactor = 1F;
float originalLodBias = 0F;
private void OnPreCull()
{
originalLodBias = QualitySettings.lodBias;
QualitySettings.lodBias = originalLodBias * LodBiasFactor;
}
private void OnPostRender()
{
QualitySettings.lodBias = originalLodBias;
}
}
}
namespace Game.Camera
{
using UnityEngine;
/// <summary>
/// Applies a custom shadow casting scheme to rendering when attached to a camera
/// </summary>
[RequireComponent(typeof(Camera))]
class CustomShadowCasting : MonoBehaviour
{
public ShadowQuality OverriddenShadowQuality = ShadowQuality.All;
ShadowQuality originalShadowQuality = ShadowQuality.All;
private void OnPreCull()
{
originalShadowQuality = QualitySettings.shadows;
QualitySettings.shadows = OverriddenShadowQuality;
}
private void OnPostRender()
{
QualitySettings.shadows = originalShadowQuality;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment