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;