0
\$\begingroup\$

I'm making a model class that is using Assimp in the background. I want my models' meshes to be able to have a material and an optional texture on top of that.

Right now I'm doing it like this: for each mesh, I store postion, normal, and texCoord for each vertex in that mesh. If the mesh doesn't have a texture, I just add vec2(0.0, 0.0) to the texCoord-array. I needed to add blank values for the meshes that doesn't have textures so the offset for the meshes that has textures would be correct.

At first I thought this would work. To draw the meshes I use the same shader-program for both the meshes without textures and the ones with textures. But since no texture will be bound when I render the ones without textures, it will sample tex-colors from nothing (?), and flickering occurs.

So my question is, what would be a good way to solve this? Is it possible to have two shader-programs and switch between them depending on if the model has a texture?

\$\endgroup\$
0
\$\begingroup\$

You could very well have two separate shaders. A nice way to do this would be to create a Material object that would contain pointers to some shader and maybe a texture (resources should be stored inside a ResourceManager or something similar).

But if that's too much work you could always use a special texture that always exists for objects with missing textures.

enter image description here

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .