private void SetupReflectionTexture(Camera camera)
        {
            if (!camera)
            {
                return;
            }

            float scaleRatio = UnityEngine.Rendering.Universal.UniversalRenderPipeline.asset.renderScale * GetScaleValue();

            int width  = (int)(camera.pixelWidth * scaleRatio);
            int height = (int)(camera.pixelHeight * scaleRatio);

            if (m_reflectionRT)
            {
                if ((m_reflectionRT.width == width) && (m_reflectionRT.height == height))
                {
                    return;
                }
                else
                {
                    RenderTexture.ReleaseTemporary(m_reflectionRT);
                    m_reflectionRT = null;
                }
            }
            const bool useHdr10 = true;
            const RenderTextureFormat hdrFormat = useHdr10 ? RenderTextureFormat.RGB111110Float : RenderTextureFormat.DefaultHDR;

            //m_reflectionRT = RenderTexture.GetTemporary(width, height, 16, RenderTextureFormat.ARGB32);
            m_reflectionRT = RenderTexture.GetTemporary(width, height, 16, GraphicsFormatUtility.GetGraphicsFormat(hdrFormat, true));
        }
Пример #2
0
 static public bool TextureHasAlpha(Texture2D inTex)
 {
     if (inTex != null)
     {
         return(GraphicsFormatUtility.HasAlphaChannel(GraphicsFormatUtility.GetGraphicsFormat(inTex.format, true)));
     }
     return(false);
 }
 static bool IsRenderTextureFormatSupportedForLinearFiltering(RenderTextureFormat format)
 {
         #if UNITY_2019_1_OR_NEWER
     GraphicsFormat graphicFormat = GraphicsFormatUtility.GetGraphicsFormat(format, RenderTextureReadWrite.Linear);
     return(SystemInfo.IsFormatSupported(graphicFormat, FormatUsage.Linear));
         #else
     return(format.IsSupported());
         #endif
 }
Пример #4
0
        static bool IsRenderTextureFormatSupportedForLinearFiltering(RenderTextureFormat format)
        {
#if UNITY_2019_1_OR_NEWER
            var gFormat = GraphicsFormatUtility.GetGraphicsFormat(format, RenderTextureReadWrite.Linear);
            return(SystemInfo.IsFormatSupported(gFormat, FormatUsage.Linear));
#else
            // No good/fast way to test it on pre-2019.1
            return(format.IsSupported());
#endif
        }
Пример #5
0
 private void PlanarReflectionTexture(Camera cam)
 {
     if (_reflectionTexture == null)
     {
         var        res      = ReflectionResolution(cam, UniversalRenderPipeline.asset.renderScale);
         const bool useHdr10 = true;
         const RenderTextureFormat hdrFormat = useHdr10 ? RenderTextureFormat.RGB111110Float : RenderTextureFormat.DefaultHDR;
         _reflectionTexture = RenderTexture.GetTemporary(res.x, res.y, 16,
                                                         GraphicsFormatUtility.GetGraphicsFormat(hdrFormat, true));
     }
     _reflectionCamera.targetTexture = _reflectionTexture;
 }
Пример #6
0
        public Texture3D(int width, int height, int depth, TextureFormat textureFormat, bool mipChain)
        {
            GraphicsFormat       format = GraphicsFormatUtility.GetGraphicsFormat(textureFormat, false);
            TextureCreationFlags flags  = TextureCreationFlags.None;

            if (mipChain)
            {
                flags |= TextureCreationFlags.MipChain;
            }
            if (GraphicsFormatUtility.IsCrunchFormat(textureFormat))
            {
                flags |= TextureCreationFlags.Crunch;
            }
            Internal_Create(this, width, height, depth, format, flags);
        }
Пример #7
0
        public SparseTexture(int width, int height, TextureFormat textureFormat, int mipCount, bool linear)
        {
            bool flag = !base.ValidateFormat(textureFormat);

            if (!flag)
            {
                SparseTexture.ValidateIsNotCrunched(textureFormat);
                GraphicsFormat graphicsFormat = GraphicsFormatUtility.GetGraphicsFormat(textureFormat, !linear);
                bool           flag2          = !this.ValidateSize(width, height, graphicsFormat);
                if (!flag2)
                {
                    SparseTexture.Internal_Create(this, width, height, graphicsFormat, mipCount);
                }
            }
        }
Пример #8
0
        internal Cubemap(int width, TextureFormat textureFormat, bool mipChain, IntPtr nativeTex)
        {
            GraphicsFormat       format = GraphicsFormatUtility.GetGraphicsFormat(textureFormat, false);
            TextureCreationFlags flags  = TextureCreationFlags.None;

            if (mipChain)
            {
                flags |= TextureCreationFlags.MipChain;
            }
            if (GraphicsFormatUtility.IsCrunchFormat(textureFormat))
            {
                flags |= TextureCreationFlags.Crunch;
            }
            Internal_Create(this, width, format, flags, nativeTex);
        }
Пример #9
0
        public CubemapArray(int width, int cubemapCount, TextureFormat textureFormat, bool mipChain, [uei.DefaultValue("false")] bool linear)
        {
            GraphicsFormat       format = GraphicsFormatUtility.GetGraphicsFormat(textureFormat, !linear);
            TextureCreationFlags flags  = TextureCreationFlags.None;

            if (mipChain)
            {
                flags |= TextureCreationFlags.MipChain;
            }
            if (GraphicsFormatUtility.IsCrunchFormat(textureFormat))
            {
                flags |= TextureCreationFlags.Crunch;
            }
            Internal_Create(this, width, cubemapCount, format, flags);
        }
Пример #10
0
        internal Texture2D(int width, int height, TextureFormat textureFormat, bool mipChain, bool linear, IntPtr nativeTex)
        {
            GraphicsFormat       format = GraphicsFormatUtility.GetGraphicsFormat(textureFormat, !linear);
            TextureCreationFlags flags  = TextureCreationFlags.None;

            if (mipChain)
            {
                flags |= TextureCreationFlags.MipChain;
            }
            if (GraphicsFormatUtility.IsCrunchFormat(textureFormat))
            {
                flags |= TextureCreationFlags.Crunch;
            }
            Internal_Create(this, width, height, format, flags, nativeTex);
        }
Пример #11
0
        public void ExecutePlanarReflections(
            ScriptableRenderContext context,
            Camera camera)
        {
            if (camera.cameraType == CameraType.Reflection)
            {
                return;
            }

            if (camera.cameraType == CameraType.Game && camera != Camera.main)
            {
                return;
            }

            GL.invertCulling   = true;
            RenderSettings.fog = false;
            var max  = QualitySettings.maximumLODLevel;
            var bias = QualitySettings.lodBias;

            QualitySettings.maximumLODLevel = 0;
            QualitySettings.lodBias         = bias / 2f;

            UpdateReflectionCamera(camera);
            m_ReflectionCamera.cameraType = camera.cameraType;

            var res = ReflectionResolution(camera, UniversalRenderPipeline.asset.renderScale);

            if (m_ReflectionTexture == null || res.x != m_ReflectionTexture.width || res.y != m_ReflectionTexture.height)
            {
                RenderTexture.ReleaseTemporary(m_ReflectionTexture);

                bool useHDR10 = camera.allowHDR;// SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.RGB111110Float);
                RenderTextureFormat hdrFormat =
                    useHDR10 ? RenderTextureFormat.RGB111110Float : RenderTextureFormat.DefaultHDR;
                m_ReflectionTexture = RenderTexture.GetTemporary(res.x, res.y, 16,
                                                                 GraphicsFormatUtility.GetGraphicsFormat(hdrFormat, true));
            }

            m_ReflectionCamera.targetTexture = m_ReflectionTexture;

            UniversalRenderPipeline.RenderSingleCamera(context, m_ReflectionCamera);

            GL.invertCulling   = false;
            RenderSettings.fog = true;
            QualitySettings.maximumLODLevel = 0;
            QualitySettings.lodBias         = bias;
            Shader.SetGlobalTexture(planarReflectionTextureID, m_ReflectionTexture);
        }
Пример #12
0
        public Texture3D(int width, int height, int depth, TextureFormat textureFormat, int mipCount)
        {
            if (!ValidateFormat(textureFormat))
            {
                return;
            }

            GraphicsFormat       format = GraphicsFormatUtility.GetGraphicsFormat(textureFormat, false);
            TextureCreationFlags flags  = (mipCount != 1) ? TextureCreationFlags.MipChain : TextureCreationFlags.None;

            if (GraphicsFormatUtility.IsCrunchFormat(textureFormat))
            {
                flags |= TextureCreationFlags.Crunch;
            }
            Internal_Create(this, width, height, depth, mipCount, format, flags);
        }
Пример #13
0
        public CubemapArray(int width, int cubemapCount, TextureFormat textureFormat, int mipCount, [uei.DefaultValue("true")] bool linear)
        {
            if (!ValidateFormat(textureFormat))
            {
                return;
            }

            GraphicsFormat       format = GraphicsFormatUtility.GetGraphicsFormat(textureFormat, !linear);
            TextureCreationFlags flags  = (mipCount != 1) ? TextureCreationFlags.MipChain : TextureCreationFlags.None;

            if (GraphicsFormatUtility.IsCrunchFormat(textureFormat))
            {
                flags |= TextureCreationFlags.Crunch;
            }
            Internal_Create(this, width, cubemapCount, mipCount, format, flags);
        }
Пример #14
0
        internal Texture2D(int width, int height, TextureFormat textureFormat, int mipCount, bool linear, IntPtr nativeTex)
        {
            if (!ValidateFormat(textureFormat))
            {
                return;
            }

            GraphicsFormat       format = GraphicsFormatUtility.GetGraphicsFormat(textureFormat, !linear);
            TextureCreationFlags flags  = (mipCount != 1) ? TextureCreationFlags.MipChain : TextureCreationFlags.None;

            if (GraphicsFormatUtility.IsCrunchFormat(textureFormat))
            {
                flags |= TextureCreationFlags.Crunch;
            }
            Internal_Create(this, width, height, mipCount, format, flags, nativeTex);
        }
Пример #15
0
        internal Texture2D(int width, int height, TextureFormat textureFormat, int mipCount, bool linear, IntPtr nativeTex)
        {
            bool flag = !base.ValidateFormat(textureFormat);

            if (!flag)
            {
                GraphicsFormat       graphicsFormat       = GraphicsFormatUtility.GetGraphicsFormat(textureFormat, !linear);
                TextureCreationFlags textureCreationFlags = (mipCount != 1) ? TextureCreationFlags.MipChain : TextureCreationFlags.None;
                bool flag2 = GraphicsFormatUtility.IsCrunchFormat(textureFormat);
                if (flag2)
                {
                    textureCreationFlags |= TextureCreationFlags.Crunch;
                }
                Texture2D.Internal_Create(this, width, height, mipCount, graphicsFormat, textureCreationFlags, nativeTex);
            }
        }
Пример #16
0
        public SparseTexture(int width, int height, TextureFormat textureFormat, int mipCount, bool linear)
        {
            if (!ValidateFormat(textureFormat))
            {
                return;
            }

            GraphicsFormat format = GraphicsFormatUtility.GetGraphicsFormat(textureFormat, !linear);

            if (!ValidateSize(width, height, format))
            {
                return;
            }

            Internal_Create(this, width, height, format, mipCount);
        }
Пример #17
0
        public Texture2DArray(int width, int height, int depth, TextureFormat textureFormat, int mipCount, [DefaultValue("true")] bool linear)
        {
            bool flag = !base.ValidateFormat(textureFormat);

            if (!flag)
            {
                GraphicsFormat       graphicsFormat       = GraphicsFormatUtility.GetGraphicsFormat(textureFormat, !linear);
                TextureCreationFlags textureCreationFlags = (mipCount != 1) ? TextureCreationFlags.MipChain : TextureCreationFlags.None;
                bool flag2 = GraphicsFormatUtility.IsCrunchFormat(textureFormat);
                if (flag2)
                {
                    textureCreationFlags |= TextureCreationFlags.Crunch;
                }
                Texture2DArray.ValidateIsNotCrunched(textureCreationFlags);
                Texture2DArray.Internal_Create(this, width, height, depth, mipCount, graphicsFormat, textureCreationFlags);
            }
        }
Пример #18
0
        internal Cubemap(int width, TextureFormat textureFormat, int mipCount, IntPtr nativeTex)
        {
            if (!ValidateFormat(textureFormat))
            {
                return;
            }

            GraphicsFormat       format = GraphicsFormatUtility.GetGraphicsFormat(textureFormat, false);
            TextureCreationFlags flags  = (mipCount != 1) ? TextureCreationFlags.MipChain : TextureCreationFlags.None;

            if (GraphicsFormatUtility.IsCrunchFormat(textureFormat))
            {
                flags |= TextureCreationFlags.Crunch;
            }

            Internal_Create(this, width, mipCount, format, flags, nativeTex);
        }
Пример #19
0
        internal Cubemap(int width, TextureFormat textureFormat, int mipCount, IntPtr nativeTex)
        {
            bool flag = !base.ValidateFormat(textureFormat);

            if (!flag)
            {
                GraphicsFormat       graphicsFormat       = GraphicsFormatUtility.GetGraphicsFormat(textureFormat, false);
                TextureCreationFlags textureCreationFlags = (mipCount != 1) ? TextureCreationFlags.MipChain : TextureCreationFlags.None;
                bool flag2 = GraphicsFormatUtility.IsCrunchFormat(textureFormat);
                if (flag2)
                {
                    textureCreationFlags |= TextureCreationFlags.Crunch;
                }
                Cubemap.ValidateIsNotCrunched(textureCreationFlags);
                Cubemap.Internal_Create(this, width, mipCount, graphicsFormat, textureCreationFlags, nativeTex);
            }
        }
Пример #20
0
    private TextureHandle CreateDepthTexture(RenderGraph graph, Camera camera)
    {
        bool colorRT_sRGB = (QualitySettings.activeColorSpace == ColorSpace.Linear);

        //Texture description
        TextureDesc colorRTDesc = new TextureDesc(camera.pixelWidth, camera.pixelHeight);

        colorRTDesc.colorFormat       = GraphicsFormatUtility.GetGraphicsFormat(RenderTextureFormat.Depth, colorRT_sRGB);
        colorRTDesc.depthBufferBits   = DepthBits.Depth24;
        colorRTDesc.msaaSamples       = MSAASamples.None;
        colorRTDesc.enableRandomWrite = false;
        colorRTDesc.clearBuffer       = true;
        colorRTDesc.clearColor        = Color.black;
        colorRTDesc.name = "Depth";

        return(graph.CreateTexture(colorRTDesc));
    }
Пример #21
0
        public Texture3D(int width, int height, int depth, TextureFormat textureFormat, int mipCount)
        {
            bool flag = !base.ValidateFormat(textureFormat);

            if (!flag)
            {
                GraphicsFormat       graphicsFormat       = GraphicsFormatUtility.GetGraphicsFormat(textureFormat, false);
                TextureCreationFlags textureCreationFlags = (mipCount != 1) ? TextureCreationFlags.MipChain : TextureCreationFlags.None;
                bool flag2 = GraphicsFormatUtility.IsCrunchFormat(textureFormat);
                if (flag2)
                {
                    textureCreationFlags |= TextureCreationFlags.Crunch;
                }
                Texture3D.ValidateIsNotCrunched(textureCreationFlags);
                Texture3D.Internal_Create(this, width, height, depth, mipCount, graphicsFormat, textureCreationFlags, IntPtr.Zero);
            }
        }
Пример #22
0
        protected override MediaStreamTrack CreateTrack()
        {
            RenderTexture rt;

            if (m_sendTexture != null)
            {
                rt = m_sendTexture;
                RenderTextureFormat supportFormat =
                    WebRTC.WebRTC.GetSupportedRenderTextureFormat(SystemInfo.graphicsDeviceType);
                GraphicsFormat graphicsFormat =
                    GraphicsFormatUtility.GetGraphicsFormat(supportFormat, RenderTextureReadWrite.Default);
                GraphicsFormat compatibleFormat = SystemInfo.GetCompatibleFormat(graphicsFormat, FormatUsage.Render);
                GraphicsFormat format           = graphicsFormat == compatibleFormat ? graphicsFormat : compatibleFormat;

                if (rt.graphicsFormat != format)
                {
                    Debug.LogWarning(
                        $"This color format:{rt.graphicsFormat} not support in unity.webrtc. Change to supported color format:{format}.");
                    rt.Release();
                    rt.graphicsFormat = format;
                    rt.Create();
                }

                m_sendTexture = rt;
            }
            else
            {
                RenderTextureFormat format =
                    WebRTC.WebRTC.GetSupportedRenderTextureFormat(SystemInfo.graphicsDeviceType);
                rt = new RenderTexture(streamingSize.x, streamingSize.y, depth, format)
                {
                    antiAliasing = antiAliasing
                };
                rt.Create();
                m_sendTexture = rt;
            }

            // The texture obtained by ScreenCapture.CaptureScreenshotIntoRenderTexture is different between OpenGL and other Graphics APIs.
            // In OpenGL, we got a texture that is not inverted, so need flip when sending.
            var isOpenGl = SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLCore ||
                           SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES2 ||
                           SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES3;

            return(new VideoStreamTrack(rt, isOpenGl));
        }
Пример #23
0
        internal static GraphicsFormat GetCompatibleFormat(RenderTextureFormat renderTextureFormat, RenderTextureReadWrite readWrite)
        {
            GraphicsFormat graphicsFormat   = GraphicsFormatUtility.GetGraphicsFormat(renderTextureFormat, readWrite);
            GraphicsFormat compatibleFormat = SystemInfo.GetCompatibleFormat(graphicsFormat, FormatUsage.Render);
            bool           flag             = graphicsFormat == compatibleFormat;
            GraphicsFormat result;

            if (flag)
            {
                result = graphicsFormat;
            }
            else
            {
                Debug.LogWarning(string.Format("'{0}' is not supported. RenderTexture::GetTemporary fallbacks to {1} format on this platform. Use 'SystemInfo.IsFormatSupported' C# API to check format support.", graphicsFormat.ToString(), compatibleFormat.ToString()));
                result = compatibleFormat;
            }
            return(result);
        }
Пример #24
0
        // private Camera camera = null;

        public void SetRT()
        {
            float scale          = (int)level;
            var   graphicsFormat = SystemInfo.GetCompatibleFormat(GraphicsFormatUtility.GetGraphicsFormat(RenderTextureFormat.Default, false), FormatUsage.MSAA8x);
            var   depthRTDesc    = new RenderTextureDescriptor((int)(Screen.width * 3), (int)(Screen.height * 3), graphicsFormat, 32);

            depthRTDesc.sRGB             = false;
            depthRTDesc.memoryless       = RenderTextureMemoryless.None;
            depthRTDesc.msaaSamples      = 8;
            depthRTDesc.autoGenerateMips = false;
            depthRTDesc.useMipMap        = false;

            QualitySettings.antiAliasing     = 8;
            QualitySettings.shadowResolution = ShadowResolution.VeryHigh;
            // SSAART =  new RenderTexture(Screen.width*scale, Screen.height*scale,-1);
            SSAART            = new RenderTexture(depthRTDesc);
            cam.targetTexture = SSAART;
            cam.allowMSAA     = true;
        }
Пример #25
0
        public Texture2DArray(int width, int height, int depth, TextureFormat textureFormat, bool mipChain, [uei.DefaultValue("false")] bool linear)
        {
            if (!ValidateFormat(textureFormat))
            {
                return;
            }

            GraphicsFormat       format = GraphicsFormatUtility.GetGraphicsFormat(textureFormat, !linear);
            TextureCreationFlags flags  = TextureCreationFlags.None;

            if (mipChain)
            {
                flags |= TextureCreationFlags.MipChain;
            }
            if (GraphicsFormatUtility.IsCrunchFormat(textureFormat))
            {
                flags |= TextureCreationFlags.Crunch;
            }
            Internal_Create(this, width, height, depth, format, flags);
        }
Пример #26
0
    public void ExecuteBeforeCameraRender(ScriptableRenderContext context, Camera camera)
    {
        if (!enabled)
        {
            return;
        }

        GL.invertCulling   = true;
        RenderSettings.fog = false;
        var max  = QualitySettings.maximumLODLevel;
        var bias = QualitySettings.lodBias;

        QualitySettings.maximumLODLevel = 1;
        QualitySettings.lodBias         = bias * 0.5f;

        UpdateReflectionCamera(camera);
        m_ReflectionCamera.cameraType = camera.cameraType;

        var res = ReflectionResolution(camera, UnityEngine.Rendering.Universal.UniversalRenderPipeline.asset.renderScale);

        if (m_ReflectionTexture == null)
        {
            bool useHDR10 = SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.RGB111110Float);
            RenderTextureFormat hdrFormat =
                useHDR10 ? RenderTextureFormat.RGB111110Float : RenderTextureFormat.DefaultHDR;
            m_ReflectionTexture = RenderTexture.GetTemporary(res.x, res.y, 16,
                                                             GraphicsFormatUtility.GetGraphicsFormat(hdrFormat, true));
            m_ReflectionTexture.useMipMap        = true;
            m_ReflectionTexture.autoGenerateMips = true;
        }

        m_ReflectionCamera.targetTexture = m_ReflectionTexture;

        UnityEngine.Rendering.Universal.UniversalRenderPipeline.RenderSingleCamera(context, m_ReflectionCamera);

        GL.invertCulling   = false;
        RenderSettings.fog = true;
        QualitySettings.maximumLODLevel = max;
        QualitySettings.lodBias         = bias;
        Shader.SetGlobalTexture(planarReflectionTextureID, m_ReflectionTexture);
    }
Пример #27
0
        void UpdateRenderTextures()
        {
            UpdateTempRenderTexture(ref tmpRenderTexture);
            var compressedFormat = GraphicsFormatUtility.GetGraphicsFormat(compressionFormat, false);

            if (savedTexture == null || settings.NeedsUpdate(graph, savedTexture, false))
            {
                if (graph.IsObjectInGraph(savedTexture))
                {
                    graph.RemoveObjectFromGraph(savedTexture);
                    Object.DestroyImmediate(savedTexture, true);
                }
                savedTexture = new Texture2D(settings.GetResolvedWidth(graph), settings.GetResolvedHeight(graph), compressedFormat, TextureCreationFlags.None)
                {
                    name = "SceneNode Rendering"
                };
                savedTexture.filterMode = settings.GetResolvedFilterMode(graph);
                savedTexture.wrapMode   = settings.GetResolvedWrapMode(graph);
                savedTexture.hideFlags  = HideFlags.NotEditable;
                graph.AddObjectToGraph(savedTexture);
            }

#if UNITY_EDITOR
            // Change texture format without touching the asset:
            if (savedTexture.graphicsFormat != compressedFormat)
            {
                if (GraphicsFormatUtility.IsCompressedFormat(compressedFormat))
                {
                    EditorUtility.CompressTexture(savedTexture, compressionFormat, TextureCompressionQuality.Best);
                }
                else
                {
                    var pixels = savedTexture.GetPixels();
                    var tmp    = new Texture2D(savedTexture.width, savedTexture.height, compressedFormat, TextureCreationFlags.None);
                    tmp.SetPixels(pixels);
                    EditorUtility.CopySerialized(tmp, savedTexture);
                    Object.DestroyImmediate(tmp);
                }
            }
#endif
        }
        // formats with higher sorting code appear first on the dropdown lists
        static uint GetSortCodeForFormat(TextureFormat fmt)
        {
            var f = GraphicsFormatUtility.GetGraphicsFormat(fmt, false);

            // first by: normalized, floating point, integer
            uint type;

            if (GraphicsFormatUtility.IsNormFormat(f))
            {
                type = 3;
            }
            else if (GraphicsFormatUtility.IsHalfFormat(f) || GraphicsFormatUtility.IsFloatFormat(f))
            {
                type = 2;
            }
            else if (GraphicsFormatUtility.IsIntegerFormat(f))
            {
                type = 1;
            }
            else
            {
                type = 0;
            }

            // then by component count: RGBA, RGB, RG, R/A
            var components = GraphicsFormatUtility.GetComponentCount(f);

            // then compression: first compressed regular, then compressed Crunch, then uncompressed
            uint compression = 0;

            if (GraphicsFormatUtility.IsCompressedFormat(f))
            {
                compression++;
                if (!GraphicsFormatUtility.IsCrunchFormat(fmt))
                {
                    compression++;
                }
            }

            return((type << 24) | (components << 16) | (compression << 8));
        }
Пример #29
0
        public void ExecuteBeforeCameraRender(
            LightweightRenderPipeline pipelineInstance,
            ScriptableRenderContext context,
            Camera camera)
        {
            if (!enabled)
            {
                return;
            }

            GL.invertCulling   = true;
            RenderSettings.fog = false;
            var max  = QualitySettings.maximumLODLevel;
            var bias = QualitySettings.lodBias;

            QualitySettings.maximumLODLevel = 1;
            QualitySettings.lodBias         = bias * 0.5f;

            UpdateReflectionCamera(camera);

            var res = ReflectionResolution(camera, LightweightRenderPipeline.asset.renderScale);

            if (m_ReflectionTexture == null)
            {
                m_ReflectionTexture = RenderTexture.GetTemporary(res.x, res.y, 16,
                                                                 GraphicsFormatUtility.GetGraphicsFormat(RenderTextureFormat.RGB111110Float, true));
            }


            m_ReflectionCamera.targetTexture = m_ReflectionTexture;

            LightweightRenderPipeline.RenderSingleCamera(pipelineInstance, context, m_ReflectionCamera);

            GL.invertCulling   = false;
            RenderSettings.fog = true;
            QualitySettings.maximumLODLevel = max;
            QualitySettings.lodBias         = bias;
            Shader.SetGlobalTexture(planarReflectionTextureID, m_ReflectionTexture);
        }
Пример #30
0
        protected override MediaStreamTrack CreateTrack()
        {
            RenderTexture rt;

            if (m_camera.targetTexture != null)
            {
                rt = m_camera.targetTexture;
                RenderTextureFormat supportFormat    = WebRTC.WebRTC.GetSupportedRenderTextureFormat(SystemInfo.graphicsDeviceType);
                GraphicsFormat      graphicsFormat   = GraphicsFormatUtility.GetGraphicsFormat(supportFormat, RenderTextureReadWrite.Default);
                GraphicsFormat      compatibleFormat = SystemInfo.GetCompatibleFormat(graphicsFormat, FormatUsage.Render);
                GraphicsFormat      format           = graphicsFormat == compatibleFormat ? graphicsFormat : compatibleFormat;

                if (rt.graphicsFormat != format)
                {
                    Debug.LogWarning(
                        $"This color format:{rt.graphicsFormat} not support in unity.webrtc. Change to supported color format:{format}.");
                    rt.Release();
                    rt.graphicsFormat = format;
                    rt.Create();
                }

                m_camera.targetTexture = rt;
            }
            else
            {
                RenderTextureFormat format = WebRTC.WebRTC.GetSupportedRenderTextureFormat(SystemInfo.graphicsDeviceType);
                rt = new RenderTexture(streamingSize.x, streamingSize.y, depth, format)
                {
                    antiAliasing = antiAliasing
                };
                rt.Create();
                m_camera.targetTexture = rt;
            }

            return(new VideoStreamTrack(m_camera.name, rt));
        }