Jump to content
  • Advertisement
Sign in to follow this  

Question about Shader/Material implementation

This topic is 4697 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been reading the Shader/Material implementation thread several times now. I understand the basic of the system but I don't like the idea of having effects defined in a .txt file and one shader per pass. lets say I have a diffuse textured and lit mesh then I would need one shader to handle that effect, and another shader if the mesh was only lit. So then I thougth I could break the shaders into two one to handle lighting and another one to handle the diffuse textures and then I define the EffectID for the material as a bitfield: enum eMaterialEffects { ME_RECIVE_LIGHT = 1<<0, //!< mesh will recive light. ME_TEXTURED = 1<<1, //!< mesh has textures. ME_SHADOWED = 1<<2, //!< use shadows ME_REFLECTION = 1<<3, // reflection }; so in the material I have an unigned int that stores the bitfield as effectID for that material depending on if the material is supposed to be lit and/or textured, then I resolve the shaders needed for each part of the effect well I could write a shader that do both. Pseudo code for shader resolving for a material

uint effectID = Material->getEffectID();

// if effectID is 0 get a default shader, no light no texture only simple color.
if( effectID == 0 ) 
 Material->addShader( ShaderManager->getShader(effectID) );

while( effectID != 0 )
 // retrive the shader with highest priority that can
 // visualize whole or the "biggest part" of the effect id
 // and ofcourse it will not return a shader that isn't supported by hardware
 pShader = ShaderManager->getShader( effectID );

 // continue to search for shader that can visualize the part
 // of the effect that the last shader couldn't do
 effectID = effectID - pShader->getEffectID();

 Material->addShader( pShader );

The above would resolve both texture and light shaders if the material is textured and lit, else it will only resolve the texture or light shader or just plain color shader (no light no texture if effectID = 0). So the problem is that I can't find a good way to create multipass rendering for shadowmaps, reflections and so on.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!