void Update() { if (Context == null) { return; } // [TODO] need to consider camera distane here? Frame3f sceneFrameW = Context.Scene.SceneFrame; if (sceneFrameW.EpsilonEqual(lastSceneFrameW, 0.001f)) { return; } lastSceneFrameW = sceneFrameW; if (AdjustShadowDistance) { // use vertical height of light to figure out appropriate shadow distance. // distance changes if we scale scene, and if we don't do this, shadow // map res gets very blurry. Vector3f thisW = lights[0].transform.position; float fHeight = Vector3f.Dot((thisW - sceneFrameW.Origin), sceneFrameW.Y); float fShadowDist = fHeight * 1.5f; // lights need to be in-range if (fShadowDist < LightDistance) { fShadowDist = LightDistance * 1.5f; } // need to be a multiple of eye distance float fEyeDist = sceneFrameW.Origin.Distance(Camera.main.transform.position); fShadowDist = Mathf.Max(fShadowDist, 1.5f * fEyeDist); int nShadowDist = (int)g3.Snapping.SnapToIncrement(fShadowDist, 50); if (cur_shadow_dist != nShadowDist) { QualitySettings.shadowDistance = nShadowDist; cur_shadow_dist = nShadowDist; } } }