Depth Buffer Shadow in OpenGL, iOS

I didn’t know that it is difficult to make shadow against objects in 3D graphics.
This is a movie I made :

At first, a view point is the same angle with a light source, and I moved the view point with pan gesture later (you can see a red point in the video). The device is iPhone 5s, iOS 7.1.2
A texture size to memorize depth values is 1024x1024.
The shadow is … I don’t know a proper word… filthy, not beautiful.

This way may be called as ‘depth buffer shadow’.
At first depth info is drawn to a texture with frame buffer. Its view point is a light source. The texture does not appear to the screen. This is so called ‘offscreen rendering’.
And next, you render from a view point. You have to convert the drawing point from view point to the light source and check the depth is the smallest or not.

You can see this kind of the way in many web pages. But this was really difficult to implement it by my self.

I wonder how and what to output. Many pages says depth values should be written with GL_DEPTH_COMPONENT. But I was not able to use this when I set frame buffer object.
Therefore my code output depth values to the texture with this code :
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,  outputLength, outputLength, 0, GL_RGBA,GL_UNSIGNED_BYTE, NULL);
Well, this is the same way when I make a texture with frame buffer object.
The fragment shader output ‘color’ info, though it actually has the depth information.
I can only transfer depth info with 8 bits value in this way, and this can include a serious problem. It is too small to express depth info with only 8 bits. So I tried to find the way to output 16 or 32 bits values in fragment shader but failed...

Develop | Comments(0) | Trackback(0)