private Bounds CalculateProjectionBoundInLightSpace(CharacterShadowCommonSettingsComponent settings, Bounds boundsInLightSpace, float offset) { float num3 = Mathf.Max(boundsInLightSpace.size.x, boundsInLightSpace.size.y) / ((float)((((settings.textureSize - settings.blurSize) - settings.blurSize) - 1) - 1)); float num4 = (2 * (1 + settings.blurSize)) * num3; float x = boundsInLightSpace.size.x + num4; float y = boundsInLightSpace.size.y + num4; if (x > y) { y += ((Mathf.Ceil((y - 0.01f) / (num3 + num3)) * (num3 + num3)) - y) * 0.5f; } else { x += ((Mathf.Ceil((x - 0.01f) / (num3 + num3)) * (num3 + num3)) - x) * 0.5f; } Bounds bounds = new Bounds { size = new Vector3(x, y, boundsInLightSpace.size.z - offset) }; bounds.center = new Vector3(boundsInLightSpace.center.x, boundsInLightSpace.center.y, boundsInLightSpace.max.z - bounds.extents.z); return(bounds); }
private void UpdateShadowMapSize(CharacterShadowCommonSettingsComponent settings, ICollection <CharacterShadowComponent> visibleCharacters, ICollection <CharacterShadowComponent> allCharacters) { int num = (settings.shadowMap != null) ? settings.shadowMap.width : 0; int num2 = Mathf.CeilToInt(Mathf.Sqrt((float)visibleCharacters.Count)); int width = Mathf.NextPowerOfTwo(settings.textureSize * num2); int num4 = Mathf.CeilToInt(Mathf.Sqrt((float)allCharacters.Count)); if ((width > num) | ((2 * Mathf.NextPowerOfTwo(settings.textureSize * num4)) < num)) { Destroy(settings.shadowMap); settings.shadowMap = null; if (width > 0) { settings.shadowMap = new RenderTexture(width, width, 0, settings.ShadowMapTextureFormat, RenderTextureReadWrite.Linear); settings.shadowMap.isPowerOfTwo = true; settings.shadowMap.filterMode = FilterMode.Bilinear; settings.shadowMap.useMipMap = false; } foreach (CharacterShadowComponent component in allCharacters) { component.GetComponent <MyShadowInternal>().Projector.material.mainTexture = settings.shadowMap; } } }
private void UpdateBoundsAndCullCharacters(ICollection <CharacterShadowComponent> collector, ICollection <CharacterShadowComponent> characters, Camera camera, CharacterShadowCommonSettingsComponent settings) { Matrix4x4 localToWorldMatrix = settings.virtualLight.localToWorldMatrix; Matrix4x4 worldToLocalMatrix = settings.virtualLight.worldToLocalMatrix; Plane[] planes = GeometryUtility.CalculateFrustumPlanes((camera.projectionMatrix * camera.worldToCameraMatrix) * localToWorldMatrix); int num = 0; int maxCharactersCountInAtlas = settings.MaxCharactersCountInAtlas; foreach (CharacterShadowComponent component in characters) { bool flag = num < maxCharactersCountInAtlas; Bounds boundsInLightSpace = BoundsUtils.TransformBounds(component.GetComponent <MyShadowCaster>().BoundsInWorldSpace, worldToLocalMatrix); CharacterShadowComponent component2 = component; MyShadowInternal internal2 = component.GetComponent <MyShadowInternal>(); internal2.ProjectionBoundInLightSpace = this.CalculateProjectionBoundInLightSpace(settings, boundsInLightSpace, component2.offset); Bounds projectionBoundInLightSpace = internal2.ProjectionBoundInLightSpace; projectionBoundInLightSpace.max += new Vector3(0f, 0f, component2.attenuation); flag &= GeometryUtility.TestPlanesAABB(planes, projectionBoundInLightSpace); internal2.Projector.enabled = flag; if (flag) { collector.Add(component); } num++; } }