
Originally Posted by
JoshV
So here is a question for technical folks: In a 3D environment, I'm trying to determine how much of a model is visible from a given viewpoint. (For example, model A is shooting at model B in an abstract strategy game, and needs to know how much cover model B is behind.) To top it off, I'd also like to know how much of the cover is Solid cover. Trees/foliage and office buildings are soft cover, while canyon walls and bunkers are solid cover.
I've thought of a few ways to determine this, but both have their downsides, maybe someone has a better idea:
1. RenderToTexture. Render model B as a solid color from the viewpoint of model A to a texture, then render the entire scene to the texture, also color coded. (So target model is red, standard cover is green, solid cover is blue) Obviously lighting & shadows would be disabled for this render. Then I'd just need to compare the two textures to get the percentage of cover, and the percentage of solid cover.
Upside is that its fairly accurate and requires no more than basic ratio math and would work on every single model without any preparation.
Downside is it requires two textures (which could be small, 64x64 could be accurate enough) and rendering the scene. Which could be slow, and also tends to require low level hooks to whatever engine is being used -- which I may not have access to.
2. Raycasting to model parts. Given that most models have a skeleton, I could do a collision ray to each bone from the camera view, and see how many of them are visible. The downside to that is that bones aren't really spaced equally, since their tend to be more bones in the hands and feet than in the head, and then it could fall completely flat for using something other than a humanoid model, like a tank, which might have weird bone layouts. Some of that could be mitigated by flagging certain bones, but that requires the model be tagged in advance.
So anyone else have a good idea how they'd go about determining something like that?