Sign in to follow this  
wandersonp

DX11 Diferent buffers in same 3D Model

Recommended Posts

wandersonp    106
Hello everyone, I´m struggling in a little problem.
I want load models exported from 3dsmax to my DX appllication.
but 3ds models have differents numbers of vertex, textureUV and normals.
like that obj file, a simple noise cube. 12 triangles, 8 vertex, 24 normals and 18 uv
I know how to load file with same size of vertex, uv and normals.

But how can I load diferent vertex buffers and combine them to a final indexed buffer to a mesh?
It is possible to do that in DX11?

#
# object Box001
#
v 0.4524 -0.4922 0.0625
v 0.4792 0.5078 0.0078
v -0.5208 0.5034 -0.0127
v -0.5476 -0.4966 0.0435
v 0.3906 -0.4820 -0.9375
v -0.6094 -0.4847 -0.9565
v -0.5934 0.5153 -1.0127
v 0.4066 0.5180 -0.9922
# 8 vertices
vn -0.0200 0.0559 0.9982
vn -0.0207 0.0553 0.9983
vn -0.0193 0.0566 0.9982
vn 0.0199 -0.0557 -0.9982
vn 0.0192 -0.0564 -0.9982
vn 0.0206 -0.0550 -0.9983
vn -0.0037 0.9999 0.0113
vn -0.0029 0.9999 0.0121
vn -0.0046 0.9999 0.0105
vn 0.9974 -0.0250 -0.0673
vn 0.9972 -0.0199 -0.0726
vn 0.9976 -0.0302 -0.0619
vn 0.0037 -0.9999 -0.0113
vn 0.0028 -0.9999 -0.0103
vn 0.0046 -0.9999 -0.0122
vn -0.9974 0.0251 0.0673
vn -0.9979 0.0194 0.0619
vn -0.9969 0.0308 0.0728
# 18 vertex normals
vt 0.0965 0.5834 0.0005
vt 0.0965 0.4166 0.0005
vt 0.2632 0.4166 0.0005
vt 0.2632 0.5834 0.0005
vt 0.4704 0.3806 0.9995
vt 0.3036 0.3806 0.9995
vt 0.3036 0.2138 0.9995
vt 0.4704 0.2138 0.9995
vt 0.4760 0.7819 0.0005
vt 0.3093 0.7819 0.0005
vt 0.3093 0.6151 0.0005
vt 0.4760 0.6151 0.0005
vt 0.6846 0.5834 0.9995
vt 0.5179 0.5834 0.9995
vt 0.5179 0.4166 0.9995
vt 0.6846 0.4166 0.9995
vt 0.8998 0.5834 0.9995
vt 0.7330 0.5834 0.9995
vt 0.7330 0.4166 0.9995
vt 0.8998 0.4166 0.9995
vt 0.4704 0.5834 0.0005
vt 0.3036 0.5834 0.0005
vt 0.3036 0.4166 0.0005
vt 0.4704 0.4166 0.0005
# 24 texture coords
g Box001
usemtl wire_148177027
f 1/1/1 2/2/2 3/3/1
f 3/3/1 4/4/3 1/1/1
f 5/5/4 6/6/5 7/7/4
f 7/7/4 8/8/6 5/5/4
f 8/9/7 7/10/8 3/11/7
f 3/11/7 2/12/9 8/9/7
f 5/13/10 8/14/11 2/15/10
f 2/15/10 1/16/12 5/13/10
f 6/17/13 5/18/14 1/19/13
f 1/19/13 4/20/15 6/17/13
f 7/21/16 6/22/17 4/23/16
f 4/23/16 3/24/18 7/21/16
# 12 faces

thanks

Share this post


Link to post
Share on other sites
Hodgman    51336
Many model formats index each attribute separately, so you can have a different number of positions/normals/texcoords/etc in the file.
However, every graphics API treats a "vertex" as a unique combination of all it's attributes, so you've got to perform the conversion. Every model importer does this, yes.

I'm not familiar with that format so I'm just guessing, but the 'f' lines down the bottom seem to contain position/tex-coord/normal indices.
For each of those groups, you can get the corresponding attributes and output them to your vertex buffer.
e.g. for "4/23/16", write the 4th position, then the 23rd tex-coord, then the 16th normal into your buffer.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By thmfrnk
      Hey,
      I found a very interesting blog post here: https://bartwronski.com/2017/04/13/cull-that-cone/
      However, I didn't really got how to use his "TestConeVsSphere" test in 3D (last piece of code on his post). I have the frustumCorners of a 2D Tile cell in ViewSpace and my 3D Cone Origin and Direction, so where to place the "testSphere"? I thought about to also move the Cone into viewspace and put the sphere to the Center of the Cell with the radius of half-cellsize, however what about depth? A sphere does not have inf depth?
      I am missing anything? Any Ideas?
      Thx, Thomas
    • By Modymek
      hi all
      I want to enable and disable shader in MPCH Media player Classic
      the MPCH have shader option using HLSL shaders
      I want the shader to read each file extension before it plays the file
      so if the video file name is video.GR.Mp4 it will play it in Grayscale shader 
      if it is not and standard file name Video.Mp4 without GR. unique extension so it plays standard without shader or end the shader
      here is the shader I have for grayscale
      // $MinimumShaderProfile: ps_2_0
      sampler s0 : register(s0);
      float4 main(float2 tex : TEXCOORD0) : COLOR {
          float c0 = dot(tex2D(s0, tex), float4(0.299, 0.587, 0.114, 0));
          return c0;
      }
       
      I want to add if or block stantement or bloean to detect file name before it call the shader in order to go to the procedure or disable it or goto end direct without it
       
      any thoughts or help
    • By noodleBowl
      I've gotten to part in my DirectX 11 project where I need to pass the MVP matrices to my vertex shader. And I'm a little lost when it comes to the use of the constant buffer with the vertex shader
      I understand I need to set up the constant buffer just like any other buffer:
      1. Create a buffer description with the D3D11_BIND_CONSTANT_BUFFER flag 2. Map my matrix data into the constant buffer 3. Use VSSetConstantBuffers to actually use the buffer But I get lost at the VertexShader part, how does my vertex shader know to use this constant buffer when we get to the shader side of things
      In the example I'm following I see they have this as their vertex shader, but I don't understand how the shader knows to use the MatrixBuffer cbuffer. They just use the members directly. What if there was multiple cbuffer declarations like the Microsoft documentation says you could have?
      //Inside vertex shader cbuffer MatrixBuffer { matrix worldMatrix; matrix viewMatrix; matrix projectionMatrix; }; struct VertexInputType { float4 position : POSITION; float4 color : COLOR; }; struct PixelInputType { float4 position : SV_POSITION; float4 color : COLOR; }; PixelInputType ColorVertexShader(VertexInputType input) { PixelInputType output; // Change the position vector to be 4 units for proper matrix calculations. input.position.w = 1.0f; // Calculate the position of the vertex against the world, view, and projection matrices. output.position = mul(input.position, worldMatrix); output.position = mul(output.position, viewMatrix); output.position = mul(output.position, projectionMatrix); // Store the input color for the pixel shader to use. output.color = input.color; return output; }  
    • By gomidas
      I am trying to add normal map to my project I have an example of a cube: 
      I have normal in my shader I think. Then I set shader resource view for texture (NOT BUMP)
                  device.ImmediateContext.PixelShader.SetShaderResource(0, textureView);             device.ImmediateContext.Draw(VerticesCount,0); What should I do to set my normal map or how it is done in dx11 generally example c++?
    • By fighting_falcon93
      Imagine that we have a vertex structure that looks like this:
      struct Vertex { XMFLOAT3 position; XMFLOAT4 color; }; The vertex shader looks like this:
      cbuffer MatrixBuffer { matrix world; matrix view; matrix projection; }; struct VertexInput { float4 position : POSITION; float4 color : COLOR; }; struct PixelInput { float4 position : SV_POSITION; float4 color : COLOR; }; PixelInput main(VertexInput input) { PixelInput output; input.position.w = 1.0f; output.position = mul(input.position, world); output.position = mul(output.position, view); output.position = mul(output.position, projection); output.color = input.color; return output; } And the pixel shader looks like this:
      struct PixelInput { float4 position : SV_POSITION; float4 color : COLOR; }; float4 main(PixelInput input) : SV_TARGET { return input.color; } Now let's create a quad consisting of 2 triangles and the vertices A, B, C and D:
      // Vertex A. vertices[0].position = XMFLOAT3(-1.0f, 1.0f, 0.0f); vertices[0].color = XMFLOAT4( 0.5f, 0.5f, 0.5f, 1.0f); // Vertex B. vertices[1].position = XMFLOAT3( 1.0f, 1.0f, 0.0f); vertices[1].color = XMFLOAT4( 0.5f, 0.5f, 0.5f, 1.0f); // Vertex C. vertices[2].position = XMFLOAT3(-1.0f, -1.0f, 0.0f); vertices[2].color = XMFLOAT4( 0.5f, 0.5f, 0.5f, 1.0f); // Vertex D. vertices[3].position = XMFLOAT3( 1.0f, -1.0f, 0.0f); vertices[3].color = XMFLOAT4( 0.5f, 0.5f, 0.5f, 1.0f); // 1st triangle. indices[0] = 0; // Vertex A. indices[1] = 3; // Vertex D. indices[2] = 2; // Vertex C. // 2nd triangle. indices[3] = 0; // Vertex A. indices[4] = 1; // Vertex B. indices[5] = 3; // Vertex D. This will result in a grey quad as shown in the image below. I've outlined the edges in red color to better illustrate the triangles:

      Now imagine that we’d want our quad to have a different color in vertex A:
      // Vertex A. vertices[0].position = XMFLOAT3(-1.0f, 1.0f, 0.0f); vertices[0].color = XMFLOAT4( 0.0f, 0.0f, 0.0f, 1.0f);
      That works as expected since there’s now an interpolation between the black color in vertex A and the grey color in vertices B, C and D. Let’s revert the previus changes and instead change the color of vertex C:
      // Vertex C. vertices[2].position = XMFLOAT3(-1.0f, -1.0f, 0.0f); vertices[2].color = XMFLOAT4( 0.0f, 0.0f, 0.0f, 1.0f);
      As you can see, the interpolation is only done half of the way across the first triangle and not across the entire quad. This is because there's no edge between vertex C and vertex B.
      Which brings us to my question:
      I want the interpolation to go across the entire quad and not only across the triangle. So regardless of which vertex we decide to change the color of, the color interpolation should always go across the entire quad. Is there any efficient way of achieving this without adding more vertices and triangles?
      An illustration of what I'm trying to achieve is shown in the image below:

       
      Background
      This is just a very brief explanation of the problems background in case that would make it easier for you to understand the problems roots and maybe help you with finding a better solution to the problem.
      I'm trying to texture a terrain mesh in DirectX11. It's working, but I'm a bit unsatisfied with the result. When changing the terrain texture of a single vertex, the interpolation with the other vertices results in a hexagon shape instead of a squared shape:

      As the red arrows illustrate, I'd like the texture to be interpolated all the way into the corners of the quads.
  • Popular Now