Hi,
I have a pixel shader for a terrain tile which samples a texture atlas for various ground cover.
I have around 8 different ground cover types which I pass to the PS via a Texture Blend Map using Texture2D NormalizedByte4 with one channel per texture weight.
Most pixels will blend perhaps 3 of the 8 possible textures, exceptionally 4.
What is the optimal way to sample the textures ?
I followed the standard "linear" "add them all up" approach, shown below;
textureColor += tex2D(TextureSamplerAtlas1,getAtlasTextureCoords(textureCoords, float2(0,0))) * textureWeights1.a;
textureColor += tex2D(TextureSamplerAtlas1,getAtlasTextureCoords(textureCoords, float2(1,0))) * textureWeights1.r ;
textureColor += tex2D(TextureSamplerAtlas1,getAtlasTextureCoords(textureCoords, float2(0,1))) * textureWeights1.g ;
textureColor += tex2D(TextureSamplerAtlas1,getAtlasTextureCoords(textureCoords, float2(1,1))) * textureWeights1.b ;
textureColor += tex2D(TextureSamplerAtlas2,getAtlasTextureCoords(textureCoords, float2(0,0))) * textureWeights2.a;
textureColor += tex2D(TextureSamplerAtlas2,getAtlasTextureCoords(textureCoords, float2(1,0))) * textureWeights2.r;
textureColor += tex2D(TextureSamplerAtlas2,getAtlasTextureCoords(textureCoords, float2(0,1))) * textureWeights2.g;
textureColor += tex2D(TextureSamplerAtlas2,getAtlasTextureCoords(textureCoords, float2(1,1))) * textureWeights2.b;
However I could have bypassed the many lookups by checking the texture weight prior to sampling. Like this
if(textureWeights1.r > 0) textureColor += tex2D(TextureSamplerAtlas1,getAtlasTextureCoords(textureCoords, float2(1,0))) * textureWeights1.r ;
Which is the recommended approach for performance in a pixel shader ? I understand that the PS can bypass texture lookups sometimes, but I dont know whether doing this manually by checking the texture weight myself is a better solution, especially because I expect only 50% maximum of the texture lookups to actually achieve anything.
Phillip