I’m in the process of better understanding shaders specifically the ability to chain/combine shaders together currently I have a simple scene with cascading shadows and phong lighting (thanks to learnopengl) now if I wanted to have a plant with a wind effect or a animated character that also has shadows and lighting it seems like the solution is duplicating code is that really the answer?
My current code is this
LoadShaderProgram("CSMPhong", "Resources/Shaders/CSMPhong.vert", "Resources/Shaders/CSMPhong.frag");
LoadShaderProgram("ShadowDepth", "Resources/Shaders/ShadowDepth.vert", "Resources/Shaders/ShadowDepth.frag", "Resources/Shaders/ShadowDepth.geom");
LoadShaderProgram("CSMPhongWind", "Resources/Shaders/CSMPhongWind.vert", "Resources/Shaders/CSMPhong.frag");
LoadShaderProgram("ShadowDepthWind", "Resources/Shaders/ShadowDepthWind.vert", "Resources/Shaders/ShadowDepth.frag", "Resources/Shaders/ShadowDepth.geom");
I did realize that I could reuse other shaders so CSMPhongWind
is reusing the fragment shader from CSMPhong
but still this feels very error prune if I update something I’ll need to make sure every variant is also updated. So yeah is this typical or are there better alternatives?