Add texture averaging
This commit is contained in:
parent
a625079d61
commit
7124e58b5e
2 changed files with 25 additions and 1 deletions
|
@ -19,6 +19,7 @@ Player player;
|
|||
|
||||
#define SHOT_SPEED 5 * UNITS_PER_SQUARE
|
||||
#define INFO_BAR_START 70
|
||||
#define TEXTURE_DISTANCE (UNITS_PER_SQUARE * 6)
|
||||
|
||||
const unsigned char level[] =
|
||||
{
|
||||
|
@ -469,6 +470,7 @@ const unsigned char spritePlasma[] =
|
|||
};
|
||||
|
||||
const unsigned char *textures[] = {texture1, texture2, texture3, texture4};
|
||||
unsigned char textureAverageColors[4];
|
||||
|
||||
Unit floorHeightAt(int16_t x, int16_t y)
|
||||
{
|
||||
|
@ -508,7 +510,9 @@ inline void pixelFunc(PixelInfo pixel)
|
|||
|
||||
if (pixel.isWall)
|
||||
{
|
||||
c = sampleImage(textures[pixel.hit.type],pixel.hit.textureCoord,pixel.textureCoordY);
|
||||
c = pixel.depth > TEXTURE_DISTANCE ?
|
||||
textureAverageColors[pixel.hit.type] :
|
||||
sampleImage(textures[pixel.hit.type],pixel.hit.textureCoord,pixel.textureCoordY);
|
||||
|
||||
if (previousColumn == pixel.position.x)
|
||||
{
|
||||
|
@ -562,6 +566,9 @@ int main()
|
|||
{
|
||||
initGeneral();
|
||||
|
||||
for (uint8_t i = 0; i < 4; ++i)
|
||||
textureAverageColors[i] = computeAverageColor(textures[i]);
|
||||
|
||||
cFloor = rgbToIndex(0,1,1);
|
||||
cCeiling = rgbToIndex(1,0,1);
|
||||
|
||||
|
|
17
general.hpp
17
general.hpp
|
@ -236,4 +236,21 @@ void initGeneral()
|
|||
zBuffer[i] = 0;
|
||||
}
|
||||
|
||||
unsigned char computeAverageColor(const unsigned char *texture)
|
||||
{
|
||||
uint32_t sumR = 0;
|
||||
uint32_t sumG = 0;
|
||||
uint32_t sumB = 0;
|
||||
uint32_t pixels = texture[0] * texture[1];
|
||||
|
||||
for (uint16_t i = 0; i < pixels; ++i)
|
||||
{
|
||||
sumR += texture[2 + i] & 0b00000111;
|
||||
sumG += (texture[2 + i] & 0b00111000) >> 3;
|
||||
sumB += (texture[2 + i] & 0b11000000) >> 6;
|
||||
}
|
||||
|
||||
return rgbToIndex(sumR / pixels,sumG / pixels,sumB / pixels);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue