Merge pull request #424 from lukaspj/feature/new-terrain-blending

Height based terrain texture blending
This commit is contained in:
Brian Roberts 2021-01-04 05:36:50 -06:00 committed by GitHub
commit 27641b16ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 3628 additions and 1280 deletions

View file

@ -11,7 +11,22 @@ function Core_Rendering::onCreate(%this)
$pref::ReflectionProbes::BakeResolution = ProjectSettings.value("Rendering/ProbeCaptureResolution", "64");
$Terrain::LerpBlend = ProjectSettings.value("Terrain/LerpBlend");
$Terrain::BlendDepth = ProjectSettings.value("Terrain/BlendDepth");
$Terrain::DetailTextureSize = ProjectSettings.value("Terrain/DetailTextureSize");
$Terrain::MacroTextureSize = ProjectSettings.value("Terrain/MacroTextureSize");
$Terrain::NormalTextureSize = ProjectSettings.value("Terrain/NormalTextureSize");
$Terrain::OrmTextureSize = ProjectSettings.value("Terrain/OrmTextureSize");
// Default to R8G8B8A8 for all textures
$Terrain::DetailTextureFormat = ProjectSettings.value("Terrain/DetailTextureFormat", 12);
$Terrain::MacroTextureFormat = ProjectSettings.value("Terrain/MacroTextureFormat", 12);
$Terrain::NormalTextureFormat = ProjectSettings.value("Terrain/NormalTextureFormat", 12);
$Terrain::OrmTextureFormat = ProjectSettings.value("Terrain/OrmTextureFormat", 12);
exec("./scripts/graphicsOptions.cs");
exec("./scripts/terrainSettings.cs");
exec("./scripts/renderManager.cs");
exec("./scripts/gfxData/clouds.cs");
exec("./scripts/gfxData/commonMaterialData.cs");
@ -20,6 +35,8 @@ function Core_Rendering::onCreate(%this)
exec("./scripts/gfxData/terrainBlock.cs");
exec("./scripts/gfxData/water.cs");
exec("./scripts/gfxData/warningTerrainMat.cs");
loadTerrainSettings();
}
function Core_Rendering::onDestroy(%this)

View file

@ -166,6 +166,35 @@ vec2 parallaxOffsetDxtnm(sampler2D texMap, vec2 texCoord, vec3 negViewTS, float
return offset;
}
/// Same as the above but for arrays
vec2 parallaxOffset( sampler2DArray texMap, vec3 texCoord, vec3 negViewTS, float depthScale )
{
float depth = texture( texMap, texCoord ).a/(PARALLAX_REFINE_STEPS*2);
vec2 offset = negViewTS.xy * vec2( depth * depthScale )/vec2(PARALLAX_REFINE_STEPS*2);
for ( int i=0; i < PARALLAX_REFINE_STEPS; i++ )
{
depth = ( depth + texture( texMap, texCoord + vec3(offset, 0.0) ).a )/(PARALLAX_REFINE_STEPS*2);
offset = negViewTS.xy * vec2( depth * depthScale )/vec2(PARALLAX_REFINE_STEPS*2);
}
return offset;
}
vec2 parallaxOffsetDxtnm(sampler2DArray texMap, vec3 texCoord, vec3 negViewTS, float depthScale)
{
float depth = texture(texMap, texCoord).r/(PARALLAX_REFINE_STEPS*2);
vec2 offset = negViewTS.xy * vec2(depth * depthScale)/vec2(PARALLAX_REFINE_STEPS*2);
for (int i = 0; i < PARALLAX_REFINE_STEPS; i++)
{
depth = (depth + texture(texMap, texCoord + vec3(offset, 0.0)).r)/(PARALLAX_REFINE_STEPS*2);
offset = negViewTS.xy * vec2(depth * depthScale)/vec2(PARALLAX_REFINE_STEPS*2);
}
return offset;
}
/// The maximum value for 10bit per component integer HDR encoding.
const float HDR_RGB10_MAX = 4.0;

View file

@ -60,6 +60,7 @@
//helper if you want to pass sampler/texture in a function
//2D
#define TORQUE_SAMPLER2D(tex) Texture2D texture_##tex, SamplerState tex
#define TORQUE_SAMPLER2DARRAY(tex) Texture2DArray texture_##tex, SamplerState tex
#define TORQUE_SAMPLER2D_MAKEARG(tex) texture_##tex, tex
// Sampler comparison state - use above MAKEARG with this
#define TORQUE_SAMPLER2DCMP(tex) Texture2D texture_##tex, SamplerComparisonState tex

View file

@ -167,6 +167,35 @@ float2 parallaxOffsetDxtnm(TORQUE_SAMPLER2D(texMap), float2 texCoord, float3 neg
return offset;
}
/// Copy of the above to functions, but for arrays
float2 parallaxOffsetTexArray(TORQUE_SAMPLER2DARRAY(texMap), float3 texCoord, float3 negViewTS, float depthScale)
{
float depth = TORQUE_TEX2D(texMap, texCoord).a/(PARALLAX_REFINE_STEPS*2);
float2 offset = negViewTS.xy * (depth * depthScale)/(PARALLAX_REFINE_STEPS);
for (int i = 0; i < PARALLAX_REFINE_STEPS; i++)
{
depth = (depth + TORQUE_TEX2D(texMap, texCoord + float3(offset, 0.0)).a)/(PARALLAX_REFINE_STEPS*2);
offset = negViewTS.xy * (depth * depthScale)/(PARALLAX_REFINE_STEPS);
}
return offset;
}
float2 parallaxOffsetDxtnmTexArray(TORQUE_SAMPLER2DARRAY(texMap), float3 texCoord, float3 negViewTS, float depthScale)
{
float depth = TORQUE_TEX2D(texMap, texCoord).r/(PARALLAX_REFINE_STEPS*2);
float2 offset = negViewTS.xy * (depth * depthScale)/(PARALLAX_REFINE_STEPS*2);
for (int i = 0; i < PARALLAX_REFINE_STEPS; i++)
{
depth = (depth + TORQUE_TEX2D(texMap, texCoord + float3(offset, 0.0)).r)/(PARALLAX_REFINE_STEPS*2);
offset = negViewTS.xy * (depth * depthScale)/(PARALLAX_REFINE_STEPS*2);
}
return offset;
}
/// The maximum value for 10bit per component integer HDR encoding.
static const float HDR_RGB10_MAX = 4.0;

View file

@ -210,7 +210,7 @@
new GuiBitmapCtrl() {
Enabled = "1";
Profile = "ToolsGuiDefaultProfile";
position = "270 3";
position = "230 3";
Extent = "2 26";
MinExtent = "1 1";
bitmap = "tools/gui/images/separator-h.png";
@ -222,7 +222,7 @@
Profile = "ToolsGuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "262 5";
Position = "222 5";
Extent = "256 50";
MinExtent = "8 2";
canSave = "1";
@ -370,7 +370,7 @@
new GuiBitmapCtrl() {
Enabled = "1";
Profile = "ToolsGuiDefaultProfile";
position = "525 3";
position = "445 3";
Extent = "2 26";
MinExtent = "1 1";
bitmap = "tools/gui/images/separator-h.png";
@ -382,7 +382,7 @@
Profile = "ToolsGuiTransparentProfile";
HorizSizing = "right";
VertSizing = "bottom";
position = "540 5";
position = "480 5";
Extent = "120 50";
MinExtent = "8 2";
canSave = "1";
@ -454,6 +454,43 @@
bitmap = "tools/gui/images/dropslider";
};
};
new GuiBitmapCtrl() {
Enabled = "1";
Profile = "ToolsGuiDefaultProfile";
position = "618 3";
Extent = "2 26";
MinExtent = "1 1";
bitmap = "tools/gui/images/separator-h.png";
};
new GuiControl(TerrainTextureSettingsButtonContainer,EditorGuiGroup) {
position = "628 5";
extent = "90 18";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "ToolsGuiTransparentProfile";
visible = "1";
active = "1";
tooltipProfile = "ToolsGuiToolTipProfile";
hovertime = "1000";
isContainer = "1";
canSave = "1";
canSaveDynamicFields = "0";
new GuiButtonCtrl() {
text = "Texture Settings";
buttonType = "pushButton";
profile = "ToolsGuiButtonProfile";
command = "TerrainTextureSettingsDlg.show();";
tooltipProfile = "ToolsGuiToolTipProfile";
position = "0 0";
extent = "90 18";
horizSizing = "right";
vertSizing = "bottom";
};
};
};
};
//--- OBJECT WRITE END ---

View file

@ -32,9 +32,9 @@
anchorBottom = "0";
anchorLeft = "0";
anchorRight = "0";
position = "315 168";
extent = "394 494";
minExtent = "358 432";
position = "315 127";
extent = "394 514";
minExtent = "358 452";
horizSizing = "center";
vertSizing = "center";
profile = "ToolsGuiWindowProfile";
@ -149,7 +149,7 @@
anchorLeft = "1";
anchorRight = "0";
position = "202 26";
extent = "185 425";
extent = "185 445";
minExtent = "8 2";
horizSizing = "left";
vertSizing = "height";
@ -511,7 +511,7 @@
anchorLeft = "1";
anchorRight = "0";
position = "6 122";
extent = "185 50";
extent = "185 100";
minExtent = "8 2";
horizSizing = "width";
vertSizing = "bottom";
@ -712,12 +712,162 @@
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiSliderCtrl(TerrainMaterialDlgBlendHeightBaseSlider) {
range = "-0.5 0.5";
ticks = "0";
snap = "0";
value = "0.5";
useFillBar = "0";
fillBarColor = "255 255 255 255";
renderTicks = "1";
position = "39 61";
extent = "70 14";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "ToolsGuiSliderProfile";
visible = "1";
active = "1";
tooltipProfile = "ToolsGuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
internalName = "blendHeightBaseSliderCtrl";
canSave = "1";
canSaveDynamicFields = "0";
};
new GuiTextCtrl() {
text = "Blend Height";
maxLength = "1024";
margin = "0 0 0 0";
padding = "0 0 0 0";
anchorTop = "1";
anchorBottom = "0";
anchorLeft = "1";
anchorRight = "0";
position = "115 61";
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(TerrainMaterialDlgBlendHeightBaseTextEdit) {
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 59";
extent = "35 18";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "ToolsGuiTextEditProfile";
visible = "1";
active = "1";
tooltipProfile = "ToolsGuiToolTipProfile";
hovertime = "1000";
isContainer = "0";
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";
};
};
new GuiBitmapCtrl() {
bitmap = "tools/gui/images/separator-v";
color = "255 255 255 255";
wrap = "0";
position = "6 177";
position = "6 222";
extent = "175 2";
minExtent = "8 2";
horizSizing = "width";
@ -738,7 +888,7 @@
anchorBottom = "0";
anchorLeft = "1";
anchorRight = "0";
position = "6 184";
position = "6 229";
extent = "185 64";
minExtent = "8 2";
horizSizing = "width";
@ -781,7 +931,7 @@
anchorLeft = "1";
anchorRight = "0";
position = "56 -3";
extent = "60 18";
extent = "64 18";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
@ -933,7 +1083,7 @@
bitmap = "tools/gui/images/separator-v";
color = "255 255 255 255";
wrap = "0";
position = "6 254";
position = "6 299";
extent = "175 2";
minExtent = "8 2";
horizSizing = "width";
@ -954,7 +1104,7 @@
anchorBottom = "0";
anchorLeft = "1";
anchorRight = "0";
position = "6 261";
position = "6 306";
extent = "185 72";
minExtent = "8 2";
horizSizing = "width";
@ -1438,7 +1588,7 @@
bitmap = "tools/gui/images/separator-v";
color = "255 255 255 255";
wrap = "0";
position = "6 336";
position = "6 381";
extent = "175 2";
minExtent = "8 2";
horizSizing = "width";
@ -1459,7 +1609,7 @@
anchorBottom = "0";
anchorLeft = "1";
anchorRight = "0";
position = "6 343";
position = "6 388";
extent = "185 72";
minExtent = "8 2";
horizSizing = "width";
@ -1766,7 +1916,7 @@
};
new GuiControl() {
position = "6 42";
extent = "189 435";
extent = "189 455";
minExtent = "8 2";
horizSizing = "width";
vertSizing = "height";
@ -1831,7 +1981,7 @@
canRenameObjects = "1";
renameInternal = "0";
position = "1 1";
extent = "8 2";
extent = "136 798";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
@ -1853,7 +2003,7 @@
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "0";
position = "202 456";
position = "202 476";
extent = "98 22";
minExtent = "8 2";
horizSizing = "left";
@ -1873,7 +2023,7 @@
groupNum = "-1";
buttonType = "PushButton";
useMouseEvents = "0";
position = "307 456";
position = "307 476";
extent = "80 22";
minExtent = "8 2";
horizSizing = "left";
@ -1893,7 +2043,7 @@
color = "255 255 255 255";
wrap = "0";
position = "199 23";
extent = "190 329";
extent = "190 349";
minExtent = "8 2";
horizSizing = "left";
vertSizing = "height";

View file

@ -0,0 +1,309 @@
//--- OBJECT WRITE BEGIN ---
%guiContent = new GuiControl(TerrainTextureSettingsDlg, EditorGuiGroup) {
position = "0 0";
extent = "1024 768";
minExtent = "8 2";
horizSizing = "right";
vertSizing = "bottom";
profile = "ToolsGuiDefaultProfile";
visible = "1";
active = "1";
tooltipProfile = "ToolsGuiToolTipProfile";
hovertime = "1000";
isContainer = "1";
canSave = "1";
canSaveDynamicFields = "1";
new GuiWindowCtrl() {
canSaveDynamicFields = "0";
internalName = "TerrainTextureSettings";
Enabled = "1";
isContainer = "1";
Profile = "ToolsGuiWindowProfile";
position = "342 184";
extent = "340 400";
minExtent = "340 400";
horizSizing = "center";
vertSizing = "center";
canSave = "1";
isDecoy = "0";
Visible = "1";
tooltipprofile = "ToolsGuiToolTipProfile";
hovertime = "1000";
Margin = "0 0 0 0";
Padding = "0 0 0 0";
AnchorTop = "1";
AnchorBottom = "1";
AnchorLeft = "1";
AnchorRight = "1";
resizeWidth = "1";
resizeHeight = "0";
canMove = "1";
canClose = "1";
canMinimize = "0";
canMaximize = "0";
minSize = "4 4";
closeCommand = "TerrainTextureSettingsDlg.cancel();";
EdgeSnap = "0";
text = "Global Terrain Texture Settings";
new GuiCheckBoxCtrl() {
internalName = "lerpBlendCheckBox";
text = "LerpBlend";
profile = "ToolsGuiCheckBoxProfile";
tooltipProfile = "ToolsGuiToolTipProfile";
tooltip = "If enabled, terrain textures will use a simple linear interpolation blending method.";
command = "TerrainTextureSettingsDlg.apply();";
position = "20 40";
extent = "300 20";
};
new GuiControl() {
position = "20 70";
profile = "ToolsGuiDefaultProfile";
extent = "300 20";
new GuiTextCtrl() {
text = "Global Blend Depth:";
profile = "ToolsGuiTextProfile";
tooltipProfile = "ToolsGuiToolTipProfile";
tooltip = "Controls the general level of bleding across all textures, has no effect if Lerp Blend is enabled.";
position = "0 0";
extent = "120 20";
};
new GuiSliderCtrl() {
internalName = "blendDepthSlider";
profile = "ToolsGuiSliderProfile";
command = "TerrainTextureSettingsDlg.apply();";
altCommand = "TerrainTextureSettingsDlg.updateBlendDepth();";
position = "130 0";
extent = "170 20";
range = "0.01 1.0";
};
};
new GuiControl() {
position = "20 100";
profile = "ToolsGuiDefaultProfile";
extent = "300 20";
new GuiTextCtrl() {
text = "Detail Texture Size:";
profile = "ToolsGuiTextProfile";
command = "TerrainTextureSettingsDlg.apply();";
position = "0 0";
extent = "120 20";
};
new GuiTextEditCtrl() {
internalName = "detailTextureSizeTextEdit";
profile = "ToolsGuiTextEditProfile";
command = "TerrainTextureSettingsDlg.apply();";
position = "130 0";
extent = "170 20";
};
};
new GuiControl() {
position = "20 130";
profile = "ToolsGuiDefaultProfile";
extent = "300 20";
new GuiTextCtrl() {
text = "Detail Texture Format:";
profile = "ToolsGuiTextProfile";
position = "0 0";
extent = "120 20";
};
new GuiPopUpMenuCtrl() {
internalName = "detailTextureFormatPopUpMenu";
profile = "ToolsGuiPopUpMenuProfile";
command = "TerrainTextureSettingsDlg.apply();";
position = "130 0";
extent = "170 20";
};
};
new GuiControl() {
position = "20 160";
profile = "ToolsGuiDefaultProfile";
extent = "300 20";
new GuiTextCtrl() {
text = "Macro Texture Size:";
profile = "ToolsGuiTextProfile";
position = "0 0";
extent = "120 20";
};
new GuiTextEditCtrl() {
internalName = "macroTextureSizeTextEdit";
profile = "ToolsGuiTextEditProfile";
command = "TerrainTextureSettingsDlg.apply();";
position = "130 0";
extent = "170 20";
};
};
new GuiControl() {
position = "20 190";
profile = "ToolsGuiDefaultProfile";
extent = "300 20";
new GuiTextCtrl() {
text = "Macro Texture Format:";
profile = "ToolsGuiTextProfile";
position = "0 0";
extent = "120 20";
};
new GuiPopUpMenuCtrl() {
internalName = "macroTextureFormatPopUpMenu";
profile = "ToolsGuiPopUpMenuProfile";
command = "TerrainTextureSettingsDlg.apply();";
position = "130 0";
extent = "170 20";
};
};
new GuiControl() {
position = "20 220";
profile = "ToolsGuiDefaultProfile";
extent = "300 20";
new GuiTextCtrl() {
text = "Normal Texture Size:";
profile = "ToolsGuiTextProfile";
position = "0 0";
extent = "120 20";
};
new GuiTextEditCtrl() {
internalName = "normalTextureSizeTextEdit";
profile = "ToolsGuiTextEditProfile";
command = "TerrainTextureSettingsDlg.apply();";
position = "130 0";
extent = "170 20";
};
};
new GuiControl() {
position = "20 250";
profile = "ToolsGuiDefaultProfile";
extent = "300 20";
new GuiTextCtrl() {
text = "Normal Texture Format:";
profile = "ToolsGuiTextProfile";
position = "0 0";
extent = "120 20";
};
new GuiPopUpMenuCtrl() {
internalName = "normalTextureFormatPopUpMenu";
profile = "ToolsGuiPopUpMenuProfile";
command = "TerrainTextureSettingsDlg.apply();";
position = "130 0";
extent = "170 20";
};
};
new GuiControl() {
position = "20 280";
profile = "ToolsGuiDefaultProfile";
extent = "300 20";
new GuiTextCtrl() {
text = "ORM Texture Size:";
profile = "ToolsGuiTextProfile";
position = "0 0";
extent = "120 20";
};
new GuiTextEditCtrl() {
internalName = "ormTextureSizeTextEdit";
profile = "ToolsGuiTextEditProfile";
position = "130 0";
extent = "170 20";
};
};
new GuiControl() {
position = "20 310";
profile = "ToolsGuiDefaultProfile";
extent = "300 20";
new GuiTextCtrl() {
text = "ORM Texture Format:";
profile = "ToolsGuiTextProfile";
position = "0 0";
extent = "120 20";
};
new GuiPopUpMenuCtrl() {
internalName = "ormTextureFormatPopUpMenu";
profile = "ToolsGuiPopUpMenuProfile";
position = "130 0";
extent = "170 20";
};
};
new GuiControl() {
position = "20 350";
profile = "ToolsGuiDefaultProfile";
extent = "300 30";
new GuiButtonCtrl() {
text = "Apply & Save";
profile = "ToolsGuiButtonProfile";
position = "0 0";
command = "TerrainTextureSettingsDlg.applyAndSave();";
extent = "145 30";
};
new GuiButtonCtrl() {
text = "Cancel";
profile = "ToolsGuiButtonProfile";
position = "155 0";
command = "TerrainTextureSettingsDlg.cancel();";
extent = "145 30";
};
};
};
};
//--- OBJECT WRITE END ---

View file

@ -119,7 +119,8 @@ function EditorGui::init(%this)
}
exec("~/worldEditor/gui/guiTerrainMaterialDlg.ed.gui");
exec("~/worldEditor/gui/TerrainBrushSoftnessCurveDlg.ed.gui");
exec("~/worldEditor/gui/TerrainBrushSoftnessCurveDlg.ed.gui");
exec("~/worldEditor/gui/guiTerrainTextureSettingsDlg.ed.gui");
}
if ( !isObject( %this-->TerrainPainterToolbar) )
{

View file

@ -443,6 +443,14 @@ function TerrainMaterialDlg::setActiveMaterial( %this, %mat )
%this-->detDistanceCtrl.setText( %mat.detailDistance );
%this-->sideProjectionCtrl.setValue( %mat.useSideProjection );
%this-->parallaxScaleCtrl.setText( %mat.parallaxScale );
%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 );
@ -504,6 +512,8 @@ function TerrainMaterialDlg::saveDirtyMaterial( %this, %mat )
%detailDistance = %this-->detDistanceCtrl.getText();
%useSideProjection = %this-->sideProjectionCtrl.getValue();
%parallaxScale = %this-->parallaxScaleCtrl.getText();
%blendHeightBase = %this-->blendHeightBaseTextEditCtrl.getText();
%blendHeightContrast = %this-->blendHeightContrastTextEditCtrl.getText();
%macroSize = %this-->macroSizeCtrl.getText();
%macroStrength = %this-->macroStrengthCtrl.getText();
@ -529,11 +539,13 @@ function TerrainMaterialDlg::saveDirtyMaterial( %this, %mat )
%mat.macroSize == %macroSize &&
%mat.macroStrength == %macroStrength &&
%mat.macroDistance == %macroDistance &&
%mat.parallaxScale == %parallaxScale &&
%mat.parallaxScale == %parallaxScale &&
%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 )
@ -567,6 +579,8 @@ function TerrainMaterialDlg::saveDirtyMaterial( %this, %mat )
%mat.macroDistance = %macroDistance;
%mat.useSideProjection = %useSideProjection;
%mat.parallaxScale = %parallaxScale;
%mat.blendHeightBase = %blendHeightBase;
%mat.blendHeightContrast = %blendHeightContrast;
%mat.isSRGB = %isSRGB;
%mat.invertRoughness = %invertRoughness;
@ -619,6 +633,8 @@ function TerrainMaterialDlg::snapshotMaterials( %this )
macroDistance = %mat.macroDistance;
useSideProjection = %mat.useSideProjection;
parallaxScale = %mat.parallaxScale;
blendHeightBase = %mat.blendHeightBase;
blendHeightContrast = %mat.blendHeightContrast;
isSRGB = %mat.isSRGB;
invertRoughness = %mat.invertRoughness;
};
@ -656,6 +672,8 @@ function TerrainMaterialDlg::restoreMaterials( %this )
%mat.macroDistance = %obj.macroDistance;
%mat.useSideProjection = %obj.useSideProjection;
%mat.parallaxScale = %obj.parallaxScale;
%mat.blendHeightBase = %obj.blendHeightBase;
%mat.blendHeightContrast = %obj.blendHeightContrast;
%mat.isSRGB = %obj.isSRGB;
%mat.invertRoughness = %obj.invertRoughness;
}
@ -693,3 +711,31 @@ function TerrainMaterialDlg::_selectTextureFileDialog( %this, %defaultFileName )
return %file;
}
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;
TerrainMaterialDlgBlendHeightContrastTextEdit.setText(%value);
TerrainMaterialDlg.activeMat.blendHeightContrast = %this.value;
}
function TerrainMaterialDlgBlendHeightContrastTextEdit::onValidate(%this)
{
TerrainMaterialDlgBlendHeightContrastSlider.setValue(%this.getText());
TerrainMaterialDlg.activeMat.blendHeightContrast = %this.getText();
}

View file

@ -0,0 +1,158 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
$TerrainTextureSettingsDlg::TerrainTextureFormat =
"R8G8B8 10" TAB
"R8G8B8_SRGB 11" TAB
"R8G8B8A8 12" TAB
"R8G8B8A8_SRGB 15" TAB
"BC5 33";
//-----------------------------------------------------------------------------
function TerrainTextureSettingsDlg::show( %this )
{
Canvas.pushDialog( %this );
}
function TerrainTextureSettingsDlg::onWake( %this ) {
%this-->lerpBlendCheckBox.setStateOn(ProjectSettings.value("Terrain/LerpBlend"));
%this-->blendDepthSlider.setValue(ProjectSettings.value("Terrain/BlendDepth"));
%this-->detailTextureFormatPopUpMenu.clear();
%this-->macroTextureFormatPopUpMenu.clear();
%this-->normalTextureFormatPopUpMenu.clear();
%this-->ormTextureFormatPopUpMenu.clear();
for(%i = 0; %i < getFieldCount($TerrainTextureSettingsDlg::TerrainTextureFormat); %i++) {
%field = getField($TerrainTextureSettingsDlg::TerrainTextureFormat, %i);
%this-->detailTextureFormatPopUpMenu.add(getWord(%field, 0), getWord(%field, 1));
%this-->macroTextureFormatPopUpMenu.add(getWord(%field, 0), getWord(%field, 1));
%this-->normalTextureFormatPopUpMenu.add(getWord(%field, 0), getWord(%field, 1));
%this-->ormTextureFormatPopUpMenu.add(getWord(%field, 0), getWord(%field, 1));
}
%this-->detailTextureFormatPopUpMenu.setSelected(ProjectSettings.value("Terrain/DetailTextureFormat", 12), false);
%this-->macroTextureFormatPopUpMenu.setSelected(ProjectSettings.value("Terrain/MacroTextureFormat", 12), false);
%this-->normalTextureFormatPopUpMenu.setSelected(ProjectSettings.value("Terrain/NormalTextureFormat", 12), false);
%this-->ormTextureFormatPopUpMenu.setSelected(ProjectSettings.value("Terrain/OrmTextureFormat", 12), false);
%this-->detailTextureSizeTextEdit.setText(ProjectSettings.value("Terrain/DetailTextureSize"));
%this-->macroTextureSizeTextEdit.setText(ProjectSettings.value("Terrain/MacroTextureSize"));
%this-->normalTextureSizeTextEdit.setText(ProjectSettings.value("Terrain/NormalTextureSize"));
%this-->ormTextureSizeTextEdit.setText(ProjectSettings.value("Terrain/OrmTextureSize"));
}
function TerrainTextureSettingsDlg::updateBlendDepth( %this ) {
$Terrain::BlendDepth = %this-->blendDepthSlider.getValue();
}
function TerrainTextureSettingsDlg::apply( %this ) {
$Terrain::LerpBlend = %this-->lerpBlendCheckBox.isStateOn();
$Terrain::BlendDepth = %this-->blendDepthSlider.getValue();
$Terrain::DetailTextureFormat = %this-->detailTextureFormatPopUpMenu.getSelected();
$Terrain::MacroTextureFormat = %this-->macroTextureFormatPopUpMenu.getSelected();
$Terrain::NormalTextureFormat = %this-->normalTextureFormatPopUpMenu.getSelected();
$Terrain::OrmTextureFormat = %this-->ormTextureFormatPopUpMenu.getSelected();
if (%this-->detailTextureSizeTextEdit.getText() $= "" || mIsPow2(%this-->detailTextureSizeTextEdit.getText())) {
$Terrain::DetailTextureSize = %this-->detailTextureSizeTextEdit.getText();
}
if (%this-->macroTextureSizeTextEdit.getText() $= "" || mIsPow2(%this-->macroTextureSizeTextEdit.getText())) {
$Terrain::MacroTextureSize = %this-->macroTextureSizeTextEdit.getText();
}
if (%this-->normalTextureSizeTextEdit.getText() $= "" || mIsPow2(%this-->normalTextureSizeTextEdit.getText())) {
$Terrain::NormalTextureSize = %this-->normalTextureSizeTextEdit.getText();
}
if (%this-->ormTextureSizeTextEdit.getText() $= "" || mIsPow2(%this-->ormTextureSizeTextEdit.getText())) {
$Terrain::OrmTextureSize = %this-->ormTextureSizeTextEdit.getText();
}
ETerrainEditor.getActiveTerrain().getClientObject().setMaterialsDirty();
}
function TerrainTextureSettingsDlg::validate( %this ) {
if (%this-->detailTextureSizeTextEdit.getText() !$= "" && !mIsPow2(%this-->detailTextureSizeTextEdit.getText())) {
toolsMessageBoxOK("Detail Texture Error!", "Detail texture resolution must be a power of 2");
return false;
}
if (%this-->macroTextureSizeTextEdit.getText() !$= "" && !mIsPow2(%this-->macroTextureSizeTextEdit.getText())) {
toolsMessageBoxOK("Macro Texture Error!", "Macro texture resolution must be a power of 2");
return false;
}
if (%this-->normalTextureSizeTextEdit.getText() !$= "" && !mIsPow2(%this-->normalTextureSizeTextEdit.getText())) {
toolsMessageBoxOK("Normal Texture Error!", "Normal texture resolution must be a power of 2");
return false;
}
if (%this-->ormTextureSizeTextEdit.getText() !$= "" && !mIsPow2(%this-->ormTextureSizeTextEdit.getText())) {
toolsMessageBoxOK("ORM Texture Error!", "ORM texture resolution must be a power of 2");
return false;
}
return true;
}
function TerrainTextureSettingsDlg::cancel( %this ) {
$Terrain::LerpBlend = ProjectSettings.value("Terrain/LerpBlend");
$Terrain::BlendDepth = ProjectSettings.value("Terrain/BlendDepth");
$Terrain::DetailTextureFormat = ProjectSettings.value("Terrain/DetailTextureFormat");
$Terrain::MacroTextureFormat = ProjectSettings.value("Terrain/MacroTextureFormat");
$Terrain::NormalTextureFormat = ProjectSettings.value("Terrain/NormalTextureFormat");
$Terrain::OrmTextureFormat = ProjectSettings.value("Terrain/OrmTextureFormat");
$Terrain::DetailTextureSize = ProjectSettings.value("Terrain/DetailTextureSize");
$Terrain::MacroTextureSize = ProjectSettings.value("Terrain/MacroTextureSize");
$Terrain::NormalTextureSize = ProjectSettings.value("Terrain/NormalTextureSize");
$Terrain::OrmTextureSize = ProjectSettings.value("Terrain/OrmTextureSize");
ETerrainEditor.getActiveTerrain().getClientObject().setMaterialsDirty();
Canvas.popDialog(%this);
}
function TerrainTextureSettingsDlg::applyAndSave( %this ) {
if (!%this.validate()) {
return;
}
%this.apply();
ProjectSettings.setValue("Terrain/LerpBlend", $Terrain::LerpBlend);
ProjectSettings.setValue("Terrain/BlendDepth", $Terrain::BlendDepth);
ProjectSettings.setValue("Terrain/DetailTextureFormat", $Terrain::DetailTextureFormat);
ProjectSettings.setValue("Terrain/MacroTextureFormat", $Terrain::MacroTextureFormat);
ProjectSettings.setValue("Terrain/NormalTextureFormat", $Terrain::NormalTextureFormat);
ProjectSettings.setValue("Terrain/OrmTextureFormat", $Terrain::OrmTextureFormat);
ProjectSettings.setValue("Terrain/DetailTextureSize", $Terrain::DetailTextureSize);
ProjectSettings.setValue("Terrain/MacroTextureSize", $Terrain::MacroTextureSize);
ProjectSettings.setValue("Terrain/NormalTextureSize", $Terrain::NormalTextureSize);
ProjectSettings.setValue("Terrain/OrmTextureSize", $Terrain::OrmTextureSize);
ProjectSettings.write();
Canvas.popDialog(%this);
}