Browse Source

Add gamma correction postprocess toggle to the editor.

Lasse Öörni 9 years ago
parent
commit
4ce51e3cc0

+ 2 - 0
bin/Data/Scripts/Editor.as

@@ -249,6 +249,7 @@ void LoadConfig()
         if (renderingElem.HasAttribute("specularlighting")) renderer.specularLighting = renderingElem.GetBool("specularlighting");
         if (renderingElem.HasAttribute("specularlighting")) renderer.specularLighting = renderingElem.GetBool("specularlighting");
         if (renderingElem.HasAttribute("dynamicinstancing")) renderer.dynamicInstancing = renderingElem.GetBool("dynamicinstancing");
         if (renderingElem.HasAttribute("dynamicinstancing")) renderer.dynamicInstancing = renderingElem.GetBool("dynamicinstancing");
         if (renderingElem.HasAttribute("framelimiter")) engine.maxFps = renderingElem.GetBool("framelimiter") ? 200 : 0;
         if (renderingElem.HasAttribute("framelimiter")) engine.maxFps = renderingElem.GetBool("framelimiter") ? 200 : 0;
+        if (renderingElem.HasAttribute("gammacorrection")) gammaCorrection = renderingElem.GetBool("gammacorrection");
     }
     }
 
 
     if (!uiElem.isNull)
     if (!uiElem.isNull)
@@ -382,6 +383,7 @@ void SaveConfig()
     }
     }
 
 
     renderingElem.SetBool("framelimiter", engine.maxFps > 0);
     renderingElem.SetBool("framelimiter", engine.maxFps > 0);
+    renderingElem.SetBool("gammacorrection", gammaCorrection);
 
 
     uiElem.SetFloat("minopacity", uiMinOpacity);
     uiElem.SetFloat("minopacity", uiMinOpacity);
     uiElem.SetFloat("maxopacity", uiMaxOpacity);
     uiElem.SetFloat("maxopacity", uiMaxOpacity);

+ 10 - 0
bin/Data/Scripts/Editor/EditorSettings.as

@@ -111,6 +111,9 @@ void UpdateEditorSettingsDialog()
     CheckBox@ frameLimiterToggle = settingsDialog.GetChild("FrameLimiterToggle", true);
     CheckBox@ frameLimiterToggle = settingsDialog.GetChild("FrameLimiterToggle", true);
     frameLimiterToggle.checked = engine.maxFps > 0;
     frameLimiterToggle.checked = engine.maxFps > 0;
     
     
+    CheckBox@ gammaCorrectionToggle = settingsDialog.GetChild("GammaCorrectionToggle", true);
+    gammaCorrectionToggle.checked = gammaCorrection;
+
     LineEdit@ cubemapPath = settingsDialog.GetChild("CubeMapGenPath", true);
     LineEdit@ cubemapPath = settingsDialog.GetChild("CubeMapGenPath", true);
     cubemapPath.text = cubeMapGen_Path;
     cubemapPath.text = cubeMapGen_Path;
     LineEdit@ cubemapName = settingsDialog.GetChild("CubeMapGenKey", true);
     LineEdit@ cubemapName = settingsDialog.GetChild("CubeMapGenKey", true);
@@ -165,6 +168,7 @@ void UpdateEditorSettingsDialog()
         SubscribeToEvent(specularLightingToggle, "Toggled", "EditSpecularLighting");
         SubscribeToEvent(specularLightingToggle, "Toggled", "EditSpecularLighting");
         SubscribeToEvent(dynamicInstancingToggle, "Toggled", "EditDynamicInstancing");
         SubscribeToEvent(dynamicInstancingToggle, "Toggled", "EditDynamicInstancing");
         SubscribeToEvent(frameLimiterToggle, "Toggled", "EditFrameLimiter");
         SubscribeToEvent(frameLimiterToggle, "Toggled", "EditFrameLimiter");
+        SubscribeToEvent(gammaCorrectionToggle, "Toggled", "EditGammaCorrection");
         SubscribeToEvent(settingsDialog.GetChild("CloseButton", true), "Released", "HideEditorSettingsDialog");
         SubscribeToEvent(settingsDialog.GetChild("CloseButton", true), "Released", "HideEditorSettingsDialog");
         
         
         SubscribeToEvent(cubemapPath, "TextChanged",  "EditCubemapPath");
         SubscribeToEvent(cubemapPath, "TextChanged",  "EditCubemapPath");
@@ -420,6 +424,12 @@ void EditFrameLimiter(StringHash eventType, VariantMap& eventData)
     engine.maxFps = edit.checked ? 200 : 0;
     engine.maxFps = edit.checked ? 200 : 0;
 }
 }
 
 
+void EditGammaCorrection(StringHash eventType, VariantMap& eventData)
+{
+    CheckBox@ edit = eventData["Element"].GetPtr();
+    SetGammaCorrection(edit.checked);
+}
+
 void EditCubemapPath(StringHash eventType, VariantMap& eventData)
 void EditCubemapPath(StringHash eventType, VariantMap& eventData)
 {
 {
     LineEdit@ edit = eventData["Element"].GetPtr();
     LineEdit@ edit = eventData["Element"].GetPtr();

+ 16 - 2
bin/Data/Scripts/Editor/EditorView.as

@@ -17,6 +17,7 @@ IntRect viewportArea; // the area where the editor viewport is. if we ever want
 IntRect viewportUIClipBorder = IntRect(27, 60, 0, 0); // used to clip viewport borders, the borders are ugly when going behind the transparent toolbars
 IntRect viewportUIClipBorder = IntRect(27, 60, 0, 0); // used to clip viewport borders, the borders are ugly when going behind the transparent toolbars
 RenderPath@ renderPath; // Renderpath to use on all views
 RenderPath@ renderPath; // Renderpath to use on all views
 String renderPathName;
 String renderPathName;
+bool gammaCorrection = false;
 bool mouseWheelCameraPosition = false;
 bool mouseWheelCameraPosition = false;
 bool contextMenuActionWaitFrame = false;
 bool contextMenuActionWaitFrame = false;
 bool cameraFlyMode = true;
 bool cameraFlyMode = true;
@@ -457,8 +458,14 @@ void SetRenderPath(const String&in newRenderPathName)
             }
             }
         }
         }
     }
     }
-    
-    // If renderPath is null, the engine default will be used
+
+    if (renderPath is null)
+        renderPath = renderer.defaultRenderPath.Clone();
+
+    // Append gamma correction postprocess and disable/enable it as requested
+    renderPath.Append(cache.GetResource("XMLFile", "PostProcess/GammaCorrection.xml"));
+    renderPath.SetEnabled("GammaCorrection", gammaCorrection);
+
     for (uint i = 0; i < renderer.numViewports; ++i)
     for (uint i = 0; i < renderer.numViewports; ++i)
         renderer.viewports[i].renderPath = renderPath;
         renderer.viewports[i].renderPath = renderPath;
 
 
@@ -469,6 +476,13 @@ void SetRenderPath(const String&in newRenderPathName)
         particleEffectPreview.viewport.renderPath = renderPath;
         particleEffectPreview.viewport.renderPath = renderPath;
 }
 }
 
 
+void SetGammaCorrection(bool enable)
+{
+    gammaCorrection = enable;
+    if (renderPath !is null)
+        renderPath.SetEnabled("GammaCorrection", gammaCorrection);
+}
+
 void CreateCamera()
 void CreateCamera()
 {
 {
     // Set the initial viewport rect
     // Set the initial viewport rect

+ 9 - 0
bin/Data/UI/EditorSettingsDialog.xml

@@ -335,6 +335,15 @@
                         </element>
                         </element>
                     </element>
                     </element>
                 </element>
                 </element>
+                <element style="ListRow">
+                    <attribute name="Layout Spacing" value="8" />
+                    <element type="CheckBox">
+                        <attribute name="Name" value="GammaCorrectionToggle" />
+                    </element>
+                    <element type="Text">
+                        <attribute name="Text" value="Gamma correction" />
+                    </element>
+                </element>
                 <element style="ListRow">
                 <element style="ListRow">
                     <attribute name="Layout Spacing" value="8" />
                     <attribute name="Layout Spacing" value="8" />
                     <element type="Text">
                     <element type="Text">