Advertisement

Managing shaders for different models with different textures

Started by May 09, 2020 10:06 PM
3 comments, last by Juliean 4 years, 9 months ago

I have a scene-manager which loads models from different files. Some models have textures like normal-map and specular-map some don't have one of which and some just have a diffuse (color) texture. As far as I noticed I need to generate different shader-programs to support all possible combinations. well I can do that but the problem is that when I want to to make a simple change in a shader's code (for example fragment-shader) I need to update all sources. So, I was wondering that is there any better solution for this? Or I need to write a thing like an automatic shader generator?

There are multiple ways to go about this without any fancy shader generation:

First, shaders usually support defines (like in C/C++) that are passed when compiling, allowing you to make conditional features like normal-mapping in one file

Also, shaders somewhat support include-files, though usually with a bit of extra work (or you could just make a system yourself, with way less work than complicated generation), meaning you could make common code light lighting-functions into a separate “header" that is included in all your shaders, reducing work in the specific shaders to only calling the right functions with the right parameters.

Advertisement

Juliean said:

There are multiple ways to go about this without any fancy shader generation:

First, shaders usually support defines (like in C/C++) that are passed when compiling, allowing you to make conditional features like normal-mapping in one file

Also, shaders somewhat support include-files, though usually with a bit of extra work (or you could just make a system yourself, with way less work than complicated generation), meaning you could make common code light lighting-functions into a separate “header" that is included in all your shaders, reducing work in the specific shaders to only calling the right functions with the right parameters.

Well I was thinking about including function method, but as far as I remember functions are not good for performance. I've heard that compilers would inline functions, but it would be very risky I think as the performance of my GLSL code is already not good. do you have any idea about that?

Pooya65 said:
Well I was thinking about including function method, but as far as I remember functions are not good for performance. I've heard that compilers would inline functions, but it would be very risky I think as the performance of my GLSL code is already not good. do you have any idea about that?

Forget anything related to functions not being good for performance. Inlining is very advanced nowadays, so thats no concern.

Morever so, functions do not even exist post compilation in HLSL or GLSL. Every function is 100% of the time being inlined intothe appropriate assembly, so its even more so only a matter of convention in shading languages.

This topic is closed to new replies.

Advertisement