From 4b5c2c3f342f495e516e55d6a5f7f96fd5752133 Mon Sep 17 00:00:00 2001 From: Sebastian Pape <Sebastian.Pape@rwth-aachen.de> Date: Wed, 25 Jul 2018 14:44:50 +0200 Subject: [PATCH] Rays now use float4 buffer for faster access --- demos/optical_bench/src/Optix Files/laser_caster.cu | 10 +++++----- demos/optical_bench/src/ray_pass.cpp | 6 +++--- resources/shader/ray.vert | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/demos/optical_bench/src/Optix Files/laser_caster.cu b/demos/optical_bench/src/Optix Files/laser_caster.cu index c2310607..3868259b 100644 --- a/demos/optical_bench/src/Optix Files/laser_caster.cu +++ b/demos/optical_bench/src/Optix Files/laser_caster.cu @@ -28,7 +28,7 @@ rtDeclareVariable(float, laserBeamWidth, , ); rtBuffer<int, 2> laserIndex; rtBuffer<float3, 2> laserDir; -rtBuffer<float3, 1> result_laser; +rtBuffer<float4, 1> result_laser; RT_PROGRAM void laser_caster(){ @@ -62,11 +62,11 @@ RT_PROGRAM void laser_caster(){ for(int i = 0; i < max_depth_laser * 2; i += 2){ //Determine if this launch_index, depth or last ray should trigger new cast if(cast_ray || prd.done || prd.depth >= max_depth_laser){ // just write rest of data as "invalid" - if(launch_index.z == 0) result_laser[startIndex + i] = make_float3(0,-1,0); - if(launch_index.z == 0) result_laser[startIndex + i + 1] = make_float3(0,-1,0); + if(launch_index.z == 0) result_laser[startIndex + i] = make_float4(0,-1,0,1); + if(launch_index.z == 0) result_laser[startIndex + i + 1] = make_float4(0,-1,0,1); continue; } - if(launch_index.z == 0) result_laser[startIndex + i] = prd.origin; + if(launch_index.z == 0) result_laser[startIndex + i] = make_float4(prd.origin,1); ray.origin = prd.origin; ray.direction = prd.direction; @@ -74,6 +74,6 @@ RT_PROGRAM void laser_caster(){ // Update ray data for the next path segment prd.depth++; - if(launch_index.z == 0) result_laser[startIndex + i + 1] = prd.origin; + if(launch_index.z == 0) result_laser[startIndex + i + 1] = make_float4(prd.origin,1); } } \ No newline at end of file diff --git a/demos/optical_bench/src/ray_pass.cpp b/demos/optical_bench/src/ray_pass.cpp index dd2b0829..a4b65b99 100644 --- a/demos/optical_bench/src/ray_pass.cpp +++ b/demos/optical_bench/src/ray_pass.cpp @@ -107,7 +107,7 @@ void RayPass::Initialize() { glBindVertexArray(vaoOpenGL); glEnableVertexAttribArray(0); // Vertices glBindBuffer(GL_ARRAY_BUFFER, bufferOpenGLLaserVertices); - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL); + glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL); glEnableVertexAttribArray(1); // Colors glBindBuffer(GL_ARRAY_BUFFER, bufferOpenGLLaserColors); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL); @@ -120,7 +120,7 @@ void RayPass::Initialize() { glBindBuffer(GL_ARRAY_BUFFER, bufferOpenGLLaserVertices); glBufferData(GL_ARRAY_BUFFER, - laser_max_depth * 50 * 50 * 2 * 3 * sizeof(float), NULL, + laser_max_depth * 50 * 50 * 2 * 4 * sizeof(float), NULL, GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -269,7 +269,7 @@ void RayPass::createLaser() { bufferLaserOptix = context->createBufferFromGLBO(RT_BUFFER_OUTPUT, bufferOpenGLLaserVertices); - bufferLaserOptix->setFormat(RT_FORMAT_FLOAT3); + bufferLaserOptix->setFormat(RT_FORMAT_FLOAT4); bufferLaserOptix->setSize(laser_max_depth * 50 * 50 * 2); context["result_laser"]->set(bufferLaserOptix); diff --git a/resources/shader/ray.vert b/resources/shader/ray.vert index 7b71c47b..28abf298 100644 --- a/resources/shader/ray.vert +++ b/resources/shader/ray.vert @@ -21,12 +21,12 @@ //------------------------------------------------------------------------------ #version 450 -layout(location = 0) in vec3 in_position; +layout(location = 0) in vec4 in_position; layout(location = 1) in vec3 in_color; out vec3 color; void main(void) { - gl_Position = vec4(in_position, 1.0f); + gl_Position = in_position; color = in_color; } -- GitLab