# SharpDX 4.2 - Access Texture1D data inside VertexShader

## Recommended Posts

Hi,

This is a continuation of the project found here:

Now that I was able to modify the positions of the vertex in a Vertex Shader through Vertex Bindings, I need to be able to nullify the triangles/vertex that aren't needed in the scene. In order to do that, I had multiple options:

Option 1: Create a ByteMap and send the data through a constant buffer inside of a geometry shader. The ByteMap wouldn't consist of the same ByteMap as I am sending through the vertexShader. It would consist again of 0's and 1's but each vertex NOT at an extremity of a chunk would be nullified in a Geometry shader, if that is even possible. I have tried this option and it failed as I do not know how to properly send the byteMap through a constant buffer.

Option 2: Create a Texture1D and access the Texture1D from within the VertexShader and THEN transfer the code to a Geometry shader if it works. I am currently trying this iteration but I am failing and need help.

Here's what I got so far:

THIS CODE IS CREATING THE TEXTURE1D with the BYTEMAP.

                    int totalWidth = SC_Globals.tinyChunkWidth * SC_Globals.tinyChunkHeight * SC_Globals.tinyChunkDepth * SC_Globals.numberOfInstancesPerObjectInWidth * SC_Globals.numberOfInstancesPerObjectInHeight * SC_Globals.numberOfInstancesPerObjectInDepth;

Texture1DDescription desc = new Texture1DDescription();
desc.Width = totalWidth;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = Format.B8G8R8A8_UNorm;
desc.Usage = ResourceUsage.Default;
desc.CpuAccessFlags = CpuAccessFlags.None;
desc.OptionFlags = ResourceOptionFlags.None;

int[] byteMap = chunkdat.arrayOfSomeMap.SelectMany(a => a).ToArray();
byte[] arrayOfBytes = new byte[byteMap.Length];

for (int i = 0; i < byteMap.Length; i++)
{
arrayOfBytes[i] = (byte)byteMap[i];
}

int rowPitch = 4 * desc.Width;
DataStream dataStream = new DataStream(rowPitch, true, true);
dataStream.WriteRange(arrayOfBytes, 0, arrayOfBytes.Length);
DataBox data = new DataBox(dataStream.DataPointer, rowPitch, rowPitch);

DataBox[] arrayOfBoxes = new DataBox[1];
arrayOfBoxes[0] = data;

Texture1D mapTexture = new Texture1D(device, desc, arrayOfBoxes);

textureView = new ShaderResourceView(device, mapTexture);

Inside of the Vertex Shader, I am trying to get the arrayOfBytes data OUT of the Texture1D like this:

    int x = input.indexPos.x;
int y = input.indexPos.y;
int z = input.indexPos.z;

int currentIndex = x + (tinyChunkWidth * (y + (tinyChunkHeight * z)));

int mainX = input.instancePosition1.x % 4;
int mainY = input.instancePosition1.y % 4;
int mainZ = input.instancePosition1.z % 4;

int indexMain  = mainX + mapWidth *( mainY + mapHeight * mainZ);
int indexTotal = (indexMain * 64) + (currentIndex);

float colordata = mapTexture[indexTotal]; // doesn't work
float colordata  = mapTexture.Load(indexTotal);  // doesn't work


But it doesn't work. I have found a good list of websites for information on how to do it but none works. Here are the references I found:

Thank you for the help,

ninekorn

aka Steve Chassé

## Create an account

Register a new account

• 10
• 13
• 52
• 11
• 15