示例#1
0
        /// <summary>
        /// Sets Opacity to Materials
        /// </summary>
        /// <param name="objects">Objects to set Opacity for (max 64)</param>
        protected override void SetToShader(List <OpacityObject> objects)
        {
            if (!CameraManager.Exists)
            {
                return;
            }
            Camera cam    = CameraManager.Instance.Camera;
            int    amount = Mathf.Min(objects.Count, 64);

            for (int i = 0; i < amount; i++)
            {
                OpacityObject obj = objects[i];
                cachedRad[i] = ResolutionMath.ConvertForWidth(obj.Opacity.OpacityRadius);
                // Move to ScreenSpace
                Vector3 pos = cam.WorldToScreenPoint(obj.Transform.position + (Vector3)obj.Opacity.OpacityOffset);
                cachedPos[i * 2]     = pos.x;
                cachedPos[i * 2 + 1] = pos.y;
            }
            for (int i = 0; i < materials.Length; i++)
            {
                Material mat = materials[i];
                mat.SetInt(useSeeThroughID, 1);
                mat.SetInt(seeThroughLengthID, amount);
                mat.SetFloatArray(centersID, cachedPos);
                mat.SetFloatArray(radiiID, cachedRad);
            }
        }
        /// <summary>
        /// Sets Opacity-Values to Shader
        /// </summary>
        /// <param name="objects">List of Objects to handle</param>
        protected override void SetToShader(List <OpacityObject> objects)
        {
            if (!CameraManager.Exists)
            {
                return; // No active Camera
            }
            Camera cam    = CameraManager.Instance.Camera;
            int    amount = objects.Count > 4 ? 4 : objects.Count;

            Vector4 vec = new Vector4(), vec2 = new Vector4(), radius = new Vector4();

            for (int i = 0; i < amount; i++)
            {
                OpacityObject obj       = objects[i];
                Vector3       screenPos = cam.WorldToScreenPoint(obj.Transform.position + (Vector3)obj.Opacity.OpacityOffset);
                Vector4       v         = i < 2 ? vec : vec2;
                if (i % 2 == 0) // Even indices
                {
                    v.x = screenPos.x;
                    v.y = screenPos.y;
                }
                else // i % 2 == 1 Odd indices
                {
                    v.z = screenPos.x;
                    v.w = screenPos.y;
                }
                if (i < 2) // Set to vector (reference)
                {
                    vec = v;
                }
                else
                {
                    vec2 = v;
                }
                radius[i] = ResolutionMath.ConvertForWidth(obj.Opacity.OpacityRadius);
            }
            for (int i = 0; i < renderers.Length; i++)
            {
                MaterialPropertyBlock mpb = propertyBlocks[i];
                renderers[i].GetPropertyBlock(mpb);
                mpb.SetInt(useSeeThroughID, 1);
                mpb.SetInt(seeThroughLengthID, amount);
                mpb.SetVector(seeThroughRadiiID, radius);
                mpb.SetVector(seeThroughCenter1ID, vec);
                mpb.SetVector(seeThroughCenter2ID, vec2);
                renderers[i].SetPropertyBlock(mpb);
            }
        }