mirror of
https://github.com/TheRedShip/RT_GPU.git
synced 2025-09-27 18:48:36 +02:00
+ | Debug view
This commit is contained in:
10
imgui.ini
10
imgui.ini
@ -4,13 +4,17 @@ Size=400,400
|
||||
|
||||
[Window][Camera]
|
||||
Pos=1652,11
|
||||
Size=259,192
|
||||
Size=259,200
|
||||
|
||||
[Window][Material]
|
||||
Pos=1650,202
|
||||
Pos=1650,214
|
||||
Size=266,285
|
||||
|
||||
[Window][Fog settings]
|
||||
Pos=1679,495
|
||||
Pos=1654,501
|
||||
Size=247,157
|
||||
|
||||
[Window][Debug]
|
||||
Pos=1650,665
|
||||
Size=260,294
|
||||
|
||||
|
@ -64,6 +64,14 @@ struct GPUVolume
|
||||
int enabled;
|
||||
};
|
||||
|
||||
struct GPUDebug
|
||||
{
|
||||
int enabled;
|
||||
int mode;
|
||||
int triangle_treshold;
|
||||
int box_treshold;
|
||||
};
|
||||
|
||||
struct GPUBvh
|
||||
{
|
||||
alignas(16) glm::vec3 min;
|
||||
@ -99,9 +107,11 @@ class Scene
|
||||
const std::vector<GPUTriangle> &getTriangleData() const;
|
||||
|
||||
std::vector<GPUMaterial> &getMaterialData();
|
||||
GPUVolume &getVolume();
|
||||
std::vector<GPUBvh> &getBVH();
|
||||
|
||||
GPUVolume &getVolume();
|
||||
GPUDebug &getDebug();
|
||||
|
||||
Camera *getCamera(void) const;
|
||||
GPUMaterial getMaterial(int material_index);
|
||||
|
||||
@ -116,6 +126,7 @@ class Scene
|
||||
std::set<int> _gpu_lights;
|
||||
|
||||
GPUVolume _gpu_volume;
|
||||
GPUDebug _gpu_debug;
|
||||
|
||||
Camera *_camera;
|
||||
};
|
||||
|
27
scenes/dragon.rt
Normal file
27
scenes/dragon.rt
Normal file
@ -0,0 +1,27 @@
|
||||
CAM 1.93858 0.961594 -0.0117614 -25 180 0.05 2.1639994842342176 29.263 5
|
||||
|
||||
|
||||
MAT 255 255 255 0.0 1. 0.5 // white 0
|
||||
|
||||
MAT 255 10 10 0.0 0.0 0.0 // red 1
|
||||
MAT 30 30 30 0.0 0.0 0.0 // gray 2
|
||||
MAT 10 255 10 0.0 0.0 0.0 // green 3
|
||||
MAT 255 255 255 0.0 0.0 0.0 // white 4
|
||||
MAT 50 50 255 0.0 0.0 0.0 // white 5
|
||||
|
||||
MAT 255 255 255 5.0 0.0 0.0 // white light 6
|
||||
|
||||
|
||||
MAT 255 255 255 0.0 0.0 0.0 TRN // glass 7
|
||||
|
||||
pl 0 0 -2 0 0 1 1 // back wall
|
||||
pl 0 0 2 0 0 -1 5 // front wall
|
||||
pl 2 0 0 -1 0 0 3 // right wall
|
||||
pl -2 0 0 1 0 0 2 // left wall
|
||||
pl 0 2 0 0 -1 0 0 // ceiling
|
||||
pl 0 -2 0 0 1 0 2 // floor
|
||||
|
||||
qu -1 1.999 -1 2 0 0 0 0 2 6
|
||||
|
||||
OBJ obj/Dragon_80K.obj
|
||||
|
@ -1,7 +1,6 @@
|
||||
CAM 1.29625 0.667446 0.00169364 -24.6 178.8 0.03 1.3 45 5
|
||||
CAM -1 0 0 0 0 0 1 90 5
|
||||
|
||||
|
||||
MAT 255 255 255 0.0 0.75 1.0 // white 0
|
||||
MAT 255 255 255 0.0 1. 0.5 // white 0
|
||||
|
||||
MAT 255 10 10 0.0 0.0 0.0 // red 1
|
||||
MAT 30 30 30 0.0 0.0 0.0 // gray 2
|
||||
@ -14,14 +13,13 @@ MAT 255 255 255 5.0 0.0 0.0 // white light 6
|
||||
|
||||
MAT 255 255 255 0.0 0.0 0.0 TRN // glass 7
|
||||
|
||||
pl 0 0 -2 0 0 1 1 // back wall
|
||||
pl 0 0 2 0 0 -1 5 // front wall
|
||||
pl 2 0 0 -1 0 0 3 // right wall
|
||||
pl -2 0 0 1 0 0 2 // left wall
|
||||
pl 0 2 0 0 -1 0 0 // ceiling
|
||||
pl 0 -2 0 0 1 0 2 // floor
|
||||
# pl 0 0 -40 0 0 1 1 // back wall
|
||||
# pl 0 0 40 0 0 -1 5 // front wall
|
||||
# pl 40 0 0 -1 0 0 3 // right wall
|
||||
# pl -40 0 0 1 0 0 2 // left wall
|
||||
# pl 0 60 0 0 -1 0 4 // ceiling
|
||||
# pl 0 -10 0 0 1 0 2 // floor
|
||||
|
||||
qu -1 1.999 -1 2 0 0 0 0 2 6
|
||||
# qu -20 59 -20 40 0 0 0 0 40 6
|
||||
|
||||
OBJ obj/Dragon_80K.obj
|
||||
|
||||
|
@ -20,6 +20,18 @@ layout(std140, binding = 0) uniform CameraData
|
||||
GPUCamera camera;
|
||||
};
|
||||
|
||||
struct GPUDebug
|
||||
{
|
||||
int enabled;
|
||||
int mode;
|
||||
int triangle_treshold;
|
||||
int box_treshold;
|
||||
};
|
||||
layout(std140, binding = 2) uniform DebugData
|
||||
{
|
||||
GPUDebug debug;
|
||||
};
|
||||
|
||||
struct GPUObject {
|
||||
mat4 rotation;
|
||||
|
||||
@ -95,6 +107,12 @@ struct hitInfo
|
||||
int mat_index;
|
||||
};
|
||||
|
||||
struct Stats
|
||||
{
|
||||
int triangle_count;
|
||||
int box_count;
|
||||
};
|
||||
|
||||
#include "shaders/intersect.glsl"
|
||||
|
||||
int traceRay(Ray ray)
|
||||
@ -114,7 +132,7 @@ int traceRay(Ray ray)
|
||||
return (num_hit);
|
||||
}
|
||||
|
||||
hitInfo traceBVH(Ray ray, inout int num_hit)
|
||||
hitInfo traceBVH(Ray ray, inout Stats stats)
|
||||
{
|
||||
hitInfo hit;
|
||||
|
||||
@ -137,12 +155,12 @@ hitInfo traceBVH(Ray ray, inout int num_hit)
|
||||
|
||||
if (intersectRayBVH(ray, node))
|
||||
{
|
||||
num_hit++;
|
||||
stats.box_count++;
|
||||
|
||||
if (node.is_leaf != 0)
|
||||
{
|
||||
for (int i = 0; i < node.primitive_count; i++)
|
||||
{
|
||||
{
|
||||
GPUTriangle obj = triangles[node.first_primitive + i];
|
||||
|
||||
hitInfo temp_hit;
|
||||
@ -152,6 +170,7 @@ hitInfo traceBVH(Ray ray, inout int num_hit)
|
||||
hit.normal = temp_hit.normal;
|
||||
hit.obj_index = node.first_primitive + i;
|
||||
}
|
||||
stats.triangle_count++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,6 +200,29 @@ Ray initRay(vec2 uv)
|
||||
return (Ray(origin, ray_direction));
|
||||
}
|
||||
|
||||
vec3 debugColor(vec2 uv)
|
||||
{
|
||||
Ray ray = initRay(uv);
|
||||
Stats stats = Stats(0, 0);
|
||||
|
||||
hitInfo hit = traceBVH(ray, stats);
|
||||
|
||||
float box_display = float(stats.box_count) / float(debug.box_treshold);
|
||||
float triangle_display = float(stats.triangle_count) / float(debug.triangle_treshold);
|
||||
|
||||
switch (debug.mode)
|
||||
{
|
||||
case 0:
|
||||
return (hit.normal * 0.5 + 0.5) * int(hit.obj_index != -1);
|
||||
case 1:
|
||||
return (box_display < 1. ? vec3(box_display) : vec3(1., 0., 0.));
|
||||
case 2:
|
||||
return (triangle_display < 1. ? vec3(triangle_display) : vec3(1., 0., 0.));
|
||||
}
|
||||
|
||||
return (vec3(0.));
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 pixel_coords = ivec2(gl_GlobalInvocationID.xy);
|
||||
@ -190,19 +232,7 @@ void main()
|
||||
vec2 uv = ((vec2(pixel_coords)) / u_resolution) * 2.0 - 1.0;;
|
||||
uv.x *= u_resolution.x / u_resolution.y;
|
||||
|
||||
|
||||
Ray ray = initRay(uv);
|
||||
|
||||
int hits = 0;
|
||||
hitInfo hit = traceBVH(ray, hits);
|
||||
|
||||
vec3 color = vec3(0.);
|
||||
// if (hit.obj_index != -1)
|
||||
// color = vec3(hit.normal);
|
||||
if (hits > 150)
|
||||
color = vec3(1., 0., 0.);
|
||||
else
|
||||
color = vec3(float(hits) / float(100));
|
||||
vec3 color = debugColor(uv);
|
||||
|
||||
imageStore(output_image, pixel_coords, vec4(color, 1.));
|
||||
}
|
45
srcs/RT.cpp
45
srcs/RT.cpp
@ -20,8 +20,8 @@ int main(int argc, char **argv)
|
||||
return (1);
|
||||
|
||||
Window window(&scene, WIDTH, HEIGHT, "RT_GPU", 0);
|
||||
Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl");
|
||||
// Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/debug.glsl");
|
||||
// Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/compute.glsl");
|
||||
Shader shader("shaders/vertex.vert", "shaders/frag.frag", "shaders/debug.glsl");
|
||||
|
||||
GLint max_gpu_size;
|
||||
glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &max_gpu_size);
|
||||
@ -80,6 +80,12 @@ int main(int argc, char **argv)
|
||||
glBufferData(GL_UNIFORM_BUFFER, sizeof(GPUVolume), nullptr, GL_STATIC_DRAW);
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, 1, volumeUBO);
|
||||
|
||||
GLuint debugUBO;
|
||||
glGenBuffers(1, &debugUBO);
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, debugUBO);
|
||||
glBufferData(GL_UNIFORM_BUFFER, sizeof(GPUDebug), nullptr, GL_STATIC_DRAW);
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, 2, debugUBO);
|
||||
|
||||
|
||||
shader.attach();
|
||||
|
||||
@ -87,8 +93,11 @@ int main(int argc, char **argv)
|
||||
size_t size = sizeof(vertices) / sizeof(Vertex) / 3;
|
||||
shader.setupVertexBuffer(vertices, size);
|
||||
|
||||
std::vector<int> recorded_fps;
|
||||
|
||||
while (!window.shouldClose())
|
||||
{
|
||||
|
||||
glUseProgram(shader.getProgramCompute());
|
||||
|
||||
glBindBuffer(GL_SHADER_STORAGE_BUFFER, objectSSBO);
|
||||
@ -110,13 +119,36 @@ int main(int argc, char **argv)
|
||||
glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, gpu_bvh.size() * sizeof(GPUBvh), gpu_bvh.data());
|
||||
|
||||
|
||||
GPUCamera camera_data = scene.getCamera()->getGPUData();
|
||||
Camera *camera = scene.getCamera();
|
||||
|
||||
// performance profiling
|
||||
if (true && window.getFps() < 2000)
|
||||
{
|
||||
float time = (float)(glfwGetTime()) ;
|
||||
|
||||
recorded_fps.push_back((int)window.getFps());
|
||||
|
||||
camera->setPosition(glm::vec3(cos((time + 6.28) * 0.5), 0., sin((time + 6.28) * 0.5)));
|
||||
glm::vec3 direction = glm::normalize(camera->getPosition());
|
||||
float yaw = glm::degrees(atan2(direction.z, direction.x));
|
||||
|
||||
if ((int)yaw == 179)
|
||||
break;
|
||||
|
||||
camera->setDirection(0, yaw - 180);
|
||||
camera->updateCameraVectors();
|
||||
}
|
||||
//
|
||||
|
||||
GPUCamera camera_data = camera->getGPUData();
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, cameraUBO);
|
||||
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(GPUCamera), &camera_data);
|
||||
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, volumeUBO);
|
||||
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(GPUVolume), &scene.getVolume());
|
||||
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, debugUBO);
|
||||
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(GPUDebug), &scene.getDebug());
|
||||
|
||||
shader.set_int("u_frameCount", window.getFrameCount());
|
||||
shader.set_int("u_objectsNum", object_data.size());
|
||||
@ -146,5 +178,12 @@ int main(int argc, char **argv)
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
// performance profiling
|
||||
std::ofstream file("fps.txt");
|
||||
for (int i = 0; i < recorded_fps.size(); i++)
|
||||
file << i << " " << recorded_fps[i] << std::endl;
|
||||
file.close();
|
||||
//
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
@ -17,10 +17,15 @@ Scene::Scene()
|
||||
_camera = new Camera(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f), -90.0f, 0.0f);
|
||||
|
||||
_gpu_volume.enabled = 0;
|
||||
_gpu_volume.sigma_a = glm::vec3(0.0001f);
|
||||
_gpu_volume.sigma_a = glm::vec3(0.0000f);
|
||||
_gpu_volume.sigma_s = glm::vec3(0.0800f);
|
||||
_gpu_volume.sigma_t = _gpu_volume.sigma_a + _gpu_volume.sigma_s;
|
||||
_gpu_volume.g = 0.9f;
|
||||
_gpu_volume.g = 1.0f;
|
||||
|
||||
_gpu_debug.enabled = 0;
|
||||
_gpu_debug.mode = 0;
|
||||
_gpu_debug.triangle_treshold = 1;
|
||||
_gpu_debug.box_treshold = 1;
|
||||
}
|
||||
|
||||
Scene::~Scene()
|
||||
@ -193,6 +198,11 @@ GPUVolume &Scene::getVolume()
|
||||
return (_gpu_volume);
|
||||
}
|
||||
|
||||
GPUDebug &Scene::getDebug()
|
||||
{
|
||||
return (_gpu_debug);
|
||||
}
|
||||
|
||||
std::vector<GPUBvh> &Scene::getBVH()
|
||||
{
|
||||
return (_gpu_bvh);
|
||||
|
@ -248,6 +248,15 @@ void Window::imGuiRender()
|
||||
|
||||
ImGui::End();
|
||||
|
||||
ImGui::Begin("Debug");
|
||||
|
||||
has_changed |= ImGui::Checkbox("Enable", (bool *)(&_scene->getDebug().enabled));
|
||||
ImGui::Separator();
|
||||
has_changed |= ImGui::SliderInt("Debug mode", &_scene->getDebug().mode, 0, 2);
|
||||
has_changed |= ImGui::SliderInt("Box treshold", &_scene->getDebug().box_treshold, 1, 2000);
|
||||
has_changed |= ImGui::SliderInt("Triangle treshold", &_scene->getDebug().triangle_treshold, 1, 2000);
|
||||
|
||||
ImGui::End();
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
Reference in New Issue
Block a user