Hey there. I am trying to simplify one of my massively sized fragment shaders to a much simpler form but without success by having multiple smaller fragment shaders communicate with one another. Right now in its current state, it has ambient lighting, diffuse lighting, specular lighting, texture mapping, reflection, and cubemapping, maybe a few other things, all bundled up into one enormous fragment shader. And its actually required because of how I designed the program rather than make a bunch of different programs to handle it. For example, if the surface of the texture has reflective properties, I can have it as an option programmably. So my idea is to link one vertex shader, and multiple individual fragment shaders to handle each of the cases in its own glsl file:
- Ambient lighting
- Diffuse lighting
- Specular lighting
- Reflection
... and so on. But the problem is, is that linking more than one fragment shader to the shader program gave me a glAttachShader error even though the program continued to run. I kinda got it working with just 2 fragment shaders but it didnt work at all with 3 or more. So i tried Googling solutions. One solution was to create a method in one shader to call into the main fragment shader. Tried it, and it did not read the method at all. Even with pre processor directives attached. Tried working with ins and outs with 3 or more fragment shaders but it only seemed to work with 2. Honestly I cant find any info on how to simplify complex shaders. Does anyone here have any ideas? Thanks in advance!