private void ApplyMapping(Texture texture, bool requiresYFlip)
        {
            if (_mesh != null && _mesh.materials != null)
            {
                for (int i = 0; i < _mesh.materials.Length; i++)
                {
                    Material mat = _mesh.materials[i];
                    if (mat != null)
                    {
                        mat.mainTexture = texture;

                        if (texture != null)
                        {
                            if (requiresYFlip)
                            {
                                mat.mainTextureScale  = new Vector2(_scale.x, -_scale.y);
                                mat.mainTextureOffset = Vector2.up + _offset;
                            }
                            else
                            {
                                mat.mainTextureScale  = _scale;
                                mat.mainTextureOffset = _offset;
                            }
                        }

                        // Apply changes for stereo videos
                        if (mat.shader.name == "Unlit/InsideSphere" && _media != null)
                        {
                            Helper.SetupStereoMaterial(mat, _media.m_StereoPacking, _media.m_DisplayDebugStereoColorTint);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void ApplyMapping(Texture texture, bool requiresYFlip)
        {
            if (_mesh != null)
            {
                _lastTextureApplied = texture;
                _isDirty            = false;

                Material[] meshMaterials = _mesh.materials;
                if (meshMaterials != null)
                {
                    for (int i = 0; i < meshMaterials.Length; i++)
                    {
                        Material mat = meshMaterials[i];
                        if (mat != null)
                        {
                            mat.mainTexture = texture;

                            if (texture != null)
                            {
                                if (requiresYFlip)
                                {
                                    mat.mainTextureScale  = new Vector2(_scale.x, -_scale.y);
                                    mat.mainTextureOffset = Vector2.up + _offset;
                                }
                                else
                                {
                                    mat.mainTextureScale  = _scale;
                                    mat.mainTextureOffset = _offset;
                                }
                            }


                            if (_media != null)
                            {
                                // Apply changes for stereo videos
                                if (mat.HasProperty(_propStereo))
                                {
                                    Helper.SetupStereoMaterial(mat, _media.m_StereoPacking, _media.m_DisplayDebugStereoColorTint);
                                }
                                // Apply changes for alpha videos
                                if (mat.HasProperty(_propAlphaPack))
                                {
                                    Helper.SetupAlphaPackedMaterial(mat, _media.m_AlphaPacking);
                                }
#if UNITY_PLATFORM_SUPPORTS_LINEAR
                                // Apply gamma
                                if (mat.HasProperty(_propApplyGamma) && _media.Info != null)
                                {
                                    Helper.SetupGammaMaterial(mat, _media.Info.PlayerSupportsLinearColorSpace());
                                }
#else
                                _propApplyGamma |= 0;
#endif
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        // We do a LateUpdate() to allow for any changes in the texture that may have happened in Update()
        void LateUpdate()
        {
            if (Application.isPlaying)
            {
                Texture texture = null;
                bool    requiresVerticalFlip = false;
                if (_mediaPlayer != null && _mediaPlayer.Control != null)
                {
                    if (_mediaPlayer.TextureProducer != null)
                    {
                        Texture resamplerTex = _mediaPlayer.FrameResampler == null || _mediaPlayer.FrameResampler.OutputTexture == null ? null : _mediaPlayer.FrameResampler.OutputTexture[0];
                        texture = _mediaPlayer.m_Resample ? resamplerTex : _mediaPlayer.TextureProducer.GetTexture();
                        requiresVerticalFlip = _mediaPlayer.TextureProducer.RequiresVerticalFlip();

                        // Detect changes that we need to apply to the material/mesh
                        if (_texture != texture ||
                            _verticalFlip != requiresVerticalFlip ||
                            (texture != null && (_textureWidth != texture.width || _textureHeight != texture.height))
                            )
                        {
                            _texture = texture;
                            if (texture != null)
                            {
                                UpdateMeshUV(texture.width, texture.height, requiresVerticalFlip);
                            }
                        }

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

                        if (_renderer.material.HasProperty(_propUseYpCbCr) && _mediaPlayer.TextureProducer.GetTextureCount() == 2)
                        {
                            _renderer.material.EnableKeyword("USE_YPCBCR");
                            Texture resamplerTexYCRCB = _mediaPlayer.FrameResampler == null || _mediaPlayer.FrameResampler.OutputTexture == null ? null : _mediaPlayer.FrameResampler.OutputTexture[1];
                            _renderer.material.SetTexture(_propChromaTex, _mediaPlayer.m_Resample ? resamplerTexYCRCB : _mediaPlayer.TextureProducer.GetTexture(1));
                            _renderer.material.SetMatrix(_propYpCbCrTransform, _mediaPlayer.TextureProducer.GetYpCbCrTransform());
                        }
                    }

                    _renderer.material.mainTexture = _texture;
                }
                else
                {
                    _renderer.material.mainTexture = null;
                }
            }
        }
Ejemplo n.º 4
0
        private void ApplyMapping(Texture texture, bool requiresYFlip)
        {
            if (_material != null)
            {
                if (string.IsNullOrEmpty(_texturePropertyName))
                {
                    _material.mainTexture = 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
                {
                    _material.SetTexture(_texturePropertyName, 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);
                        }
                    }
                }

                if (_media != null)
                {
                    // 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);
                    }
                }
            }
        }
 private void ApplyMapping(Texture texture, bool requiresYFlip)
 {
     if (_material != null)
     {
         if (string.IsNullOrEmpty(_texturePropertyName))
         {
             _material.mainTexture = texture;
             if (texture != null)
             {
                 if (requiresYFlip)
                 {
                     _material.mainTextureScale  = new Vector2(_scale.x, 0f - _scale.y);
                     _material.mainTextureOffset = Vector2.up + _offset;
                 }
                 else
                 {
                     _material.mainTextureScale  = _scale;
                     _material.mainTextureOffset = _offset;
                 }
             }
         }
         else
         {
             _material.SetTexture(_texturePropertyName, texture);
             if (texture != null)
             {
                 if (requiresYFlip)
                 {
                     _material.SetTextureScale(_texturePropertyName, new Vector2(_scale.x, 0f - _scale.y));
                     _material.SetTextureOffset(_texturePropertyName, Vector2.up + _offset);
                 }
                 else
                 {
                     _material.SetTextureScale(_texturePropertyName, _scale);
                     _material.SetTextureOffset(_texturePropertyName, _offset);
                 }
             }
         }
         if (_media != null)
         {
             if (_material.HasProperty(_propStereo))
             {
                 Helper.SetupStereoMaterial(_material, _media.m_StereoPacking, _media.m_DisplayDebugStereoColorTint);
             }
             if (_material.HasProperty(_propAlphaPack))
             {
                 Helper.SetupAlphaPackedMaterial(_material, _media.m_AlphaPacking);
             }
             if (_material.HasProperty(_propApplyGamma) && _media.Info != null)
             {
                 Helper.SetupGammaMaterial(_material, _media.Info.PlayerSupportsLinearColorSpace());
             }
         }
     }
 }
Ejemplo n.º 6
0
 private void LateUpdate()
 {
     if (_setNativeSize)
     {
         SetNativeSize();
     }
     if (_lastTexture != mainTexture)
     {
         _lastTexture = mainTexture;
         SetVerticesDirty();
     }
     if (HasValidTexture() && mainTexture != null && (mainTexture.width != _lastWidth || mainTexture.height != _lastHeight))
     {
         _lastWidth  = mainTexture.width;
         _lastHeight = mainTexture.height;
         SetVerticesDirty();
     }
     if (!_userMaterial && Application.isPlaying)
     {
         UpdateInternalMaterial();
     }
     if (material != null && _mediaPlayer != null)
     {
         if (material.HasProperty(_propAlphaPack))
         {
             Helper.SetupAlphaPackedMaterial(material, _mediaPlayer.m_AlphaPacking);
             if (_flipY && _mediaPlayer.m_AlphaPacking != 0)
             {
                 material.SetFloat(_propVertScale, -1f);
             }
             else
             {
                 material.SetFloat(_propVertScale, 1f);
             }
         }
         if (material.HasProperty(_propStereo))
         {
             Helper.SetupStereoMaterial(material, _mediaPlayer.m_StereoPacking, _mediaPlayer.m_DisplayDebugStereoColorTint);
         }
         if (material.HasProperty(_propApplyGamma) && _mediaPlayer.Info != null)
         {
             Helper.SetupGammaMaterial(material, _mediaPlayer.Info.PlayerSupportsLinearColorSpace());
         }
     }
     SetMaterialDirty();
 }
Ejemplo n.º 7
0
		private void ApplyMapping(Texture texture, bool requiresYFlip)
		{
			if (_mesh != null)
			{
				Material[] materials = _mesh.materials;
				if (materials != null)
				{
					foreach (Material material in materials)
					{
						if (material != null)
						{
							material.mainTexture = texture;
							if (texture != null)
							{
								if (requiresYFlip)
								{
									material.mainTextureScale = new Vector2(_scale.x, 0f - _scale.y);
									material.mainTextureOffset = Vector2.up + _offset;
								}
								else
								{
									material.mainTextureScale = _scale;
									material.mainTextureOffset = _offset;
								}
							}
							if (_media != null)
							{
								if (material.HasProperty(_propStereo))
								{
									Helper.SetupStereoMaterial(material, _media.m_StereoPacking, _media.m_DisplayDebugStereoColorTint);
								}
								if (material.HasProperty(_propAlphaPack))
								{
									Helper.SetupAlphaPackedMaterial(material, _media.m_AlphaPacking);
								}
								if (material.HasProperty(_propApplyGamma) && _media.Info != null)
								{
									Helper.SetupGammaMaterial(material, _media.Info.PlayerSupportsLinearColorSpace());
								}
							}
						}
					}
				}
			}
		}
Ejemplo n.º 8
0
        private void ApplyMapping(Texture texture, bool requiresYFlip)
        {
            if (_mesh != null && _mesh.materials != null)
            {
                for (int i = 0; i < _mesh.materials.Length; i++)
                {
                    Material mat = _mesh.materials[i];
                    if (mat != null)
                    {
                        mat.mainTexture = texture;

                        if (texture != null)
                        {
                            if (requiresYFlip)
                            {
                                mat.mainTextureScale  = new Vector2(_scale.x, -_scale.y);
                                mat.mainTextureOffset = Vector2.up + _offset;
                            }
                            else
                            {
                                mat.mainTextureScale  = _scale;
                                mat.mainTextureOffset = _offset;
                            }
                        }


                        if (_media != null)
                        {
                            // Apply changes for stereo videos
                            if (mat.HasProperty(_propStereo))
                            {
                                Helper.SetupStereoMaterial(mat, _media.m_StereoPacking, _media.m_DisplayDebugStereoColorTint);
                            }
                            // Apply changes for alpha videos
                            if (mat.HasProperty(_propAlphaPack))
                            {
                                Helper.SetupAlphaPackedMaterial(mat, _media.m_AlphaPacking);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
        private void ApplyMapping(Texture texture, bool requiresYFlip, int plane = 0)
        {
            if (_mesh != null)
            {
                _isDirty = false;

                Material[] meshMaterials = _mesh.materials;
                if (meshMaterials != null)
                {
                    for (int i = 0; i < meshMaterials.Length; i++)
                    {
                        Material mat = meshMaterials[i];
                        if (mat != null)
                        {
                            if (plane == 0)
                            {
#if UNITY_5_6_OR_NEWER
                                mat.SetTexture(_propTexture, texture);
#else
                                mat.SetTexture(_texturePropertyName, texture);
#endif

                                _lastTextureApplied = texture;

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

                            if (_media != null)
                            {
                                // Apply changes for stereo videos
                                if (mat.HasProperty(_propStereo))
                                {
                                    Helper.SetupStereoMaterial(mat, _media.m_StereoPacking, _media.m_DisplayDebugStereoColorTint);
                                }
                                // Apply changes for alpha videos
                                if (mat.HasProperty(_propAlphaPack))
                                {
                                    Helper.SetupAlphaPackedMaterial(mat, _media.m_AlphaPacking);
                                }
#if UNITY_PLATFORM_SUPPORTS_LINEAR
                                // Apply gamma
                                if (mat.HasProperty(_propApplyGamma) && _media.Info != null)
                                {
                                    Helper.SetupGammaMaterial(mat, _media.Info.PlayerSupportsLinearColorSpace());
                                }
#else
                                _propApplyGamma |= 0;
#endif
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 10
0
        private void ApplyMapping(Texture texture, bool requiresYFlip, int plane = 0)
        {
            if (_material != null)
            {
                if (plane == 0)
                {
                    if (string.IsNullOrEmpty(_texturePropertyName))
                    {
                        _material.mainTexture = 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
                    {
                        _material.SetTexture(_texturePropertyName, 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);
                        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 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
                }
            }
        }
Ejemplo n.º 11
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();
        }
        private void ApplyMapping(Texture texture, bool requiresYFlip, int plane = 0)
        {
            if (_mesh != null)
            {
                _isDirty = false;

                Material[] meshMaterials = _mesh.materials;
                if (meshMaterials != null)
                {
                    for (int i = 0; i < meshMaterials.Length; i++)
                    {
                        Material mat = meshMaterials[i];
                        if (mat != null)
                        {
                            if (plane == 0)
                            {
#if UNITY_5_6_OR_NEWER
                                mat.SetTexture(_propTexture, texture);
#else
                                mat.SetTexture(_texturePropertyName, texture);
#endif

                                _lastTextureApplied = texture;

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

                            if (_media != null)
                            {
                                // Apply changes for layout
                                if (mat.HasProperty(_propLayout))
                                {
                                    Helper.SetupLayoutMaterial(mat, _media.VideoLayoutMapping);
                                }
                                // Apply changes for stereo videos
                                if (mat.HasProperty(_propStereo))
                                {
                                    Helper.SetupStereoMaterial(mat, _media.m_StereoPacking, _media.m_DisplayDebugStereoColorTint);
                                }
                                // Apply changes for alpha videos
                                if (mat.HasProperty(_propAlphaPack))
                                {
                                    Helper.SetupAlphaPackedMaterial(mat, _media.m_AlphaPacking);
                                }
#if UNITY_PLATFORM_SUPPORTS_LINEAR
                                // Apply gamma
                                if (mat.HasProperty(_propApplyGamma))
                                {
                                    if (texture == _defaultTexture || _media.Info == null)
                                    {
                                        Helper.SetupGammaMaterial(mat, true);
                                    }
                                    else
                                    {
                                        Helper.SetupGammaMaterial(mat, _media.Info.PlayerSupportsLinearColorSpace());
                                    }
                                }
#else
                                _propApplyGamma |= 0;                                   // Prevent compiler warning about unused variable
#endif

#if (!UNITY_EDITOR && UNITY_ANDROID)
                                // 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 (_media.PlatformOptionsAndroid.useFastOesPath &&
                                    _media.Info != null &&
                                    mat.HasProperty(_propCroppingScalars))
                                {
                                    float[] transform = _media.Info.GetTextureTransform();
                                    if (transform != null)
                                    {
                                        mat.SetVector(_propCroppingScalars, new Vector4(transform[0], transform[3], 1.0f, 1.0f));
                                    }
                                }
#else
                                _propCroppingScalars |= 0;                                      // Prevent compiler warning about unused variable
#endif
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 13
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");
                    material.SetMatrix(_propYpCbCrTransform, _mediaPlayer.TextureProducer.GetYpCbCrTransform());
                    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
            }
        }
Ejemplo n.º 14
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");
                    material.SetMatrix(_propYpCbCrTransform, _mediaPlayer.TextureProducer.GetYpCbCrTransform());
                    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;                   // Prevent compiler warning about unused variable
#endif

#if (!UNITY_EDITOR && UNITY_ANDROID)
                // 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 (_mediaPlayer.PlatformOptionsAndroid.useFastOesPath &&
                    _mediaPlayer.Info != null &&
                    material.HasProperty(_propCroppingScalars))
                {
                    float[] transform = _mediaPlayer.Info.GetTextureTransform();
                    if (transform != null)
                    {
                        material.SetVector(_propCroppingScalars, new Vector4(transform[0], transform[3], 1.0f, 1.0f));
                    }
                }
#else
                _propCroppingScalars |= 0;                      // Prevent compiler warning about unused variable
#endif
            }
        }