Add blend contrast slider

This commit is contained in:
Lukas Aldershaab 2021-01-02 03:20:18 +01:00
parent 6f23dd191d
commit 1ffec9ab56
7 changed files with 152 additions and 29 deletions

View file

@ -1425,6 +1425,16 @@ void TerrainHeightMapBlendHLSL::processPix(Vector<ShaderComponent*>& componentLi
blendDepth->constSortPos = cspPrimitive; 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)); Var* detailH = (Var*)LangElement::find(String::ToString("detailH%d", idx));
if (!detailH) 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", meta->addStatement(new GenOp(" @ = clamp(0.5 + @, 0.0, 1.0);\r\n",
detailH, blendDepth)); detailH, blendDepth));
} }
meta->addStatement(new GenOp(" @ = ((@ - 0.5f) * max(@, 0.0f)) + 0.5f;\r\n",
detailH, detailH, blendContrast));
meta->addStatement(new GenOp(" }\r\n")); meta->addStatement(new GenOp(" }\r\n"));
} }
} }

View file

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

View file

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

View file

@ -69,6 +69,7 @@ TerrainMaterial::TerrainMaterial()
mMacroDistance( 500.0f ), mMacroDistance( 500.0f ),
mParallaxScale( 0.0f ), mParallaxScale( 0.0f ),
mBlendDepth( 0.5f ), mBlendDepth( 0.5f ),
mBlendContrast( 1.0f ),
mIsSRGB(false), mIsSRGB(false),
mInvertRoughness(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 " 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" ); "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."); "Higher numbers = larger blend radius.");
scriptBindMapSlot(DetailMap, TerrainMaterial, "Raises and lowers the RGB result of the Base Albedo up close."); scriptBindMapSlot(DetailMap, TerrainMaterial, "Raises and lowers the RGB result of the Base Albedo up close.");

View file

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

View file

@ -511,7 +511,7 @@
anchorLeft = "1"; anchorLeft = "1";
anchorRight = "0"; anchorRight = "0";
position = "6 122"; position = "6 122";
extent = "185 80"; extent = "185 100";
minExtent = "8 2"; minExtent = "8 2";
horizSizing = "width"; horizSizing = "width";
vertSizing = "bottom"; vertSizing = "bottom";
@ -712,7 +712,7 @@
canSave = "1"; canSave = "1";
canSaveDynamicFields = "0"; canSaveDynamicFields = "0";
}; };
new GuiSliderCtrl(TerrainMaterialDlgBlendDepthSlider) { new GuiSliderCtrl(TerrainMaterialDlgBlendHeightBaseSlider) {
range = "-0.5 0.5"; range = "-0.5 0.5";
ticks = "0"; ticks = "0";
snap = "0"; snap = "0";
@ -731,12 +731,12 @@
tooltipProfile = "ToolsGuiToolTipProfile"; tooltipProfile = "ToolsGuiToolTipProfile";
hovertime = "1000"; hovertime = "1000";
isContainer = "0"; isContainer = "0";
internalName = "blendDepthSliderCtrl"; internalName = "blendHeightBaseSliderCtrl";
canSave = "1"; canSave = "1";
canSaveDynamicFields = "0"; canSaveDynamicFields = "0";
}; };
new GuiTextCtrl() { new GuiTextCtrl() {
text = "Blend Depth"; text = "Blend Height";
maxLength = "1024"; maxLength = "1024";
margin = "0 0 0 0"; margin = "0 0 0 0";
padding = "0 0 0 0"; padding = "0 0 0 0";
@ -758,7 +758,7 @@
canSave = "1"; canSave = "1";
canSaveDynamicFields = "0"; canSaveDynamicFields = "0";
}; };
new GuiTextEditCtrl(TerrainMaterialDlgBlendDepthTextEdit) { new GuiTextEditCtrl(TerrainMaterialDlgBlendHeightBaseTextEdit) {
historySize = "0"; historySize = "0";
tabComplete = "0"; tabComplete = "0";
sinkAllKeyEvents = "0"; sinkAllKeyEvents = "0";
@ -783,7 +783,82 @@
tooltipProfile = "ToolsGuiToolTipProfile"; tooltipProfile = "ToolsGuiToolTipProfile";
hovertime = "1000"; hovertime = "1000";
isContainer = "0"; 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"; canSave = "1";
canSaveDynamicFields = "0"; canSaveDynamicFields = "0";
}; };
@ -792,7 +867,7 @@
bitmap = "tools/gui/images/separator-v"; bitmap = "tools/gui/images/separator-v";
color = "255 255 255 255"; color = "255 255 255 255";
wrap = "0"; wrap = "0";
position = "6 202"; position = "6 222";
extent = "175 2"; extent = "175 2";
minExtent = "8 2"; minExtent = "8 2";
horizSizing = "width"; horizSizing = "width";
@ -813,7 +888,7 @@
anchorBottom = "0"; anchorBottom = "0";
anchorLeft = "1"; anchorLeft = "1";
anchorRight = "0"; anchorRight = "0";
position = "6 209"; position = "6 229";
extent = "185 64"; extent = "185 64";
minExtent = "8 2"; minExtent = "8 2";
horizSizing = "width"; horizSizing = "width";
@ -1008,7 +1083,7 @@
bitmap = "tools/gui/images/separator-v"; bitmap = "tools/gui/images/separator-v";
color = "255 255 255 255"; color = "255 255 255 255";
wrap = "0"; wrap = "0";
position = "6 279"; position = "6 299";
extent = "175 2"; extent = "175 2";
minExtent = "8 2"; minExtent = "8 2";
horizSizing = "width"; horizSizing = "width";
@ -1029,7 +1104,7 @@
anchorBottom = "0"; anchorBottom = "0";
anchorLeft = "1"; anchorLeft = "1";
anchorRight = "0"; anchorRight = "0";
position = "6 286"; position = "6 306";
extent = "185 72"; extent = "185 72";
minExtent = "8 2"; minExtent = "8 2";
horizSizing = "width"; horizSizing = "width";
@ -1513,7 +1588,7 @@
bitmap = "tools/gui/images/separator-v"; bitmap = "tools/gui/images/separator-v";
color = "255 255 255 255"; color = "255 255 255 255";
wrap = "0"; wrap = "0";
position = "6 361"; position = "6 381";
extent = "175 2"; extent = "175 2";
minExtent = "8 2"; minExtent = "8 2";
horizSizing = "width"; horizSizing = "width";
@ -1534,7 +1609,7 @@
anchorBottom = "0"; anchorBottom = "0";
anchorLeft = "1"; anchorLeft = "1";
anchorRight = "0"; anchorRight = "0";
position = "6 368"; position = "6 388";
extent = "185 72"; extent = "185 72";
minExtent = "8 2"; minExtent = "8 2";
horizSizing = "width"; horizSizing = "width";

View file

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