3
\$\begingroup\$

I've got a working OBJ loader that loads vertices, indices, texture coordinates, and normals. As of right now it doesn't process texture coordinates or normals but it stores them in arrays and creates a valid mesh with the vertices and indices.

Now I am trying to figure out how can I make the shader use the correct normal in the array for the current vertex if I can't setnormals() to my mesh. If I were to just use an index in my array of normals corresponding to the index in the vertices, how would I retrieve the current index the shader is processing? BTW: I am trying to write a blinn-phong shader technique.

Also when I create the input layout and I've added the semantic NORMAL to it, how would I list the multiple semantics in that single parameter? Would I just separate it with a space?

PS: If you need to see any code, just let me know.

\$\endgroup\$
  • \$\begingroup\$ Short question, why not use DirectX 9 or 11? \$\endgroup\$ – LaVolpe May 11 '14 at 14:33
1
\$\begingroup\$

Your question is slightly ambigious, but if you're actually asking if you can use the triples to sample buffers arbitrarily from your shader, you can (in D3D11) use some StructuredBuffer<T> in your shader and index those with each of your index values. If you're stuck on D3D10, you could make a horrible approximation with Vertex-Texture-Fetch from a FP texture holding your geometry values. If this is not what you wanted to know, read below on how to make an multi-indexed mesh single-indexed.

When D3D (and OpenGL) does indexed rendering they sample the streams of attributes at the same index in all vertex attribute streams. This means that if you've got index i, you get a vertex made up of position[i], texcoord[i], and normal[i].

OBJ on the other side has faces made up of separate indices for each attribute, where a triple p/t/n is intended to gather position[p], texcoord[t], normal[n].

The traditional way to solve this is to while processing your OBJ file, you build a new set of single-indexed vertices. This can be as easy as gathering the attributes corresponding to the p/t/n triples, putting the corresponding attributes into a sequence and using the sequence position as the single-index to use.

An optimization is to keep track of which elements of the new buffer corresponds to the attributes for a p/t/n triple and reuse those elements if the same triple occurs multiple times, with a map<Triple,Index> or so.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.