summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/images/atlas.pngbin4653 -> 4671 bytes
-rw-r--r--assets/images/atlas.ppm696
-rw-r--r--assets/shaders/fragment.glsl6
-rw-r--r--src/GFX/Image/PPMParser.cpp16
-rw-r--r--src/GFX/Image/PPMParser.hpp2
-rw-r--r--src/GFX/Image/RawImage.cpp4
-rw-r--r--src/GFX/Image/RawImage.hpp2
-rw-r--r--src/GFX/Texture.cpp2
-rw-r--r--src/World/BlockType.hpp12
-rw-r--r--src/World/Generation/ChunkMeshing.cpp6
10 files changed, 383 insertions, 363 deletions
diff --git a/assets/images/atlas.png b/assets/images/atlas.png
index 72ff329..37e6457 100644
--- a/assets/images/atlas.png
+++ b/assets/images/atlas.png
Binary files differ
diff --git a/assets/images/atlas.ppm b/assets/images/atlas.ppm
index bf31022..b5599d3 100644
--- a/assets/images/atlas.ppm
+++ b/assets/images/atlas.ppm
@@ -6245,9 +6245,9 @@ P3
44
113
68
-39
-92
-67
+192
+0
+255
44
113
68
@@ -6257,9 +6257,9 @@ P3
44
113
68
-39
-92
-67
+192
+0
+255
44
113
68
@@ -6269,21 +6269,21 @@ P3
44
113
68
-39
-92
-67
-39
-92
-67
-39
-92
-67
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
+192
+0
+255
+192
+0
+255
+192
+0
+255
44
113
68
@@ -6434,51 +6434,51 @@ P3
89
51
43
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
39
128
70
44
113
68
-39
-92
-67
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
+192
+0
+255
44
113
68
-39
-92
-67
+192
+0
+255
39
128
70
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
44
113
68
44
113
68
-39
-92
-67
+192
+0
+255
44
113
68
@@ -6626,9 +6626,9 @@ P3
89
51
43
-39
-92
-67
+192
+0
+255
39
128
70
@@ -6638,18 +6638,18 @@ P3
39
128
70
-39
-92
-67
+192
+0
+255
44
113
68
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
39
128
70
@@ -6659,21 +6659,21 @@ P3
39
128
70
-39
-92
-67
+192
+0
+255
44
113
68
44
113
68
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
192
0
255
@@ -6818,9 +6818,9 @@ P3
89
51
43
-39
-92
-67
+192
+0
+255
39
128
70
@@ -6839,9 +6839,9 @@ P3
44
113
68
-39
-92
-67
+192
+0
+255
39
128
70
@@ -6854,12 +6854,12 @@ P3
39
128
70
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
39
128
70
@@ -7010,12 +7010,12 @@ P3
89
51
43
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
39
128
70
@@ -7031,12 +7031,12 @@ P3
44
113
68
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
39
128
70
@@ -7046,12 +7046,12 @@ P3
39
128
70
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
39
128
70
@@ -7205,27 +7205,27 @@ P3
44
113
68
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
39
128
70
-39
-92
-67
+192
+0
+255
44
113
68
44
113
68
-39
-92
-67
+192
+0
+255
44
113
68
@@ -7241,12 +7241,12 @@ P3
44
113
68
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
44
113
68
@@ -7400,21 +7400,21 @@ P3
44
113
68
-39
-92
-67
-39
-92
-67
-39
-92
-67
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
+192
+0
+255
+192
+0
+255
+192
+0
+255
39
128
70
@@ -7424,9 +7424,9 @@ P3
44
113
68
-39
-92
-67
+192
+0
+255
44
113
68
@@ -7436,9 +7436,9 @@ P3
44
113
68
-39
-92
-67
+192
+0
+255
44
113
68
@@ -7589,24 +7589,24 @@ P3
44
113
68
-39
-92
-67
+192
+0
+255
39
128
70
39
128
70
-39
-92
-67
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
+192
+0
+255
39
128
70
@@ -7616,24 +7616,24 @@ P3
39
128
70
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
44
113
68
44
113
68
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
192
0
255
@@ -7778,12 +7778,12 @@ P3
89
51
43
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
39
128
70
@@ -7793,39 +7793,39 @@ P3
39
128
70
-39
-92
-67
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
+192
+0
+255
39
128
70
39
128
70
-39
-92
-67
-39
-92
-67
-39
-92
-67
-39
-92
-67
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
+192
+0
+255
+192
+0
+255
+192
+0
+255
+192
+0
+255
192
0
255
@@ -7973,33 +7973,33 @@ P3
44
113
68
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
39
128
70
-39
-92
-67
+192
+0
+255
39
128
70
39
128
70
-39
-92
-67
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
+192
+0
+255
44
113
68
@@ -8012,9 +8012,9 @@ P3
44
113
68
-39
-92
-67
+192
+0
+255
44
113
68
@@ -8168,15 +8168,15 @@ P3
44
113
68
-39
-92
-67
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
+192
+0
+255
39
128
70
@@ -8186,9 +8186,9 @@ P3
39
128
70
-39
-92
-67
+192
+0
+255
44
113
68
@@ -8201,12 +8201,12 @@ P3
44
113
68
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
44
113
68
@@ -8357,21 +8357,21 @@ P3
44
113
68
-39
-92
-67
+192
+0
+255
39
128
70
-39
-92
-67
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
+192
+0
+255
39
128
70
@@ -8390,18 +8390,18 @@ P3
44
113
68
-39
-92
-67
+192
+0
+255
39
128
70
39
128
70
-39
-92
-67
+192
+0
+255
192
0
255
@@ -8546,9 +8546,9 @@ P3
89
51
43
-39
-92
-67
+192
+0
+255
39
128
70
@@ -8558,33 +8558,33 @@ P3
39
128
70
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
39
128
70
39
128
70
-39
-92
-67
-39
-92
-67
-39
-92
-67
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
+192
+0
+255
+192
+0
+255
+192
+0
+255
39
128
70
@@ -8738,9 +8738,9 @@ P3
89
51
43
-39
-92
-67
+192
+0
+255
39
128
70
@@ -8753,39 +8753,39 @@ P3
39
128
70
-39
-92
-67
-39
-92
-67
-39
-92
-67
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
+192
+0
+255
+192
+0
+255
+192
+0
+255
39
128
70
39
128
70
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
39
128
70
-39
-92
-67
+192
+0
+255
192
0
255
@@ -8930,12 +8930,12 @@ P3
89
51
43
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
39
128
70
@@ -8945,21 +8945,21 @@ P3
39
128
70
-39
-92
-67
+192
+0
+255
44
113
68
44
113
68
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
39
128
70
@@ -8969,15 +8969,15 @@ P3
39
128
70
-39
-92
-67
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
+192
+0
+255
192
0
255
@@ -9122,24 +9122,24 @@ P3
71
39
32
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
44
113
68
39
128
70
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
44
113
68
@@ -9149,21 +9149,21 @@ P3
44
113
68
-39
-92
-67
-39
-92
-67
+192
+0
+255
+192
+0
+255
39
128
70
39
128
70
-39
-92
-67
+192
+0
+255
44
113
68
diff --git a/assets/shaders/fragment.glsl b/assets/shaders/fragment.glsl
index 71435ef..a7f019d 100644
--- a/assets/shaders/fragment.glsl
+++ b/assets/shaders/fragment.glsl
@@ -14,6 +14,10 @@ void main() {
float brightness = dot(normalize(surface_normal), normalize(-sun_direction));
vec3 diffuse = vec3(max(brightness, 0.3));
- color = vec4(diffuse, 1.0) * texture(tex, frag_tex_coord);
+ vec4 texture_color = texture(tex, frag_tex_coord);
+ if (texture_color.a < 0.5) {
+ discard;
+ }
+ color = vec4(diffuse, 1.0) * texture_color;
color = mix(vec4(sky_color, 1.0), color, 1 - depth);
} \ No newline at end of file
diff --git a/src/GFX/Image/PPMParser.cpp b/src/GFX/Image/PPMParser.cpp
index f002db8..1f62871 100644
--- a/src/GFX/Image/PPMParser.cpp
+++ b/src/GFX/Image/PPMParser.cpp
@@ -68,12 +68,18 @@ RawImage::Pixel PPMParser::parse_pixel(uint8_t max_color) {
auto map_to_range = [=](uint64_t s) -> uint8_t { return s * 255 / max_color; };
- RawImage::Pixel pixel{};
- pixel.r = map_to_range(r_sample);
- pixel.g = map_to_range(g_sample);
- pixel.b = map_to_range(b_sample);
+ RawImage::Pixel p{
+ map_to_range(r_sample),
+ map_to_range(g_sample),
+ map_to_range(b_sample),
+ 255
+ };
- return pixel;
+ if (p.r == alpha_color.r && p.g == alpha_color.g && p.b == alpha_color.b) {
+ p.a = 0;
+ }
+
+ return p;
}
uint64_t PPMParser::parse_sample() {
diff --git a/src/GFX/Image/PPMParser.hpp b/src/GFX/Image/PPMParser.hpp
index 07ff3c2..a7e9b41 100644
--- a/src/GFX/Image/PPMParser.hpp
+++ b/src/GFX/Image/PPMParser.hpp
@@ -37,6 +37,8 @@ private:
bool is_eof() const;
+ static constexpr RawImage::Pixel alpha_color{192, 0, 255};
+
std::string_view m_source;
uint64_t m_cursor = 0;
};
diff --git a/src/GFX/Image/RawImage.cpp b/src/GFX/Image/RawImage.cpp
index 6cb06b2..0bd2947 100644
--- a/src/GFX/Image/RawImage.cpp
+++ b/src/GFX/Image/RawImage.cpp
@@ -28,9 +28,9 @@ std::string RawImage::string() const {
bool comma = false;
str << "[";
- for (const auto [r, g, b] : m_pixels) {
+ for (const auto [r, g, b, a] : m_pixels) {
if (comma) { str << ", "; }
- str << "{r=" << (uint)r << ", g=" << (uint)g << ", b=" << (uint)r << "}";
+ str << "{r=" << (uint)r << ", g=" << (uint)g << ", b=" << (uint)b << ", a=" << (uint)a << "}";
comma = true;
}
str << "]";
diff --git a/src/GFX/Image/RawImage.hpp b/src/GFX/Image/RawImage.hpp
index be3c83a..809ddd9 100644
--- a/src/GFX/Image/RawImage.hpp
+++ b/src/GFX/Image/RawImage.hpp
@@ -16,7 +16,7 @@ public:
}
struct Pixel {
- uint8_t r, g, b;
+ uint8_t r, g, b, a;
};
void add(Pixel pixel);
diff --git a/src/GFX/Texture.cpp b/src/GFX/Texture.cpp
index 64151a5..16f7dce 100644
--- a/src/GFX/Texture.cpp
+++ b/src/GFX/Texture.cpp
@@ -17,7 +17,7 @@ Texture::Texture(const Image::RawImage& image) {
// will begin at the incorrect byte, causing color artifacts.
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.width(), image.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, image.raw());
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image.width(), image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, image.raw());
glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
diff --git a/src/World/BlockType.hpp b/src/World/BlockType.hpp
index 472523f..82c63d3 100644
--- a/src/World/BlockType.hpp
+++ b/src/World/BlockType.hpp
@@ -26,6 +26,16 @@ public:
operator Value() const { return m_block; }
+ bool is_transparent() const {
+ switch (m_block) {
+ case Air:
+ case Leaves:
+ return true;
+ default:
+ return false;
+ }
+ }
+
static std::vector<BlockType> all() {
return {
Air,
@@ -34,6 +44,8 @@ public:
Stone,
Sand,
Snow,
+ Wood,
+ Leaves,
Water,
};
}
diff --git a/src/World/Generation/ChunkMeshing.cpp b/src/World/Generation/ChunkMeshing.cpp
index 0494da4..e065987 100644
--- a/src/World/Generation/ChunkMeshing.cpp
+++ b/src/World/Generation/ChunkMeshing.cpp
@@ -129,11 +129,7 @@ bool is_face_visible(Chunk& chunk, const ChunkMeshing::ChunkNeighbors& neighbors
}
auto [neighbor] = chunk_to_ask->get(neighbor_pos.x(), neighbor_pos.y(), neighbor_pos.z());
- if (neighbor == BlockType::Air) {
- return true;
- }
-
- return false;
+ return neighbor.is_transparent();
}
GFX::Mesh ChunkMeshing::create_mesh_for_chunk(Chunk& chunk, const ChunkNeighbors& neighbors) {