Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About ninekorn

  • Rank

Personal Information

  • Interests

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. 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.BindFlags = BindFlags.ShaderResource; 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: https://stackoverflow.com/questions/8514695/can-you-look-sample-a-texture-in-a-vertex-shader https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/dx-graphics-hlsl-to-samplelevel https://forum.unity.com/threads/how-to-sample-a-texture-in-vertex-shader.513816/ Thank you for the help, ninekorn aka Steve Chassé
  2. 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. Project => https://drive.google.com/open?id=1-kum0phM_iBMc8xRxYShmCNRWRs6W0Aw 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: 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. 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. 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. 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.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

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!