Fixed loading
This commit is contained in:
parent
faf97687a9
commit
a3efba825f
@ -6,7 +6,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(CMAKE_CXX_FLAGS "-D_DEBUG")
|
set(CMAKE_CXX_FLAGS "-D_DEBUG")
|
||||||
else()
|
else()
|
||||||
set(CMAKE_CXX_FLAGS "-D_DEBUG -Wall")
|
set(CMAKE_CXX_FLAGS "-D_DEBUG -Wall -D_GLIBCXX_DEBUG -fsanitize=address")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
project(Pleascach)
|
project(Pleascach)
|
||||||
|
|||||||
@ -191,7 +191,11 @@ Renderer::Renderer(Window& win) : win(win) {
|
|||||||
command_buffer = std::make_unique<CommandBuffer>(dev, queue_family);
|
command_buffer = std::make_unique<CommandBuffer>(dev, queue_family);
|
||||||
|
|
||||||
uniform_buffer = std::make_unique<UniformBuffer>(phys_dev, dev);
|
uniform_buffer = std::make_unique<UniformBuffer>(phys_dev, dev);
|
||||||
shader_buffer = std::make_unique<ShaderBuffer>(phys_dev, dev);
|
|
||||||
|
/* load map */
|
||||||
|
bsp = std::make_unique<Q3BSP::BSP>("assets/maps/git.bsp");
|
||||||
|
|
||||||
|
shader_buffer = std::make_unique<ShaderBuffer>(phys_dev, dev, bsp->planes.size());
|
||||||
|
|
||||||
textures = createResources({
|
textures = createResources({
|
||||||
"assets/textures/oil.jpg",
|
"assets/textures/oil.jpg",
|
||||||
@ -220,10 +224,6 @@ Renderer::Renderer(Window& win) : win(win) {
|
|||||||
{ { -1.0,-1.0 } },
|
{ { -1.0,-1.0 } },
|
||||||
});
|
});
|
||||||
|
|
||||||
/* load map */
|
|
||||||
bsp = std::make_unique<Q3BSP::BSP>("assets/maps/git.bsp");
|
|
||||||
|
|
||||||
std::vector<Object> objects;
|
|
||||||
objects.reserve(bsp->planes.size());
|
objects.reserve(bsp->planes.size());
|
||||||
uint id = 0;
|
uint id = 0;
|
||||||
for (const auto& plane : bsp->planes) {
|
for (const auto& plane : bsp->planes) {
|
||||||
@ -358,7 +358,7 @@ void Renderer::draw() {
|
|||||||
command_buffer->command_buffer.setScissor(0, scissor);
|
command_buffer->command_buffer.setScissor(0, scissor);
|
||||||
command_buffer->bind(pipeline->layout, pipeline->desc_set);
|
command_buffer->bind(pipeline->layout, pipeline->desc_set);
|
||||||
command_buffer->bind(*vertex_buffer);
|
command_buffer->bind(*vertex_buffer);
|
||||||
shader_buffer->objects[0].center.y += glm::sin(time)/10.0;
|
//shader_buffer->objects[0].center.y += glm::sin(time)/10.0;
|
||||||
command_buffer->command_buffer.draw(6, 1, 0, 0);
|
command_buffer->command_buffer.draw(6, 1, 0, 0);
|
||||||
|
|
||||||
/* draw User Interface stuff */
|
/* draw User Interface stuff */
|
||||||
|
|||||||
@ -60,6 +60,8 @@ struct Renderer {
|
|||||||
uint32_t current_image_idx;
|
uint32_t current_image_idx;
|
||||||
uint64_t frame = 0;
|
uint64_t frame = 0;
|
||||||
|
|
||||||
|
std::vector<Object> objects;
|
||||||
|
|
||||||
std::unique_ptr<UI> ui;
|
std::unique_ptr<UI> ui;
|
||||||
|
|
||||||
Camera cam{ .pos = glm::vec3(0.0, 0.0, -1.0), };
|
Camera cam{ .pos = glm::vec3(0.0, 0.0, -1.0), };
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <util/glsl_types.hpp>
|
#include <util/glsl_types.hpp>
|
||||||
|
|
||||||
#include <Scene/Object.hpp>
|
#include <Scene/Object.hpp>
|
||||||
|
|||||||
@ -3,6 +3,8 @@
|
|||||||
#include <util/file.hpp>
|
#include <util/file.hpp>
|
||||||
#include <util/log.hpp>
|
#include <util/log.hpp>
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
using namespace Q3BSP;
|
using namespace Q3BSP;
|
||||||
|
|
||||||
static inline void copy_data(void* file_data, std::string& dst, Lump& lump) {
|
static inline void copy_data(void* file_data, std::string& dst, Lump& lump) {
|
||||||
@ -12,9 +14,11 @@ static inline void copy_data(void* file_data, std::string& dst, Lump& lump) {
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static inline void copy_data(void* file_data, std::vector<T>& dst, Lump& lump) {
|
static inline void copy_data(void* file_data, std::vector<T>& dst, Lump& lump) {
|
||||||
|
Log::debug("Size: %zu (%zu)\n", lump.len/sizeof(T), lump.len);
|
||||||
dst.resize(lump.len / sizeof(T));
|
dst.resize(lump.len / sizeof(T));
|
||||||
|
puts("ALLOC'D");
|
||||||
//Log::debug("%p %p\n", dst.data(), (u8*)file_data + lump.offset);
|
//Log::debug("%p %p\n", dst.data(), (u8*)file_data + lump.offset);
|
||||||
std::memcpy(dst.data(), (u8*)file_data + (size_t)lump.offset, lump.len);
|
std::memcpy(dst.data(), ((u8*)file_data) + lump.offset, lump.len);
|
||||||
}
|
}
|
||||||
|
|
||||||
BSP::BSP(const std::string& fname) : filename(fname) {
|
BSP::BSP(const std::string& fname) : filename(fname) {
|
||||||
@ -28,11 +32,9 @@ BSP::BSP(const std::string& fname) : filename(fname) {
|
|||||||
Log::error("BSP file missing magic!\n");
|
Log::error("BSP file missing magic!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t i = 0;
|
for (size_t i = 0; i < std::size(header->lumps); i++) {
|
||||||
for (auto& lump : header->lumps) {
|
Log::debug("%i: Offset: %u | Length: %u\n", i, header->lumps[i].offset, header->lumps[i].len);
|
||||||
i++;
|
Log::debug("\tPointer: 0x%p\n", (u8*)file_data.data() + (size_t)header->lumps[i].offset);
|
||||||
Log::debug("%i: Offset: %u | Length: %u\n", i, lump.offset, lump.len);
|
|
||||||
Log::debug("\tPointer: 0x%p\n", (u8*)file_data.data() + (size_t)lump.offset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
copy_data(file_data.data(), entities, header->entities);
|
copy_data(file_data.data(), entities, header->entities);
|
||||||
@ -51,10 +53,10 @@ BSP::BSP(const std::string& fname) : filename(fname) {
|
|||||||
copy_data(file_data.data(), faces, header->faces);
|
copy_data(file_data.data(), faces, header->faces);
|
||||||
copy_data(file_data.data(), lightmaps, header->lightmaps);
|
copy_data(file_data.data(), lightmaps, header->lightmaps);
|
||||||
copy_data(file_data.data(), lightvols, header->lightvols);
|
copy_data(file_data.data(), lightvols, header->lightvols);
|
||||||
|
|
||||||
vis_info.sz_vectors = *reinterpret_cast<u32*>(file_data.data() + header->vis_info.offset);
|
|
||||||
vis_info.vectors.resize(header->vis_info.len);
|
|
||||||
std::memcpy(vis_info.vectors.data(), file_data.data() + header->vis_info.offset + sizeof(u32), header->vis_info.len);
|
|
||||||
|
|
||||||
vis_info = *reinterpret_cast<VisibilityInfo*>(file_data.data() + header->vis_info.offset);
|
vis_info.sz_vectors = reinterpret_cast<u32*>(file_data.data() + header->vis_info.offset)[1];
|
||||||
|
auto sz = header->vis_info.len;
|
||||||
|
Log::debug("Size: %u\n", sz);
|
||||||
|
vis_info.vectors.resize(sz);
|
||||||
|
std::memcpy(vis_info.vectors.data(), file_data.data() + header->vis_info.offset + 2*sizeof(u32), sz);
|
||||||
}
|
}
|
||||||
@ -23,23 +23,25 @@ namespace Q3BSP {
|
|||||||
|
|
||||||
union {
|
union {
|
||||||
Lump lumps[17];
|
Lump lumps[17];
|
||||||
Lump entities,
|
struct {
|
||||||
textures,
|
Lump entities,
|
||||||
planes,
|
textures,
|
||||||
nodes,
|
planes,
|
||||||
leafs,
|
nodes,
|
||||||
leaf_faces,
|
leafs,
|
||||||
leaf_brushes,
|
leaf_faces,
|
||||||
models,
|
leaf_brushes,
|
||||||
brushes,
|
models,
|
||||||
brush_sides,
|
brushes,
|
||||||
vertices,
|
brush_sides,
|
||||||
mesh_vertices,
|
vertices,
|
||||||
effects,
|
mesh_vertices,
|
||||||
faces,
|
effects,
|
||||||
lightmaps,
|
faces,
|
||||||
lightvols,
|
lightmaps,
|
||||||
vis_info;
|
lightvols,
|
||||||
|
vis_info;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -108,7 +110,8 @@ namespace Q3BSP {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Vertex {
|
struct Vertex {
|
||||||
glm::vec3 tex_coords;
|
glm::vec3 position;
|
||||||
|
glm::vec2 tex_coords;
|
||||||
glm::vec2 lightmap_coords;
|
glm::vec2 lightmap_coords;
|
||||||
glm::vec3 normal;
|
glm::vec3 normal;
|
||||||
glm::u8vec4 color;
|
glm::u8vec4 color;
|
||||||
|
|||||||
14
UI/UI.cpp
14
UI/UI.cpp
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
#include <Scene/Camera.hpp>
|
#include <Scene/Camera.hpp>
|
||||||
|
|
||||||
UI::UI(Renderer* ren) : info { .flycam = ren->flycam, .time = ren->time, .rad = ren->rad, .cam = ren->cam }, dev(ren->dev) {
|
UI::UI(Renderer* ren) : info { .flycam = ren->flycam, .time = ren->time, .rad = ren->rad, .cam = ren->cam, .objects = ren->objects}, dev(ren->dev) {
|
||||||
IMGUI_CHECKVERSION();
|
IMGUI_CHECKVERSION();
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
|
|
||||||
@ -95,9 +95,15 @@ void UI::newFrame() {
|
|||||||
ImGui::SliderFloat("Theta", &info.cam.theta, 0.0, glm::pi<float>());
|
ImGui::SliderFloat("Theta", &info.cam.theta, 0.0, glm::pi<float>());
|
||||||
ImGui::SliderFloat("Phi", &info.cam.phi, 0.0, glm::two_pi<float>());
|
ImGui::SliderFloat("Phi", &info.cam.phi, 0.0, glm::two_pi<float>());
|
||||||
|
|
||||||
ImGui::SliderFloat("X", &info.cam.pos.x, -10.0, 10.0);
|
ImGui::SliderFloat("X", &info.cam.pos.x, -1000.0, 1000.0);
|
||||||
ImGui::SliderFloat("Y", &info.cam.pos.y, -10.0, 10.0);
|
ImGui::SliderFloat("Y", &info.cam.pos.y, -1000.0, 1000.0);
|
||||||
ImGui::SliderFloat("Z", &info.cam.pos.z, -10.0, 10.0);
|
ImGui::SliderFloat("Z", &info.cam.pos.z, -1000.0, 1000.0);
|
||||||
|
|
||||||
|
if(ImGui::CollapsingHeader("Objects")) {
|
||||||
|
for(const auto& obj : info.objects) {
|
||||||
|
ImGui::Text("(%f %f %f) + %f", obj.center.x, obj.center.y, obj.center.z, obj.dimensions.x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|||||||
@ -5,6 +5,9 @@
|
|||||||
|
|
||||||
#include <Renderer/CommandBuffer.hpp>
|
#include <Renderer/CommandBuffer.hpp>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
struct Object;
|
||||||
struct Renderer;
|
struct Renderer;
|
||||||
struct Camera;
|
struct Camera;
|
||||||
|
|
||||||
@ -17,6 +20,7 @@ struct UI {
|
|||||||
float& rad;
|
float& rad;
|
||||||
/* camera stuff */
|
/* camera stuff */
|
||||||
Camera& cam;
|
Camera& cam;
|
||||||
|
const std::vector<Object>& objects;
|
||||||
} info;
|
} info;
|
||||||
|
|
||||||
vk::Device dev;
|
vk::Device dev;
|
||||||
|
|||||||
@ -41,8 +41,10 @@ layout (location = 0) in vec2 pos;
|
|||||||
layout (location = 0) out vec4 fragColor;
|
layout (location = 0) out vec4 fragColor;
|
||||||
|
|
||||||
/* joins two parts of a scene */
|
/* joins two parts of a scene */
|
||||||
float op_union(float v1, float v2) {
|
vec2 op_union(vec2 v1, float v2, float id) {
|
||||||
return min(v1, v2);
|
if(v1.x > v2)
|
||||||
|
return vec2(v2, id);
|
||||||
|
return v1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* subtracts sdf from scene */
|
/* subtracts sdf from scene */
|
||||||
@ -51,7 +53,7 @@ float op_subtract(float v1, float v2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float sphere(vec3 p, vec3 c, float r) {
|
float sphere(vec3 p, vec3 c, float r) {
|
||||||
return length(p-c) - r;
|
return abs(length(p-c) - r);
|
||||||
}
|
}
|
||||||
|
|
||||||
float box(vec3 p, vec3 c, vec3 r) {
|
float box(vec3 p, vec3 c, vec3 r) {
|
||||||
@ -61,7 +63,7 @@ float box(vec3 p, vec3 c, vec3 r) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float plane(vec3 p, vec3 norm, float d) {
|
float plane(vec3 p, vec3 norm, float d) {
|
||||||
return dot(p, norm) + d;
|
return dot(p, normalize(norm)) + d;
|
||||||
}
|
}
|
||||||
|
|
||||||
float obj_to_sdf(vec3 p, uint n) {
|
float obj_to_sdf(vec3 p, uint n) {
|
||||||
@ -72,6 +74,9 @@ float obj_to_sdf(vec3 p, uint n) {
|
|||||||
case BOX:
|
case BOX:
|
||||||
return box(p, objects[n].center.xyz, objects[n].dimensions.xyz);
|
return box(p, objects[n].center.xyz, objects[n].dimensions.xyz);
|
||||||
break;
|
break;
|
||||||
|
case PLANE:
|
||||||
|
return plane(p, objects[n].center.xyz, objects[n].dimensions.x);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,42 +89,48 @@ float terrain(vec3 p) {
|
|||||||
return box(p, vec3(0.0), vec3(100.0, 0.1, 100.0)) - abs(map(p.xz));
|
return box(p, vec3(0.0), vec3(100.0, 0.1, 100.0)) - abs(map(p.xz));
|
||||||
}
|
}
|
||||||
|
|
||||||
float sdf(vec3 pos) {
|
/* <distance, id> */
|
||||||
/*float d = 100000000.0;
|
vec2 sdf(vec3 pos) {
|
||||||
|
vec2 d = vec2(100000000.0, -1.0);
|
||||||
for(uint i = 0; i < n_objects; i++) {
|
for(uint i = 0; i < n_objects; i++) {
|
||||||
d = op_union(d, obj_to_sdf(pos, i));
|
d = op_union(d, obj_to_sdf(pos, i), objects[n_objects].id);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
|
||||||
/*float dsphere = sphere(pos, vec3(0.0, 3.0*sin(time)-10.0, 0.0), 1.0);
|
/*float dsphere = sphere(pos, vec3(0.0, 3.0*sin(time)-10.0, 0.0), 1.0);
|
||||||
float dbox = box(pos, vec3(0.0, -10.0, 0.0), vec3(10.0, 1.0, 10.0));
|
float dbox = box(pos, vec3(0.0, -10.0, 0.0), vec3(10.0, 1.0, 10.0));
|
||||||
float dpellet = sphere(pos, vec3(0.0, 10.0*sin(time) - 10.0, 0.0), 0.1);
|
float dpellet = sphere(pos, vec3(0.0, 10.0*sin(time) - 10.0, 0.0), 0.1);
|
||||||
float d = op_union(op_subtract(dbox, dsphere), dpellet);*/
|
float d = op_union(op_subtract(dbox, dsphere), dpellet);*/
|
||||||
|
|
||||||
|
//d = op_union(d, plane(pos, normalize(vec3(1.0)), 50.0));
|
||||||
|
|
||||||
return terrain(pos);
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
float raycast(vec3 dir) {
|
vec2 raycast(vec3 dir) {
|
||||||
float t = 0.0;
|
float t = 0.0;
|
||||||
for(int i = 0; i < MAX_STEPS; i++) {
|
for(int i = 0; i < MAX_STEPS; i++) {
|
||||||
float dt = sdf(cam_pos + dir * t);
|
vec2 dt = sdf(cam_pos + dir * t);
|
||||||
if(dt < 0.0001*t)
|
if(dt.y == -1.0)
|
||||||
return float(i)/MAX_STEPS;
|
return dt;
|
||||||
else if(dt > 200.0)
|
if(dt.x < 0.0001*t)
|
||||||
return -1.0;
|
return vec2(t, dt.y);
|
||||||
t += dt;
|
// return float(i)/MAX_STEPS;
|
||||||
|
else if(dt.x > 2000.0)
|
||||||
|
return vec2(dt.x, -1.0);
|
||||||
|
t += dt.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1.0;
|
return vec2(0.0, -1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 norm(vec3 pos) {
|
vec3 norm(vec3 pos) {
|
||||||
return normalize(
|
return normalize(
|
||||||
vec3(
|
vec3(
|
||||||
sdf(pos+eps.xyy),
|
sdf(pos+eps.xyy).x,
|
||||||
sdf(pos+eps.yxy),
|
sdf(pos+eps.yxy).x,
|
||||||
sdf(pos+eps.yyx)
|
sdf(pos+eps.yyx).x
|
||||||
) - sdf(pos)
|
) - sdf(pos).x
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,10 +145,12 @@ vec3 raygen() {
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec3 dir = raygen();
|
vec3 dir = raygen();
|
||||||
float d = raycast(dir);
|
vec2 d = raycast(dir);
|
||||||
|
|
||||||
if(d < 0.0)
|
vec3 p = d.x*dir + cam_pos;
|
||||||
fragColor = vec4(0.0);
|
|
||||||
|
if(d.y != -1.0)
|
||||||
|
fragColor = vec4(d.y/n_objects);
|
||||||
else
|
else
|
||||||
fragColor = vec4(abs(norm(d*dir+cam_pos)).r);
|
fragColor = vec4(0.0);
|
||||||
}
|
}
|
||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user