mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-12 15:14:35 +00:00
Improve terrain rendering, handle bug with no detail
This commit is contained in:
parent
27641b16ca
commit
481e2a7230
5 changed files with 74 additions and 24 deletions
|
|
@ -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)
|
bool GFXTextureArray::fromTextureArray(const Vector<GFXTexHandle>& textureArray, U32 capacity)
|
||||||
{
|
{
|
||||||
|
PROFILE_SCOPE(GFXTextureArray_fromTextureArray)
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
// Not initialized, infer it from the given array of textures
|
// 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)
|
void GFXTextureArray::setTexture(const GFXTexHandle& texture, U32 slot)
|
||||||
{
|
{
|
||||||
|
PROFILE_SCOPE(GFXTextureArray_setTexture)
|
||||||
GFXTexHandle handle = texture;
|
GFXTexHandle handle = texture;
|
||||||
if (texture->getPath().isNotEmpty())
|
if (texture->getPath().isNotEmpty())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1290,9 +1290,13 @@ void TerrainHeightMapBlendGLSL::processVert(
|
||||||
|
|
||||||
MultiLine* meta = new MultiLine;
|
MultiLine* meta = new MultiLine;
|
||||||
|
|
||||||
// Make sure the world to tangent transform
|
// Handle an edge-case when there are no detail-maps available
|
||||||
// is created and available for the pixel shader.
|
if (fd.features.getNextFeatureIndex(MFT_TerrainDetailMap, -1) >= 0)
|
||||||
getOutViewToTangent(componentList, meta, fd);
|
{
|
||||||
|
// Make sure the world to tangent transform
|
||||||
|
// is created and available for the pixel shader.
|
||||||
|
getOutViewToTangent(componentList, meta, fd);
|
||||||
|
}
|
||||||
|
|
||||||
output = meta;
|
output = meta;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1370,9 +1370,13 @@ void TerrainHeightMapBlendHLSL::processVert(Vector<ShaderComponent*>& componentL
|
||||||
|
|
||||||
MultiLine* meta = new MultiLine;
|
MultiLine* meta = new MultiLine;
|
||||||
|
|
||||||
// Make sure the world to tangent transform
|
// Handle an edge-case when there are no detail-maps available
|
||||||
// is created and available for the pixel shader.
|
if (fd.features.getNextFeatureIndex(MFT_TerrainDetailMap, -1) >= 0)
|
||||||
getOutViewToTangent(componentList, meta, fd);
|
{
|
||||||
|
// Make sure the world to tangent transform
|
||||||
|
// is created and available for the pixel shader.
|
||||||
|
getOutViewToTangent(componentList, meta, fd);
|
||||||
|
}
|
||||||
|
|
||||||
output = meta;
|
output = meta;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -675,16 +675,53 @@ bool TerrainCellMaterial::_initShader(bool deferredMat,
|
||||||
void TerrainCellMaterial::_updateMaterialConsts( )
|
void TerrainCellMaterial::_updateMaterialConsts( )
|
||||||
{
|
{
|
||||||
PROFILE_SCOPE( 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;
|
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 detailSize = matInfo->mat->getDetailSize();
|
||||||
F32 detailScale = 1.0f;
|
F32 detailScale = 1.0f;
|
||||||
|
|
@ -716,11 +753,19 @@ void TerrainCellMaterial::_updateMaterialConsts( )
|
||||||
matInfo->mat->getDetailStrength(),
|
matInfo->mat->getDetailStrength(),
|
||||||
matInfo->mat->getParallaxScale(), 0 );
|
matInfo->mat->getParallaxScale(), 0 );
|
||||||
|
|
||||||
detailScaleAndFadeArray[j] = detailScaleAndFade;
|
detailScaleAndFadeArray[detailIndex] = detailScaleAndFade;
|
||||||
detailInfoArray[j] = detailIdStrengthParallax;
|
detailInfoArray[detailIndex] = detailIdStrengthParallax;
|
||||||
|
|
||||||
mConsts->setSafe(matInfo->mBlendDepthConst, matInfo->mat->getBlendDepth());
|
if (matInfo->mBlendDepthConst != NULL)
|
||||||
mConsts->setSafe(matInfo->mBlendContrastConst, matInfo->mat->getBlendContrast());
|
{
|
||||||
|
mConsts->setSafe(matInfo->mBlendDepthConst, matInfo->mat->getBlendDepth());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (matInfo->mBlendContrastConst != NULL)
|
||||||
|
{
|
||||||
|
mConsts->setSafe(matInfo->mBlendContrastConst, matInfo->mat->getBlendContrast());
|
||||||
|
}
|
||||||
|
detailIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
mConsts->setSafe(mDetailInfoVArrayConst, detailScaleAndFadeArray);
|
mConsts->setSafe(mDetailInfoVArrayConst, detailScaleAndFadeArray);
|
||||||
|
|
@ -739,11 +784,6 @@ bool TerrainCellMaterial::setupPass( const SceneRenderState *state,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mMaterialInfos.size() > 4)
|
|
||||||
{
|
|
||||||
int a = 2 + 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
mCurrPass++;
|
mCurrPass++;
|
||||||
|
|
||||||
_updateMaterialConsts();
|
_updateMaterialConsts();
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ protected:
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MaterialInfo()
|
MaterialInfo()
|
||||||
:mat(NULL), layerId(0)
|
:mat(NULL), layerId(0), mBlendDepthConst(NULL), mBlendContrastConst(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,8 +69,8 @@ protected:
|
||||||
|
|
||||||
TerrainMaterial *mat;
|
TerrainMaterial *mat;
|
||||||
U32 layerId;
|
U32 layerId;
|
||||||
GFXShaderConstHandle* mBlendDepthConst;
|
GFXShaderConstHandle *mBlendDepthConst;
|
||||||
GFXShaderConstHandle* mBlendContrastConst;
|
GFXShaderConstHandle *mBlendContrastConst;
|
||||||
};
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue