Problem (TL; DR)
My problem, basically, is that I don’t know how OpenGL ES 2.0 expects me to write and use several shaders; or if it is even appropriate / expected that a person will do it.
The main question here: if I have an apple, a glowing stone and a fuzzy grid, all in the same 3D world, all best drawn using different shader programs, but using the same mvpMatrix, then how would I start using all of them in the same OpenGL rendering that they all use their most suitable shaders that I wrote?
What I've done
So, I wrote the basic OpenGL ES 2.0 program for my Android game, which works great in that it can draw outlines of objects on the screen. But he does nothing; largely because shaders look like this:
Vertex Shader
uniform mat4 uMVPMatrix; attribute vec4 aPosition; void main() { gl_Position = uMVPMatrix * aPosition; }
Fragment shader
void main() { gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); }
Now they are pretty simple. The reason I didn’t go further is because I can’t understand if I should write one shader to apply to all my other objects, or if I should use several shaders. And if I have to use several shaders to draw several different objects, then how can I do this in an efficient way?
It seems to me that this should be basic knowledge for anyone who does OpenGL ES 2.0 every day, so I hope someone can answer my question or point me in the right direction.
I have:
- Looked at a few manuals; none of which uses anything but the most basic shaders.
- Read the entire OpenGL ES 2.0 GLSL specification (none of which mentioned how it should have been used, it was just what everything did, not how it combined).
- I tried changing my shaders a bit.
Therefore, I hope that I am close to understanding the OpenGL workflow, but it seems that I do not see it yet.
Edit: I found this after this:
If your application is written for OpenGL ES 2.0, do not create a single shader with a large number of switches and conditional expressions that perform each task that your application should display. Instead, compile several shader programs, each of which performs a specific purposeful task.
This is from iOS OpenGL ES 2.0.