Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualill

Posted 29 August 2013 - 04:33 PM

My shader system worked pretty much exactly that way as well and using GLSL.  Startup times are just fine.  I reuse shader programs between materials that are already compiled.  If I have 10 materials that all use diffuse, normal, and specular, and 3 materials that are only diffuse, I only compile 2 shaders on demand.  Performance is pretty good.

 

And if you try to use an unsupported uniform or attribute for that shader, GlGetUniform will return an error, so it makes it easy to debug during development.

 

When I load up a shader I have my C++ code look at the bit mask.

 

Then I say:

 

if(shaderBitMask & NORMALS) {

   defines += "#define NORMALS\n";

}

 

Then that defines string is passed in along with the shader text to the GLSL compiler.  My shader text has

 

#ifdef NORMALS

   code that uses normal goes here

#endif

 

At the moment though I'm writing an even more flexible system but this has worked for my school project for the last year or so.  I was able to render some really huge environments with many shader permutations very nicely without any noticeable performance losses.


#2ill

Posted 29 August 2013 - 04:33 PM

My shader system worked pretty much exactly that way as well and using GLSL.  Startup times are just fine.  I reuse shader programs between materials that are already compiled.  If I have 10 materials that all use diffuse, normal, and specular, and 3 materials that are only diffuse, I only compile 2 shaders on demand.  Performance is pretty good.

 

And if you try to use an unsupported uniform or attribute for that shader, GlGetUniform will return an error, so it makes it easy to debug during development.

 

When I load up a shader I have my C++ code look at the bit mask.

 

Then I say:

 

if(shaderBitMask & NORMALS) {

   defines += "#define NORMALS\n";

}

 

Then that defines string is passed in along with the shader text to the GLSL compiler.  My shader text has

 

#ifdef NORMALS

   code that uses normal goes here

#endif

 

At the moment though I'm writing an even more flexible system but this has worked for my school project for the last year or so.


#1ill

Posted 29 August 2013 - 04:27 PM

My shader system worked pretty much exactly that way as well and using GLSL.  Startup times are just fine.  I reuse shader programs between materials that are already compiled.  If I have 10 materials that all use diffuse, normal, and specular, and 3 materials that are only diffuse, I only compile 2 shaders on demand.  Performance is pretty good.


PARTNERS