Optimise block tinting

This commit is contained in:
UnknownShadow200 2016-12-21 14:27:24 +11:00
parent a4cb1e80be
commit eddf8229f0
8 changed files with 123 additions and 101 deletions

View File

@ -45,7 +45,7 @@ namespace ClassicalSharp {
fullBright = info.FullBright[block];
if (info.Draw[block] == DrawType.Sprite) {
minBB = Vector3.Zero; maxBB = Vector3.One;
minBB = Vector3.Zero; maxBB = Vector3.One;
}
if (info.Draw[block] == DrawType.Gas) return;
@ -59,10 +59,10 @@ namespace ClassicalSharp {
if (info.Draw[block] == DrawType.Sprite) {
SpriteXQuad(block, true);
SpriteZQuad(block, true);
SpriteZQuad(block, true);
SpriteZQuad(block, false);
SpriteXQuad(block, false);
SpriteXQuad(block, false);
} else {
XQuad(block, maxBB.X, Side.Left);
ZQuad(block, minBB.Z, Side.Back);
@ -85,15 +85,15 @@ namespace ClassicalSharp {
int texLoc = game.BlockInfo.GetTextureLoc(block, side);
texIndex = texLoc / atlas.elementsPerAtlas1D;
if (lastIndex != texIndex) Flush();
VertexP3fT2fC4b v = default(VertexP3fT2fC4b);
v.Colour = colNormal;
if (game.BlockInfo.Name[block].EndsWith("#")) {
FastColour fogCol = game.BlockInfo.FogColour[block];
FastColour newCol = FastColour.Unpack(v.Colour);
newCol *= fogCol;
v.Colour = newCol.Pack();
if (game.BlockInfo.Tinted[block]) {
FastColour fogCol = game.BlockInfo.FogColour[block];
FastColour newCol = FastColour.Unpack(v.Colour);
newCol *= fogCol;
v.Colour = newCol.Pack();
}
TextureRec rec;
@ -102,7 +102,7 @@ namespace ClassicalSharp {
rec.V1 = vOrigin + minBB.Z * atlas.invElementSize;
rec.V2 = vOrigin + maxBB.Z * atlas.invElementSize * (15.99f/16f);
y = scale * (1 - y * 2);
y = scale * (1 - y * 2);
float minX = scale * (1 - minBB.X * 2), maxX = scale * (1 - maxBB.X * 2);
float minZ = scale * (1 - minBB.Z * 2), maxZ = scale * (1 - maxBB.Z * 2);
v.X = minX; v.Y = y; v.Z = minZ; v.U = rec.U2; v.V = rec.V2; Transform(ref v);
@ -119,22 +119,22 @@ namespace ClassicalSharp {
VertexP3fT2fC4b v = default(VertexP3fT2fC4b);
v.Colour = fullBright ? colNormal : colZSide;
if (game.BlockInfo.Name[block].EndsWith("#")) {
FastColour fogCol = game.BlockInfo.FogColour[block];
FastColour newCol = FastColour.Unpack(v.Colour);
newCol *= fogCol;
v.Colour = newCol.Pack();
if (game.BlockInfo.Tinted[block]) {
FastColour fogCol = game.BlockInfo.FogColour[block];
FastColour newCol = FastColour.Unpack(v.Colour);
newCol *= fogCol;
v.Colour = newCol.Pack();
}
TextureRec rec;
TextureRec rec;
float vOrigin = (texLoc % atlas.elementsPerAtlas1D) * atlas.invElementSize;
rec.U1 = minBB.X; rec.U2 = maxBB.X;
rec.V1 = vOrigin + (1 - minBB.Y) * atlas.invElementSize;
rec.V2 = vOrigin + (1 - maxBB.Y) * atlas.invElementSize * (15.99f/16f);
z = scale * (1 - z * 2);
z = scale * (1 - z * 2);
float minX = scale * (1 - minBB.X * 2), maxX = scale * (1 - maxBB.X * 2);
float minY = scale * (1 - minBB.Y * 2), maxY = scale * (1 - maxBB.Y * 2);
float minY = scale * (1 - minBB.Y * 2), maxY = scale * (1 - maxBB.Y * 2);
v.X = minX; v.Y = maxY; v.Z = z; v.U = rec.U2; v.V = rec.V2; Transform(ref v);
v.X = minX; v.Y = minY; v.Z = z; v.U = rec.U2; v.V = rec.V1; Transform(ref v);
v.X = maxX; v.Y = minY; v.Z = z; v.U = rec.U1; v.V = rec.V1; Transform(ref v);
@ -149,11 +149,11 @@ namespace ClassicalSharp {
VertexP3fT2fC4b v = default(VertexP3fT2fC4b);
v.Colour = fullBright ? colNormal : colXSide;
if (game.BlockInfo.Name[block].EndsWith("#")) {
FastColour fogCol = game.BlockInfo.FogColour[block];
FastColour newCol = FastColour.Unpack(v.Colour);
newCol *= fogCol;
v.Colour = newCol.Pack();
if (game.BlockInfo.Tinted[block]) {
FastColour fogCol = game.BlockInfo.FogColour[block];
FastColour newCol = FastColour.Unpack(v.Colour);
newCol *= fogCol;
v.Colour = newCol.Pack();
}
TextureRec rec;
@ -164,7 +164,7 @@ namespace ClassicalSharp {
x = scale * (1 - x * 2);
float minY = scale * (1 - minBB.Y * 2), maxY = scale * (1 - maxBB.Y * 2);
float minZ = scale * (1 - minBB.Z * 2), maxZ = scale * (1 - maxBB.Z * 2);
float minZ = scale * (1 - minBB.Z * 2), maxZ = scale * (1 - maxBB.Z * 2);
v.X = x; v.Y = maxY; v.Z = minZ; v.U = rec.U2; v.V = rec.V2; Transform(ref v);
v.X = x; v.Y = minY; v.Z = minZ; v.U = rec.U2; v.V = rec.V1; Transform(ref v);
v.X = x; v.Y = minY; v.Z = maxZ; v.U = rec.U1; v.V = rec.V1; Transform(ref v);
@ -179,17 +179,17 @@ namespace ClassicalSharp {
VertexP3fT2fC4b v = default(VertexP3fT2fC4b);
v.Colour = colNormal;
if (game.BlockInfo.Name[block].EndsWith("#")) {
FastColour fogCol = game.BlockInfo.FogColour[block];
FastColour newCol = FastColour.Unpack(v.Colour);
newCol *= fogCol;
v.Colour = newCol.Pack();
if (game.BlockInfo.Tinted[block]) {
FastColour fogCol = game.BlockInfo.FogColour[block];
FastColour newCol = FastColour.Unpack(v.Colour);
newCol *= fogCol;
v.Colour = newCol.Pack();
}
float x1 = firstPart ? 0.5f : -0.1f, x2 = firstPart ? 1.1f : 0.5f;
rec.U1 = firstPart ? 0.0f : 0.5f; rec.U2 = (firstPart ? 0.5f : 1.0f) * (15.99f/16f);
float minX = scale * (1 - x1 * 2), maxX = scale * (1 - x2 * 2);
float minY = scale * (1 - 0 * 2), maxY = scale * (1 - 1.1f * 2);
float minY = scale * (1 - 0 * 2), maxY = scale * (1 - 1.1f * 2);
v.X = minX; v.Y = minY; v.Z = 0; v.U = rec.U2; v.V = rec.V2; Transform(ref v);
v.X = minX; v.Y = maxY; v.Z = 0; v.U = rec.U2; v.V = rec.V1; Transform(ref v);
@ -205,11 +205,11 @@ namespace ClassicalSharp {
VertexP3fT2fC4b v = default(VertexP3fT2fC4b);
v.Colour = colNormal;
if (game.BlockInfo.Name[block].EndsWith("#")) {
FastColour fogCol = game.BlockInfo.FogColour[block];
FastColour newCol = FastColour.Unpack(v.Colour);
newCol *= fogCol;
v.Colour = newCol.Pack();
if (game.BlockInfo.Tinted[block]) {
FastColour fogCol = game.BlockInfo.FogColour[block];
FastColour newCol = FastColour.Unpack(v.Colour);
newCol *= fogCol;
v.Colour = newCol.Pack();
}
float z1 = firstPart ? 0.5f : -0.1f, z2 = firstPart ? 1.1f : 0.5f;

View File

@ -149,12 +149,10 @@ namespace ClassicalSharp {
}
public static FastColour operator * (FastColour left, FastColour right) {
FastColour outColor;
outColor.R = (byte)((left.R * right.R) / 255);
outColor.G = (byte)((left.G * right.G) / 255);
outColor.B = (byte)((left.B * right.B) / 255);
outColor.A = left.A;
return outColor;
left.R = (byte)((left.R * right.R) / 255);
left.G = (byte)((left.G * right.G) / 255);
left.B = (byte)((left.B * right.B) / 255);
return left;
}
public static implicit operator FastColour(Color col) {

View File

@ -60,6 +60,8 @@ namespace ClassicalSharp {
public SoundType[] StepSounds = new SoundType[Block.Count];
public bool[] Tinted = new bool[Block.Count];
public void Reset(Game game) {
Init();
// TODO: Make this part of TerrainAtlas2D maybe?
@ -111,6 +113,7 @@ namespace ClassicalSharp {
SetBlockDraw(id, DefaultSet.Draw(id));
SpeedMultiplier[id] = 1;
Name[id] = DefaultName(id);
Tinted[id] = false;
if (Draw[id] == DrawType.Sprite) {
MinBB[id] = new Vector3(2.50f/16f, 0, 2.50f/16f);

View File

@ -97,7 +97,7 @@ namespace ClassicalSharp.Model {
block = Utils.FastByte(p.ModelName);
}
if (game.BlockInfo.Name[block].EndsWith("#")) {
if (game.BlockInfo.Tinted[block]) {
FastColour fogCol = game.BlockInfo.FogColour[block];
FastColour newCol = FastColour.Unpack(col);
newCol *= fogCol;

View File

@ -21,7 +21,7 @@ namespace ClassicalSharp {
int max = chunkSize - xx;
while (count < max && x < width && CanStretch(block, chunkIndex, x, y, z, Side.Top)
&& !OccludedLiquid(chunkIndex)) {
&& !OccludedLiquid(chunkIndex)) {
counts[countIndex] = 0;
count++;
x++;
@ -76,7 +76,7 @@ namespace ClassicalSharp {
bool CanStretch(byte initialTile, int chunkIndex, int x, int y, int z, int face) {
byte rawBlock = chunk[chunkIndex];
bitFlags[chunkIndex] = ComputeLightFlags(x, y, z, chunkIndex);
return rawBlock == initialTile
return rawBlock == initialTile
&& !info.IsFaceHidden(rawBlock, chunk[chunkIndex + offsets[face]], face)
&& (initBitFlags == bitFlags[chunkIndex]
// Check that this face is either fully bright or fully in shadow
@ -102,12 +102,13 @@ namespace ClassicalSharp {
int aY1_Z1 = ((F >> xM1_yP1_zP1) & 1) + ((F >> xM1_yCC_zP1) & 1) + ((F >> xM1_yP1_zCC) & 1) + ((F >> xM1_yCC_zCC) & 1);
int col0_0 = fullBright ? FastColour.WhitePacked : MakeXSide(aY0_Z0), col1_0 = fullBright ? FastColour.WhitePacked : MakeXSide(aY1_Z0);
int col1_1 = fullBright ? FastColour.WhitePacked : MakeXSide(aY1_Z1), col0_1 = fullBright ? FastColour.WhitePacked : MakeXSide(aY0_Z1);
if (info.Name[curBlock].EndsWith("#")) {
col0_0 = tintBlock(curBlock, col0_0);
col1_0 = tintBlock(curBlock, col1_0);
col1_1 = tintBlock(curBlock, col1_1);
col0_1 = tintBlock(curBlock, col0_1);
if (tinted) {
col0_0 = TintBlock(curBlock, col0_0);
col1_0 = TintBlock(curBlock, col1_0);
col1_1 = TintBlock(curBlock, col1_1);
col0_1 = TintBlock(curBlock, col0_1);
}
if (aY0_Z0 + aY1_Z1 > aY0_Z1 + aY1_Z0) {
part.vertices[part.vIndex.left++] = new VertexP3fT2fC4b(x1, y2, z1, u1, v1, col1_0);
part.vertices[part.vIndex.left++] = new VertexP3fT2fC4b(x1, y1, z1, u1, v2, col0_0);
@ -139,12 +140,13 @@ namespace ClassicalSharp {
int aY1_Z1 = ((F >> xP1_yP1_zP1) & 1) + ((F >> xP1_yCC_zP1) & 1) + ((F >> xP1_yP1_zCC) & 1) + ((F >> xP1_yCC_zCC) & 1);
int col0_0 = fullBright ? FastColour.WhitePacked : MakeXSide(aY0_Z0), col1_0 = fullBright ? FastColour.WhitePacked : MakeXSide(aY1_Z0);
int col1_1 = fullBright ? FastColour.WhitePacked : MakeXSide(aY1_Z1), col0_1 = fullBright ? FastColour.WhitePacked : MakeXSide(aY0_Z1);
if (info.Name[curBlock].EndsWith("#")) {
col0_0 = tintBlock(curBlock, col0_0);
col1_0 = tintBlock(curBlock, col1_0);
col1_1 = tintBlock(curBlock, col1_1);
col0_1 = tintBlock(curBlock, col0_1);
if (tinted) {
col0_0 = TintBlock(curBlock, col0_0);
col1_0 = TintBlock(curBlock, col1_0);
col1_1 = TintBlock(curBlock, col1_1);
col0_1 = TintBlock(curBlock, col0_1);
}
if (aY0_Z0 + aY1_Z1 > aY0_Z1 + aY1_Z0) {
part.vertices[part.vIndex.right++] = new VertexP3fT2fC4b(x2, y2, z1, u1, v1, col1_0);
part.vertices[part.vIndex.right++] = new VertexP3fT2fC4b(x2, y2, z2 + (count - 1), u2, v1, col1_1);
@ -176,12 +178,13 @@ namespace ClassicalSharp {
int aX1_Y1 = ((F >> xP1_yP1_zM1) & 1) + ((F >> xP1_yCC_zM1) & 1) + ((F >> xCC_yP1_zM1) & 1) + ((F >> xCC_yCC_zM1) & 1);
int col0_0 = fullBright ? FastColour.WhitePacked : MakeZSide(aX0_Y0), col1_0 = fullBright ? FastColour.WhitePacked : MakeZSide(aX1_Y0);
int col1_1 = fullBright ? FastColour.WhitePacked : MakeZSide(aX1_Y1), col0_1 = fullBright ? FastColour.WhitePacked : MakeZSide(aX0_Y1);
if (info.Name[curBlock].EndsWith("#")) {
col0_0 = tintBlock(curBlock, col0_0);
col1_0 = tintBlock(curBlock, col1_0);
col1_1 = tintBlock(curBlock, col1_1);
col0_1 = tintBlock(curBlock, col0_1);
if (tinted) {
col0_0 = TintBlock(curBlock, col0_0);
col1_0 = TintBlock(curBlock, col1_0);
col1_1 = TintBlock(curBlock, col1_1);
col0_1 = TintBlock(curBlock, col0_1);
}
if (aX1_Y1 + aX0_Y0 > aX0_Y1 + aX1_Y0) {
part.vertices[part.vIndex.front++] = new VertexP3fT2fC4b(x2 + (count - 1), y1, z1, u2, v2, col1_0);
part.vertices[part.vIndex.front++] = new VertexP3fT2fC4b(x1, y1, z1, u1, v2, col0_0);
@ -213,12 +216,13 @@ namespace ClassicalSharp {
int aX1_Y1 = ((F >> xP1_yP1_zP1) & 1) + ((F >> xP1_yCC_zP1) & 1) + ((F >> xCC_yP1_zP1) & 1) + ((F >> xCC_yCC_zP1) & 1);
int col1_1 = fullBright ? FastColour.WhitePacked : MakeZSide(aX1_Y1), col1_0 = fullBright ? FastColour.WhitePacked : MakeZSide(aX1_Y0);
int col0_0 = fullBright ? FastColour.WhitePacked : MakeZSide(aX0_Y0), col0_1 = fullBright ? FastColour.WhitePacked : MakeZSide(aX0_Y1);
if (info.Name[curBlock].EndsWith("#")) {
col0_0 = tintBlock(curBlock, col0_0);
col1_0 = tintBlock(curBlock, col1_0);
col1_1 = tintBlock(curBlock, col1_1);
col0_1 = tintBlock(curBlock, col0_1);
if (tinted) {
col0_0 = TintBlock(curBlock, col0_0);
col1_0 = TintBlock(curBlock, col1_0);
col1_1 = TintBlock(curBlock, col1_1);
col0_1 = TintBlock(curBlock, col0_1);
}
if (aX1_Y1 + aX0_Y0 > aX0_Y1 + aX1_Y0) {
part.vertices[part.vIndex.back++] = new VertexP3fT2fC4b(x1, y2, z2, u1, v1, col0_1);
part.vertices[part.vIndex.back++] = new VertexP3fT2fC4b(x1, y1, z2, u1, v2, col0_0);
@ -250,12 +254,13 @@ namespace ClassicalSharp {
int aX1_Z1 = ((F >> xP1_yM1_zP1) & 1) + ((F >> xP1_yM1_zCC) & 1) + ((F >> xCC_yM1_zP1) & 1) + ((F >> xCC_yM1_zCC) & 1);
int col0_1 = fullBright ? FastColour.WhitePacked : MakeYSide(aX0_Z1), col1_1 = fullBright ? FastColour.WhitePacked : MakeYSide(aX1_Z1);
int col1_0 = fullBright ? FastColour.WhitePacked : MakeYSide(aX1_Z0), col0_0 = fullBright ? FastColour.WhitePacked : MakeYSide(aX0_Z0);
if (info.Name[curBlock].EndsWith("#")) {
col0_0 = tintBlock(curBlock, col0_0);
col1_0 = tintBlock(curBlock, col1_0);
col1_1 = tintBlock(curBlock, col1_1);
col0_1 = tintBlock(curBlock, col0_1);
if (tinted) {
col0_0 = TintBlock(curBlock, col0_0);
col1_0 = TintBlock(curBlock, col1_0);
col1_1 = TintBlock(curBlock, col1_1);
col0_1 = TintBlock(curBlock, col0_1);
}
if (aX0_Z1 + aX1_Z0 > aX0_Z0 + aX1_Z1) {
part.vertices[part.vIndex.bottom++] = new VertexP3fT2fC4b(x2 + (count - 1), y1, z2, u2, v2, col1_1);
part.vertices[part.vIndex.bottom++] = new VertexP3fT2fC4b(x1, y1, z2, u1, v2, col0_1);
@ -287,12 +292,13 @@ namespace ClassicalSharp {
int aX1_Z1 = ((F >> xP1_yP1_zP1) & 1) + ((F >> xP1_yP1_zCC) & 1) + ((F >> xCC_yP1_zP1) & 1) + ((F >> xCC_yP1_zCC) & 1);
int col0_0 = fullBright ? FastColour.WhitePacked : Make(aX0_Z0), col1_0 = fullBright ? FastColour.WhitePacked : Make(aX1_Z0);
int col1_1 = fullBright ? FastColour.WhitePacked : Make(aX1_Z1), col0_1 = fullBright ? FastColour.WhitePacked : Make(aX0_Z1);
if (info.Name[curBlock].EndsWith("#")) {
col0_0 = tintBlock(curBlock, col0_0);
col1_0 = tintBlock(curBlock, col1_0);
col1_1 = tintBlock(curBlock, col1_1);
col0_1 = tintBlock(curBlock, col0_1);
if (tinted) {
col0_0 = TintBlock(curBlock, col0_0);
col1_0 = TintBlock(curBlock, col1_0);
col1_1 = TintBlock(curBlock, col1_1);
col0_1 = TintBlock(curBlock, col0_1);
}
if (aX0_Z0 + aX1_Z1 > aX0_Z1 + aX1_Z0) {
part.vertices[part.vIndex.top++] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z1, u2, v1, col1_0);
part.vertices[part.vIndex.top++] = new VertexP3fT2fC4b(x1, y2, z1, u1, v1, col0_0);
@ -350,7 +356,7 @@ namespace ClassicalSharp {
int Lit(int x, int y, int z, int cIndex) {
if (x < 0 || y < 0 || z < 0
|| x >= width || y >= height || z >= length) return 7;
|| x >= width || y >= height || z >= length) return 7;
int flags = 0;
byte block = chunk[cIndex];
int lightHeight = lighting.heightmap[(z * width) + x];
@ -374,28 +380,28 @@ namespace ClassicalSharp {
static int[] masks = {
// Left face
(1 << xM1_yM1_zM1) | (1 << xM1_yM1_zCC) | (1 << xM1_yM1_zP1) |
(1 << xM1_yCC_zM1) | (1 << xM1_yCC_zCC) | (1 << xM1_yCC_zP1) |
(1 << xM1_yP1_zM1) | (1 << xM1_yP1_zCC) | (1 << xM1_yP1_zP1),
(1 << xM1_yCC_zM1) | (1 << xM1_yCC_zCC) | (1 << xM1_yCC_zP1) |
(1 << xM1_yP1_zM1) | (1 << xM1_yP1_zCC) | (1 << xM1_yP1_zP1),
// Right face
(1 << xP1_yM1_zM1) | (1 << xP1_yM1_zCC) | (1 << xP1_yM1_zP1) |
(1 << xP1_yP1_zM1) | (1 << xP1_yP1_zCC) | (1 << xP1_yP1_zP1) |
(1 << xP1_yCC_zM1) | (1 << xP1_yCC_zCC) | (1 << xP1_yCC_zP1),
(1 << xP1_yP1_zM1) | (1 << xP1_yP1_zCC) | (1 << xP1_yP1_zP1) |
(1 << xP1_yCC_zM1) | (1 << xP1_yCC_zCC) | (1 << xP1_yCC_zP1),
// Front face
(1 << xM1_yM1_zM1) | (1 << xCC_yM1_zM1) | (1 << xP1_yM1_zM1) |
(1 << xM1_yCC_zM1) | (1 << xCC_yCC_zM1) | (1 << xP1_yCC_zM1) |
(1 << xM1_yP1_zM1) | (1 << xCC_yP1_zM1) | (1 << xP1_yP1_zM1),
(1 << xM1_yCC_zM1) | (1 << xCC_yCC_zM1) | (1 << xP1_yCC_zM1) |
(1 << xM1_yP1_zM1) | (1 << xCC_yP1_zM1) | (1 << xP1_yP1_zM1),
// Back face
(1 << xM1_yM1_zP1) | (1 << xCC_yM1_zP1) | (1 << xP1_yM1_zP1) |
(1 << xM1_yCC_zP1) | (1 << xCC_yCC_zP1) | (1 << xP1_yCC_zP1) |
(1 << xM1_yP1_zP1) | (1 << xCC_yP1_zP1) | (1 << xP1_yP1_zP1),
(1 << xM1_yCC_zP1) | (1 << xCC_yCC_zP1) | (1 << xP1_yCC_zP1) |
(1 << xM1_yP1_zP1) | (1 << xCC_yP1_zP1) | (1 << xP1_yP1_zP1),
// Bottom face
(1 << xM1_yM1_zM1) | (1 << xM1_yM1_zCC) | (1 << xM1_yM1_zP1) |
(1 << xCC_yM1_zM1) | (1 << xCC_yM1_zCC) | (1 << xCC_yM1_zP1) |
(1 << xP1_yM1_zM1) | (1 << xP1_yM1_zCC) | (1 << xP1_yM1_zP1),
(1 << xCC_yM1_zM1) | (1 << xCC_yM1_zCC) | (1 << xCC_yM1_zP1) |
(1 << xP1_yM1_zM1) | (1 << xP1_yM1_zCC) | (1 << xP1_yM1_zP1),
// Top face
(1 << xM1_yP1_zM1) | (1 << xM1_yP1_zCC) | (1 << xM1_yP1_zP1) |
(1 << xCC_yP1_zM1) | (1 << xCC_yP1_zCC) | (1 << xCC_yP1_zP1) |
(1 << xP1_yP1_zM1) | (1 << xP1_yP1_zCC) | (1 << xP1_yP1_zP1),
(1 << xCC_yP1_zM1) | (1 << xCC_yP1_zCC) | (1 << xCC_yP1_zP1) |
(1 << xP1_yP1_zM1) | (1 << xP1_yP1_zCC) | (1 << xP1_yP1_zP1),
};
#endregion

View File

@ -17,7 +17,7 @@ namespace ClassicalSharp {
int max = chunkSize - xx;
while (count < max && x < width && CanStretch(block, chunkIndex, x, y, z, Side.Top)
&& !OccludedLiquid(chunkIndex)) {
&& !OccludedLiquid(chunkIndex)) {
counts[countIndex] = 0;
count++;
x++;
@ -65,7 +65,7 @@ namespace ClassicalSharp {
bool CanStretch(byte initialTile, int chunkIndex, int x, int y, int z, int face) {
byte rawBlock = chunk[chunkIndex];
return rawBlock == initialTile
return rawBlock == initialTile
&& !info.IsFaceHidden(rawBlock, chunk[chunkIndex + offsets[face]], face)
&& (fullBright || IsLit(X, Y, Z, face, initialTile) == IsLit(x, y, z, face, rawBlock));
}
@ -80,10 +80,12 @@ namespace ClassicalSharp {
float u1 = minBB.Z, u2 = (count - 1) + maxBB.Z * 15.99f/16f;
float v1 = vOrigin + maxBB.Y * invVerElementSize;
float v2 = vOrigin + minBB.Y * invVerElementSize * 15.99f/16f;
DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i];
int col = fullBright ? FastColour.WhitePacked :
X >= offset ? lighting.LightCol_XSide_Fast(X - offset, Y, Z) : lighting.OutsideXSide;
if (info.Name[curBlock].EndsWith("#")) col = tintBlock(curBlock, col);
if (tinted) col = TintBlock(curBlock, col);
part.vertices[part.vIndex.left++] = new VertexP3fT2fC4b(x1, y2, z2 + (count - 1), u2, v1, col);
part.vertices[part.vIndex.left++] = new VertexP3fT2fC4b(x1, y2, z1, u1, v1, col);
part.vertices[part.vIndex.left++] = new VertexP3fT2fC4b(x1, y1, z1, u1, v2, col);
@ -99,10 +101,12 @@ namespace ClassicalSharp {
float u1 = (count - minBB.Z), u2 = (1 - maxBB.Z) * 15.99f/16f;
float v1 = vOrigin + maxBB.Y * invVerElementSize;
float v2 = vOrigin + minBB.Y * invVerElementSize * 15.99f/16f;
DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i];
int col = fullBright ? FastColour.WhitePacked :
X <= (maxX - offset) ? lighting.LightCol_XSide_Fast(X + offset, Y, Z) : lighting.OutsideXSide;
if (info.Name[curBlock].EndsWith("#")) col = tintBlock(curBlock, col);
if (tinted) col = TintBlock(curBlock, col);
part.vertices[part.vIndex.right++] = new VertexP3fT2fC4b(x2, y2, z1, u1, v1, col);
part.vertices[part.vIndex.right++] = new VertexP3fT2fC4b(x2, y2, z2 + (count - 1), u2, v1, col);
part.vertices[part.vIndex.right++] = new VertexP3fT2fC4b(x2, y1, z2 + (count - 1), u2, v2, col);
@ -118,10 +122,12 @@ namespace ClassicalSharp {
float u1 = (count - minBB.X), u2 = (1 - maxBB.X) * 15.99f/16f;
float v1 = vOrigin + maxBB.Y * invVerElementSize;
float v2 = vOrigin + minBB.Y * invVerElementSize * 15.99f/16f;
DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i];
int col = fullBright ? FastColour.WhitePacked :
Z >= offset ? lighting.LightCol_ZSide_Fast(X, Y, Z - offset) : lighting.OutsideZSide;
if (info.Name[curBlock].EndsWith("#")) col = tintBlock(curBlock, col);
if (tinted) col = TintBlock(curBlock, col);
part.vertices[part.vIndex.front++] = new VertexP3fT2fC4b(x2 + (count - 1), y1, z1, u2, v2, col);
part.vertices[part.vIndex.front++] = new VertexP3fT2fC4b(x1, y1, z1, u1, v2, col);
part.vertices[part.vIndex.front++] = new VertexP3fT2fC4b(x1, y2, z1, u1, v1, col);
@ -137,10 +143,12 @@ namespace ClassicalSharp {
float u1 = minBB.X, u2 = (count - 1) + maxBB.X * 15.99f/16f;
float v1 = vOrigin + maxBB.Y * invVerElementSize;
float v2 = vOrigin + minBB.Y * invVerElementSize * 15.99f/16f;
DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i];
int col = fullBright ? FastColour.WhitePacked :
Z <= (maxZ - offset) ? lighting.LightCol_ZSide_Fast(X, Y, Z + offset) : lighting.OutsideZSide;
if (info.Name[curBlock].EndsWith("#")) col = tintBlock(curBlock, col);
if (tinted) col = TintBlock(curBlock, col);
part.vertices[part.vIndex.back++] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z2, u2, v1, col);
part.vertices[part.vIndex.back++] = new VertexP3fT2fC4b(x1, y2, z2, u1, v1, col);
part.vertices[part.vIndex.back++] = new VertexP3fT2fC4b(x1, y1, z2, u1, v2, col);
@ -156,9 +164,11 @@ namespace ClassicalSharp {
float u1 = minBB.X, u2 = (count - 1) + maxBB.X * 15.99f/16f;
float v1 = vOrigin + minBB.Z * invVerElementSize;
float v2 = vOrigin + maxBB.Z * invVerElementSize * 15.99f/16f;
DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i];
int col = fullBright ? FastColour.WhitePacked : lighting.LightCol_YBottom_Fast(X, Y - offset, Z);
if (info.Name[curBlock].EndsWith("#")) col = tintBlock(curBlock, col);
if (tinted) col = TintBlock(curBlock, col);
part.vertices[part.vIndex.bottom++] = new VertexP3fT2fC4b(x2 + (count - 1), y1, z2, u2, v2, col);
part.vertices[part.vIndex.bottom++] = new VertexP3fT2fC4b(x1, y1, z2, u1, v2, col);
part.vertices[part.vIndex.bottom++] = new VertexP3fT2fC4b(x1, y1, z1, u1, v1, col);
@ -176,12 +186,13 @@ namespace ClassicalSharp {
float v2 = vOrigin + maxBB.Z * invVerElementSize * 15.99f/16f;
DrawInfo part = isTranslucent ? translucentParts[i] : normalParts[i];
int col = fullBright ? FastColour.WhitePacked : lighting.LightCol_YTop_Fast(X, Y - offset, Z);
if (info.Name[curBlock].EndsWith("#")) col = tintBlock(curBlock, col);
if (tinted) col = TintBlock(curBlock, col);
part.vertices[part.vIndex.top++] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z1, u2, v1, col);
part.vertices[part.vIndex.top++] = new VertexP3fT2fC4b(x1, y2, z1, u1, v1, col);
part.vertices[part.vIndex.top++] = new VertexP3fT2fC4b(x1, y2, z2, u1, v2, col);
part.vertices[part.vIndex.top++] = new VertexP3fT2fC4b(x2 + (count - 1), y2, z2, u2, v2, col);
}
}
}

View File

@ -12,7 +12,7 @@ namespace ClassicalSharp {
protected DrawInfo[] normalParts, translucentParts;
protected TerrainAtlas1D atlas;
protected int arraysCount = 0;
protected bool fullBright;
protected bool fullBright, tinted;
protected int lightFlags;
protected Vector3 minBB, maxBB;
@ -80,6 +80,7 @@ namespace ClassicalSharp {
void RenderTile(int index) {
if (info.Draw[curBlock] == DrawType.Sprite) {
fullBright = info.FullBright[curBlock];
tinted = info.Tinted[curBlock];
int count = counts[index + Side.Top];
if (count != 0) DrawSprite(count);
return;
@ -94,6 +95,7 @@ namespace ClassicalSharp {
fullBright = info.FullBright[curBlock];
isTranslucent = info.Draw[curBlock] == DrawType.Translucent;
lightFlags = info.LightOffset[curBlock];
tinted = info.Tinted[curBlock];
Vector3 min = info.MinBB[curBlock], max = info.MaxBB[curBlock];
x1 = X + min.X; y1 = Y + min.Y; z1 = Z + min.Z;
@ -182,7 +184,7 @@ namespace ClassicalSharp {
float v1 = vOrigin, v2 = vOrigin + invVerElementSize * 15.99f/16f;
DrawInfo part = normalParts[i];
int col = fullBright ? FastColour.WhitePacked : lighting.LightCol_Sprite_Fast(X, Y, Z);
if (info.Name[curBlock].EndsWith("#")) col = tintBlock(curBlock, col);
if (tinted) col = TintBlock(curBlock, col);
// Draw Z axis
part.vertices[part.sIndex.left++] = new VertexP3fT2fC4b(X + 2.50f/16, Y, Z + 2.5f/16, u2, v2, col);
@ -209,12 +211,11 @@ namespace ClassicalSharp {
part.vertices[part.sIndex.back++] = new VertexP3fT2fC4b(X + 2.50f/16, Y, Z + 13.5f/16, u1, v2, col);
}
public int tintBlock(byte curBlock, int col) {
protected int TintBlock(byte curBlock, int col) {
FastColour fogCol = info.FogColour[curBlock];
FastColour newCol = FastColour.Unpack(col);
newCol *= fogCol;
col = newCol.Pack();
return col;
return newCol.Pack();
}
}
}

View File

@ -106,6 +106,9 @@ namespace ClassicalSharp.Network.Protocols {
info.FogColour[id] = new FastColour(
reader.ReadUInt8(), reader.ReadUInt8(), reader.ReadUInt8());
string name = info.Name[id];
info.Tinted[id] = fogDensity > 0 && name.Length > 0 && name[name.Length - 1] == '#';
info.UpdateCulling(id);
game.Events.RaiseBlockDefinitionChanged();
info.DefinedCustomBlocks[id >> 5] |= (1u << (id & 0x1F));