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

Implemented the laser target in a different way. Now working.

parent a78549d1
No related branches found
No related tags found
No related merge requests found
#include <optix.h>
#include <optix_world.h>
using namespace optix;
rtDeclareVariable(float3, p1, , );
rtDeclareVariable(float3, p2, , );
rtDeclareVariable(float2, stretchXY1, , );
rtDeclareVariable(float2, stretchXY2, , );
rtDeclareVariable(float, scene_epsilon, , );
rtDeclareVariable(optix::Ray, ray, rtCurrentRay, );
rtDeclareVariable(float2, texture_coord, attribute texture_coord, );
rtDeclareVariable(int, writeable_surface, attribute writeable_surface, );
RT_PROGRAM void intersect(int primIdx)
{
float invDir = 1.0f / ray.direction.z;
float t_1 = (p1.z - ray.origin.z) * invDir;
float t_2 = (p2.z - ray.origin.z) * invDir;
float tmin = fminf(t_1, t_2);
float3 hit_point = ray.origin + ray.direction * tmin;
float2 rel_size;
if(tmin == t_1){
rel_size = (make_float2(hit_point) - (make_float2(p1) - stretchXY1/2))/stretchXY1;
}else{
rel_size = (make_float2(hit_point) - (make_float2(p2) - stretchXY2/2))/stretchXY2;
}
if(rel_size.x < 1 && rel_size.y < 1 && rel_size.x >= 0 && rel_size.y >= 0 && rtPotentialIntersection(tmin)) {
texture_coord = rel_size;
writeable_surface = tmin == t_1;
rtReportIntersection(0);
}
}
RT_PROGRAM void bounds (int, optix::Aabb* aabb)
{
float min_x = fminf(p1.x, p2.x) - fmaxf(stretchXY1, stretchXY2).x/2;
float min_y = fminf(p1.y, p2.y) - fmaxf(stretchXY1, stretchXY2).y/2;
float min_z = fminf(p1.z, p2.z);
float max_x = fmaxf(p1.x, p2.x) + fmaxf(stretchXY1, stretchXY2).x/2;
float max_y = fmaxf(p1.y, p2.y) + fmaxf(stretchXY1, stretchXY2).y/2;
float max_z = fmaxf(p1.z, p2.z);
aabb->m_min = make_float3(min_x,min_y,min_z);
aabb->m_max = make_float3(max_x,max_y,max_z);
}
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
rtDeclareVariable(PerRayData_radiance, prd_radiance, rtPayload, ); rtDeclareVariable(PerRayData_radiance, prd_radiance, rtPayload, );
rtDeclareVariable(PerRayData_radiance_iterative, prd_radiance_it, rtPayload, ); rtDeclareVariable(PerRayData_radiance_iterative, prd_radiance_it, rtPayload, );
rtDeclareVariable(float2, texture_coord, attribute texture_coord, ); rtDeclareVariable(float2, texture_coord, attribute texture_coord, );
rtDeclareVariable(int, writeable_surface, attribute writeable_surface, );
rtDeclareVariable(float, hit_depth, rtIntersectionDistance, ); rtDeclareVariable(float, hit_depth, rtIntersectionDistance, );
rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); rtDeclareVariable(optix::Ray, ray, rtCurrentRay, );
...@@ -49,5 +50,5 @@ RT_PROGRAM void closest_hit_iterative() ...@@ -49,5 +50,5 @@ RT_PROGRAM void closest_hit_iterative()
float3 hit_point = ray.origin + hit_depth * ray.direction; float3 hit_point = ray.origin + hit_depth * ray.direction;
prd_radiance_it.origin = hit_point; prd_radiance_it.origin = hit_point;
prd_radiance_it.done = true; prd_radiance_it.done = true;
if(targetBufferWrite) targetBuffer[make_uint2(texture_coord * targetBufferDim)] = prd_radiance_it.radiance; if(targetBufferWrite && writeable_surface) targetBuffer[make_uint2(texture_coord * targetBufferDim)] = prd_radiance_it.radiance;
} }
...@@ -178,7 +178,8 @@ void OptixContextManager::createLensGeometry() { ...@@ -178,7 +178,8 @@ void OptixContextManager::createLensGeometry() {
lensGeomerty = context_->createGeometry(); lensGeomerty = context_->createGeometry();
lensGeomerty->setPrimitiveCount(1u); lensGeomerty->setPrimitiveCount(1u);
std::string ptx = OptixContextManager::getPtxString("lens_parametric.cu"); const std::string ptx =
OptixContextManager::getPtxString("lens_parametric.cu");
lensGeomerty->setBoundingBoxProgram( lensGeomerty->setBoundingBoxProgram(
context_->createProgramFromPTXString(ptx, "bounds")); context_->createProgramFromPTXString(ptx, "bounds"));
lensGeomerty->setIntersectionProgram( lensGeomerty->setIntersectionProgram(
...@@ -189,7 +190,7 @@ void OptixContextManager::createTargetGeometry() { ...@@ -189,7 +190,7 @@ void OptixContextManager::createTargetGeometry() {
targetGeomerty = context_->createGeometry(); targetGeomerty = context_->createGeometry();
targetGeomerty->setPrimitiveCount(1u); targetGeomerty->setPrimitiveCount(1u);
std::string ptx = OptixContextManager::getPtxString("box_intersect.cu"); const std::string ptx = OptixContextManager::getPtxString("box_intersect.cu");
targetGeomerty->setBoundingBoxProgram( targetGeomerty->setBoundingBoxProgram(
context_->createProgramFromPTXString(ptx, "bounds")); context_->createProgramFromPTXString(ptx, "bounds"));
targetGeomerty->setIntersectionProgram( targetGeomerty->setIntersectionProgram(
......
...@@ -257,11 +257,11 @@ void RayPass::createTarget() { ...@@ -257,11 +257,11 @@ void RayPass::createTarget() {
// Buffer // Buffer
targetBuffer = context->createBuffer(RT_BUFFER_INPUT_OUTPUT, RT_FORMAT_FLOAT3, targetBuffer = context->createBuffer(RT_BUFFER_INPUT_OUTPUT, RT_FORMAT_FLOAT3,
target_dims.x, target_dims.y); target_res, target_res);
clearTarget(); clearTarget();
// Material // Material
const std::string ptx = std::string ptx =
OptixContextManager::getPtxString("laser_target_material.cu"); OptixContextManager::getPtxString("laser_target_material.cu");
optix::Program closeHitP = optix::Program closeHitP =
context->createProgramFromPTXString(ptx, "closest_hit_radiance"); context->createProgramFromPTXString(ptx, "closest_hit_radiance");
...@@ -273,32 +273,45 @@ void RayPass::createTarget() { ...@@ -273,32 +273,45 @@ void RayPass::createTarget() {
targetMaterial->setClosestHitProgram(1, closeHitI); targetMaterial->setClosestHitProgram(1, closeHitI);
// Geometry // Geometry
auto geo = context->createGeometry();
geo->setPrimitiveCount(1u);
ptx = OptixContextManager::getPtxString("laser_target.cu");
geo->setBoundingBoxProgram(
context->createProgramFromPTXString(ptx, "bounds"));
geo->setIntersectionProgram(
context->createProgramFromPTXString(ptx, "intersect"));
targetTransform = context->createTransform(); targetTransform = context->createTransform();
targetGeometry = targetGeometry = context->createGeometryInstance(geo, &targetMaterial,
context->createGeometryInstance(optixContextManager_->GetTargetGeometry(), &targetMaterial + 1);
&targetMaterial, &targetMaterial + 1);
targetGroup = context->createGeometryGroup(); targetGroup = context->createGeometryGroup();
targetGroup->addChild(targetGeometry); targetGroup->addChild(targetGeometry);
targetAcc = context->createAcceleration("Trbvh"); targetAcc = context->createAcceleration("Trbvh");
targetGroup->setAcceleration(targetAcc); targetGroup->setAcceleration(targetAcc);
glm::vec3 size = glm::vec3(0.2f, 0.2f * target_dims.y / target_dims.x, 0.02); targetGeometry["p1"]->setFloat(0, 0.0336f, 0.059f);
targetGeometry["p2"]->setFloat(0, 0.0869f, -0.059f);
targetGeometry["stretchXY1"]->setFloat(0.05f, 0.05f);
targetGeometry["stretchXY2"]->setFloat(0.15f, 0.15f);
targetGeometry["size"]->setFloat(size.x, size.y, size.z);
targetGeometry["targetBufferWrite"]->setInt(1); targetGeometry["targetBufferWrite"]->setInt(1);
targetGeometry["targetBuffer"]->setBuffer(targetBuffer); targetGeometry["targetBuffer"]->setBuffer(targetBuffer);
targetGeometry["targetBufferDim"]->setFloat((float)target_dims.x, targetGeometry["targetBufferDim"]->setFloat((float)target_res,
(float)target_dims.y); (float)target_res);
targetTransform->setChild<optix::GeometryGroup>(targetGroup); targetTransform->setChild<optix::GeometryGroup>(targetGroup);
optixContextManager_->getTopObject()->addChild(targetTransform); optixContextManager_->getTopObject()->addChild(targetTransform);
optixContextManager_->getTopObject()->getAcceleration()->markDirty(); optixContextManager_->getTopObject()->getAcceleration()->markDirty();
targetEntity = engine_->GetScene()->CreateEntity(); targetEntity = phx::SceneLoader::InsertModelIntoScene(
targetEntity->AddComponent<phx::Transform>()->Translate( "models/opticalBench/laser/target.obj", engine_->GetScene().get());
targetEntity->GetFirstComponent<phx::Transform>()->Translate(
glm::vec3(-0.2f, 1.20f, -0.6f)); glm::vec3(-0.2f, 1.20f, -0.6f));
auto selector = targetEntity->AddComponent<phx::Selector>();
auto selector = targetEntity->AddComponent<phx::Selector>(targetEntity);
selector->SetMove([this](phx::Transform* t, glm::mat4 r) { selector->SetMove([this](phx::Transform* t, glm::mat4 r) {
targetEntity->GetFirstComponent<phx::Transform>()->SetGlobalMatrix( targetEntity->GetFirstComponent<phx::Transform>()->SetGlobalMatrix(
...@@ -316,10 +329,6 @@ void RayPass::createTarget() { ...@@ -316,10 +329,6 @@ void RayPass::createTarget() {
selector->intersection_dist = 1.5f; selector->intersection_dist = 1.5f;
selector->SetCollider(
glm::vec3(-size.x / 2.0f, -size.y / 2.0f, -size.z / 2.0f),
glm::vec3(size.x / 2.0f, size.y / 2.0f, size.z / 2.0f));
targetSupportRod = new SupportRod(engine_->GetScene().get(), selector); targetSupportRod = new SupportRod(engine_->GetScene().get(), selector);
} }
...@@ -327,7 +336,7 @@ void RayPass::clearTarget() { ...@@ -327,7 +336,7 @@ void RayPass::clearTarget() {
// null initially // null initially
float* buffer_data = float* buffer_data =
static_cast<float*>(targetBuffer->map(0, RT_BUFFER_MAP_WRITE_DISCARD)); static_cast<float*>(targetBuffer->map(0, RT_BUFFER_MAP_WRITE_DISCARD));
for (unsigned int i = 0; i < target_dims.x * target_dims.y * 3; ++i) { for (unsigned int i = 0; i < target_res * target_res * 3; ++i) {
buffer_data[i] = 0.0f; buffer_data[i] = 0.0f;
} }
targetBuffer->unmap(); targetBuffer->unmap();
......
...@@ -113,7 +113,7 @@ class RayPass : public RenderPass { ...@@ -113,7 +113,7 @@ class RayPass : public RenderPass {
std::vector<phx::ResourcePointer<phx::Image>> patterns_; std::vector<phx::ResourcePointer<phx::Image>> patterns_;
unsigned int current_pattern_index_; unsigned int current_pattern_index_;
const glm::uvec2 target_dims = {100, 100}; const unsigned int target_res = 150u;
void createLaser(); void createLaser();
void createTarget(); void createTarget();
optix::Buffer targetBuffer; optix::Buffer targetBuffer;
......
File added
File added
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment