Beispiel #1
0
        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);
        }
Beispiel #2
0
        private void UpdateShadowMapSize(CharacterShadowCommonSettingsComponent settings, ICollection <CharacterShadowNode> visibleCharacters, ICollection <CharacterShadowNode> 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))
            {
                Object.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 (CharacterShadowNode node in allCharacters)
                {
                    node.characterShadowInternal.Projector.material.mainTexture = settings.shadowMap;
                }
            }
        }
Beispiel #3
0
        private void CalculateShadowInternalData(CharacterShadowInternalComponent shadowInternalData, CharacterShadowComponent characterShadow, CharacterShadowCommonSettingsComponent shadowCommonSettings)
        {
            Projector projector = this.CreateProjector(shadowCommonSettings);

            shadowInternalData.Projector      = projector;
            shadowInternalData.BaseAlpha      = characterShadow.color.a;
            shadowInternalData.CasterMaterial = new Material(shadowCommonSettings.casterShader);
        }
Beispiel #4
0
        private void UpdateBoundsAndCullCharacters(ICollection <CharacterShadowNode> collector, ICollection <CharacterShadowNode> characters, CameraComponent cameraComponent, CharacterShadowCommonSettingsComponent settings)
        {
            Matrix4x4 localToWorldMatrix = settings.virtualLight.localToWorldMatrix;
            Matrix4x4 worldToLocalMatrix = settings.virtualLight.worldToLocalMatrix;

            Plane[] planes = GeometryUtility.CalculateFrustumPlanes((cameraComponent.ProjectionMatrix * cameraComponent.WorldToCameraMatrix) * localToWorldMatrix);
            int     num    = 0;
            int     maxCharactersCountInAtlas = settings.MaxCharactersCountInAtlas;

            foreach (CharacterShadowNode node in characters)
            {
                bool   flag = num < maxCharactersCountInAtlas;
                Bounds boundsInLightSpace = BoundsUtils.TransformBounds(node.characterShadowCasters.BoundsInWorldSpace, worldToLocalMatrix);
                CharacterShadowComponent         characterShadow         = node.characterShadow;
                CharacterShadowInternalComponent characterShadowInternal = node.characterShadowInternal;
                characterShadowInternal.ProjectionBoundInLightSpace = this.CalculateProjectionBoundInLightSpace(settings, boundsInLightSpace, characterShadow.offset);
                Bounds projectionBoundInLightSpace = characterShadowInternal.ProjectionBoundInLightSpace;
                projectionBoundInLightSpace.max += new Vector3(0f, 0f, characterShadow.attenuation);
                flag &= GeometryUtility.TestPlanesAABB(planes, projectionBoundInLightSpace);
                characterShadowInternal.Projector.enabled = flag;
                if (flag)
                {
                    collector.Add(node);
                }
                num++;
            }
        }