1
\$\begingroup\$

I'm working through my first attempt at a "graphics engine" (I use the term loosely as I'm not aiming for much more than something that will display a few meshes). I want to leave my classes as extensible as possible and am currently working on my mesh class.

I want my mesh class to be able to have optional UVs and optional normals, although I generally expect to use these. As I'm new to Direct3d I'm curious if I still have to define matching "zeroed" buffers for the missing normals and UV data if the vertex shader and input assembler is otherwise expecting this data? Should I have my mesh class assemble the missing data zeroed out and declare empty buffers or does Direct3d know to pass null arguments for missing data?

EDIT: I guess zeroed normals wouldn't work as any shader expecting normals would produce bad/bizarre results, but the question regarding texture coords still stands.

\$\endgroup\$
1
\$\begingroup\$

If i understand your question correctly, you are asking if not providing any buffers for normals will cause the shaders to behave weirdly. Not providing buffers will simply cause the data to be uninitialized, or if you already set data before- to the data you last set. Therefore if you do not want to include texture and normal processing in your shader (omit the data input entirely) you should create a separate shader couple (vertex&pixel) that only inputs positions. When you want to render with normals/textures, you switch to that kind of shader, and when rendering with only positions you switch to the simplifed shader. This swap has generally negligible performance impact compared to filling a buffer with data, so this is the preferred approach.

I assume since you already have working shaders (right?), you know how to create others and set them accordingly. One thing to remember is that those different shaders have different input layouts and consequently different vertex structures/buffers, so don't forget to set those as well.

\$\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.