Example #1
0
        private void ApplyMapping(Texture texture, bool requiresYFlip, int plane = 0)
        {
            if (_material != null)
            {
                _isDirty = false;

                if (plane == 0)
                {
                    if (string.IsNullOrEmpty(_texturePropertyName))
                    {
                        _material.mainTexture = texture;
                        _lastTextureApplied   = texture;

                        if (texture != null)
                        {
                            if (requiresYFlip)
                            {
                                _material.mainTextureScale  = new Vector2(_scale.x, -_scale.y);
                                _material.mainTextureOffset = Vector2.up + _offset;
                            }
                            else
                            {
                                _material.mainTextureScale  = _scale;
                                _material.mainTextureOffset = _offset;
                            }
                        }
                    }
                    else
                    {
#if UNITY_5_6_OR_NEWER
                        _material.SetTexture(_propTexture, texture);
#else
                        _material.SetTexture(_texturePropertyName, texture);
#endif
                        _lastTextureApplied = texture;

                        if (texture != null)
                        {
                            if (requiresYFlip)
                            {
                                _material.SetTextureScale(_texturePropertyName, new Vector2(_scale.x, -_scale.y));
                                _material.SetTextureOffset(_texturePropertyName, Vector2.up + _offset);
                            }
                            else
                            {
                                _material.SetTextureScale(_texturePropertyName, _scale);
                                _material.SetTextureOffset(_texturePropertyName, _offset);
                            }
                        }
                    }
                }
                else if (plane == 1)
                {
                    if (_material.HasProperty(_propUseYpCbCr))
                    {
                        _material.EnableKeyword("USE_YPCBCR");
                    }
                    if (_material.HasProperty(_propChromaTex))
                    {
                        _material.SetTexture(_propChromaTex, texture);
                        _material.SetMatrix(_propYpCbCrTransform, _media.TextureProducer.GetYpCbCrTransform());
                        if (texture != null)
                        {
                                                        #if UNITY_5_6_OR_NEWER
                            if (requiresYFlip)
                            {
                                _material.SetTextureScale(_propChromaTex, new Vector2(_scale.x, -_scale.y));
                                _material.SetTextureOffset(_propChromaTex, Vector2.up + _offset);
                            }
                            else
                            {
                                _material.SetTextureScale(_propChromaTex, _scale);
                                _material.SetTextureOffset(_propChromaTex, _offset);
                            }
                                                        #else
                            if (requiresYFlip)
                            {
                                _material.SetTextureScale(PropChromaTexName, new Vector2(_scale.x, -_scale.y));
                                _material.SetTextureOffset(PropChromaTexName, Vector2.up + _offset);
                            }
                            else
                            {
                                _material.SetTextureScale(PropChromaTexName, _scale);
                                _material.SetTextureOffset(PropChromaTexName, _offset);
                            }
                                                        #endif
                        }
                    }
                }

                if (_media != null)
                {
                    // Apply changes for layout
                    if (_material.HasProperty(_propLayout))
                    {
                        Helper.SetupLayoutMaterial(_material, _media.VideoLayoutMapping);
                    }
                    // Apply changes for stereo videos
                    if (_material.HasProperty(_propStereo))
                    {
                        Helper.SetupStereoMaterial(_material, _media.m_StereoPacking, _media.m_DisplayDebugStereoColorTint);
                    }
                    // Apply changes for alpha videos
                    if (_material.HasProperty(_propAlphaPack))
                    {
                        Helper.SetupAlphaPackedMaterial(_material, _media.m_AlphaPacking);
                    }
#if UNITY_PLATFORM_SUPPORTS_LINEAR
                    // Apply gamma
                    if (_material.HasProperty(_propApplyGamma) && _media.Info != null)
                    {
                        Helper.SetupGammaMaterial(_material, _media.Info.PlayerSupportsLinearColorSpace());
                    }
#else
                    _propApplyGamma |= 0;
#endif
                }
            }
        }
Example #2
0
        // We do a LateUpdate() to allow for any changes in the texture that may have happened in Update()
        void LateUpdate()
        {
            if (_setNativeSize)
            {
                SetNativeSize();
            }

            if (_lastTexture != mainTexture)
            {
                _lastTexture = mainTexture;
                SetVerticesDirty();
                SetMaterialDirty();
            }

            if (HasValidTexture())
            {
                if (mainTexture != null)
                {
                    if (mainTexture.width != _lastWidth || mainTexture.height != _lastHeight)
                    {
                        _lastWidth  = mainTexture.width;
                        _lastHeight = mainTexture.height;
                        SetVerticesDirty();
                        SetMaterialDirty();
                    }
                }
            }

            if (!_userMaterial && Application.isPlaying)
            {
                UpdateInternalMaterial();
            }

            if (material != null && _mediaPlayer != null)
            {
                // YpCbCr support
                if (material.HasProperty(_propUseYpCbCr) && _mediaPlayer.TextureProducer != null && _mediaPlayer.TextureProducer.GetTextureCount() == 2)
                {
                    material.EnableKeyword("USE_YPCBCR");
                    Texture resamplerTex = _mediaPlayer.FrameResampler == null || _mediaPlayer.FrameResampler.OutputTexture == null ? null : _mediaPlayer.FrameResampler.OutputTexture[1];
                    material.SetTexture(_propChromaTex, _mediaPlayer.m_Resample ? resamplerTex : _mediaPlayer.TextureProducer.GetTexture(1));
                }

                // Apply changes for alpha videos
                if (material.HasProperty(_propAlphaPack))
                {
                    Helper.SetupAlphaPackedMaterial(material, _mediaPlayer.m_AlphaPacking);

                    if (_flipY && _mediaPlayer.m_AlphaPacking != AlphaPacking.None)
                    {
                        material.SetFloat(_propVertScale, -1f);
                    }
                    else
                    {
                        material.SetFloat(_propVertScale, 1f);
                    }

#if UNITY_UGUI_NOSET_TEXELSIZE
                    if (mainTexture != null)
                    {
                        material.SetVector(_propMainTextureTexelSize, new Vector4(1.0f / mainTexture.width, 1.0f / mainTexture.height, mainTexture.width, mainTexture.height));
                    }
#endif
                }

                // Apply changes for stereo videos
                if (material.HasProperty(_propStereo))
                {
                    Helper.SetupStereoMaterial(material, _mediaPlayer.m_StereoPacking, _mediaPlayer.m_DisplayDebugStereoColorTint);
                }
#if UNITY_PLATFORM_SUPPORTS_LINEAR
                if (material.HasProperty(_propApplyGamma) && _mediaPlayer.Info != null)
                {
                    Helper.SetupGammaMaterial(material, _mediaPlayer.Info.PlayerSupportsLinearColorSpace());
                }
#else
                _propApplyGamma |= 0;
#endif
            }
        }
Example #3
0
        // We do a LateUpdate() to allow for any changes in the texture that may have happened in Update()
        void LateUpdate()
        {
            if (_setNativeSize)
            {
                SetNativeSize();
            }

            if (_lastTexture != mainTexture)
            {
                _lastTexture = mainTexture;
                SetVerticesDirty();
            }

            if (HasValidTexture())
            {
                if (mainTexture != null)
                {
                    if (mainTexture.width != _lastWidth || mainTexture.height != _lastHeight)
                    {
                        _lastWidth  = mainTexture.width;
                        _lastHeight = mainTexture.height;
                        SetVerticesDirty();
                    }
                }
            }

            if (!_userMaterial && Application.isPlaying)
            {
                UpdateInternalMaterial();
            }

            if (material != null && _mediaPlayer != null)
            {
                // Apply changes for alpha videos
                if (material.HasProperty(_propAlphaPack))
                {
                    Helper.SetupAlphaPackedMaterial(material, _mediaPlayer.m_AlphaPacking);

                    if (_flipY && _mediaPlayer.m_AlphaPacking != AlphaPacking.None)
                    {
                        material.SetFloat(_propVertScale, -1f);
                    }
                    else
                    {
                        material.SetFloat(_propVertScale, 1f);
                    }

#if UNITY_UGUI_NOSET_TEXELSIZE
                    if (mainTexture != null)
                    {
                        material.SetVector(_propMainTextureTexelSize, new Vector4(1.0f / mainTexture.width, 1.0f / mainTexture.height, mainTexture.width, mainTexture.height));
                    }
#endif
                }

                // Apply changes for stereo videos
                if (material.HasProperty(_propStereo))
                {
                    Helper.SetupStereoMaterial(material, _mediaPlayer.m_StereoPacking, _mediaPlayer.m_DisplayDebugStereoColorTint);
                }
#if UNITY_PLATFORM_SUPPORTS_LINEAR
                if (material.HasProperty(_propApplyGamma) && _mediaPlayer.Info != null)
                {
                    Helper.SetupGammaMaterial(material, _mediaPlayer.Info.PlayerSupportsLinearColorSpace());
                }
#else
                _propApplyGamma |= 0;
#endif
            }

            SetMaterialDirty();
        }