On iOS or Android, I have the option to switch to OpenGL ES 2 or 3. I'm not sure why I would, as I'm not developing a 3D game, but if I were to switch, how would I implement clipping planes? These were allegedly removed in ES 2.
I'd especially like to avoid having to recompile any shader code when a clipping plane's vector changes.
In OpenGL ES you have to use the EXT_clip_cull_distance extension.
In the vertex shader you have to set the
gl_ClipDistance[i]output.gl_ClipDistance[i]specifies a clip distance for each user clip plane i. Where 0.0 means that the vertex is on the clip plane and > 0.0 means that is it inside the clip plane.The clipping capabilities has to be enabled.
e.g.
A vertex shader using
gl_ClipDistancemay look like this, whereu_clipPlaneis the equation for a plane in the form Ax + By + Cz + D (imagine this as the normal vector of the plane and the distance to the origin):See also Vertex Post-Processing - User-defined clipping and The little Grasshopper - Clip Planes tutorial.
If the extension is not available, then the clipping can be emulated in the fragment shader, by discarding fragments. See Fragment Shader - Special operations.
See also OpenGL ES Shading Language 1.00 Specification; 6.4 Jumps; page 58:
The following WebGL example demonstrates this. Note, the WebGL 1.0 context conforms closely to the OpenGL ES 2.0 API.