public void BeginPreview(Rect r, GUIStyle previewBackground)
        {
            InitPreview(r);

            if (previewBackground == null || previewBackground == GUIStyle.none)
            {
                return;
            }

            Graphics.DrawTexture(
                previewBackground.overflow.Add(new Rect(0, 0, m_RenderTexture.width, m_RenderTexture.height)),
                previewBackground.normal.background,
                new Rect(0, 0, 1, 1),
                previewBackground.border.left, previewBackground.border.right, previewBackground.border.top,
                previewBackground.border.bottom,
                new Color(.5f, .5f, .5f, 0.5f),
                null
                );


            if (Unsupported.SetOverrideRenderSettings(previewScene.scene))
            {
                RenderSettings.ambientMode  = AmbientMode.Flat;
                RenderSettings.ambientLight = ambientColor;
            }
        }
        public void BeginPreview(Rect r, GUIStyle previewBackground)
        {
            Texture defaultEnvTexture = ReflectionProbe.defaultTexture;

            if (Unsupported.SetOverrideRenderSettings(previewScene.scene))
            {
                RenderSettings.ambientMode  = AmbientMode.Flat;
                RenderSettings.ambientLight = ambientColor;

                RenderSettings.defaultReflectionMode = UnityEngine.Rendering.DefaultReflectionMode.Custom;
                RenderSettings.customReflection      = defaultEnvTexture as Cubemap;
            }

            InitPreview(r);

            if (previewBackground == null || previewBackground == GUIStyle.none)
            {
                return;
            }

            Graphics.DrawTexture(
                previewBackground.overflow.Add(new Rect(0, 0, m_RenderTexture.width, m_RenderTexture.height)),
                previewBackground.normal.background,
                new Rect(0, 0, 1, 1),
                previewBackground.border.left, previewBackground.border.right, previewBackground.border.top,
                previewBackground.border.bottom,
                new Color(.5f, .5f, .5f, 0.5f),
                null
                );
        }
        private void InitPreview(Rect r)
        {
            camera.backgroundColor = new Color(49.0f / 255.0f, 49.0f / 255.0f, 49.0f / 255.0f, 1.0f);
            if (QualitySettings.activeColorSpace == ColorSpace.Linear)
            {
                camera.backgroundColor = camera.backgroundColor.linear;
            }

            m_TargetRect = r;
            float scaleFac = GetScaleFactor(r.width, r.height);

            int rtWidth  = (int)(r.width * scaleFac);
            int rtHeight = (int)(r.height * scaleFac);

            if (!m_RenderTexture || m_RenderTexture.width != rtWidth || m_RenderTexture.height != rtHeight)
            {
                if (m_RenderTexture)
                {
                    Object.DestroyImmediate(m_RenderTexture);
                    m_RenderTexture = null;
                }

                // Do not use GetTemporary to manage render textures. Temporary RTs are only
                // garbage collected each N frames, and in the editor we might be wildly resizing
                // the inspector, thus using up tons of memory.
                RenderTextureFormat format = camera.allowHDR ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.ARGB32;
                m_RenderTexture           = new RenderTexture(rtWidth, rtHeight, 16, format, RenderTextureReadWrite.Linear);
                m_RenderTexture.hideFlags = HideFlags.HideAndDontSave;

                camera.targetTexture = m_RenderTexture;

                foreach (var light in lights)
                {
                    light.enabled = true;
                }
            }

            m_SavedState = new SavedRenderTargetState();
            EditorGUIUtility.SetRenderTextureNoViewport(m_RenderTexture);
            GL.LoadOrtho();
            GL.LoadPixelMatrix(0, m_RenderTexture.width, m_RenderTexture.height, 0);
            ShaderUtil.rawViewportRect = new Rect(0, 0, m_RenderTexture.width, m_RenderTexture.height);
            ShaderUtil.rawScissorRect  = new Rect(0, 0, m_RenderTexture.width, m_RenderTexture.height);
            GL.Clear(true, true, camera.backgroundColor);

            foreach (var light in lights)
            {
                light.enabled = true;
            }

            var oldProbe = RenderSettings.ambientProbe;

            Unsupported.SetOverrideRenderSettings(previewScene.scene);
            // Most preview windows just want the light probe from the main scene so by default we copy it here. It can then be overridden if user wants.
            RenderSettings.ambientProbe = oldProbe;
        }
Esempio n. 4
0
 public void BeginPreview(Rect r, GUIStyle previewBackground)
 {
     this.InitPreview(r);
     if (previewBackground != null && previewBackground != GUIStyle.none)
     {
         Graphics.DrawTexture(previewBackground.overflow.Add(new Rect(0f, 0f, (float)this.m_RenderTexture.width, (float)this.m_RenderTexture.height)), previewBackground.normal.background, new Rect(0f, 0f, 1f, 1f), previewBackground.border.left, previewBackground.border.right, previewBackground.border.top, previewBackground.border.bottom, new Color(0.5f, 0.5f, 0.5f, 1f), null);
         if (Unsupported.SetOverrideRenderSettings(this.previewScene.scene))
         {
             RenderSettings.ambientMode  = AmbientMode.Flat;
             RenderSettings.ambientLight = this.ambientColor;
         }
     }
 }
Esempio n. 5
0
        private void InitPreview(Rect r)
        {
            this.camera.backgroundColor = new Color(0.192156866f, 0.192156866f, 0.192156866f, 1f);
            if (QualitySettings.activeColorSpace == ColorSpace.Linear)
            {
                this.camera.backgroundColor = this.camera.backgroundColor.linear;
            }
            this.m_TargetRect = r;
            float scaleFactor = this.GetScaleFactor(r.width, r.height);
            int   num         = (int)(r.width * scaleFactor);
            int   num2        = (int)(r.height * scaleFactor);

            if (!this.m_RenderTexture || this.m_RenderTexture.width != num || this.m_RenderTexture.height != num2)
            {
                if (this.m_RenderTexture)
                {
                    UnityEngine.Object.DestroyImmediate(this.m_RenderTexture);
                    this.m_RenderTexture = null;
                }
                RenderTextureFormat format = (!this.camera.allowHDR) ? RenderTextureFormat.ARGB32 : RenderTextureFormat.ARGBHalf;
                this.m_RenderTexture           = new RenderTexture(num, num2, 16, format, RenderTextureReadWrite.Linear);
                this.m_RenderTexture.hideFlags = HideFlags.HideAndDontSave;
                this.camera.targetTexture      = this.m_RenderTexture;
                Light[] lights = this.lights;
                for (int i = 0; i < lights.Length; i++)
                {
                    Light light = lights[i];
                    light.enabled = true;
                }
            }
            this.m_SavedState = new SavedRenderTargetState();
            EditorGUIUtility.SetRenderTextureNoViewport(this.m_RenderTexture);
            GL.LoadOrtho();
            GL.LoadPixelMatrix(0f, (float)this.m_RenderTexture.width, (float)this.m_RenderTexture.height, 0f);
            ShaderUtil.rawViewportRect = new Rect(0f, 0f, (float)this.m_RenderTexture.width, (float)this.m_RenderTexture.height);
            ShaderUtil.rawScissorRect  = new Rect(0f, 0f, (float)this.m_RenderTexture.width, (float)this.m_RenderTexture.height);
            GL.Clear(true, true, this.camera.backgroundColor);
            Light[] lights2 = this.lights;
            for (int j = 0; j < lights2.Length; j++)
            {
                Light light2 = lights2[j];
                light2.enabled = true;
            }
            SphericalHarmonicsL2 ambientProbe = RenderSettings.ambientProbe;

            Unsupported.SetOverrideRenderSettings(this.previewScene.scene);
            RenderSettings.ambientProbe = ambientProbe;
        }
        public void BeginStaticPreview(Rect r)
        {
            InitPreview(r);
            var color = new Color(82 / 255f, 82 / 255f, 82 / 255f, 1.0f);
            var darkGreyBackground = new Texture2D(1, 1, TextureFormat.RGBA32, true);

            darkGreyBackground.SetPixel(0, 0, color);
            darkGreyBackground.Apply();
            Graphics.DrawTexture(new Rect(0, 0, m_RenderTexture.width, m_RenderTexture.height), darkGreyBackground);
            Object.DestroyImmediate(darkGreyBackground);

            if (!EditorApplication.isUpdating)
            {
                var     oldProbe          = RenderSettings.ambientProbe;
                Texture defaultEnvTexture = ReflectionProbe.defaultTexture;
                if (Unsupported.SetOverrideRenderSettings(previewScene.scene))
                {
                    // Most preview windows just want the light probe from the main scene so by default we copy it here. It can then be overridden if user wants.
                    RenderSettings.ambientProbe          = oldProbe;
                    RenderSettings.defaultReflectionMode = UnityEngine.Rendering.DefaultReflectionMode.Custom;
                    RenderSettings.customReflection      = defaultEnvTexture as Cubemap;
                }
            }
        }