Improve terrain rendering, handle bug with no detail

This commit is contained in:
Lukas Aldershaab 2021-01-04 20:06:17 +01:00
parent 27641b16ca
commit 481e2a7230
5 changed files with 74 additions and 24 deletions

View file

@ -49,6 +49,7 @@ void GFXTextureArray::set(U32 width, U32 height, U32 size, GFXFormat format, U32
bool GFXTextureArray::fromTextureArray(const Vector<GFXTexHandle>& textureArray, U32 capacity)
{
PROFILE_SCOPE(GFXTextureArray_fromTextureArray)
bool success = true;
// Not initialized, infer it from the given array of textures
@ -114,6 +115,7 @@ bool GFXTextureArray::fromTextureArray(const Vector<GFXTexHandle>& textureArray,
void GFXTextureArray::setTexture(const GFXTexHandle& texture, U32 slot)
{
PROFILE_SCOPE(GFXTextureArray_setTexture)
GFXTexHandle handle = texture;
if (texture->getPath().isNotEmpty())
{

View file

@ -1289,10 +1289,14 @@ void TerrainHeightMapBlendGLSL::processVert(
return;
MultiLine* meta = new MultiLine;
// Make sure the world to tangent transform
// is created and available for the pixel shader.
getOutViewToTangent(componentList, meta, fd);
// Handle an edge-case when there are no detail-maps available
if (fd.features.getNextFeatureIndex(MFT_TerrainDetailMap, -1) >= 0)
{
// Make sure the world to tangent transform
// is created and available for the pixel shader.
getOutViewToTangent(componentList, meta, fd);
}
output = meta;
}

View file

@ -1370,9 +1370,13 @@ void TerrainHeightMapBlendHLSL::processVert(Vector<ShaderComponent*>& componentL
MultiLine* meta = new MultiLine;
// Make sure the world to tangent transform
// is created and available for the pixel shader.
getOutViewToTangent(componentList, meta, fd);
// Handle an edge-case when there are no detail-maps available
if (fd.features.getNextFeatureIndex(MFT_TerrainDetailMap, -1) >= 0)
{
// Make sure the world to tangent transform
// is created and available for the pixel shader.
getOutViewToTangent(componentList, meta, fd);
}
output = meta;
}

View file

@ -675,16 +675,53 @@ bool TerrainCellMaterial::_initShader(bool deferredMat,
void TerrainCellMaterial::_updateMaterialConsts( )
{
PROFILE_SCOPE( TerrainCellMaterial_UpdateMaterialConsts );
if (mMaterialInfos.empty())
int detailMatCount = 0;
for (MaterialInfo* materialInfo : mMaterialInfos)
{
if (materialInfo == NULL)
continue;
TerrainMaterial* mat = materialInfo->mat;
if (mat == NULL)
continue;
// We only include materials that
// have more than a base texture.
if (mat->getDetailSize() <= 0 ||
mat->getDetailDistance() <= 0 ||
mat->getDetailMap().isEmpty())
continue;
detailMatCount++;
}
if (detailMatCount == 0)
{
return;
}
AlignedArray<Point4F> detailInfoArray(mMaterialInfos.size(), sizeof(Point4F));
AlignedArray<Point4F> detailScaleAndFadeArray(mMaterialInfos.size(), sizeof(Point4F));
for ( U32 j=0; j < mMaterialInfos.size(); j++ )
AlignedArray<Point4F> detailInfoArray(detailMatCount, sizeof(Point4F));
AlignedArray<Point4F> detailScaleAndFadeArray(detailMatCount, sizeof(Point4F));
int detailIndex = 0;
for (MaterialInfo* matInfo : mMaterialInfos)
{
MaterialInfo *matInfo = mMaterialInfos[j];
if (matInfo == NULL)
continue;
TerrainMaterial* mat = matInfo->mat;
if (mat == NULL)
continue;
// We only include materials that
// have more than a base texture.
if (mat->getDetailSize() <= 0 ||
mat->getDetailDistance() <= 0 ||
mat->getDetailMap().isEmpty())
continue;
F32 detailSize = matInfo->mat->getDetailSize();
F32 detailScale = 1.0f;
@ -716,11 +753,19 @@ void TerrainCellMaterial::_updateMaterialConsts( )
matInfo->mat->getDetailStrength(),
matInfo->mat->getParallaxScale(), 0 );
detailScaleAndFadeArray[j] = detailScaleAndFade;
detailInfoArray[j] = detailIdStrengthParallax;
detailScaleAndFadeArray[detailIndex] = detailScaleAndFade;
detailInfoArray[detailIndex] = detailIdStrengthParallax;
mConsts->setSafe(matInfo->mBlendDepthConst, matInfo->mat->getBlendDepth());
mConsts->setSafe(matInfo->mBlendContrastConst, matInfo->mat->getBlendContrast());
if (matInfo->mBlendDepthConst != NULL)
{
mConsts->setSafe(matInfo->mBlendDepthConst, matInfo->mat->getBlendDepth());
}
if (matInfo->mBlendContrastConst != NULL)
{
mConsts->setSafe(matInfo->mBlendContrastConst, matInfo->mat->getBlendContrast());
}
detailIndex++;
}
mConsts->setSafe(mDetailInfoVArrayConst, detailScaleAndFadeArray);
@ -739,11 +784,6 @@ bool TerrainCellMaterial::setupPass( const SceneRenderState *state,
return false;
}
if (mMaterialInfos.size() > 4)
{
int a = 2 + 2;
}
mCurrPass++;
_updateMaterialConsts();

View file

@ -59,7 +59,7 @@ protected:
public:
MaterialInfo()
:mat(NULL), layerId(0)
:mat(NULL), layerId(0), mBlendDepthConst(NULL), mBlendContrastConst(NULL)
{
}
@ -69,8 +69,8 @@ protected:
TerrainMaterial *mat;
U32 layerId;
GFXShaderConstHandle* mBlendDepthConst;
GFXShaderConstHandle* mBlendContrastConst;
GFXShaderConstHandle *mBlendDepthConst;
GFXShaderConstHandle *mBlendContrastConst;
};
///