Exemplo n.º 1
0
        public static void GetResolveTextureSize(AlphaPacking alphaPacking, StereoPacking stereoPacking, StereoEye eyeMode, ref int width, ref int height)
        {
            switch (alphaPacking)
            {
            case AlphaPacking.LeftRight:
                width /= 2;
                break;

            case AlphaPacking.TopBottom:
                height /= 2;
                break;
            }
            if (eyeMode != StereoEye.Both)
            {
                switch (stereoPacking)
                {
                case StereoPacking.LeftRight:
                    width /= 2;
                    break;

                case StereoPacking.TopBottom:
                    height /= 2;
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public static void SetupAlphaPackedMaterial(Material material, AlphaPacking packing)
        {
            material.DisableKeyword("ALPHAPACK_TOP_BOTTOM");
            material.DisableKeyword("ALPHAPACK_LEFT_RIGHT");
            material.DisableKeyword("ALPHAPACK_NONE");
            switch (packing)
            {
            case AlphaPacking.TopBottom:
                material.EnableKeyword("ALPHAPACK_TOP_BOTTOM");
                break;

            case AlphaPacking.LeftRight:
                material.EnableKeyword("ALPHAPACK_LEFT_RIGHT");
                break;
            }
        }
Exemplo n.º 3
0
        public static void SetupAlphaPackedMaterial(Material material, AlphaPacking packing)
        {
            switch (packing)
            {
            case AlphaPacking.None:
                material.DisableKeyword(Keyword_AlphaPackTopBottom);
                material.DisableKeyword(Keyword_AlphaPackLeftRight);
                material.EnableKeyword(Keyword_AlphaPackNone);
                break;

            case AlphaPacking.TopBottom:
                material.DisableKeyword(Keyword_AlphaPackNone);
                material.DisableKeyword(Keyword_AlphaPackLeftRight);
                material.EnableKeyword(Keyword_AlphaPackTopBottom);
                break;

            case AlphaPacking.LeftRight:
                material.DisableKeyword(Keyword_AlphaPackNone);
                material.DisableKeyword(Keyword_AlphaPackTopBottom);
                material.EnableKeyword(Keyword_AlphaPackLeftRight);
                break;
            }
        }
Exemplo n.º 4
0
        public static void DrawTexture(Rect screenRect, Texture texture, ScaleMode scaleMode, AlphaPacking alphaPacking, Material material)
        {
            if (Event.current.type == EventType.Repaint)
            {
                float textureWidth  = texture.width;
                float textureHeight = texture.height;
                switch (alphaPacking)
                {
                case AlphaPacking.LeftRight:
                    textureWidth *= 0.5f;
                    break;

                case AlphaPacking.TopBottom:
                    textureHeight *= 0.5f;
                    break;
                }

                float aspectRatio = (float)textureWidth / (float)textureHeight;
                Rect  sourceRect  = new Rect(0f, 0f, 1f, 1f);
                switch (scaleMode)
                {
                case ScaleMode.ScaleAndCrop:
                {
                    float screenRatio = screenRect.width / screenRect.height;
                    if (screenRatio > aspectRatio)
                    {
                        float adjust = aspectRatio / screenRatio;
                        sourceRect = new Rect(0f, (1f - adjust) * 0.5f, 1f, adjust);
                    }
                    else
                    {
                        float adjust = screenRatio / aspectRatio;
                        sourceRect = new Rect(0.5f - adjust * 0.5f, 0f, adjust, 1f);
                    }
                }
                break;

                case ScaleMode.ScaleToFit:
                {
                    float screenRatio = screenRect.width / screenRect.height;
                    if (screenRatio > aspectRatio)
                    {
                        float adjust = aspectRatio / screenRatio;
                        screenRect = new Rect(screenRect.xMin + screenRect.width * (1f - adjust) * 0.5f, screenRect.yMin, adjust * screenRect.width, screenRect.height);
                    }
                    else
                    {
                        float adjust = screenRatio / aspectRatio;
                        screenRect = new Rect(screenRect.xMin, screenRect.yMin + screenRect.height * (1f - adjust) * 0.5f, screenRect.width, adjust * screenRect.height);
                    }
                }
                break;

                case ScaleMode.StretchToFill:
                    break;
                }

                Graphics.DrawTexture(screenRect, texture, sourceRect, 0, 0, 0, 0, GUI.color, material);
            }
        }
Exemplo n.º 5
0
        public static void DrawTexture(Rect destRect, Texture texture, ScaleMode scaleMode, AlphaPacking alphaPacking, Material material)
        {
            if (Event.current == null || Event.current.type == EventType.Repaint)
            {
                int sourceWidth  = texture.width;
                int sourceHeight = texture.height;
                GetResolveTextureSize(alphaPacking, StereoPacking.Unknown, StereoEye.Both, ref sourceWidth, ref sourceHeight);

                float sourceRatio = (float)sourceWidth / (float)sourceHeight;
                Rect  sourceRect  = new Rect(0f, 0f, 1f, 1f);
                switch (scaleMode)
                {
                case ScaleMode.ScaleAndCrop:
                {
                    float destRatio = destRect.width / destRect.height;
                    if (destRatio > sourceRatio)
                    {
                        float adjust = sourceRatio / destRatio;
                        sourceRect = new Rect(0f, (1f - adjust) * 0.5f, 1f, adjust);
                    }
                    else
                    {
                        float adjust = destRatio / sourceRatio;
                        sourceRect = new Rect(0.5f - adjust * 0.5f, 0f, adjust, 1f);
                    }
                }
                break;

                case ScaleMode.ScaleToFit:
                {
                    float destRatio = destRect.width / destRect.height;
                    if (destRatio > sourceRatio)
                    {
                        float adjust = sourceRatio / destRatio;
                        destRect = new Rect(destRect.xMin + destRect.width * (1f - adjust) * 0.5f, destRect.yMin, adjust * destRect.width, destRect.height);
                    }
                    else
                    {
                        float adjust = destRatio / sourceRatio;
                        destRect = new Rect(destRect.xMin, destRect.yMin + destRect.height * (1f - adjust) * 0.5f, destRect.width, adjust * destRect.height);
                    }
                }
                break;

                case ScaleMode.StretchToFill:
                    break;
                }

                GL.PushMatrix();
                if (RenderTexture.active == null)
                {
                    //GL.LoadPixelMatrix();
                    GL.LoadPixelMatrix(0f, Screen.width, Screen.height, 0f);
                }
                else
                {
                    GL.LoadPixelMatrix(0f, RenderTexture.active.width, RenderTexture.active.height, 0f);
                }
                Graphics.DrawTexture(destRect, texture, sourceRect, 0, 0, 0, 0, GUI.color, material);
                GL.PopMatrix();
            }
        }
Exemplo n.º 6
0
        internal static void SetupMaterial(Material material, bool flipVertically, bool playerSupportsLinear, Matrix4x4 ycbcrTransform, Texture ycbcrTexture = null, float[] textureTransform = null,
                                           VideoMapping mapping = VideoMapping.Normal, StereoPacking stereoPacking = StereoPacking.None, AlphaPacking alphaPacking = AlphaPacking.None)
        {
            SetupVerticalFlipMaterial(material, flipVertically);

            // Apply changes for layout
            if (material.HasProperty(VideoRender.PropLayout.Id))
            {
                VideoRender.SetupLayoutMaterial(material, mapping);
            }

            // Apply changes for stereo videos
            if (material.HasProperty(VideoRender.PropStereo.Id))
            {
                VideoRender.SetupStereoMaterial(material, stereoPacking);
            }

            // Apply changes for alpha videos
            if (material.HasProperty(VideoRender.PropAlphaPack.Id))
            {
                VideoRender.SetupAlphaPackedMaterial(material, alphaPacking);
            }

            // Apply gamma correction
                        #if UNITY_PLATFORM_SUPPORTS_LINEAR
            if (material.HasProperty(VideoRender.PropApplyGamma.Id))
            {
                VideoRender.SetupGammaMaterial(material, playerSupportsLinear);
            }
                        #endif

            // Adjust for cropping (when the decoder decodes in blocks that overrun the video frame size, it pads), OES only as we apply this lower down for none-OES
                        #if (!UNITY_EDITOR && UNITY_ANDROID)
// STE: HasProperty doesn't work on Matrix'
//			if (material.HasProperty(VideoRender.PropTextureMatrix.Id))
            {
                VideoRender.SetupTextureMatrix(material, textureTransform);
            }
                        #endif

                        #if UNITY_PLATFORM_SUPPORTS_YPCBCR
            VideoRender.SetupYpCbCrMaterial(material, ycbcrTexture != null, ycbcrTransform, ycbcrTexture);
                        #endif
        }
Exemplo n.º 7
0
        public static void DrawTexture(Rect screenRect, Texture texture, ScaleMode scaleMode, AlphaPacking alphaPacking, Material material)
        {
            if (Event.current.type == EventType.Repaint)
            {
                float num  = (float)texture.width;
                float num2 = (float)texture.height;
                switch (alphaPacking)
                {
                case AlphaPacking.LeftRight:
                    num *= 0.5f;
                    break;

                case AlphaPacking.TopBottom:
                    num2 *= 0.5f;
                    break;
                }
                float num3       = num / num2;
                Rect  sourceRect = new Rect(0f, 0f, 1f, 1f);
                switch (scaleMode)
                {
                case ScaleMode.ScaleAndCrop:
                {
                    float num7 = screenRect.width / screenRect.height;
                    if (num7 > num3)
                    {
                        float num8 = num3 / num7;
                        sourceRect = new Rect(0f, (1f - num8) * 0.5f, 1f, num8);
                    }
                    else
                    {
                        float num9 = num7 / num3;
                        sourceRect = new Rect(0.5f - num9 * 0.5f, 0f, num9, 1f);
                    }
                    break;
                }

                case ScaleMode.ScaleToFit:
                {
                    float num4 = screenRect.width / screenRect.height;
                    if (num4 > num3)
                    {
                        float num5 = num3 / num4;
                        screenRect = new Rect(screenRect.xMin + screenRect.width * (1f - num5) * 0.5f, screenRect.yMin, num5 * screenRect.width, screenRect.height);
                    }
                    else
                    {
                        float num6 = num4 / num3;
                        screenRect = new Rect(screenRect.xMin, screenRect.yMin + screenRect.height * (1f - num6) * 0.5f, screenRect.width, num6 * screenRect.height);
                    }
                    break;
                }
                }
                Graphics.DrawTexture(screenRect, texture, sourceRect, 0, 0, 0, 0, GUI.color, material);
            }
        }