Skip to content
Snippets Groups Projects
Commit 4b5c2c3f authored by Sebastian Pape's avatar Sebastian Pape
Browse files

Rays now use float4 buffer for faster access

parent a645bcf8
Branches
Tags v18.01.0
No related merge requests found
...@@ -28,7 +28,7 @@ rtDeclareVariable(float, laserBeamWidth, , ); ...@@ -28,7 +28,7 @@ rtDeclareVariable(float, laserBeamWidth, , );
rtBuffer<int, 2> laserIndex; rtBuffer<int, 2> laserIndex;
rtBuffer<float3, 2> laserDir; rtBuffer<float3, 2> laserDir;
rtBuffer<float3, 1> result_laser; rtBuffer<float4, 1> result_laser;
RT_PROGRAM void laser_caster(){ RT_PROGRAM void laser_caster(){
...@@ -62,11 +62,11 @@ 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){ for(int i = 0; i < max_depth_laser * 2; i += 2){
//Determine if this launch_index, depth or last ray should trigger new cast //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(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] = make_float4(0,-1,0,1);
if(launch_index.z == 0) result_laser[startIndex + i + 1] = make_float3(0,-1,0); if(launch_index.z == 0) result_laser[startIndex + i + 1] = make_float4(0,-1,0,1);
continue; 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.origin = prd.origin;
ray.direction = prd.direction; ray.direction = prd.direction;
...@@ -74,6 +74,6 @@ RT_PROGRAM void laser_caster(){ ...@@ -74,6 +74,6 @@ RT_PROGRAM void laser_caster(){
// Update ray data for the next path segment // Update ray data for the next path segment
prd.depth++; 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
...@@ -107,7 +107,7 @@ void RayPass::Initialize() { ...@@ -107,7 +107,7 @@ void RayPass::Initialize() {
glBindVertexArray(vaoOpenGL); glBindVertexArray(vaoOpenGL);
glEnableVertexAttribArray(0); // Vertices glEnableVertexAttribArray(0); // Vertices
glBindBuffer(GL_ARRAY_BUFFER, bufferOpenGLLaserVertices); 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 glEnableVertexAttribArray(1); // Colors
glBindBuffer(GL_ARRAY_BUFFER, bufferOpenGLLaserColors); glBindBuffer(GL_ARRAY_BUFFER, bufferOpenGLLaserColors);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
...@@ -120,7 +120,7 @@ void RayPass::Initialize() { ...@@ -120,7 +120,7 @@ void RayPass::Initialize() {
glBindBuffer(GL_ARRAY_BUFFER, bufferOpenGLLaserVertices); glBindBuffer(GL_ARRAY_BUFFER, bufferOpenGLLaserVertices);
glBufferData(GL_ARRAY_BUFFER, 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); GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
...@@ -269,7 +269,7 @@ void RayPass::createLaser() { ...@@ -269,7 +269,7 @@ void RayPass::createLaser() {
bufferLaserOptix = context->createBufferFromGLBO(RT_BUFFER_OUTPUT, bufferLaserOptix = context->createBufferFromGLBO(RT_BUFFER_OUTPUT,
bufferOpenGLLaserVertices); bufferOpenGLLaserVertices);
bufferLaserOptix->setFormat(RT_FORMAT_FLOAT3); bufferLaserOptix->setFormat(RT_FORMAT_FLOAT4);
bufferLaserOptix->setSize(laser_max_depth * 50 * 50 * 2); bufferLaserOptix->setSize(laser_max_depth * 50 * 50 * 2);
context["result_laser"]->set(bufferLaserOptix); context["result_laser"]->set(bufferLaserOptix);
......
...@@ -21,12 +21,12 @@ ...@@ -21,12 +21,12 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#version 450 #version 450
layout(location = 0) in vec3 in_position; layout(location = 0) in vec4 in_position;
layout(location = 1) in vec3 in_color; layout(location = 1) in vec3 in_color;
out vec3 color; out vec3 color;
void main(void) void main(void)
{ {
gl_Position = vec4(in_position, 1.0f); gl_Position = in_position;
color = in_color; color = in_color;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment