diff --git a/demos/optical_bench/src/Optix Files/laser_caster.cu b/demos/optical_bench/src/Optix Files/laser_caster.cu index a6d4d78d05eb047f03b663082e88e9c97bb21326..11316aa2f4521202ffbaa4853be1f80a4b42f81c 100644 --- a/demos/optical_bench/src/Optix Files/laser_caster.cu +++ b/demos/optical_bench/src/Optix Files/laser_caster.cu @@ -2,6 +2,7 @@ #include <optixu/optixu_math_namespace.h> #include "prd.h" #include "helpers.h" +#include "random.h" using namespace optix; @@ -11,20 +12,30 @@ rtDeclareVariable(rtObject, top_object, , ); rtDeclareVariable(float, scene_epsilon, , ); rtDeclareVariable(int, max_depth_laser, , ); +rtDeclareVariable(unsigned int, random_frame_seed, , ); + rtDeclareVariable(float3, laser_origin, , ); rtDeclareVariable(float3, laser_forward, , ); rtDeclareVariable(float3, laser_right, , ); rtDeclareVariable(float3, laser_up, , ); + rtBuffer<int, 2> laserIndex; rtBuffer<float3, 1> result_laser; RT_PROGRAM void laser_caster() { const float laserSize = 0.04; + const float laserBeamWidth = 0.005; + + unsigned int seed = tea<16>(launch_dim.x*launch_index.y+launch_index.x, random_frame_seed); + float2 random = make_float2(rnd(seed), rnd(seed)); + float r = sqrt(-2*log(random.x)); + float theta = 2*3.141592654f*random.y; + random = clamp(make_float2(r*cos(theta), r*sin(theta)), -4.5f, 4.5f) * laserBeamWidth/4.5f; float2 d = make_float2(launch_index) / make_float2(launch_dim) - make_float2(0.5f, 0.5f); - float3 ray_origin = laser_origin + laser_right * laserSize * d.x + laser_up * laserSize * d.y; + float3 ray_origin = laser_origin + laser_right * laserSize * d.x + laser_up * laserSize * d.y + laser_right * random.x + laser_up * random.y; float3 ray_direction = laser_forward; PerRayData_radiance_iterative prd; @@ -32,7 +43,7 @@ RT_PROGRAM void laser_caster() prd.seed = launch_index.y + launch_index.x; prd.done = false; prd.hit_lens = false; //track if the ray ever hit the lens - prd.radiance = make_float3(1); + prd.radiance = make_float3(1) * (1 - length(random)/laserBeamWidth); // next ray to be traced prd.origin = ray_origin; diff --git a/demos/optical_bench/src/ray_pass.cpp b/demos/optical_bench/src/ray_pass.cpp index 25863f4203e2d656e8f793b5fb9671dce491f8b0..55e98214041a1ef851f86ddfb3d22ca8e5d0c1f9 100644 --- a/demos/optical_bench/src/ray_pass.cpp +++ b/demos/optical_bench/src/ray_pass.cpp @@ -49,7 +49,6 @@ SUPPRESS_WARNINGS_END #undef CreateWindow namespace phx { - RayPass::RayPass(RenderTarget* render_target, Engine* engine, std::shared_ptr<OptixContextManager> optixContextManager) { render_target_right_ = render_target; @@ -207,6 +206,9 @@ void RayPass::render(RenderTarget* render_target) { } void RayPass::launchLaser() { + static unsigned int random_seed = 0; + optixContextManager_->getContext()["random_frame_seed"]->setUint( + random_seed++); // totally "random" (only used as seed) try { optixContextManager_->getContext()->launch(laser_entry, 50, 50); } catch (optix::Exception e) { @@ -218,7 +220,6 @@ void RayPass::launchLaser() { target_texture->set_sub_image(0, 0, 0, target_res, target_res, GL_RGB, GL_FLOAT, nullptr); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); - // target_texture->generate_mipmap(); } void RayPass::createLaser() { @@ -281,7 +282,7 @@ void RayPass::createTarget() { glGenBuffers(1, &targetBufferOpenGL); glBindBuffer(GL_ARRAY_BUFFER, targetBufferOpenGL); - glBufferData(GL_ARRAY_BUFFER, target_res * target_res * sizeof(float) * 3, + glBufferData(GL_ARRAY_BUFFER, target_res * target_res * sizeof(float) * 3l, nullptr, GL_STREAM_DRAW); targetBuffer = @@ -360,7 +361,7 @@ void RayPass::clearTarget() { // null initially float* buffer_data = static_cast<float*>(targetBuffer->map(0, RT_BUFFER_MAP_WRITE_DISCARD)); - for (unsigned int i = 0; i < target_res * target_res * 3; i = i + 3) { + for (unsigned long i = 0; i < target_res * target_res * 3; i = i + 3) { buffer_data[i] = 0.0f; buffer_data[i + 1] = 0.0f; buffer_data[i + 2] = 0.0f; diff --git a/demos/optical_bench/src/ray_pass.hpp b/demos/optical_bench/src/ray_pass.hpp index cd97c9ff3a580454afc9cdf6c841049f733d17dd..ff15e6ddc7c0722b9e754e8b2389a66852607250 100644 --- a/demos/optical_bench/src/ray_pass.hpp +++ b/demos/optical_bench/src/ray_pass.hpp @@ -113,7 +113,8 @@ class RayPass : public RenderPass { std::vector<phx::ResourcePointer<phx::Image>> patterns_; unsigned int current_pattern_index_; - const unsigned int target_res = 150u; + // The resource image needs to be adjusted to set the right texture size + const unsigned long target_res = 512l; gl::texture_2d* target_texture; GLuint targetBufferOpenGL = 0; phx::MaterialHandle* target_screen_; diff --git a/resources/models/opticalBench/laser/texture.png b/resources/models/opticalBench/laser/texture.png index 9b6f045781d34d31d8a201249b5c912870fb0ce2..ad5c93ab3b5b5dceae7f1e797425cc1c63eab9b2 100644 --- a/resources/models/opticalBench/laser/texture.png +++ b/resources/models/opticalBench/laser/texture.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:08a18a9d6063c07e85dbe0c7218bd4f8b52ff4390d0199b1a2338fbd6eec7d37 -size 1008 +oid sha256:7dcd064b5c8fb931ee4fa8dcd9deed3ac7b99d39e9cee96370678dd8aee31887 +size 2879