Skip to content

Commit b67c20d

Browse files
NikZappBrentDaMage
andauthored
Cleanup torch tessellation (#129)
* Cleanup torch tessellation * Fixed torch particles spawning too low --------- Co-authored-by: Brent <43089001+BrentDaMage@users.noreply.github.com>
1 parent 53200be commit b67c20d

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

source/client/renderer/TileRenderer.cpp

+30-19
Original file line numberDiff line numberDiff line change
@@ -1000,14 +1000,14 @@ void TileRenderer::tesselateTorch(Tile* tile, const Vec3& pos, float a, float b)
10001000
constexpr float C_RATIO = 1.0f / 256.0f;
10011001
constexpr float C_ONE_PIXEL = 1.0f / 16.0f;
10021002
constexpr float C_HALF_TILE = 1.0f / 2.0f;
1003-
constexpr float C_UNK_1 = 0.375f;
1003+
constexpr float C_TOP_SKEW_RATIO = 0.375f;
10041004

10051005
int texture = tile->getTexture(Facing::DOWN);
10061006

10071007
if (m_textureOverride >= 0)
10081008
texture = m_textureOverride;
10091009

1010-
// @TODO: Clean up a bit
1010+
// @TODO: Clean up a bit more
10111011

10121012
float texX = float(16 * (texture % 16));
10131013
float texY = float(16 * (texture / 16));
@@ -1017,58 +1017,69 @@ void TileRenderer::tesselateTorch(Tile* tile, const Vec3& pos, float a, float b)
10171017
float texV_1 = (texY * C_RATIO) + 1.0f / 32.0f;
10181018
float texV_2 = (texY + 15.99f) * C_RATIO;
10191019

1020-
float x1 = pos.x + 0.5f, z1 = pos.z + 0.5f;
1021-
float z2 = z1 + (float)(b * C_UNK_1);
1020+
float x1 = pos.x + C_HALF_TILE, z1 = pos.z + C_HALF_TILE;
1021+
float x2 = x1 + (float)(a * C_TOP_SKEW_RATIO);
1022+
float z2 = z1 + (float)(b * C_TOP_SKEW_RATIO);
10221023

10231024
Tesselator& t = Tesselator::instance;
1025+
1026+
// Top side (flame)
1027+
float x_1 = x2 - C_ONE_PIXEL;
1028+
float x_2 = x2 + C_ONE_PIXEL;
1029+
float z_1 = z2 - C_ONE_PIXEL;
1030+
float z_2 = z2 + C_ONE_PIXEL;
10241031

1025-
float x_1 = (x1 + (a * C_UNK_1)) - C_ONE_PIXEL;
1026-
float x_2 = (x1 + (a * C_UNK_1)) + C_ONE_PIXEL;
1032+
// Edges (close by)
10271033
float x_3 = x1 - C_ONE_PIXEL;
10281034
float x_4 = x1 + C_ONE_PIXEL;
1029-
float x_5 = x1 - C_HALF_TILE;
1035+
float z_5 = z1 - C_ONE_PIXEL;
1036+
float z_6 = z1 + C_ONE_PIXEL;
1037+
1038+
// Far edges
1039+
float x_5 = x1 - C_HALF_TILE;
10301040
float x_6 = x1 + C_HALF_TILE;
1031-
float x_7 = x_6 + a;
1041+
float z_3 = z1 - C_HALF_TILE;
1042+
float z_4 = z1 + C_HALF_TILE;
1043+
1044+
float x_7 = x_6 + a; // Skewed bottom
10321045
float x_8 = x_3 + a;
10331046
float x_9 = x_4 + a;
10341047
float x_0 = x_5 + a;
1035-
1036-
float y_1 = pos.y + C_ONE_PIXEL * 10.0f;
1037-
float y_2 = pos.y + 1.0f;
1038-
float y_3 = pos.y + 0.0f;
1039-
1040-
float z_1 = z2 - C_ONE_PIXEL;
1041-
float z_2 = z2 + C_ONE_PIXEL;
1042-
float z_3 = z1 - 0.5f;
1043-
float z_4 = z1 + 0.5f;
1044-
float z_5 = z1 - C_ONE_PIXEL;
1045-
float z_6 = z1 + C_ONE_PIXEL;
10461048
float z_7 = z_3 + b;
10471049
float z_8 = z_4 + b;
10481050
float z_9 = z_5 + b;
10491051
float z_0 = z_6 + b;
10501052

1053+
float y_1 = pos.y + C_ONE_PIXEL * 10.0f; // Torch height
1054+
float y_2 = pos.y + 1.0f; // Top
1055+
float y_3 = pos.y + 0.0f; // Bottom
1056+
10511057
float texU_3 = texU_1 + 0.027344f;
10521058
float texU_4 = texU_1 + 0.035156f;
10531059
float texV_3 = texY * C_RATIO;
10541060
float texV_4 = texY * C_RATIO + 0.023438f;
10551061

1062+
// Top
10561063
t.vertexUV(x_1, y_1, z_1, texU_3, texV_4);
10571064
t.vertexUV(x_1, y_1, z_2, texU_3, texV_1);
10581065
t.vertexUV(x_2, y_1, z_2, texU_4, texV_1);
10591066
t.vertexUV(x_2, y_1, z_1, texU_4, texV_4);
1067+
// Sides
10601068
t.vertexUV(x_3, y_2, z_3, texU_1, texV_3);
10611069
t.vertexUV(x_8, y_3, z_7, texU_1, texV_2);
10621070
t.vertexUV(x_8, y_3, z_8, texU_2, texV_2);
10631071
t.vertexUV(x_3, y_2, z_4, texU_2, texV_3);
1072+
10641073
t.vertexUV(x_4, y_2, z_4, texU_1, texV_3);
10651074
t.vertexUV(x_9, y_3, z_8, texU_1, texV_2);
10661075
t.vertexUV(x_9, y_3, z_7, texU_2, texV_2);
10671076
t.vertexUV(x_4, y_2, z_3, texU_2, texV_3);
1077+
10681078
t.vertexUV(x_5, y_2, z_6, texU_1, texV_3);
10691079
t.vertexUV(x_0, y_3, z_0, texU_1, texV_2);
10701080
t.vertexUV(x_7, y_3, z_0, texU_2, texV_2);
10711081
t.vertexUV(x_6, y_2, z_6, texU_2, texV_3);
1082+
10721083
t.vertexUV(x_6, y_2, z_5, texU_1, texV_3);
10731084
t.vertexUV(x_7, y_3, z_9, texU_1, texV_2);
10741085
t.vertexUV(x_0, y_3, z_9, texU_2, texV_2);

source/world/level/Level.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1663,6 +1663,7 @@ void Level::animateTick(const TilePos& pos)
16631663
{
16641664
Random random;
16651665

1666+
// frequency is 1000 on JE, 100 on PE
16661667
for (int i = 0; i < 100; i++)
16671668
{
16681669
TilePos aPos(pos.x + m_random.nextInt(16) - m_random.nextInt(16),

source/world/tile/TorchTile.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ void TorchTile::animateTick(Level* level, const TilePos& pos, Random* random)
3838
{
3939
Vec3 part(pos);
4040
part += 0.5f;
41+
part.y += 0.2f;
4142

4243
// @NOTE: Need to use addParticle("smoke") 5 times. Invalid data values don't actually generate a smoke
4344
switch (level->getData(pos))

0 commit comments

Comments
 (0)