Browse Source

Add blend contrast slider

Lukas Aldershaab 4 years ago
parent
commit
1ffec9ab56

+ 14 - 0
Engine/source/terrain/hlsl/terrFeatureHLSL.cpp

@@ -1425,6 +1425,16 @@ void TerrainHeightMapBlendHLSL::processPix(Vector<ShaderComponent*>& componentLi
          blendDepth->constSortPos = cspPrimitive;
       }
 
+      Var* blendContrast = (Var*)LangElement::find(String::ToString("blendContrast%d", idx));
+      if (!blendContrast)
+      {
+         blendContrast = new Var;
+         blendContrast->setType("float");
+         blendContrast->setName(String::ToString("blendContrast%d", idx));
+         blendContrast->uniform = true;
+         blendContrast->constSortPos = cspPrimitive;
+      }
+
       Var* detailH = (Var*)LangElement::find(String::ToString("detailH%d", idx));
       if (!detailH)
       {
@@ -1445,6 +1455,10 @@ void TerrainHeightMapBlendHLSL::processPix(Vector<ShaderComponent*>& componentLi
             meta->addStatement(new GenOp("      @ = clamp(0.5 + @, 0.0, 1.0);\r\n",
                detailH, blendDepth));
          }
+
+         meta->addStatement(new GenOp("      @ = ((@ - 0.5f) * max(@, 0.0f)) + 0.5f;\r\n",
+            detailH, detailH, blendContrast));
+
          meta->addStatement(new GenOp("   }\r\n"));
       }
    }

+ 2 - 0
Engine/source/terrain/terrCellMaterial.cpp

@@ -648,6 +648,7 @@ bool TerrainCellMaterial::_initShader(bool deferredMat,
          continue;
 
       mMaterialInfos[i]->mBlendDepthConst = mShader->getShaderConstHandle(avar("$blendDepth%d", i));
+      mMaterialInfos[i]->mBlendContrastConst = mShader->getShaderConstHandle(avar("$blendContrast%d", i));
    }
 
    // If we're doing deferred it requires some 
@@ -719,6 +720,7 @@ void TerrainCellMaterial::_updateMaterialConsts( )
       detailInfoArray[j] = detailIdStrengthParallax;
 
       mConsts->setSafe(matInfo->mBlendDepthConst, matInfo->mat->getBlendDepth());
+      mConsts->setSafe(matInfo->mBlendContrastConst, matInfo->mat->getBlendContrast());
    }
 
    mConsts->setSafe(mDetailInfoVArrayConst, detailScaleAndFadeArray);

+ 1 - 0
Engine/source/terrain/terrCellMaterial.h

@@ -70,6 +70,7 @@ protected:
       TerrainMaterial *mat;
       U32 layerId;
       GFXShaderConstHandle* mBlendDepthConst;
+      GFXShaderConstHandle* mBlendContrastConst;
    };
 
    ///

+ 5 - 1
Engine/source/terrain/terrMaterial.cpp

@@ -69,6 +69,7 @@ TerrainMaterial::TerrainMaterial()
       mMacroDistance( 500.0f ),
       mParallaxScale( 0.0f ),
       mBlendDepth( 0.5f ),
+      mBlendContrast( 1.0f ),
       mIsSRGB(false),
       mInvertRoughness(false)
 {
@@ -92,7 +93,10 @@ void TerrainMaterial::initPersistFields()
    addField( "parallaxScale", TypeF32, Offset( mParallaxScale, TerrainMaterial ), "Used to scale the height from the normal map to give some self "
 	   "occlusion effect (aka parallax) to the terrain material" );
 
-   addField("blendDepth", TypeF32, Offset(mBlendDepth, TerrainMaterial), "Depth for blending the textures using the new blending method by Lukas Joergensen."
+   addField("blendHeightBase", TypeF32, Offset(mBlendDepth, TerrainMaterial), "A fixed value to add while blending using heightmap-based blending."
+      "Higher numbers = larger blend radius.");
+
+   addField("blendHeightContrast", TypeF32, Offset(mBlendContrast, TerrainMaterial), "A fixed value to add while blending using heightmap-based blending."
       "Higher numbers = larger blend radius.");
 
    scriptBindMapSlot(DetailMap, TerrainMaterial, "Raises and lowers the RGB result of the Base Albedo up close.");

+ 4 - 0
Engine/source/terrain/terrMaterial.h

@@ -90,6 +90,8 @@ protected:
    /// radius.
    F32 mBlendDepth;
 
+   F32 mBlendContrast;
+
 public:
 
    TerrainMaterial();
@@ -129,6 +131,8 @@ public:
 
    F32 getBlendDepth() const { return mBlendDepth; }
 
+   F32 getBlendContrast() const { return mBlendContrast; }
+
    bool getIsSRGB() const { return mIsSRGB; }
 
    bool getInvertRoughness() const { return mInvertRoughness; }

+ 87 - 12
Templates/BaseGame/game/tools/worldEditor/gui/guiTerrainMaterialDlg.ed.gui

@@ -511,7 +511,7 @@
             anchorLeft = "1";
             anchorRight = "0";
             position = "6 122";
-            extent = "185 80";
+            extent = "185 100";
             minExtent = "8 2";
             horizSizing = "width";
             vertSizing = "bottom";
@@ -712,7 +712,7 @@
                canSave = "1";
                canSaveDynamicFields = "0";
             };
-            new GuiSliderCtrl(TerrainMaterialDlgBlendDepthSlider) {
+            new GuiSliderCtrl(TerrainMaterialDlgBlendHeightBaseSlider) {
                range = "-0.5 0.5";
                ticks = "0";
                snap = "0";
@@ -731,12 +731,12 @@
                tooltipProfile = "ToolsGuiToolTipProfile";
                hovertime = "1000";
                isContainer = "0";
-               internalName = "blendDepthSliderCtrl";
+               internalName = "blendHeightBaseSliderCtrl";
                canSave = "1";
                canSaveDynamicFields = "0";
             };
             new GuiTextCtrl() {
-               text = "Blend Depth";
+               text = "Blend Height";
                maxLength = "1024";
                margin = "0 0 0 0";
                padding = "0 0 0 0";
@@ -758,7 +758,7 @@
                canSave = "1";
                canSaveDynamicFields = "0";
             };
-            new GuiTextEditCtrl(TerrainMaterialDlgBlendDepthTextEdit) {
+            new GuiTextEditCtrl(TerrainMaterialDlgBlendHeightBaseTextEdit) {
                historySize = "0";
                tabComplete = "0";
                sinkAllKeyEvents = "0";
@@ -783,7 +783,82 @@
                tooltipProfile = "ToolsGuiToolTipProfile";
                hovertime = "1000";
                isContainer = "0";
-               internalName = "blendDepthTextEditCtrl";
+               internalName = "blendHeightBaseTextEditCtrl";
+               canSave = "1";
+               canSaveDynamicFields = "0";
+            };
+            new GuiSliderCtrl(TerrainMaterialDlgBlendHeightContrastSlider) {
+               range = "0.0 5.0";
+               ticks = "0";
+               snap = "0";
+               value = "1.0";
+               useFillBar = "0";
+               fillBarColor = "255 255 255 255";
+               renderTicks = "1";
+               position = "39 81";
+               extent = "70 14";
+               minExtent = "8 2";
+               horizSizing = "right";
+               vertSizing = "bottom";
+               profile = "ToolsGuiSliderProfile";
+               visible = "1";
+               active = "1";
+               tooltipProfile = "ToolsGuiToolTipProfile";
+               hovertime = "1000";
+               isContainer = "0";
+               internalName = "blendHeightContrastSliderCtrl";
+               canSave = "1";
+               canSaveDynamicFields = "0";
+            };
+            new GuiTextCtrl() {
+               text = "Blend Contrast";
+               maxLength = "1024";
+               margin = "0 0 0 0";
+               padding = "0 0 0 0";
+               anchorTop = "1";
+               anchorBottom = "0";
+               anchorLeft = "1";
+               anchorRight = "0";
+               position = "115 81";
+               extent = "58 15";
+               minExtent = "8 2";
+               horizSizing = "right";
+               vertSizing = "bottom";
+               profile = "ToolsGuiTextProfile";
+               visible = "1";
+               active = "1";
+               tooltipProfile = "ToolsGuiToolTipProfile";
+               hovertime = "1000";
+               isContainer = "1";
+               canSave = "1";
+               canSaveDynamicFields = "0";
+            };
+            new GuiTextEditCtrl(TerrainMaterialDlgBlendHeightContrastTextEdit) {
+               historySize = "0";
+               tabComplete = "0";
+               sinkAllKeyEvents = "0";
+               password = "0";
+               passwordMask = "*";
+               text = "0.3";
+               maxLength = "1024";
+               margin = "0 0 0 0";
+               padding = "0 0 0 0";
+               anchorTop = "0";
+               anchorBottom = "0";
+               anchorLeft = "0";
+               anchorRight = "0";
+               position = "1 79";
+               extent = "35 18";
+               minExtent = "8 2";
+               horizSizing = "right";
+               vertSizing = "bottom";
+               profile = "ToolsGuiTextEditProfile";
+               visible = "1";
+               active = "1";
+               tooltipProfile = "ToolsGuiToolTipProfile";
+               hovertime = "1000";
+               isContainer = "0";
+               internalName = "blendHeightContrastTextEditCtrl";
                canSave = "1";
                canSaveDynamicFields = "0";
             };
@@ -792,7 +867,7 @@
             bitmap = "tools/gui/images/separator-v";
             color = "255 255 255 255";
             wrap = "0";
-            position = "6 202";
+            position = "6 222";
             extent = "175 2";
             minExtent = "8 2";
             horizSizing = "width";
@@ -813,7 +888,7 @@
             anchorBottom = "0";
             anchorLeft = "1";
             anchorRight = "0";
-            position = "6 209";
+            position = "6 229";
             extent = "185 64";
             minExtent = "8 2";
             horizSizing = "width";
@@ -1008,7 +1083,7 @@
             bitmap = "tools/gui/images/separator-v";
             color = "255 255 255 255";
             wrap = "0";
-            position = "6 279";
+            position = "6 299";
             extent = "175 2";
             minExtent = "8 2";
             horizSizing = "width";
@@ -1029,7 +1104,7 @@
             anchorBottom = "0";
             anchorLeft = "1";
             anchorRight = "0";
-            position = "6 286";
+            position = "6 306";
             extent = "185 72";
             minExtent = "8 2";
             horizSizing = "width";
@@ -1513,7 +1588,7 @@
             bitmap = "tools/gui/images/separator-v";
             color = "255 255 255 255";
             wrap = "0";
-            position = "6 361";
+            position = "6 381";
             extent = "175 2";
             minExtent = "8 2";
             horizSizing = "width";
@@ -1534,7 +1609,7 @@
             anchorBottom = "0";
             anchorLeft = "1";
             anchorRight = "0";
-            position = "6 368";
+            position = "6 388";
             extent = "185 72";
             minExtent = "8 2";
             horizSizing = "width";

+ 39 - 16
Templates/BaseGame/game/tools/worldEditor/scripts/interfaces/terrainMaterialDlg.ed.cs

@@ -444,9 +444,13 @@ function TerrainMaterialDlg::setActiveMaterial( %this, %mat )
       %this-->sideProjectionCtrl.setValue( %mat.useSideProjection );
       %this-->parallaxScaleCtrl.setText( %mat.parallaxScale );
       
-      %blendDepth = mFloor(%mat.blendDepth * 1000)/1000;
-      %this-->blendDepthTextEditCtrl.setText( %blendDepth );
-      %this-->blendDepthSliderCtrl.setValue( %mat.blendDepth );
+      %blendHeightBase = mFloor(%mat.blendHeightBase * 1000)/1000;
+      %this-->blendHeightBaseTextEditCtrl.setText( %blendHeightBase );
+      %this-->blendHeightBaseSliderCtrl.setValue( %mat.blendHeightBase );
+      
+      %blendHeightContrast = mFloor(%mat.blendHeightContrast * 1000)/1000;
+      %this-->blendHeightContrastTextEditCtrl.setText( %blendHeightContrast );
+      %this-->blendHeightContrastSliderCtrl.setValue( %mat.blendHeightContrast );
 
       %this-->macroSizeCtrl.setText( %mat.macroSize );
       %this-->macroStrengthCtrl.setText( %mat.macroStrength );
@@ -508,7 +512,8 @@ function TerrainMaterialDlg::saveDirtyMaterial( %this, %mat )
    %detailDistance = %this-->detDistanceCtrl.getText();   
    %useSideProjection = %this-->sideProjectionCtrl.getValue();   
    %parallaxScale = %this-->parallaxScaleCtrl.getText();
-   %blendDepth = %this-->blendDepthTextEditCtrl.getText();
+   %blendHeightBase = %this-->blendHeightBaseTextEditCtrl.getText();
+   %blendHeightContrast = %this-->blendHeightContrastTextEditCtrl.getText();
 
    %macroSize = %this-->macroSizeCtrl.getText();      
    %macroStrength = %this-->macroStrengthCtrl.getText();
@@ -535,11 +540,12 @@ function TerrainMaterialDlg::saveDirtyMaterial( %this, %mat )
          %mat.macroStrength == %macroStrength &&
          %mat.macroDistance == %macroDistance &&         
          %mat.parallaxScale == %parallaxScale &&
-         %mat.blendDepth == %blendDepth &&         
+         %mat.blendHeightBase == %blendHeightBase &&
+         %mat.blendHeightContrast == %blendHeightContrast &&
          %mat.isSRGB == %isSRGB &&         
-         %mat.invertRoughness == %invertRoughness)               
+         %mat.invertRoughness == %invertRoughness && false)               
       return;
-      
+   
    // Make sure the material name is unique.
    
    if( %mat.internalName !$= %newName )
@@ -573,7 +579,8 @@ function TerrainMaterialDlg::saveDirtyMaterial( %this, %mat )
    %mat.macroDistance = %macroDistance;    
    %mat.useSideProjection = %useSideProjection;
    %mat.parallaxScale = %parallaxScale;
-   %mat.blendDepth = %blendDepth;
+   %mat.blendHeightBase = %blendHeightBase;
+   %mat.blendHeightContrast = %blendHeightContrast;
    %mat.isSRGB = %isSRGB;
    %mat.invertRoughness = %invertRoughness;
    
@@ -626,7 +633,8 @@ function TerrainMaterialDlg::snapshotMaterials( %this )
          macroDistance = %mat.macroDistance;
          useSideProjection = %mat.useSideProjection;
          parallaxScale = %mat.parallaxScale;
-         blendDepth = %mat.blendDepth;
+         blendHeightBase = %mat.blendHeightBase;
+         blendHeightContrast = %mat.blendHeightContrast;
          isSRGB = %mat.isSRGB;
          invertRoughness = %mat.invertRoughness;
       };
@@ -664,7 +672,8 @@ function TerrainMaterialDlg::restoreMaterials( %this )
       %mat.macroDistance = %obj.macroDistance;
       %mat.useSideProjection = %obj.useSideProjection;
       %mat.parallaxScale = %obj.parallaxScale;
-      %mat.blendDepth = %obj.blendDepth;
+      %mat.blendHeightBase = %obj.blendHeightBase;
+      %mat.blendHeightContrast = %obj.blendHeightContrast;
       %mat.isSRGB = %obj.isSRGB;
       %mat.invertRoughness = %obj.invertRoughness;
    }
@@ -703,16 +712,30 @@ function TerrainMaterialDlg::_selectTextureFileDialog( %this, %defaultFileName )
    return %file;
 }
 
-function TerrainMaterialDlgBlendDepthSlider::onMouseDragged(%this)
+function TerrainMaterialDlgBlendHeightBaseSlider::onMouseDragged(%this)
+{
+   %value = mFloor(%this.value * 1000)/1000;
+   TerrainMaterialDlgBlendHeightBaseTextEdit.setText(%value);
+   TerrainMaterialDlg.activeMat.blendHeightBase = %this.value;
+
+}
+
+function TerrainMaterialDlgBlendHeightBaseTextEdit::onValidate(%this)
+{
+   TerrainMaterialDlgBlendHeightBaseSlider.setValue(%this.getText());
+   TerrainMaterialDlg.activeMat.blendHeightBase = %this.getText();
+}
+
+function TerrainMaterialDlgBlendHeightContrastSlider::onMouseDragged(%this)
 {
    %value = mFloor(%this.value * 1000)/1000;
-   TerrainMaterialDlgBlendDepthTextEdit.setText(%value);
-   TerrainMaterialDlg.activeMat.blendDepth = %this.value;
+   TerrainMaterialDlgBlendHeightContrastTextEdit.setText(%value);
+   TerrainMaterialDlg.activeMat.blendHeightContrast = %this.value;
 
 }
 
-function TerrainMaterialDlgBlendDepthTextEdit::onValidate(%this)
+function TerrainMaterialDlgBlendHeightContrastTextEdit::onValidate(%this)
 {
-   TerrainMaterialDlgBlendDepthSlider.setValue(%this.getText());
-   TerrainMaterialDlg.activeMat.blendDepth = %this.getText();
+   TerrainMaterialDlgBlendHeightContrastSlider.setValue(%this.getText());
+   TerrainMaterialDlg.activeMat.blendHeightContrast = %this.getText();
 }