I have a terrain shader that needs to support texture blending for a large amount of textures, with bumpmaps.
To achieve this, I have a large amount of samplers in my fragment shader. It looks something like this:
Code :uniform sampler2D terrainNormalsTexture; //normal texture uniform sampler2D terrainTangentsTexture; //tangents texture, used for bump-mapping uniform sampler2DArray terrainTextures; //each array contains 2 textures, the diffuse texture and the bumpmap texture uniform float detailScales; //every texture can have a different UV scaling constant uniform sampler2DArrayShadow textureShadowMap; //the array contains 5 shadowmap cascades uniform sampler2DArray terrainAlphas; //contains 3 textures, each component (.rgba) corresponds to the blending "alpha" of the terrain textures
I'm using a bunch of sampler2DArrays in an attempt to reduce the amount of texture image units (previously these were all individual sampler2Ds, and I was going over my texture image unit target of 16).
However, I am running into an issue that sampling some of the textures will result in a complete failure of the shader. It compiles and links without error. However the terrain will not render.
For example, if I reduce the amount of terrainTextures and detailScales used (from for example 13 to 2), along with the lookups of those textures, it does work.
But increased that amount, and the terrain just completely stops rendering.
I do my texture lookups for example like this:
Like I said this works fine up until a certain amount. For example if I would replace the last .r with .a, it could stop rendering the terrain entirely.Code :float alpha = texture2DArray(terrainAlphas, vec3(texCoord0,0)).r; //access the zero'th terrainAlphas, component r
I know my code works in principal, since before I had bumpmaps in my code I wasn't hitting this sort of behaviour, even with 13 terrain textures being sampled.
Could anyone give me advice on what may be causing this, and how to deal with it (or potential work-arounds)? I'm a hobbyist developer, so I may be tackling rendering using a large amount of textures the wrong way!
I can post the entire shader if requested, but it's become a bit of a behemoth.
Much thanks in advance!