Hi!
First off, this is useful: OpenGL ES 2.0 Reference Card
Assuming you’ve already got a depth, you can find where (or whether) it fits between gl_DepthRange.near and gl_DepthRange.far , and map it onto a 16-bit integer[1].
lowp is exact for each multiple of 1/256 from 0 to 2, inclusive[2]. Presumably this is for use with colors, as suggested by the corresponding entry on the reference card. That actually gives you 256 extra values to work with, but I’m guessing that means within the shader, and it depends upon whatever frame buffer format is in use whether something is legal as an output, so best to keep in the range [0, 1).
Now that you have a 16-bit integer, you can break it into 8-bit chunks, and send those to the red and green channels (don’t scale them!), and blue too if you have 24-bit. This will involve some combination of mod (), fract (), and multiplies by (1.0 / 256.0), and (1.0 / 65536.0) for 24-bit. Also keep in mind that you want a multiple of 1/256 and not the inexact 1/255; the coefficient should be the same, but it’s not a color.
Anyhow, that’s the “depth write” shader, so once you’ve got your texture, you just reverse the process in another shader (where the texture is an input), forming the color components back into an integer and that in turn into your original depth.
On the matter of texture coordinates, this should be easy, at least for triangles and quads, if Corona provides something like CoronaGetUV () in the vertex shader.[3] Then you could pass in barycentric coordinates for each of your vertices as inputs and use these to map the vertex’s uv to a varying, then use that as the uv instead, in the fragment shader.
[1] - 16-bit being as precise as you can assume from a highp value. If you’re brave, with enough research and system.getInfo () calls you could probably surmise better capabilities on your hardware and incorporate that into your shaders, e.g. if 24- or 32-bit is available.
You could also get 17-bit by using the sign, too, but it might be a chore to do. I’m not sure if the interval is closed, i.e. is 2^16 representable or not? I suspect yes; if this is IEEE-ish floating point, there will be ever-widening gaps from that point onward, thus the floating point ranges.
[2] - In this case obviously inclusive, since 2 is also in the integer range.
[3] - This should be trivial, since the attribute obviously must exist for it to be fed to the fragment shader, but the names of the background variables aren’t exposed to us. This function would be read-only, though another function to assign the uv varying would have its uses, as well.
EDIT : Argh, I realized you don’t really need hardware support if you want 24- or 32-bit, since you could just use two variables–a “high word” and a “low word”–with some extra effort. That said, the general approach remains the same.