Skip to content

Commit e141c8d

Browse files
committed
Fix adjoining transparent face rendering
- Render both faces when two different transparent faces are next to each other.
1 parent 0ae548b commit e141c8d

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

polymer/math.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,16 @@ struct Vector4f {
521521
}
522522
};
523523

524+
struct BoundingBox {
525+
Vector3f min;
526+
Vector3f max;
527+
528+
inline bool Intersects(const BoundingBox& b) const {
529+
return (min.x <= b.max.x && max.x >= b.min.x && min.y <= b.max.y && max.y >= b.min.y && min.z <= b.max.z &&
530+
max.z >= b.min.z);
531+
}
532+
};
533+
524534
// Column major matrix4x4
525535
struct mat4 {
526536
float data[4][4];

polymer/render/block_mesher.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,8 @@ FaceQuad GetFaceQuad(BlockElement& element, BlockFace direction) {
194194
inline bool IsOccluding(BlockModel* from, BlockModel* to, BlockFace face) {
195195
BlockFace opposite_face = world::GetOppositeFace(face);
196196

197-
bool from_is_transparent = !HasOccludableFace(*from, face);
198-
bool to_is_transparent = !HasOccludableFace(*to, opposite_face);
199-
200197
// TODO: Clean this up once rotation is settled.
201198
if (to->element_count == 0) return false;
202-
//if (from->has_variant_rotation || to->has_variant_rotation) return false;
203199
if (to->has_leaves || !to->has_shaded) return false;
204200

205201
for (size_t i = 0; i < from->element_count; ++i) {
@@ -220,16 +216,16 @@ inline bool IsOccluding(BlockModel* from, BlockModel* to, BlockFace face) {
220216
// Check if the element of the 'to' model fully occludes the 'from' face
221217
if (to_start.x <= from_start.x && to_start.y <= from_start.y && to_start.z <= from_start.z &&
222218
to_end.x >= from_end.x && to_end.y >= from_end.y && to_end.z >= from_end.z) {
223-
if (to_is_transparent) {
224-
if (from_is_transparent) {
225-
return true;
219+
if (to_face.transparency) {
220+
if (from_face.transparency) {
221+
return from_face.texture_id == to_face.texture_id;
226222
}
227223
return false;
228224
}
229225

230-
if (from_is_transparent) {
231-
if (to_is_transparent) {
232-
return true;
226+
if (from_face.transparency) {
227+
if (to_face.transparency) {
228+
return from_face.texture_id == to_face.texture_id;
233229
}
234230
return false;
235231
}

polymer/world/block.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,31 @@ struct FaceQuad {
4848
Vector2f br_uv;
4949
Vector2f tl_uv;
5050
Vector2f tr_uv;
51+
52+
inline BoundingBox GetBoundsAt(const Vector3f& v) {
53+
BoundingBox result;
54+
55+
result.min.x = ChooseMin(bl_pos.x, br_pos.x, tl_pos.x, tr_pos.x) + v.x;
56+
result.min.y = ChooseMin(bl_pos.y, br_pos.y, tl_pos.y, tr_pos.y) + v.y;
57+
58+
result.max.x = ChooseMax(bl_pos.x, br_pos.x, tl_pos.x, tr_pos.x) + v.x;
59+
result.max.y = ChooseMax(bl_pos.y, br_pos.y, tl_pos.y, tr_pos.y) + v.y;
60+
61+
return result;
62+
}
63+
64+
private:
65+
inline static float ChooseMin(float x0, float x1, float x2, float x3) {
66+
float m1 = x0 < x1 ? x0 : x1;
67+
float m2 = x2 < x3 ? x2 : x3;
68+
return m1 < m2 ? m1 : m2;
69+
}
70+
71+
inline static float ChooseMax(float x0, float x1, float x2, float x3) {
72+
float m1 = x0 > x1 ? x0 : x1;
73+
float m2 = x2 > x3 ? x2 : x3;
74+
return m1 > m2 ? m1 : m2;
75+
}
5176
};
5277

5378
struct RenderableFace {

0 commit comments

Comments
 (0)