I am trying to optimize drawing a cube with 3 different textures. An effect I want to achieve is:
What I am doing now is drawing cube using three Draw() calls:
graphicsDevice.Textures[0] = cube.frontTexture;
graphicsDevice
.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0,
36, 0, 2);
graphicsDevice.Textures[0] = cube.backTexture;
graphicsDevice
.DrawIndexedPrimitives(PrimitiveType.TriangleList, 6, 0,
30, 0, 2);
graphicsDevice.Textures[0] = cube.sideTexture;
graphicsDevice
.DrawIndexedPrimitives(PrimitiveType.TriangleList, 12, 0,
24, 0, 8);
Then my texture is processed in pixel shader I sample my texture:
texture Texture;
sampler textureSampler : register(s0) = sampler_state {
Texture = (Texture);
Filter = MIN_MAG_MIP_POINT;
AddressU = Wrap;
AddressV = Wrap;
};
and produce output:
return tex2D(textureSampler, texCoord); // I have my texCoords from vertex shader output
Unfortunately in my scene there are hundreds of similar cubes with different textures, as well as other objects and it has bad influence on FPS rate. What I noticed is that I can sample in my pixel shader more than one texture:
graphicsDevice.Textures[0] = cube.frontTexture;
graphicsDevice.Textures[1] = cube.backTexture;
graphicsDevice.Textures[2] = cube.sideTexture;
Can I somehow stick each texture to proper face of cuboid in my pixel shader, in order to draw it in one Draw() call? I use Silverlight 5.0, but any answers also concerning XNA, or MonoGames will be appreciated :)
