Game Development Community

Torque 3D HDR editor

by Alex Huck · 09/01/2009 (10:27 am) · 19 comments

*Below is obsolete (For the most part). Scroll down to comments where I posted download links to updated files for the HDR / SSAO editor. Below does contain a useful modification to GuiWindowCtrl you may be interested in, giving it a setTitle/getTitle method. This C++ mod is no longer required in the up to date files posted in the comments.
Instructions for the files posted: Extract the folder in the zip to game/tools folder, you will find a new button in the world editor's list of editors.


Old resource:
----

Hi, this tutorial will create a new gui called FilterAdjust to Torque3D which will allow you to adjust all the variables to the HDR shader that have been exposed to script. It also allows you to quickly toggle HDR on and off to see a scene with and without the effect. It can also restore settings to some default values I came up with.

Part I: A modification to the C++
This part is optional, what it will do is add a new method to the GuiWindowCtrl class allowing you to quickly change the title bar text with guiCtrl.setTitle("My new Title");

First go to the gui/guiWindowCtrl.h header file.
Once there find the line that says
void setFont(S32 fntTag);
and right underneath it add
void setText(const char *text); // title bar mod
Now in the gui/guiWindowCtrl.cpp code file find the guiWindowCtrl::onRender() method, and right above that add
// title bar mod
void GuiWindowCtrl::setText(const char *text)

{ 

	mText = StringTable->insert(text, true);

}
// end title bar mod
Now at the very end of the CPP file append these last few lines:

// title bar mod:
ConsoleMethod( GuiWindowCtrl, getTitle, const char *, 2, 2, "() - Gets the window title." )
{
return object->mText;
}

ConsoleMethod( GuiWindowCtrl, setTitle, void, 3, 3, "() - Sets the window title." )
{
TORQUE_UNUSED(argc);
object->setText(argv[2]);
}
// end title bar mod
[/code]

Part II: scripts

This tutorial was created using a new FPS project newly created from the Torque Toolbox, as such, the exact location of scripts may vary depending on which project folder you use.

In game/art/gui folder add the following code to a file called "FilterAdjust.gui":

//--- OBJECT WRITE BEGIN ---
%guiContent = new GuiControl(FilterAdjust) {
   isContainer = "1";
   Profile = "GuiDefaultProfile";
   HorizSizing = "right";
   VertSizing = "bottom";
   position = "0 0";
   Extent = "1024 768";
   MinExtent = "8 2";
   canSave = "1";
   Visible = "1";
   tooltipprofile = "GuiToolTipProfile";
   hovertime = "1000";
   canSaveDynamicFields = "1";

   new GuiWindowCtrl(FilterAdjustDlg) {
      resizeWidth = "0";
      resizeHeight = "0";
      canMove = "1";
      canClose = "1";
      canMinimize = "0";
      canMaximize = "0";
      minSize = "160 256";
      closeCommand = "Canvas.popDialog(FilterAdjust);";
      EdgeSnap = "1";
      text = "HDR: 1";
      Docking = "Left";
      Margin = "0 0 0 0";
      Padding = "0 0 0 0";
      AnchorTop = "1";
      AnchorBottom = "0";
      AnchorLeft = "1";
      AnchorRight = "0";
      isContainer = "1";
      Profile = "GuiWindowProfile";
      HorizSizing = "right";
      VertSizing = "center";
      position = "0 251";
      Extent = "160 256";
      MinExtent = "160 256";
      canSave = "1";
      Visible = "1";
      tooltipprofile = "GuiToolTipProfile";
      hovertime = "1000";
      canSaveDynamicFields = "0";

      new GuiTextCtrl() {
         text = "Gaussian Standard Deviation:";
         maxLength = "1024";
         Margin = "0 0 0 0";
         Padding = "0 0 0 0";
         AnchorTop = "1";
         AnchorBottom = "0";
         AnchorLeft = "1";
         AnchorRight = "0";
         isContainer = "0";
         Profile = "GuiTextProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "8 32";
         Extent = "143 8";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         tooltipprofile = "GuiToolTipProfile";
         hovertime = "1000";
         canSaveDynamicFields = "0";
      };
      new GuiTextCtrl() {
         text = "Gaussian Multiplier:";
         maxLength = "1024";
         Margin = "0 0 0 0";
         Padding = "0 0 0 0";
         AnchorTop = "1";
         AnchorBottom = "0";
         AnchorLeft = "1";
         AnchorRight = "0";
         isContainer = "0";
         Profile = "GuiTextProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "8 64";
         Extent = "93 8";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         tooltipprofile = "GuiToolTipProfile";
         hovertime = "1000";
         canSaveDynamicFields = "0";
      };
      new GuiSliderCtrl(FAD_gaussStdDev) {
         range = "0 5";
         ticks = "19";
         value = "2";
         isContainer = "0";
         Profile = "GuiSliderProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "8 40";
         Extent = "128 16";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         Command = "setHDRVar("gaussStdDev", $ThisControl.getValue());";
         tooltipprofile = "GuiToolTipProfile";
         hovertime = "1000";
         canSaveDynamicFields = "0";
      };
      new GuiSliderCtrl(FAD_gaussMultiplier) {
         range = "0 5";
         ticks = "19";
         value = "1";
         isContainer = "0";
         Profile = "GuiSliderProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "8 72";
         Extent = "128 16";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         Command = "setHDRVar("gaussMultiplier", $ThisControl.getValue());";
         tooltipprofile = "GuiToolTipProfile";
         hovertime = "1000";
         canSaveDynamicFields = "0";
      };
      new GuiSliderCtrl(FAD_gaussMean) {
         range = "0 5";
         ticks = "19";
         value = "3";
         isContainer = "0";
         Profile = "GuiSliderProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "8 104";
         Extent = "128 16";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         Command = "setHDRVar("gaussMean", $ThisControl.getValue());";
         tooltipprofile = "GuiToolTipProfile";
         hovertime = "1000";
         canSaveDynamicFields = "0";
      };
      new GuiTextCtrl() {
         text = "Gaussian Mean:";
         maxLength = "1024";
         Margin = "0 0 0 0";
         Padding = "0 0 0 0";
         AnchorTop = "1";
         AnchorBottom = "0";
         AnchorLeft = "1";
         AnchorRight = "0";
         isContainer = "0";
         Profile = "GuiTextProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "8 96";
         Extent = "93 8";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         tooltipprofile = "GuiToolTipProfile";
         hovertime = "1000";
         canSaveDynamicFields = "0";
      };
      new GuiSliderCtrl(FAD_gaussianScalar) {
         range = "0 5";
         ticks = "19";
         value = "4";
         isContainer = "0";
         Profile = "GuiSliderProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "8 136";
         Extent = "128 16";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         Command = "setHDRVar("gaussianScalar", $ThisControl.getValue());";
         tooltipprofile = "GuiToolTipProfile";
         hovertime = "1000";
         canSaveDynamicFields = "0";
      };
      new GuiTextCtrl() {
         text = "Gaussian Scalar:";
         maxLength = "1024";
         Margin = "0 0 0 0";
         Padding = "0 0 0 0";
         AnchorTop = "1";
         AnchorBottom = "0";
         AnchorLeft = "1";
         AnchorRight = "0";
         isContainer = "0";
         Profile = "GuiTextProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "8 128";
         Extent = "93 8";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         tooltipprofile = "GuiToolTipProfile";
         hovertime = "1000";
         canSaveDynamicFields = "0";
      };
      new GuiSliderCtrl(FAD_exposure) {
         range = "0 5";
         ticks = "19";
         value = "1";
         isContainer = "0";
         Profile = "GuiSliderProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "8 168";
         Extent = "128 16";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         Command = "setHDRVar("exposure", $ThisControl.getValue());";
         tooltipprofile = "GuiToolTipProfile";
         hovertime = "1000";
         canSaveDynamicFields = "0";
      };
      new GuiTextCtrl() {
         text = "Exposure:";
         maxLength = "1024";
         Margin = "0 0 0 0";
         Padding = "0 0 0 0";
         AnchorTop = "1";
         AnchorBottom = "0";
         AnchorLeft = "1";
         AnchorRight = "0";
         isContainer = "0";
         Profile = "GuiTextProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "8 160";
         Extent = "93 8";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         tooltipprofile = "GuiToolTipProfile";
         hovertime = "1000";
         canSaveDynamicFields = "0";
      };
      new GuiSliderCtrl(FAD_brightScalar) {
         range = "1 6";
         ticks = "19";
         value = "1";
         isContainer = "0";
         Profile = "GuiSliderProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "8 200";
         Extent = "128 16";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         Command = "setHDRVar("brightScalar", $ThisControl.getValue());";
         tooltipprofile = "GuiToolTipProfile";
         hovertime = "1000";
         canSaveDynamicFields = "0";
      };
      new GuiTextCtrl() {
         text = "Brightness scalar:";
         maxLength = "1024";
         Margin = "0 0 0 0";
         Padding = "0 0 0 0";
         AnchorTop = "1";
         AnchorBottom = "0";
         AnchorLeft = "1";
         AnchorRight = "0";
         isContainer = "0";
         Profile = "GuiTextProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "8 192";
         Extent = "93 8";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         tooltipprofile = "GuiToolTipProfile";
         hovertime = "1000";
         canSaveDynamicFields = "0";
      };
      new GuiSliderCtrl(FAD_brightPassThreshold) {
         range = "0 1";
         ticks = "19";
         value = "0";
         isContainer = "0";
         Profile = "GuiSliderProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "8 232";
         Extent = "128 16";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         Command = "setHDRVar("brightPassThreshold", $ThisControl.getValue());";
         tooltipprofile = "GuiToolTipProfile";
         hovertime = "1000";
         canSaveDynamicFields = "0";
      };
      new GuiTextCtrl() {
         text = "Bright pass threshold:";
         maxLength = "1024";
         Margin = "0 0 0 0";
         Padding = "0 0 0 0";
         AnchorTop = "1";
         AnchorBottom = "0";
         AnchorLeft = "1";
         AnchorRight = "0";
         isContainer = "0";
         Profile = "GuiTextProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "8 224";
         Extent = "119 8";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         tooltipprofile = "GuiToolTipProfile";
         hovertime = "1000";
         canSaveDynamicFields = "0";
      };
      new GuiButtonCtrl() {
         text = "1/ 0";
         groupNum = "-1";
         buttonType = "ToggleButton";
         useMouseEvents = "0";
         isContainer = "0";
         Profile = "GuiButtonProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "113 0";
         Extent = "21 21";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         Command = "HDRPostFX.toggle();";
         tooltipprofile = "GuiToolTipProfile";
         ToolTip = "Toggles the HDR effect";
         hovertime = "1000";
         canSaveDynamicFields = "0";
      };
      new GuiButtonCtrl() {
         text = "R";
         groupNum = "-1";
         buttonType = "PushButton";
         useMouseEvents = "0";
         isContainer = "0";
         Profile = "GuiButtonProfile";
         HorizSizing = "right";
         VertSizing = "bottom";
         position = "92 0";
         Extent = "21 21";
         MinExtent = "8 2";
         canSave = "1";
         Visible = "1";
         Command = "FilterAdjustDlg.resetDefaults();";
         tooltipprofile = "GuiToolTipProfile";
         ToolTip = "Resets values to their defaults";
         hovertime = "1000";
         canSaveDynamicFields = "0";
      };
   };
};
//--- OBJECT WRITE END ---

Now in the same folder create "FilterAdjust.cs" and add:

function setHDRVar(%var, %val) 
{
   if(%var $= "gaussStdDev")
   {
      $HDRPostFX::gaussStdDev = %val;
      FilterAdjustDlg.setTitle("HDR:" SPC %val);
   }
 
   
   else if(%var $= "exposure")
   {
      $HDRPostFX::exposure = %val;
      FilterAdjustDlg.setTitle("HDR:" SPC %val);
   }
     
   
   else if(%var $= "brightPassThreshold")
   {
      $HDRPostFX::brightPassThreshold = %val;
      FilterAdjustDlg.setTitle("HDR:" SPC %val);
   }
   
   
   else if(%var $= "brightScalar")
   {
      $HDRPostFX::brightScalar = %val;
      FilterAdjustDlg.setTitle("HDR:" SPC %val);
   }
   
   
   else if(%var $= "gaussianScalar")
   {
      $HDRPostFX::gaussianScalar = %val;
      FilterAdjustDlg.setTitle("HDR:" SPC %val);
   }
   
   
   else if(%var $= "gaussMean")
   {
      $HDRPostFX::gaussMean = %val;
      FilterAdjustDlg.setTitle("HDR:" SPC %val);
   }


   else if(%var $= "gaussMultiplier")
   {
      $HDRPostFX::gaussMultiplier = %val;
      FilterAdjustDlg.setTitle("HDR:" SPC %val);
   }
   
}

function FilterAdjustDlg::resetDefaults()
{
   FilterAdjustDlg.setTitle("HDR: Defaults");

   $HDRPostFX::gaussStdDev = 1;
   $HDRPostFX::gaussMultiplier = 0.5;
   $HDRPostFX::gaussMean = 3; 
   $HDRPostFX::gaussianScalar = 4; 
   $HDRPostFX::exposure = 1; 
   $HDRPostFX::brightScalar = 1;
   $HDRPostFX::brightPassThreshold = 0.1; 
   
   FAD_gaussStdDev.setValue($HDRPostFX::gaussStdDev);
   FAD_gaussMultiplier.setValue($HDRPostFX::gaussMultiplier);
   FAD_gaussMean.setValue($HDRPostFX::gaussMean);
   FAD_gaussianScalar.setValue($HDRPostFX::gaussianScalar);
   FAD_exposure.setValue($HDRPostFX::exposure);
   FAD_brightScalar.setValue($HDRPostFX::brightScalar);
   FAD_brightPassThreshold.setValue($HDRPostFX::brightPassThreshold);   
}

Now go to "/scripts/client/init.cs"

and add these lines to the end of the other exec("art/gui/*"); calls at about line 100

exec("art/gui/FilterAdjust.gui");
exec("art/gui/FilterAdjust.cs");


Finally, in "scripts/client/default.bind.cs" add this new function:

function enableFilterAdjust()
{

   FilterAdjustDlg.setTitle("HDR:");
   
   FAD_gaussStdDev.setValue($HDRPostFX::gaussStdDev);
    
   FAD_gaussMultiplier.setValue($HDRPostFX::gaussMultiplier);
     
   FAD_gaussMean.setValue($HDRPostFX::gaussMean);
    
   FAD_gaussianScalar.setValue($HDRPostFX::gaussianScalar);
    
   FAD_exposure.setValue($HDRPostFX::exposure);
   
   FAD_brightScalar.setValue($HDRPostFX::brightScalar);
    
   FAD_brightPassThreshold.setValue($HDRPostFX::brightPassThreshold);
   
   Canvas.pushDialog(FilterAdjust);
   
}



In game try it out by typing in the console enableFilterAdjust();


#1
09/01/2009 (8:27 pm)
Totally Cool Alex, Input! Input! One can learn much from posts like this.
#2
09/01/2009 (11:43 pm)
sounds great, got any screenshots you can post for us? good job!
#3
09/02/2009 (1:59 am)
Here's a Youtube video I uploaded of me messing around making ugly HDR effects in it:


Best viewed on youtube in HD / fullscreen
#4
09/02/2009 (3:56 am)
very nice, very useful. will be using once i pick up T3D.
#5
09/02/2009 (4:11 am)
Minor bug fix, I missed a step: In the header file also find mText member of GuiWindowCtrl move it from being protected to being public member, this is done by finding mText then cutting it and scrolling down until you find "public:" and pasting it under that, somewhere among those other public variable members.
#6
09/02/2009 (9:08 am)
i think make do this.. above code some script error

change : Command = "setHDRVar(gaussStdDev, $ThisControl.getValue());";
new GuiSliderCtrl(FAD_gaussStdDev) {   
         range = "0 5";   
         ticks = "19";   
         value = "2";   
         isContainer = "0";   
         Profile = "GuiSliderProfile";   
         HorizSizing = "right";   
         VertSizing = "bottom";   
         position = "8 40";   
         Extent = "128 16";   
         MinExtent = "8 2";   
         canSave = "1";   
         Visible = "1";   
         Command = "setHDRVar(gaussStdDev, $ThisControl.getValue());";   
         tooltipprofile = "GuiToolTipProfile";   
         hovertime = "1000";   
         canSaveDynamicFields = "0";   
      };


change : (%var $= gaussStdDev)
if(%var $= gaussStdDev)   
   {   
      $HDRPostFX::gaussStdDev = %val;   
      FilterAdjustDlg.setTitle("HDR:" SPC %val);   
   }


i have some question

when once use HDR Mode it has occur aliasing phenomenom...

how can i solve it?
#7
09/03/2009 (2:42 pm)
Yeah, I have noticed that too Gwang. It seems that HDR makes everything really pixelated.

Edit: Great resource also.
#8
09/03/2009 (7:15 pm)
FYI.

HDR has gotten a revamp for the next update... it works better, it has more features, and it works in Basic Lighting too.

And while we do have a simple hacked GUI for tweaking the global vars for HDR... this is much better.
#9
09/05/2009 (9:09 am)
Right now I'm working on adding a button in the world editor to toggle my HDR editor I'll post any updates on progress here. THen I might start working on the other PostFX's and making GUIs for them
#10
09/05/2009 (10:33 am)
that, mr Huck, is a splendid idea.
#11
09/05/2009 (10:59 am)
Ok I reworked the script parts... it's now an editor plugin all you have to do is extract this zip into the /tools subfolder of your game
The files

*edit* after you extract to /tools open up the editor and it should appear in the list of buttons for terrain/datablock/terrain painter/ particle/ decal etc editors
#12
09/05/2009 (3:30 pm)
Here is a major revision:
Changelog:
* Eliminated need for any C++ modification.
* All values displayed at all times.
* SSAO filter editor.
* New icons, thanks to my terrible art skill. (It's supposed to look like a magic wand...)

* tooltips added to explain what each function does (Almost).
* Better naming convention for function/variables.

Bug notes:
* Not all tooltips are explained.

Filter editor version 2.0

Let me know any difficulties this is my first time using sky-drive file hosting... might have messed up the download url
#13
09/27/2009 (6:50 am)
Very nice resource.
#14
09/27/2009 (1:43 pm)
@GG: Any chance this can make it into the production T3D release?
#16
10/01/2009 (10:46 pm)
anyone try this in 1.0 yet ?
#17
10/03/2009 (10:18 am)
yeah, it works.
#18
12/22/2009 (9:49 am)
is this broken in 1.1a? i had some troubles.
#19
12/24/2009 (2:32 pm)
wow, great work!

btw, i'm kinda new here.. but, how do you dynamically change the HDR settings in-game? (ie:changing HDR for dynamic day/night cycles, etc.)