In our previous example, 1_SceneGraphRenderer
, we used a single shader program to render all objects in the scene. Now, our renderer will become multipass. We need to create shadow maps, and then render shadowed objects and calculate lighting. This is done using three different shader programs in three different rendering passes. To distinguish between passes, we define the ePass
enum as follows:
enum ePass { ePass_Ambient, ePass_Light, ePass_Shadow };
To handle different shader programs based on passes and material properties, we implement the clMaterialSystem
class:
class clMaterialSystem: public iIntrusiveCounter { public: clMaterialSystem();
The GetShaderProgramForPass()
method returns the shader program for the specified pass stored in std::map
:
clPtr<clGLSLShaderProgram> GetShaderProgramForPass(ePass P) { return m_ShaderPrograms[ P ]; } private: std::map<ePass, clPtr<clGLSLShaderProgram>> m_ShaderPrograms; };
The constructor of this class...