How is this effect achieved?

Started by
8 comments, last by Bimble Bob 14 years ago
To I'm referring to the selection decals merging together when the two groups move together. I've been wondering how this is achieved. My thinking was that all of the decal geometry is rendered to the stencil buffer, or something similar, and that is used to generate an outline somehow? Anyone enlighten me
It's not a bug... it's a feature!
Advertisement
I think one way of achieving this is to find the convex hull(s) formed by the units. There are a quite a few algorithms to do this, like: Graham scan, Jarvis march etc.
This may be relevant:
I mean this
Circular selections seem like they would be more straight forward, using the method I was originally thinking of before, but this doesn't like it would work in quite the same way because of the irregular shape of the selection outline and the fact that the outline seems to have some sort of texture applied to it.

Calculating the hull of the selection seems plausible but I'm not sure how you go from that to actually generating the outline seen there.
It's not a bug... it's a feature!
Quote:Original post by Deliverance
I think one way of achieving this is to find the convex hull(s) formed by the units. There are a quite a few algorithms to do this, like: Graham scan, Jarvis march etc.


You think so? I don't think those polygons look convex.

I don't know how it's done, but I can make up a way to do something similar as you suggested with the stencil buffer:
1 - Clear the stencil buffer to zero.
2 - Draw a solid hexagon around each unit to the stencil buffer in "One, always" mode, without stencil testing.
3 - Draw a hexagon-shaped border around each unit to the color buffer, with stencil testing (of the "only draw if stencil buffer is one and z-test passes" variety).

The other thing I can imagine someone doing is generating the outline geometry on the CPU by finding a level curve of an influence function of your units. You'd do this with a... damn it, forgetting the word; you flip simplices around... it's like marching triangles but instead of testing all triangles on the plane, you start with one which is known to straddle the curve and then repeatedly flip it along the curve... ah, yes: Simplicial continuation.
Original post by Emergent
Quote:Original post by Deliverance
The other thing I can imagine someone doing is generating the outline geometry on the CPU by finding a level curve of an influence function of your units. You'd do this with a... damn it, forgetting the word; you flip simplices around... it's like marching triangles but instead of testing all triangles on the plane, you start with one which is known to straddle the curve and then repeatedly flip it along the curve... ah, yes: Simplicial continuation.


You just said a bunch of things I don't understand right there!
But as for the other part of your post, yeah that makes sense.

It's not a bug... it's a feature!
Quote:Original post by Dom_152
You just said a bunch of things I don't understand right there!
But as for the other part of your post, yeah that makes sense.


Sorry; I probably should have edited my post instead of thinking aloud...

The idea was that you'd have some "influence" that falls off radially as you move away from a unit (say, linear ramp down with distance), and that you either add up all these influences or otherwise combine them (e.g., you could also take the max influence) to get a scalar-valued function over your domain. Then a level set of this function will be a closed curve around your units. I was proposing that one could use an algorithm for drawing level curves then. One such algorithm which is rather nice is the "simplicial continuation" algorithm I referenced. (Note: In two dimensions (like you have), the word "simplex" as used here is more-or-less just fancy-speak for "triangle.")
I'm curious. What does the selection field look like around a single unit? It is difficult to tell how they are merged from looking at already merged selections.

No, I am not a professional programmer. I'm just a hobbyist having fun...

If you have any kind of 2D, bird's-eye-view data structure storing and/or counting the number of units, this would be very easy.

You might already have a grid-like structure like that for making collision detection quicker & easier. If so, sample that.

If you can sample each square metre or so and sum the proximity of all friendly units to that location of the grid, you have a 2D map of unit density.

Then for each cell of the grid, you compare its density to its neighbours. If the current cell's unit density is below a certain threshold and one of its neighbours is above that threshold, draw a segment of that boundary between the two cells.

You'll only need to compare each cell to half its neighbours (eg: to the north, east & northeast), as you only need to test each cell boundary once - but if you test several neighbours before drawing anything, you can then choose to draw a segment with appropriate corner geometry.

This is part of the 'marching cubes' strategy behind rendering metaballs and related blobbies, but you only need to do it in 2D and you're probably not concerned about smoothing that boundary.

Oh - and you could have enemy units contribute negative unit density, and even draw another boundary (in a different colour) where their density is lower than a negative threshold, so that you have clearly demarcated friendly/unfriendly regions that never overlap. You could also show things like artillery ranges in the same way.
Quote:Original post by Emergent
Quote:Original post by Dom_152
You just said a bunch of things I don't understand right there!
But as for the other part of your post, yeah that makes sense.


Sorry; I probably should have edited my post instead of thinking aloud...

The idea was that you'd have some "influence" that falls off radially as you move away from a unit (say, linear ramp down with distance), and that you either add up all these influences or otherwise combine them (e.g., you could also take the max influence) to get a scalar-valued function over your domain. Then a level set of this function will be a closed curve around your units. I was proposing that one could use an algorithm for drawing level curves then. One such algorithm which is rather nice is the "simplicial continuation" algorithm I referenced. (Note: In two dimensions (like you have), the word "simplex" as used here is more-or-less just fancy-speak for "triangle.")


Thanks, that's clearer now. I'm not the most mathematically sound person (Something I'm trying to improve at uni!) but yeah, that makes more sense now, cheers!

Quote:Original post by maspeir
I'm curious. What does the selection field look like around a single unit? It is difficult to tell how they are merged from looking at already merged selections.


In that game (CnC 3), the units are built as groups like you see in the pictures. You can't split them up any further.

It's not a bug... it's a feature!

This topic is closed to new replies.

Advertisement