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
                            }
                        }
                    }
                }
            }
        }
        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;
#endif
                            }
                        }
                    }
                }
            }
        }
Exemple #3
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 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
                }
            }
        }