For simplicity, I’m only using one Post-Processing layer at this point in time (the tutorial uses 2).
I’ve followed the tutorial (it’s essentially copy and pasting code) and have gotten the effect. However, for whatever reason the vertexZ buffering I’m using for the Tiled Maps isn’t being applied. (The depth buffering thing here: http://www.cocos2d-x.org/wiki/TileMap)
Minor update because it’s very late here. The reason it works fine without gl_FragColor being set to anything is because it’s transparent so it shows the original scene underneath.
Problem still persists otherwise with when it IS set to something it doesn’t work.
I removed all of the shader nonsense and tried to simply have a RenderTexture render the scene as mentioned here: http://www.cocos2d-x.org/wiki/Render_To_Texture The problem still persists.
If I initialize the RenderTexture differently, like in the following, it only shows the item with the smallest vertexZ.
I’m going to test out if it’s drawing the item with the smallest vertexZ last (and covering up everything else because it takes up the fullscreen) or not a bit later.
Ah so you’re rendering into a RenderTexture. If so, I’m surprised it doesn’t work the same with depth since internally the default camera is essentially using one (well an FBO).
So is the first screenshot rendering normally w/o post-processing and the second is rendering into a RenderTexture with it?
Yep. I’m pretty confused. I figured maybe initiallizing the render texture as follows would help, but then it’s only rendering items with the lowest vertexZ order. That or it’s rendering it backwards (lowest ontop). I haven’t tested the backwards thing just yet.
Try using GL_DEPTH24_STENCIL8_OES instead, I doubt you’ll be needing 32bits of floating point depth, and GL_DEPTH32F_STENCIL8 generates a 64bit pixel buffer, 24bits of which are used for alignment - i.e. wasted.
I’m not even sure if many if any mobile devices support GL_DEPTH32F_STENCIL8
That particular version? isn’t available (I got a compile error) so I just tried GL_DEPTH24_STENCIL8. No dice. Same error as I mentioned before, it’s not drawing everything in its proper order anymore.
I did some testing and this is what I found:
My Background layer is set to cc_vertexz of -500 normally; it was drawn on top of everything. I changed it to 0 and it was finally drawn behind the characters.
My Overlay/Foreground is set to cc_vertexz of 0 normally. It was always drawn behind the character. Changing it to 500 put it always on top of the character.
My other TMX layers are using cc_vertexz set to automatic. When the player is in front of a tile, the tile is drawn on top of the character, instead of the other way around. When the player moves behind the tile, the character is drawn on top.
So essentially, the issue here is that the RenderTexture is ordering the vertexZ (Position Z) backwards from how it is normally. I can only think that it must be related to the reason why you need to set “setFlippedY” to true. So perhaps whatever it is that’s going on in there needs to be applied to the PositionZ as well?