# (SOLVED) - SharpDX 4.2 Vertex Shader Instanced Vertex Position Manipulation

## Recommended Posts

Hi, my original question which I again deleted by accident and cannot get it back was to find a way to Manipulate each individual vertex in instances with a vertex shader. I have now solved that problem and wanted to post it here. The project is in VR and requires you to have an Oculus Rift VR Headset. I will soon have the project without VR.

I have yet to find a suitable License for the project though. I was thinking of MIT license.

Original question on another forum => https://gamedev.stackexchange.com/questions/169506/vertex-manipulation-in-instanced-shader-hlsl-sharpdx-4-2?noredirect=1#comment302452_169506

How it works:

1. I am creating a single chunk and assign to each individual vertex an index to which cube they belong to. This chunk also creates the original vertex and original triangle index. Those vertex index and triangle index will be the same for each instance but their position will be modified. The data is accessible inside of the vertexBufferBinding.
2. I am then creating all of the chunks that are needed but only ouput the byteMap out of them in the form of integers with 8-9 digits each. For this project, 8 integers of 8 digits (9 digits total) are used and stored to be sent as INSTANCED data. Why only 8 integers? Well the chunks are 4*4*4 (width/height/depth) which is 64 bytes. I am taking padding each integer with a 1 (starting them with the digit 1) and then I fill them up with 0's and 1's until they reach 9 digit long. I might use decimals later on to increase the length of the data I can pass to the vertexBufferBinding.
3. An integer is 32bit long maximum so you need to make sacrifices and you have to PAD your integers starting with a number and if you decide to go in Decimals, you need to PAD at the end with a digit also other than zero. I could've reduced the number to maybe 4 integers instead but it worked well like this so I kept it at 8-9 digits per integers.
4. I don't even need to create a constant buffer to send the data to the instances, because the vertexBufferBindings as InstancedVertexBufferBindings are taking the integers array and sending that to each instances of each objects created in the scene.

It's a bit complicated to explain, so it's better that you see the code for yourself. The next goal of this type of terrain is to access the byteMaps from a Texture1D instead of the vertexBufferBindings because the vertexBufferBindings is limiting me to 32bit floats and creating a huge amount of VertexBufferBindings to cover all of the different sizes of chunks that I want to make would take a while. A Texture1D seems more suitable for the task and this will be part of my next question.

Current Result: - practically instant creation of a huge chunk 4*4*4 x 4*4*4 x 4*4*4.... each tinyChunk is 4*4*4. Each tinyChunk is instanced 4*4*4 and there is 4*4*4 objects on the screen. So this is 64 draw calls instead of 4096 draw calls. The problem now, is that ALL vertex and ALL triangles are drawn but their positions only changed so that you won't notice that they are there. The next step in the project is to remove the extra triangles and extra vertex by using a Geometry shader... I think that we can nullify faces in a Geometry shader, which would make it suitable to do the job.

## Create an account

Register a new account

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 12
• 9
• 11
• 15
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!