|
|
>> Do somebody have a idea how to render
>> transparent liquids in that trench?
>> All my Alpha-Blending stuff is very slow.
DISCLAIMER: I'm a lamer. I've never actually done this (quick, software blending), but I was thinking about it recently. Let me know if you think it'd work.
If the colors are represented as 0x00RRGGBB, then the following should be a quick way to average two colors:
int color1 = 0x00ffffff;
int color2 = 0x00007f00;
#define MASK 0x00FEFEFE
int color_ave = ((color1 & MASK) + (color2 & MASK)) >> 1;
How it works: (or how I think it should work) 8-)
To average two colors, you want to average the red, the green, and the blue seperately.
int color1 = 0x00ffffff;
int color2 = 0x00007f00;
int red = (color1 & 0x00ff0000) >> 16;
red += (color2 & 0x00ff0000) >> 16;
red /= 2;
int green = (color1 & 0x0000ff00) >> 8;
green += (color2 & 0x0000ff00) >> 8;
green /= 2;
int blue = color1 & 0x000000ff;
blue += color2 & 0x000000ff;
blue /= 2;
int color_ave = (red << 16) + (green << 8) + blue;
By killing the least significant bit (and-ing with the MASK), you can safely add all three components of the ints (r,g,b) together at the same time without worrying about overflow. Since the largest value for any component would be 255, you'll never see an overflow larger than a bit. (0xff + 0xff = 0x1fe).
Problems:
You lose precision. When you and with the mask, you lose the least signifigant bit. So a red of 255 becomes 254. Not a huge deal.
This is even blending (50/50). Although variations on this theme could produce 66%, 75%, ... by weighing the average of one number. (ie. (c1 + c1 + c1 + c2) >> 2). Of course, you'd have to monkey with the mask, and you'd lose more precision.
Since you're doing the voxel thing, you can't render a voxel over a voxel -- that is, the rocks can't "show thru" the water like they would in 3d. You'll need to pick a new hight above selected rock voxels and color it with this average. Using an animated hight-map and texture map for the river, I think this would be a pretty cool approximation - but the only way it'd be accurate is if you selected your texels from the rock texture and the river texture based on a line cast from the viewpoint. So if you're looking from directly overhead, the rock and river textures align perfectly -- if you're looking from any other angle, you'll need to select a different rock texel based on a cast ray.
|