The big tech feature that I'm pleased to be getting working for this game is that the entire background jungle and terrain is pre-rendered, with a scrolling system, so it takes very little CPU / GPU / battery at runtime and can thus support large numbers of background models and vegetation. As well as storing the colour channel for the background, it also has to store and process my own custom Z buffer for the background, so that models of characters and animals will correctly interact depth-wise with the background. :ph34r:
As in my previous version of the game it is quite easy to get 3d models storing their z into a custom z buffer, and the terrain. The billboards were also simply rendered to the z buffer as rectangles standing up on the terrain surface. This works when a player is behind a tree for example, or in front, but there is no fine grained interaction with the tree because it is essentially a flat plane as far as the game is concerned. :(
So I have currently been experimenting with rendering the trees from blender with a depth channel, loading this into the game, and using it to offset the z in the sprite shader. Firstly I completely rewrote my sprite rendering library and export tool, as it needed a refresh, and it needed to support depth (and possibly other channels, such as normals?).
I now have it beginning to work in the game. In the top pic you can see the player is interacting with a 2d billboard with depth - the backpack is in front of the tree trunk, but the head is hidden by the leaves in the foreground. :D I still have some jiggling to do with the maths - the z buffer may not be linear, and I need to take account that the z render from blender is at a 45 degree angle, whereas the billboard is currently drawn straight up relative to the ground, rather than the screen. So I may have to fudge the z render, or change the billboard up-orientation to the screen.
The other difficulty I've been having is exporting the z buffer from blender. :unsure: As the trees themselves are using billboards for the leaves, the z output comes out with lots of squares instead of leaf shapes. I'm also experimenting with exporting a mist layer to see if this solves it, but there are transparency issues. Really it would be nice if blender would do alpha testing for the z render, but I'm not sure it supports it (any help on this issue would be welcome!)
Other Work
Aside from this, I have been doing a lot of behind the scenes work since my last journal entry. Have got keyboard input working on android, and can even control the player with my tv remote (!) on my android media player. I intend to get a bluetooth gamepad and get it working with analog controllers too. I personally find this annoying, too many android games seem to rely on you playing with a touchscreen, and have no support for other inputs like keyboards, gamepads and mouse on other devices. It really isn't difficult to add keyboard input at a minimum. :rolleyes:
I also rejigged the OpenGL creation code to support restoring after lost contexts, in order to support resuming. This was less hassle than I was fearing, and seems to work fine. Unlike PCs, Android seems to have been built with the idea you never 'exit' apps, you just switch them to the background, and the OS deletes them if it needs to free up space. I can see the reasons why in theory this is the optimum arrangement for a device, but it does seem to assume that developers will properly clean up after themselves when their app is in the background, and pause their processing. And there is a famous saying about assumption... :lol: