Original Post
I am working on a material system and am finding that I am coupling a material to various shader programs (its main shader program, but also others like a depth only pass). So I have a base Material class and then derive from it--for example, NormalMappedMaterial will have additional properties like a normal map texture.
Then I assign a Material to a mesh, and do something like:
void Mesh::Draw()
{
// Draws using NormalMappedMaterial which has access to the normal map and NormalMappedShader
m_material->Draw( this->GeometryBuffers );
}
I'm not sure if this is considered bad design or not. I tried separating my shader programs from materials, but I can't really get nice polymorphic behavior. If a mesh has a base Material* pointing to a NormalMappedMaterial and a base ShaderPrograms* pointing to a NormalMappedShader, I need to somehow get the normal map from the material and set it to the shader. However, at the base Material level, the material does not know it has a normal map, and at the base ShaderProgram level, it does not know it needs a normal map.
Then I assign a Material to a mesh, and do something like:
void Mesh::Draw()
{
// Draws using NormalMappedMaterial which has access to the normal map and NormalMappedShader
m_material->Draw( this->GeometryBuffers );
}
I'm not sure if this is considered bad design or not. I tried separating my shader programs from materials, but I can't really get nice polymorphic behavior. If a mesh has a base Material* pointing to a NormalMappedMaterial and a base ShaderPrograms* pointing to a NormalMappedShader, I need to somehow get the normal map from the material and set it to the shader. However, at the base Material level, the material does not know it has a normal map, and at the base ShaderProgram level, it does not know it needs a normal map.