Multiple Shaders in GLSL

Started by
4 comments, last by olemars 14 years, 11 months ago
Hi, My problem: 1. having multiple shaders (GLSL) in one program. 2. in that program i would have (lets say) 3 cubes. 3. i want the 3 different cubes to be affected by three different shaders. So far, i can only program multiple shaders into one program and all 3 cubes are affected by the 3 shaders. Question: Is it GLSL-possible to have the 3 different cubes (in the same program) to be affected by different vertex/fragment shader. if yes, how? my current solution for this right now is having three different programs with the different shaders attached to them. and toggling between the programs.
Advertisement
Creating 3 different programs and switching between them is the correct way. A single program will perform the same render operations on all geometry it is used on.

You could technically use only one program and switch and relink the shader objects in it between the draw calls, but that would be just silly.
[ You could technically use only one program and switch and relink the shader objects in it between the draw calls, but that would be just silly. ]


that is what i did previously... haha...

i thought so... there is no way 2 shaders can have 2 different impact on 2 different objects in the same program. =.="

thanks for the clarification tho...
You could implement your three different shader all inside one shader. Then use a variable to branch your logic. That is what is done in the leadwerks game engine.
Quote:Original post by mmakrzem
You could implement your three different shader all inside one shader. Then use a variable to branch your logic. That is what is done in the leadwerks game engine.


Perhaps that's not a good idea. Perhaps it will reduce performance specially when used in the FS.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Quote:Original post by mmakrzem
You could implement your three different shader all inside one shader. Then use a variable to branch your logic. That is what is done in the leadwerks game engine.


I can't see what there is to gain by doing this though. The whole purpose of the ogl shader program abstraction is to simplify switching between shaders for different objects. Last thing you want to do is increase the complexity of your actual shader.

This topic is closed to new replies.

Advertisement