Fixed rendering issues due to insufficent far plane.

This commit is contained in:
connellpaxton 2024-02-19 22:25:57 -05:00
parent ff771ba127
commit 346038a8f7
6 changed files with 12 additions and 6 deletions

View File

@ -107,7 +107,7 @@ GraphicsPipeline::GraphicsPipeline(vk::Device dev, const std::vector<Shader>& sh
const auto depth_stencil_info = vk::PipelineDepthStencilStateCreateInfo{ const auto depth_stencil_info = vk::PipelineDepthStencilStateCreateInfo{
.depthTestEnable = vk::True, .depthTestEnable = vk::True,
.depthWriteEnable = vk::True, .depthWriteEnable = vk::True,
.depthCompareOp = vk::CompareOp::eLessOrEqual, .depthCompareOp = vk::CompareOp::eLess,
.depthBoundsTestEnable = vk::False, .depthBoundsTestEnable = vk::False,
.stencilTestEnable = vk::False, .stencilTestEnable = vk::False,
.minDepthBounds = 0.0, .minDepthBounds = 0.0,

View File

@ -364,7 +364,7 @@ void Renderer::draw() {
auto sz = win.getDimensions(); auto sz = win.getDimensions();
const auto p = glm::perspective(glm::radians(90.0f), static_cast<float>(sz.width) / static_cast<float>(sz.height), 0.01f, 200000.0f); const auto p = glm::perspective(glm::radians(90.0f), static_cast<float>(sz.width) / static_cast<float>(sz.height), 0.01f, 10000.0f);
auto uni = UniformData{ auto uni = UniformData{
.view = cam.view(), .view = cam.view(),
@ -404,6 +404,8 @@ void Renderer::draw() {
command_buffer->bind(bsp.get()); command_buffer->bind(bsp.get());
command_buffer->command_buffer.drawIndexed(bsp->indices.size(), 1, 0, 0, 0); command_buffer->command_buffer.drawIndexed(bsp->indices.size(), 1, 0, 0, 0);
n_indices = bsp->indices.size();
/* draw User Interface stuff */ /* draw User Interface stuff */
ui->newFrame(); ui->newFrame();

View File

@ -77,6 +77,7 @@ struct Renderer {
float speed = 1.0; float speed = 1.0;
bool running = true; bool running = true;
size_t n_indices;
bool visibility_testing; bool visibility_testing;
float tess_factor = 1.8f; float tess_factor = 1.8f;

View File

@ -24,12 +24,11 @@ static inline void copy_data(void* file_data, std::vector<T>& dst, Lump& lump) {
} }
void BSP::load_indices(const glm::vec3& cam_pos, bool visibility_test) { void BSP::load_indices(const glm::vec3& cam_pos, bool visibility_test) {
indices.clear();
std::set<int> present_faces; std::set<int> present_faces;
std::vector<Face> visible_faces; std::vector<Face> visible_faces;
if (visibility_test) { if (visibility_test) {
auto leaf_idx = determine_leaf(cam_pos); auto leaf_idx = determine_leaf(cam_pos);
if (leaf_idx == last_leaf)
return;
last_leaf = leaf_idx; last_leaf = leaf_idx;
auto& cam_leaf = leafs[leaf_idx]; auto& cam_leaf = leafs[leaf_idx];
@ -60,13 +59,15 @@ void BSP::load_indices(const glm::vec3& cam_pos, bool visibility_test) {
case Face::ePATCH: case Face::ePATCH:
break; break;
case Face::ePOLYGON: case Face::ePOLYGON:
case Face::eMESH: // case Face::eMESH:
for (size_t i = 0; i < face.n_mesh_vertices; i++) for (size_t i = 0; i < face.n_mesh_vertices; i++)
indices.push_back(face.first_vertex_idx + mesh_vertices[face.first_mesh_vertex_idx+i].idx); indices.push_back(face.first_vertex_idx + mesh_vertices[face.first_mesh_vertex_idx+i].idx);
break; break;
} }
} }
assert(indices.size() % 3 == 0);
index_buffer->upload(indices); index_buffer->upload(indices);
} }

View File

@ -11,7 +11,7 @@
#include <Scene/Camera.hpp> #include <Scene/Camera.hpp>
UI::UI(Renderer* ren) : info{ .flycam = ren->flycam, .visibility_testing = ren->visibility_testing, .time = ren->time, .cam = ren->cam, .tess_factor = ren->tess_factor, .tess_edge_size = ren->tess_edge_size }, dev(ren->dev) { UI::UI(Renderer* ren) : info{ .flycam = ren->flycam, .visibility_testing = ren->visibility_testing, .time = ren->time, .cam = ren->cam, .tess_factor = ren->tess_factor, .tess_edge_size = ren->tess_edge_size, .n_indices = ren->n_indices }, dev(ren->dev) {
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
ImGui::CreateContext(); ImGui::CreateContext();
@ -89,6 +89,7 @@ void UI::newFrame() {
ImGui::SetNextWindowBgAlpha(0.5f); ImGui::SetNextWindowBgAlpha(0.5f);
ImGui::Begin("Rendering Info", nullptr); ImGui::Begin("Rendering Info", nullptr);
ImGui::Text("# of Indices: %zu", info.n_indices);
ImGui::Text("FPS: %f", info.fps); ImGui::Text("FPS: %f", info.fps);
ImGui::Text("Time: %f", info.time); ImGui::Text("Time: %f", info.time);
ImGui::Checkbox("Fly Camera", &info.flycam); ImGui::Checkbox("Fly Camera", &info.flycam);

View File

@ -18,6 +18,7 @@ struct UI {
Camera& cam; Camera& cam;
float& tess_factor; float& tess_factor;
float& tess_edge_size; float& tess_edge_size;
const size_t& n_indices;
} info; } info;
vk::Device dev; vk::Device dev;