Esempio n. 1
0
        Texture2D CreateEnvMapTextureFromResult()
        {
            Assert.IsNotNull(m_ColorCorrect);

            var mat = DelightingService.GetLatLongMaterial(
                vm.latLongA,
                vm.normalsTexture,
                vm.latLongAverage,
                vm.overrideReferenceZone,
                vm.latLongExposure,
                vm.safetyZoneParams,
                true);

            var temporaryRT = RenderTexture.GetTemporary(vm.latLongA.width, vm.latLongA.height, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear);

            DelightingHelpers.PushSRGBWrite(false);
            Graphics.Blit(null, temporaryRT, mat, 0);
            DelightingHelpers.PopSRGBWrite();

            var           exportedLatLong = new Texture2D(vm.latLongA.width, vm.latLongA.height, TextureFormat.RGBAFloat, false, true);
            RenderTexture previous        = RenderTexture.active;

            RenderTexture.active = temporaryRT;
            exportedLatLong.ReadPixels(new Rect(0, 0, vm.latLongA.width, vm.latLongA.height), 0, 0, false);
            exportedLatLong.Apply();
            RenderTexture.active = previous;
            GL.sRGBWrite         = false;

            return(exportedLatLong);
        }
        public override void OnGUI()
        {
            SetValue(kLatLongExposure, EditorGUILayout.Slider(Content.kLatLongExposureLabel, GetValue(kLatLongExposure), 0, 1));

            var latLongA = GetValue(kLatLongA);

            if (latLongA != null)
            {
                var mat = DelightingService.GetLatLongMaterial(
                    latLongA,
                    GetValue(kNormalsTexture),
                    GetValue(kLatLongAverage),
                    GetValue(kOverrideReferenceZone),
                    GetValue(kLatLongExposure),
                    GetValue(kSafetyZoneParams),
                    false);

                var oldRt = RenderTexture.active;
                m_latLongExposed = DelightingHelpers.InstantiateRTIfRequired(m_latLongExposed, latLongA.width, latLongA.height, false, TextureWrapMode.Clamp);
                DelightingHelpers.PushSRGBWrite(false);
                Graphics.Blit(null, m_latLongExposed, mat);
                DelightingHelpers.PopSRGBWrite();
                RenderTexture.active = oldRt;

                GUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(Content.kLatLongALabel, EditorStyles.boldLabel);
                GUILayout.FlexibleSpace();
                if (GUILayout.Button(Content.kExportLabel))
                {
                    ExecuteCommand(kCmdExportMainEnvMap);
                }
                GUILayout.EndHorizontal();

                EditorGUILayout.Space();

                var rect = GUILayoutUtility.GetAspectRect(latLongA.width / (float)latLongA.height);
                GUI.DrawTexture(rect, m_latLongExposed);
                EditorGUILayout.Space();
            }



            var bakedLut = GetValue(kBakedLUT);

            if (bakedLut != null)
            {
                EditorGUILayout.Space();

                EditorGUILayout.LabelField(Content.kBakedLUTLabel, EditorStyles.boldLabel);

                EditorGUILayout.Space();

                var rect = GUILayoutUtility.GetAspectRect(bakedLut.width / (float)bakedLut.height);
                GUI.DrawTexture(rect, bakedLut);
                EditorGUILayout.Space();
            }
        }
Esempio n. 3
0
        Texture2D CreateDelightedTextureFromResult()
        {
            Assert.IsNotNull(m_ColorCorrect);

            var temporaryRT = RenderTexture.GetTemporary(m_ColorCorrect.width, m_ColorCorrect.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);

#if UNITY_2018_1_OR_NEWER
            DelightingHelpers.PushSRGBWrite(true);
#else
            DelightingHelpers.PushSRGBWrite(false);
#endif
            Graphics.Blit(m_ColorCorrect, temporaryRT);
            DelightingHelpers.PopSRGBWrite();

            var           exportedUnlit = new Texture2D(m_ColorCorrect.width, m_ColorCorrect.height, TextureFormat.ARGB32, false, false);
            RenderTexture previous      = RenderTexture.active;
            RenderTexture.active = temporaryRT;
            exportedUnlit.ReadPixels(new Rect(0, 0, m_ColorCorrect.width, m_ColorCorrect.height), 0, 0, false);
            exportedUnlit.Apply();
            RenderTexture.active = previous;

            return(exportedUnlit);
        }
        public override void OnGUI()
        {
            var controlId  = EditorGUIUtility.GetControlID(kCanvasHash, FocusType.Passive);
            var dropZoneId = EditorGUIUtility.GetControlID(kDropZoneHash, FocusType.Passive);

            var texture = GetValue(kPreviewTexture);

            var hasTexture    = texture != null;
            var targetTexture = (Texture)texture ?? Texture2D.whiteTexture;

            Rect canvasRectViewport;

            if (hasTexture)
            {
                var width  = texture != null ? texture.width : 256;
                var height = texture != null ? texture.height : 256;

                var cameraPosition = GetValue(kCameraPosition);
                var zoom           = GetValue(kZoom);
                EditorGUIXLayout.Canvas(controlId, ref cameraPosition, ref zoom, null, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                canvasRectViewport = GUILayoutUtility.GetLastRect();
                SetValue(kCameraPosition, cameraPosition);
                SetValue(kZoom, zoom);

                GUI.BeginClip(canvasRectViewport);
                DelightingHelpers.PushSRGBWrite(false);
                GUI.DrawTexture(EditorGUIX.GetCanvasDestinationRect(cameraPosition, zoom, width, height), targetTexture, ScaleMode.ScaleToFit);
                DelightingHelpers.PopSRGBWrite();

                if (Event.current.type == EventType.Repaint)
                {
                    m_Separator.OnGUI();
                    if (GetValue(kOverrideReferenceZone))
                    {
                        m_Gizmo.OnGUI();
                    }
                }
                else
                {
                    if (GetValue(kOverrideReferenceZone))
                    {
                        m_Gizmo.OnGUI();
                    }
                    m_Separator.OnGUI();
                }
                GUI.EndClip();

                var fitCanvasToWindow = GetValue(kFitCanvasToWindow);
                if (fitCanvasToWindow && Event.current.type == EventType.Repaint)
                {
                    EditorGUIX.CancelCanvasZoom(controlId);
                    var widthRatio   = canvasRectViewport.width / (float)width;
                    var heightRatio  = canvasRectViewport.height / (float)height;
                    var widthOffset  = 0f;
                    var heightOffset = 0f;
                    if (widthRatio < heightRatio)
                    {
                        zoom         = widthRatio;
                        heightOffset = (canvasRectViewport.height - zoom * height) * 0.5f;
                    }
                    else
                    {
                        zoom        = heightRatio;
                        widthOffset = (canvasRectViewport.width - zoom * width) * 0.5f;
                    }
                    SetValue(kZoom, zoom);
                    SetValue(kCameraPosition, new Vector2(widthOffset, heightOffset));
                    SetValue(kFitCanvasToWindow, false);
                }
            }
            else
            {
                EditorGUIXLayout.DropZoneHint(Content.dropZoneLabel);
                canvasRectViewport = GUILayoutUtility.GetLastRect();
            }

            if (EditorGUIX.DropZone(dropZoneId, canvasRectViewport, CanAcceptCallback))
            {
                var objs = DragAndDrop.objectReferences;
                if (objs.Length > 0)
                {
                    var path = AssetDatabase.GetAssetPath(objs[0]);
                    if (AssetDatabase.IsValidFolder(path))
                    {
                        SetValue(kInputFolderPath, path);
                        ExecuteCommand(kCmdLoadInputFolder);
                    }
                }
            }
        }