Ejemplo n.º 1
0
        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++;
            }
        }
Ejemplo n.º 2
0
        public void Init(CharacterShadowComponent characterShadow)
        {
            MyShadowInternal internal2 = characterShadow.gameObject.AddComponent <MyShadowInternal>();

            internal2.Projector      = this.CreateProjector(this.shadowCommonSettings);
            internal2.BaseAlpha      = characterShadow.color.a;
            internal2.CasterMaterial = new Material(this.shadowCommonSettings.casterShader);
            Debug.Log("Shadow System Init " + this.shadowCommonSettings.casterShader.name);
        }
Ejemplo n.º 3
0
        private void SetProjectorData(MyShadowInternal characterInternal, Vector3 position, Quaternion rotation, CharacterShadowComponent characterShadow, Rect atlasData)
        {
            Projector projector = characterInternal.Projector;
            Bounds    projectionBoundInLightSpace = characterInternal.ProjectionBoundInLightSpace;
            float     num = projectionBoundInLightSpace.size.x / projectionBoundInLightSpace.size.y;

            projector.transform.position = position;
            projector.transform.rotation = rotation;
            projector.orthographicSize   = Mathf.Max(projectionBoundInLightSpace.extents.x, projectionBoundInLightSpace.extents.y);
            projector.aspectRatio        = num;
            projector.nearClipPlane      = -projectionBoundInLightSpace.extents.z;
            projector.farClipPlane       = projectionBoundInLightSpace.extents.z + characterShadow.attenuation;
            float    num2     = projectionBoundInLightSpace.size.z + 0.01f;
            float    x        = num;
            float    y        = (num2 + characterShadow.attenuation) / num2;
            float    z        = (characterShadow.attenuation <= 0f) ? 100000f : (1f / (characterShadow.attenuation / num2));
            Material material = projector.material;

            material.SetVector("Params", new Vector4(x, y, z, (characterShadow.backFadeRange <= 0f) ? 100000f : (1f / (characterShadow.backFadeRange / num2))));
            material.mainTextureOffset = atlasData.position;
            material.mainTextureScale  = atlasData.size;
            material.color             = characterShadow.color;
        }