Cleanup and fixes

This commit is contained in:
Lukas Aldershaab 2021-01-02 02:08:22 +01:00
parent f55e7f7a22
commit 3c8d07a03e
10 changed files with 159 additions and 188 deletions

View file

@ -1,9 +1,9 @@
#include "gfxTextureArray.h"
#include "gfxDevice.h"
#include "gfxTextureManager.h"
#include "bitmap/imageUtils.h"
#include "console/console.h"
void GFXTextureArray::set(U32 width, U32 height, U32 size, GFXFormat format, U32 mipLevels)
@ -12,7 +12,8 @@ void GFXTextureArray::set(U32 width, U32 height, U32 size, GFXFormat format, U32
mHeight = height;
mArraySize = size;
mFormat = format;
mMipLevels = mipLevels;
mIsCompressed = ImageUtil::isCompressedFormat(mFormat);
mMipLevels = getMax(mipLevels, static_cast<U32>(1));
mTextures.setSize(size);

View file

@ -59,6 +59,7 @@ public:
virtual const String describeSelf() const;
GFXFormat mFormat;
bool mIsCompressed;
U32 mWidth;
U32 mHeight;
U32 mArraySize;

View file

@ -11,8 +11,8 @@ GFXGLTextureArray::GFXGLTextureArray()
void GFXGLTextureArray::init()
{
glGenTextures(1, &mTextureArray);
PRESERVE_2D_TEXTURE_ARRAY();
glGenTextures(1, &mTextureArray);
glBindTexture(GL_TEXTURE_2D_ARRAY, mTextureArray);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, mMin(mMipLevels - 1, 1));
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@ -20,7 +20,7 @@ void GFXGLTextureArray::init()
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexStorage3D(GL_TEXTURE_2D_ARRAY, mMipLevels, GL_RGBA8, mWidth, mHeight, mArraySize);
glTexStorage3D(GL_TEXTURE_2D_ARRAY, mMipLevels, GFXGLTextureInternalFormat[mFormat], mWidth, mHeight, mArraySize);
}
void GFXGLTextureArray::_setTexture(const GFXTexHandle& texture, U32 slot)
@ -73,9 +73,10 @@ void GFXGLTextureArray::bind(U32 textureUnit) const
{
glActiveTexture(GL_TEXTURE0 + textureUnit);
glBindTexture(GL_TEXTURE_2D_ARRAY, mTextureArray);
dynamic_cast<GFXGLDevice*>(getOwningDevice())->getOpenglCache()->setCacheBindedTex(textureUnit, GL_TEXTURE_2D_ARRAY, mTextureArray);
GFXGLStateBlockRef sb = static_cast<GFXGLDevice*>(GFX)->getCurrentStateBlock();
GFXGLStateBlockRef sb = dynamic_cast<GFXGLDevice*>(GFX)->getCurrentStateBlock();
AssertFatal(sb, "GFXGLTextureArray::bind - No active stateblock!");
if (!sb)
return;

View file

@ -29,8 +29,6 @@ protected:
private:
GLuint mTextureArray;
bool mIsCompressed;
};

View file

@ -336,9 +336,11 @@ void TerrainBaseMapFeatGLSL::processPix( Vector<ShaderComponent*> &componentLis
ShaderFeature::Resources TerrainBaseMapFeatGLSL::getResources( const MaterialFeatureData &fd )
{
Resources res;
Resources res;
// Sample base texture
res.numTexReg = 1;
res.numTex = 1;
res.numTex = 1;
return res;
}
@ -521,73 +523,40 @@ void TerrainDetailMapFeatGLSL::processPix( Vector<ShaderComponent*> &component
meta->addStatement( new GenOp( " @ = calcBlend( @.x, @.xy, @, @ );\r\n",
new DecOp( detailBlend ), new IndexOp(detailInfo, detailIndex), inTex, layerSize, layerSample ) );
// New terrain
Var *lerpBlend = (Var*)LangElement::find("lerpBlend");
if (!lerpBlend)
// If we had a parallax feature... then factor in the parallax
// amount so that it fades out with the layer blending.
if (fd.features.hasFeature(MFT_TerrainParallaxMap, detailIndex))
{
lerpBlend = new Var;
lerpBlend->setType("float");
lerpBlend->setName("lerpBlend");
lerpBlend->uniform = true;
lerpBlend->constSortPos = cspPrimitive;
// Get the normal map texture.
Var* normalMap = _getNormalMapSampler();
// Call the library function to do the rest.
if (fd.features.hasFeature(MFT_IsBC3nm, detailIndex))
{
meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, vec3(@.xy, @.x), @, @.z * @ );\r\n",
inDet, normalMap, inDet, new IndexOp(detailInfo, detailIndex), negViewTS, new IndexOp(detailInfo, detailIndex), detailBlend));
}
else
{
meta->addStatement(new GenOp(" @.xy += parallaxOffset( @, vec3(@.xy, @.x), @, @.z * @ );\r\n",
inDet, normalMap, inDet, new IndexOp(detailInfo, detailIndex), negViewTS, new IndexOp(detailInfo, detailIndex), detailBlend));
}
}
Var *blendDepth = (Var*)LangElement::find(String::ToString("blendDepth%d", detailIndex));
if (!blendDepth)
{
blendDepth = new Var;
blendDepth->setType("float");
blendDepth->setName(String::ToString("blendDepth%d", detailIndex));
blendDepth->uniform = true;
blendDepth->constSortPos = cspPrimitive;
}
ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
if (fd.features.hasFeature(MFT_isDeferred))
target= ShaderFeature::RenderTarget1;
Var *outColor = (Var*)LangElement::find( getOutputTargetVarName(target) );
if (!outColor)
{
// create color var
outColor = new Var;
outColor->setType("vec4");
outColor->setName("col");
outColor->setStructName("OUT");
meta->addStatement(new GenOp(" @;\r\n", outColor));
}
Var *detailColor = (Var*)LangElement::find(String::ToString("detailColor%d", detailIndex));
Var* detailColor = (Var*)LangElement::find(String::ToString("detailColor%d", detailIndex));
if (!detailColor)
{
detailColor = new Var;
detailColor->setType("vec4");
detailColor->setName(String::ToString("detailColor%d", detailIndex));
meta->addStatement(new GenOp(" @;\r\n", new DecOp(detailColor)));
detailColor = new Var;
detailColor->setType("vec4");
detailColor->setName(String::ToString("detailColor%d", detailIndex));
meta->addStatement(new GenOp(" @;\r\n", new DecOp(detailColor)));
}
// Get the detail texture.
Var *detailMap = _getDetailMapSampler();
// Get the normal map texture.
Var *normalMap = _getNormalMapSampler();
// Sample the normal map.
//
// We take two normal samples and lerp between them for
// side projection layers... else a single sample.
//
// Note that we're doing the standard greyscale detail
// map technique here which can darken and lighten the
// diffuse texture.
//
// We take two color samples and lerp between them for
// side projection layers... else a single sample.
//
// If we had a parallax feature... then factor in the parallax
// amount so that it fades out with the layer blending.
if (fd.features.hasFeature(MFT_TerrainSideProject, detailIndex))
{
meta->addStatement(new GenOp(" @ = ( lerp( tex2D( @, vec3(@.yz, @.x) ), tex2D( @, vec3(@.xz, @.x) ), @.z ) * 2.0 ) - 1.0;\r\n",
@ -602,31 +571,6 @@ void TerrainDetailMapFeatGLSL::processPix( Vector<ShaderComponent*> &component
meta->addStatement(new GenOp(" @ *= @.y * @.w;\r\n",
detailColor, new IndexOp(detailInfo, detailIndex), inDet));
// If we had a parallax feature... then factor in the parallax
// amount so that it fades out with the layer blending.
if ( fd.features.hasFeature( MFT_TerrainParallaxMap, detailIndex ) )
{
// Call the library function to do the rest.
if (fd.features.hasFeature(MFT_IsBC3nm, detailIndex))
{
meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, vec3(@.xy, @.x), @, @.z * @ );\r\n",
inDet, normalMap, inDet, new IndexOp(detailInfo, detailIndex), negViewTS, new IndexOp(detailInfo, detailIndex), detailBlend));
}
else
{
meta->addStatement(new GenOp(" @.xy += parallaxOffset( @, vec3(@.xy, @.x), @, @.z * @ );\r\n",
inDet, normalMap, inDet, new IndexOp(detailInfo, detailIndex), negViewTS, new IndexOp(detailInfo, detailIndex), detailBlend));
}
}
// Check to see if we have a gbuffer normal.
Var* viewToTangent = (Var*)LangElement::find("viewToTangent");
if (!viewToTangent && fd.features.hasFeature(MFT_TerrainHeightBlend))
{
// This needs to be here, to ensure consistent ordering of texcoords, be careful with moving it
getInViewToTangent(componentList);
}
if (!fd.features.hasFeature(MFT_TerrainHeightBlend))
{
// Check to see if we have a gbuffer normal.
@ -651,6 +595,14 @@ void TerrainDetailMapFeatGLSL::processPix( Vector<ShaderComponent*> &component
meta->addStatement(new GenOp(" if ( @ > 0.0f )\r\n", detailBlend));
meta->addStatement(new GenOp(" {\r\n"));
ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
if (fd.features.hasFeature(MFT_isDeferred))
target = ShaderFeature::RenderTarget1;
Var* outColor = (Var*)LangElement::find(getOutputTargetVarName(target));
meta->addStatement(new GenOp(" @.rgb = toGamma(@.rgb);\r\n", outColor, outColor));
meta->addStatement(new GenOp(" @ += @ * @;\r\n",
@ -672,10 +624,10 @@ ShaderFeature::Resources TerrainDetailMapFeatGLSL::getResources( const MaterialF
{
// If this is the first detail pass then we
// samples from the layer tex.
res.numTex += 1;
res.numTexReg += 1;
res.numTex = 1;
res.numTexReg = 1;
// Texture Array
// Add Detail TextureArray
res.numTex += 1;
res.numTexReg += 1;
}
@ -930,9 +882,12 @@ void TerrainNormalMapFeatGLSL::processVert( Vector<ShaderComponent*> &component
MultiLine *meta = new MultiLine;
// Make sure the world to tangent transform
// is created and available for the pixel shader.
getOutViewToTangent( componentList, meta, fd );
if (!fd.features.hasFeature(MFT_TerrainHeightBlend))
{
// Make sure the world to tangent transform
// is created and available for the pixel shader.
getOutViewToTangent(componentList, meta, fd);
}
output = meta;
}
@ -1018,24 +973,26 @@ ShaderFeature::Resources TerrainNormalMapFeatGLSL::getResources( const MaterialF
{
Resources res;
if (getProcessIndex() == 0)
// We only need to process normals during the deferred.
if (!fd.features.hasFeature(MFT_DeferredConditioner))
{
// Texture Array
res.numTex += 1;
res.numTexReg += 1;
return res;
}
S32 featureIndex = 0, firstNormalMapIndex = 0;
for (int idx = 0; idx < fd.features.getCount(); ++idx) {
const FeatureType& type = fd.features.getAt(idx, &featureIndex);
if (type == MFT_TerrainNormalMap) {
firstNormalMapIndex = getMin(firstNormalMapIndex, featureIndex);
}
}
// We only need to process normals during the deferred.
if ( fd.features.hasFeature( MFT_DeferredConditioner ) )
if (getProcessIndex() == firstNormalMapIndex)
{
// If this is the first normal map and there
// are no parallax features then we will
// generate the worldToTanget transform.
if ( !fd.features.hasFeature( MFT_TerrainParallaxMap ) &&
( getProcessIndex() == 0 || !fd.features.hasFeature( MFT_TerrainNormalMap, getProcessIndex() - 1 ) ) )
res.numTexReg = 3;
res.numTex = 1;
// Normal Texture Array
res.numTexReg += 1;
res.numTex += 1;
}
return res;
@ -1260,10 +1217,23 @@ void TerrainORMMapFeatGLSL::processPix(Vector<ShaderComponent*> &componentList,
ShaderFeature::Resources TerrainORMMapFeatGLSL::getResources(const MaterialFeatureData &fd)
{
Resources res;
res.numTex = 1;
res.numTexReg += 1;
return res;
Resources res;
S32 featureIndex = 0, firstOrmMapIndex = 0;
for (int idx = 0; idx < fd.features.getCount(); ++idx) {
const FeatureType& type = fd.features.getAt(idx, &featureIndex);
if (type == MFT_TerrainORMMap) {
firstOrmMapIndex = getMin(firstOrmMapIndex, featureIndex);
}
}
// We only need to process normals during the deferred.
if (getProcessIndex() == firstOrmMapIndex)
{
res.numTexReg = 1;
res.numTex = 1;
}
return res;
}
@ -1312,8 +1282,23 @@ void TerrainBlankInfoMapFeatGLSL::processPix(Vector<ShaderComponent*> &component
output = meta;
}
void TerrainHeightMapBlendGLSL::processVert(
Vector<ShaderComponent *> &componentList, const MaterialFeatureData &fd) {
// We only need to process normals during the deferred.
if (!fd.features.hasFeature(MFT_DeferredConditioner))
return;
MultiLine* meta = new MultiLine;
// Make sure the world to tangent transform
// is created and available for the pixel shader.
getOutViewToTangent(componentList, meta, fd);
output = meta;
}
void TerrainHeightMapBlendGLSL::processPix(Vector<ShaderComponent*>& componentList,
const MaterialFeatureData& fd)
const MaterialFeatureData& fd)
{
ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;

View file

@ -182,6 +182,9 @@ class TerrainHeightMapBlendGLSL : public TerrainFeatGLSL
{
public:
virtual void processVert(Vector<ShaderComponent*>& componentList,
const MaterialFeatureData& fd);
virtual void processPix(Vector<ShaderComponent*>& componentList,
const MaterialFeatureData& fd);

View file

@ -30,6 +30,7 @@
#include "gfx/gfxDevice.h"
#include "shaderGen/langElement.h"
#include "shaderGen/shaderOp.h"
#include "shaderGen/featureType.h"
#include "shaderGen/featureMgr.h"
#include "shaderGen/shaderGen.h"
#include "core/module.h"
@ -609,7 +610,6 @@ void TerrainDetailMapFeatHLSL::processPix( Vector<ShaderComponent*> &component
}
Var *detailColor = (Var*)LangElement::find(String::ToString("detailColor%d", detailIndex));
if ( !detailColor )
{
@ -619,19 +619,6 @@ void TerrainDetailMapFeatHLSL::processPix( Vector<ShaderComponent*> &component
meta->addStatement( new GenOp( " @;\r\n", new DecOp( detailColor ) ) );
}
// Sample the normal map.
//
// We take two normal samples and lerp between them for
// side projection layers... else a single sample.
//
// Note that we're doing the standard greyscale detail
// map technique here which can darken and lighten the
// diffuse texture.
//
// We take two color samples and lerp between them for
// side projection layers... else a single sample.
//
//Sampled detail texture that is not expanded
Var* detailMapArray = _getDetailMapArray();
Var* detailMapSampler = _getDetailMapSampler();
@ -650,15 +637,6 @@ void TerrainDetailMapFeatHLSL::processPix( Vector<ShaderComponent*> &component
meta->addStatement(new GenOp(" @ *= @.y * @.w;\r\n",
detailColor, new IndexOp(detailInfo, detailIndex), inDet));
// Check to see if we have a gbuffer normal.
Var* viewToTangent = (Var*)LangElement::find("viewToTangent");
if (!viewToTangent && fd.features.hasFeature(MFT_TerrainHeightBlend))
{
// This needs to be here, to ensure consistent ordering of texcoords, be careful with moving it
getInViewToTangent(componentList);
}
if (!fd.features.hasFeature(MFT_TerrainHeightBlend))
{
// Check to see if we have a gbuffer normal.
@ -720,18 +698,6 @@ ShaderFeature::Resources TerrainDetailMapFeatHLSL::getResources( const MaterialF
res.numTexReg += 1;
}
// sample from the detail texture for diffuse coloring.
// res.numTex += 1;
// If we have parallax for this layer then we'll also
// be sampling the normal map for the parallax heightmap.
//if ( fd.features.hasFeature( MFT_TerrainParallaxMap, getProcessIndex() ) )
//res.numTex += 1;
// Finally we always send the detail texture
// coord to the pixel shader.
// res.numTexReg += 1;
return res;
}
@ -1003,9 +969,12 @@ void TerrainNormalMapFeatHLSL::processVert( Vector<ShaderComponent*> &component
MultiLine *meta = new MultiLine;
// Make sure the world to tangent transform
// is created and available for the pixel shader.
getOutViewToTangent( componentList, meta, fd );
if ( !fd.features.hasFeature(MFT_TerrainHeightBlend) )
{
// Make sure the world to tangent transform
// is created and available for the pixel shader.
getOutViewToTangent(componentList, meta, fd);
}
output = meta;
}
@ -1092,20 +1061,26 @@ ShaderFeature::Resources TerrainNormalMapFeatHLSL::getResources( const MaterialF
{
Resources res;
if (!fd.features.hasFeature(MFT_DeferredConditioner))
{
return res;
}
if (getProcessIndex() == 0)
S32 featureIndex = 0, firstNormalMapIndex = 0;
for (int idx = 0; idx < fd.features.getCount(); ++idx) {
const FeatureType &type = fd.features.getAt(idx, &featureIndex);
if (type == MFT_TerrainNormalMap) {
firstNormalMapIndex = getMin(firstNormalMapIndex, featureIndex);
}
}
// We only need to process normals during the deferred.
if (getProcessIndex() == firstNormalMapIndex)
{
res.numTexReg += 1;
res.numTex += 1;
}
// If this is the first normal map and there
// are no parallax features then we will
// generate the worldToTanget transform.
//if ( !fd.features.hasFeature( MFT_TerrainParallaxMap ) &&
// ( getProcessIndex() == 0 || !fd.features.hasFeature( MFT_TerrainNormalMap, getProcessIndex() - 1 ) ) )
// res.numTexReg = 3;
//res.numTex = 1;
return res;
}
@ -1386,6 +1361,22 @@ void TerrainBlankInfoMapFeatHLSL::processPix(Vector<ShaderComponent*> &component
output = meta;
}
void TerrainHeightMapBlendHLSL::processVert(Vector<ShaderComponent*>& componentList,
const MaterialFeatureData& fd)
{
// We only need to process normals during the deferred.
if (!fd.features.hasFeature(MFT_DeferredConditioner))
return;
MultiLine* meta = new MultiLine;
// Make sure the world to tangent transform
// is created and available for the pixel shader.
getOutViewToTangent(componentList, meta, fd);
output = meta;
}
void TerrainHeightMapBlendHLSL::processPix(Vector<ShaderComponent*>& componentList,
const MaterialFeatureData& fd)
{
@ -1482,8 +1473,6 @@ void TerrainHeightMapBlendHLSL::processPix(Vector<ShaderComponent*>& componentLi
for (S32 idx = 0; idx < detailCount; ++idx)
{
Var* detCoord = (Var*)LangElement::find(String::ToString("detCoord%d", idx));
Var* detailH = (Var*)LangElement::find(String::ToString("detailH%d", idx));
Var* detailBlend = (Var*)LangElement::find(String::ToString("detailBlend%d", idx));

View file

@ -188,6 +188,9 @@ class TerrainHeightMapBlendHLSL : public TerrainFeatHLSL
{
public:
virtual void processVert(Vector<ShaderComponent*>& componentList,
const MaterialFeatureData& fd);
virtual void processPix(Vector<ShaderComponent*>& componentList,
const MaterialFeatureData& fd);

View file

@ -53,23 +53,13 @@ Vector<String> _initSamplerNames()
{
Vector<String> samplerNames;
samplerNames.push_back("$baseTexMap");
samplerNames.push_back("$layerTex");
//samplerNames.push_back("$macrolayerTex");
samplerNames.push_back("$layerTex");
samplerNames.push_back("$lightMapTex");
samplerNames.push_back("$lightInfoBuffer");
samplerNames.push_back("$normalMapSampler");
samplerNames.push_back("$detailMapSampler");
samplerNames.push_back("$macroMapSampler");
samplerNames.push_back("$ormMapSampler");
// samplerNames.push_back("$ormConfigMapArray");
for(int i = 0; i < sgMaxTerrainMaterialsPerPass; ++i)
{
//samplerNames.push_back(avar("$normalMap%d",i));
//samplerNames.push_back(avar("$detailMap%d",i));
//samplerNames.push_back(avar("$macroMap%d", i));
// samplerNames.push_back(avar("$ormConfigMap%d", i));
}
samplerNames.push_back("$ormMapSampler");
return samplerNames;
}
@ -783,13 +773,13 @@ bool TerrainCellMaterial::setupPass( const SceneRenderState *state,
0,
mConsts );
if (mDetailTexArrayConst->isValid())
if (mDetailTexArrayConst->isValid() && mTerrain->getDetailTextureArray().isValid())
GFX->setTextureArray(mDetailTexArrayConst->getSamplerRegister(), mTerrain->getDetailTextureArray());
if (mMacroTexArrayConst->isValid())
if (mMacroTexArrayConst->isValid() && mTerrain->getMacroTextureArray().isValid())
GFX->setTextureArray(mMacroTexArrayConst->getSamplerRegister(), mTerrain->getMacroTextureArray());
if (mNormalTexArrayConst->isValid())
if (mNormalTexArrayConst->isValid() && mTerrain->getNormalTextureArray().isValid())
GFX->setTextureArray(mNormalTexArrayConst->getSamplerRegister(), mTerrain->getNormalTextureArray());
if (mOrmTexArrayConst->isValid())
if (mOrmTexArrayConst->isValid() && mTerrain->getOrmTextureArray().isValid())
GFX->setTextureArray(mOrmTexArrayConst->getSamplerRegister(), mTerrain->getOrmTextureArray());
mConsts->setSafe( mLayerSizeConst, (F32)mTerrain->mLayerTex.getWidth() );

View file

@ -135,10 +135,10 @@ protected:
///
Vector<GFXTexHandle> mBaseTextures;
GFXTextureArray* mDetailTextureArray;
GFXTextureArray* mMacroTextureArray;
GFXTextureArray* mNormalTextureArray;
GFXTextureArray* mOrmTextureArray;
GFXTextureArrayHandle mDetailTextureArray;
GFXTextureArrayHandle mMacroTextureArray;
GFXTextureArrayHandle mNormalTextureArray;
GFXTextureArrayHandle mOrmTextureArray;
///
GFXTexHandle mLayerTex;
@ -331,10 +331,10 @@ public:
U32 getMaterialCount() const;
GFXTextureArray* getDetailTextureArray() const { return mDetailTextureArray; }
GFXTextureArray* getMacroTextureArray() const { return mMacroTextureArray; }
GFXTextureArray* getNormalTextureArray() const { return mNormalTextureArray; }
GFXTextureArray* getOrmTextureArray() const { return mOrmTextureArray; }
GFXTextureArrayHandle getDetailTextureArray() const { return mDetailTextureArray; }
GFXTextureArrayHandle getMacroTextureArray() const { return mMacroTextureArray; }
GFXTextureArrayHandle getNormalTextureArray() const { return mNormalTextureArray; }
GFXTextureArrayHandle getOrmTextureArray() const { return mOrmTextureArray; }
//BaseMatInstance* getMaterialInst( U32 x, U32 y );