I'm currently working on some drawing routines using geometry generated at runtime and only flat colored. While searching for a minimal GL setup to do my drawing (I'm matching the screen resolution and on I'm iOS, but the question holds for other ES 2 platforms as well), I'm seeing that most examples use vertex and fragment shaders, but not all of them.
If I don't plan to use any textures or lighting (just direct color copying/blending) and I don't plan on doing any transformations that can't be done by manipulating the view matrix, do I really need to set up vertex and/or fragment shaders? If not, is there any advantage to using shaders over a shader-less approach?
Fragment shaders are technically an optional shader stage. If no fragment shader is used, then the color values of the output Fragment have undefined values. However, the depth and stencil values for the output fragment have the same values as the inputs.
If you skip the vertex shader, then in your application you would have to create a number of textures with information on which pixels are to be drawn, depth, etc - which happens in the background already. To add to that: On a modern graphiccard there are 5 shader stages, not just 2.
Fragment shaders Fragment (or texture) shaders define RGBA (red, green, blue, alpha) colors for each pixel being processed — a single fragment shader is called once per pixel. The purpose of the fragment shader is to set up the gl_FragColor variable. gl_FragColor is a built-in GLSL variable like gl_Position .
Vertex shaders typically perform transformations to post-projection space, for consumption by the Vertex Post-Processing stage. They can also be used to do per-vertex lighting, or to perform setup work for later shader stages.
As far as I know, yes, they are necessary. OpenGL ES 2.0 is not backward compatible with OpenGL ES 1.x and the main differences between the two are custom shaders.
The advantage of using shaders (2.0) or not (1.x) depends on your application's current and long-term functionality, but the fixed-function pipeline of 1.x is quickly becoming a thing of the past. The recently released OpenGL ES 3.0 specification is backward compatible with 2.0, but not 1.x.
OpenGL ES 2.0 uses a programmable pipeline, so you must always declare a vertex and a fragment shader. The simplest ones you can declare for geometry + color are:
// Vertex Shader
attribute vec3 position;
void main(void)
{
gl_Position = vec4(position, 1.0);
}
and:
// Fragment Shader
uniform lowp vec3 color;
void main(void)
{
gl_FragColor = vec4(color, 1.0);
}
Source: Khronos Website & Docs
"The significant change in the OpenGL ES 2.0 specification is that the OpenGL fixed function transformation and fragment pipeline is not supported."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With