Cull Revision magenta out-of-bounds void sentinel tile (tile 160)
This commit is contained in:
1 parent
3b4fbe76af
commit
35cdf34d03
3 files changed
+42
-2
No files matched your search
+21
-1
@@ -33,14 +33,34 @@ bool WorldTextures::load(const Vfs& vfs, int world_index, const Palette& pal) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr uint8_t kVoidSentinelIndex = 198;
|
||||||
|
constexpr size_t kTilePixels = static_cast<size_t>(kTileSize) * static_cast<size_t>(kTileSize);
|
||||||
tile_rgba.resize(tile_indices.size() * 4);
|
tile_rgba.resize(tile_indices.size() * 4);
|
||||||
for (size_t i = 0; i < tile_indices.size(); ++i) {
|
for (int t = 0; t < kTileCount; ++t) {
|
||||||
|
const size_t base_idx = static_cast<size_t>(t) * kTilePixels;
|
||||||
|
bool is_void_tile = true;
|
||||||
|
for (size_t k = 0; k < kTilePixels; ++k) {
|
||||||
|
if (tile_indices[base_idx + k] != kVoidSentinelIndex) {
|
||||||
|
is_void_tile = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (size_t k = 0; k < kTilePixels; ++k) {
|
||||||
|
const size_t i = base_idx + k;
|
||||||
|
if (is_void_tile) {
|
||||||
|
tile_rgba[i * 4 + 0] = 0;
|
||||||
|
tile_rgba[i * 4 + 1] = 0;
|
||||||
|
tile_rgba[i * 4 + 2] = 0;
|
||||||
|
tile_rgba[i * 4 + 3] = 0;
|
||||||
|
} else {
|
||||||
const Rgba8& c = pal.colors[tile_indices[i]];
|
const Rgba8& c = pal.colors[tile_indices[i]];
|
||||||
tile_rgba[i * 4 + 0] = c.r;
|
tile_rgba[i * 4 + 0] = c.r;
|
||||||
tile_rgba[i * 4 + 1] = c.g;
|
tile_rgba[i * 4 + 1] = c.g;
|
||||||
tile_rgba[i * 4 + 2] = c.b;
|
tile_rgba[i * 4 + 2] = c.b;
|
||||||
tile_rgba[i * 4 + 3] = 255; // terrain tiles are opaque
|
tile_rgba[i * 4 + 3] = 255; // terrain tiles are opaque
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<uint8_t> raw_sky, sky_indices;
|
std::vector<uint8_t> raw_sky, sky_indices;
|
||||||
if (!vfs.read_file(sky_path, raw_sky) || !rnc_unpack(raw_sky, sky_indices)) {
|
if (!vfs.read_file(sky_path, raw_sky) || !rnc_unpack(raw_sky, sky_indices)) {
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ vec3 softTone(vec3 c) {
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 texel = texture(uTexArray, vec3(vUv, floor(vTile + 0.5)));
|
vec4 texel = texture(uTexArray, vec3(vUv, floor(vTile + 0.5)));
|
||||||
|
if (texel.a < 0.5) discard;
|
||||||
vec3 sunDir = normalize(uModernLighting > 0.5 ? uSunDir : vec3(0.45, 0.80, 0.38));
|
vec3 sunDir = normalize(uModernLighting > 0.5 ? uSunDir : vec3(0.45, 0.80, 0.38));
|
||||||
vec3 N = normalize(vNormal);
|
vec3 N = normalize(vNormal);
|
||||||
|
|
||||||
@@ -421,15 +422,26 @@ void main() {
|
|||||||
constexpr const char* kShadowWorldVS = R"glsl(
|
constexpr const char* kShadowWorldVS = R"glsl(
|
||||||
#version 330 core
|
#version 330 core
|
||||||
layout(location = 0) in vec3 aPos;
|
layout(location = 0) in vec3 aPos;
|
||||||
|
layout(location = 2) in vec2 aUv;
|
||||||
|
layout(location = 3) in float aTile;
|
||||||
uniform mat4 uLightSpace;
|
uniform mat4 uLightSpace;
|
||||||
|
out vec2 vUv;
|
||||||
|
out float vTile;
|
||||||
void main() {
|
void main() {
|
||||||
|
vUv = aUv;
|
||||||
|
vTile = aTile;
|
||||||
gl_Position = uLightSpace * vec4(aPos, 1.0);
|
gl_Position = uLightSpace * vec4(aPos, 1.0);
|
||||||
}
|
}
|
||||||
)glsl";
|
)glsl";
|
||||||
|
|
||||||
constexpr const char* kShadowWorldFS = R"glsl(
|
constexpr const char* kShadowWorldFS = R"glsl(
|
||||||
#version 330 core
|
#version 330 core
|
||||||
void main() {}
|
in vec2 vUv;
|
||||||
|
in float vTile;
|
||||||
|
uniform sampler2DArray uTexArray;
|
||||||
|
void main() {
|
||||||
|
if (texture(uTexArray, vec3(vUv, floor(vTile + 0.5))).a < 0.5) discard;
|
||||||
|
}
|
||||||
)glsl";
|
)glsl";
|
||||||
|
|
||||||
constexpr const char* kShadowModelVS = R"glsl(
|
constexpr const char* kShadowModelVS = R"glsl(
|
||||||
@@ -1324,6 +1336,9 @@ void WorldRenderer::render_world_view(const RenderCamera& cam, const std::vector
|
|||||||
|
|
||||||
shadow_world_shader_.use();
|
shadow_world_shader_.use();
|
||||||
shadow_world_shader_.set_mat4("uLightSpace", light_space);
|
shadow_world_shader_.set_mat4("uLightSpace", light_space);
|
||||||
|
gl::ActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D_ARRAY, tex_terrain_array_);
|
||||||
|
shadow_world_shader_.set_int("uTexArray", 0);
|
||||||
if (terrain_mesh_.vao && terrain_mesh_.index_count > 0) {
|
if (terrain_mesh_.vao && terrain_mesh_.index_count > 0) {
|
||||||
gl::BindVertexArray(terrain_mesh_.vao);
|
gl::BindVertexArray(terrain_mesh_.vao);
|
||||||
glDrawElements(GL_TRIANGLES, terrain_mesh_.index_count, GL_UNSIGNED_INT, nullptr);
|
glDrawElements(GL_TRIANGLES, terrain_mesh_.index_count, GL_UNSIGNED_INT, nullptr);
|
||||||
|
|||||||
@@ -45,6 +45,11 @@ int main() {
|
|||||||
CHECK(wtex.load(vfs, w, pal));
|
CHECK(wtex.load(vfs, w, pal));
|
||||||
CHECK(wtex.tile_rgba.size() == 256u * 64u * 64u * 4u);
|
CHECK(wtex.tile_rgba.size() == 256u * 64u * 64u * 4u);
|
||||||
CHECK(wtex.sky_rgba.size() == 256u * 256u * 4u);
|
CHECK(wtex.sky_rgba.size() == 256u * 256u * 4u);
|
||||||
|
CHECK(wtex.tile_rgba[3] == 255);
|
||||||
|
constexpr size_t kVoidTileBase = 160u * 64u * 64u * 4u;
|
||||||
|
for (size_t p = 0; p < 64u * 64u; ++p) {
|
||||||
|
CHECK(wtex.tile_rgba[kVoidTileBase + p * 4u + 3u] == 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
std::cout << "[PASS] Palette, 9 ColorTables, 9 WorldTextures & Skies\n";
|
std::cout << "[PASS] Palette, 9 ColorTables, 9 WorldTextures & Skies\n";
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user