diff --git a/demos/optical_bench/src/Optix Files/laser_target_material.cu b/demos/optical_bench/src/Optix Files/laser_target_material.cu index 459aa62dd9a27ffe753c7e4ff6603fda6d3d1a3a..38ba778b1da13a2bb1066334dcb8c239cbd06024 100644 --- a/demos/optical_bench/src/Optix Files/laser_target_material.cu +++ b/demos/optical_bench/src/Optix Files/laser_target_material.cu @@ -33,16 +33,8 @@ rtBuffer<float3, 2> targetBuffer; rtDeclareVariable(float2, targetBufferDim, , ); rtDeclareVariable(int, targetBufferWrite, , ); -RT_PROGRAM void closest_hit_radiance() -{ - - if(texture_coord.x >= 0 && texture_coord.y >= 0){ - prd_radiance.result = targetBuffer[make_uint2(texture_coord * targetBufferDim)]; - }else{ - prd_radiance.result = make_float3(1.0f); - } - - prd_radiance.hit_depth = hit_depth; +RT_PROGRAM void any_hit_radiance(){ + rtIgnoreIntersection(); } RT_PROGRAM void closest_hit_iterative() diff --git a/demos/optical_bench/src/Optix Files/skybox.cu b/demos/optical_bench/src/Optix Files/skybox.cu index da21daa474e1c05367299bf0f4f1ddb910ee0c2b..7a18c6e52d8b2219fee2fbe6e6a45c1848497e60 100644 --- a/demos/optical_bench/src/Optix Files/skybox.cu +++ b/demos/optical_bench/src/Optix Files/skybox.cu @@ -28,6 +28,6 @@ rtDeclareVariable(optix::Ray, ray, rtCurrentRay, ); RT_PROGRAM void skyboxLookup() { - prd_radiance.result = make_float3(optix::rtTexCubemap<float4>(skybox, ray.direction.x, ray.direction.y, -ray.direction.z)); + prd_radiance.result = prd_radiance.hit_lens * make_float3(optix::rtTexCubemap<float4>(skybox, ray.direction.x, ray.direction.y, -ray.direction.z)); prd_radiance.miss = !prd_radiance.hit_lens; } diff --git a/demos/optical_bench/src/menu_button.hpp b/demos/optical_bench/src/menu_button.hpp index 0e5850c1825c822c5d875dc57871d6eb0c93f990..9083a6f7417ffe3f3e7fd7f7c595e3bf5ccc9bda 100644 --- a/demos/optical_bench/src/menu_button.hpp +++ b/demos/optical_bench/src/menu_button.hpp @@ -37,7 +37,7 @@ class MenuButton { phx::Entity* entity_; phx::Selector* selector_; bool grabbed_ = false; - glm::vec3 color_unhovered = glm::vec3(1); + glm::vec3 color_unhovered = glm::vec3(0.8f); glm::vec3 color_hovered = glm::vec3(1.0f, 0.502f, 0.0f); glm::vec3 color_pressed = glm::vec3(1.0f, 0.0f, 0.0f); std::chrono::duration<double> grab_time_; diff --git a/demos/optical_bench/src/menu_slider.hpp b/demos/optical_bench/src/menu_slider.hpp index 066e50b068e9bfa83c652f9fcb5000f2813f760d..30cc3891be524285de885a40525a44418f5b0867 100644 --- a/demos/optical_bench/src/menu_slider.hpp +++ b/demos/optical_bench/src/menu_slider.hpp @@ -51,7 +51,7 @@ class MenuSlider { std::function<void(float)> value_changed_ = nullptr; // highlight stuff - glm::vec3 color_normal = glm::vec3(1); + glm::vec3 color_normal = glm::vec3(0.8f); glm::vec3 color_hovered = glm::vec3(1.0f, 0.502f, 0.0f); glm::vec3 color_pressed = glm::vec3(1.0f, 0.0f, 0.0f); glm::vec3 color_selected = glm::vec3(0.424f, 0.851f, 0.141f); diff --git a/demos/optical_bench/src/menu_switch.hpp b/demos/optical_bench/src/menu_switch.hpp index 1c261cc3bc878764e869401dac7403a69adc0e35..2c17103c84e7afc07287de3ce79e93552e500b61 100644 --- a/demos/optical_bench/src/menu_switch.hpp +++ b/demos/optical_bench/src/menu_switch.hpp @@ -33,7 +33,7 @@ class MenuSwitch { private: phx::Entity* entity_; phx::Selector* selector_; - glm::vec3 color_unhovered = glm::vec3(1); + glm::vec3 color_unhovered = glm::vec3(0.8f); glm::vec3 color_hovered = glm::vec3(1.0f, 0.502f, 0.0f); bool activated_ = false; diff --git a/demos/optical_bench/src/optical_bench.cpp b/demos/optical_bench/src/optical_bench.cpp index 15ee8254c61e007c048fd38e69d6e3b2820e45b6..91cb5b33b56cedff1fc7286e78c6f149c6869555 100644 --- a/demos/optical_bench/src/optical_bench.cpp +++ b/demos/optical_bench/src/optical_bench.cpp @@ -150,8 +150,8 @@ int main(int, char**) { phx::Light* light = light_entity->AddComponent<phx::Light>(); light->SetType(phx::Light::Type::kDirectional); - light->SetColor(glm::vec3(1.0, 1.0, 1.0)); - light->SetIntensity(0.8f); + light->SetColor(glm::vec3(1)); + light->SetIntensity(1); } auto virtual_platform = scene->GetEntitiesWithComponents< phx::RuntimeComponent<phx::USER_PLATFORM>>()[0]; diff --git a/demos/optical_bench/src/ray_pass.cpp b/demos/optical_bench/src/ray_pass.cpp index 0f77b89c0e65006df3c685fe1c69e180626af9b6..25863f4203e2d656e8f793b5fb9671dce491f8b0 100644 --- a/demos/optical_bench/src/ray_pass.cpp +++ b/demos/optical_bench/src/ray_pass.cpp @@ -71,6 +71,7 @@ RayPass::~RayPass() { // delete openGL resources glDeleteBuffers(1, &bufferOpenGLLaserVertices); glDeleteBuffers(1, &bufferOpenGLLaserColors); + glDeleteBuffers(1, &targetBufferOpenGL); glDeleteVertexArrays(1, &vaoOpenGL); bufferLaserOptix->destroy(); @@ -211,6 +212,13 @@ void RayPass::launchLaser() { } catch (optix::Exception e) { phx::error(e.getErrorString().c_str()); } + + // copy buffer from optix + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, targetBufferOpenGL); + 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() { @@ -255,21 +263,43 @@ void RayPass::createLaser() { void RayPass::createTarget() { auto context = optixContextManager_->getContext(); - // Buffer - targetBuffer = context->createBuffer(RT_BUFFER_INPUT_OUTPUT, RT_FORMAT_FLOAT3, - target_res, target_res); + targetEntity = phx::SceneLoader::InsertModelIntoScene( + "models/opticalBench/laser/target.obj", engine_->GetScene().get()); + targetEntity->GetFirstComponent<phx::Transform>()->Translate( + glm::vec3(-0.2f, 1.20f, -0.6f)); + + auto transform = targetEntity->GetFirstComponent<phx::Transform>(); + for (auto i = 0u; i < transform->GetChildCount(); i++) { + auto handle = transform->GetChild(i) + ->GetEntity() + ->GetFirstComponent<phx::MaterialHandle>(); + if (handle->GetMaterial()->GetName().compare("Screen") == 0) { + target_screen_ = handle; + } + } + target_texture = target_screen_->GetMaterial()->GetAmbientTexture(); + + glGenBuffers(1, &targetBufferOpenGL); + glBindBuffer(GL_ARRAY_BUFFER, targetBufferOpenGL); + glBufferData(GL_ARRAY_BUFFER, target_res * target_res * sizeof(float) * 3, + nullptr, GL_STREAM_DRAW); + + targetBuffer = + context->createBufferFromGLBO(RT_BUFFER_INPUT_OUTPUT, targetBufferOpenGL); + targetBuffer->setFormat(RT_FORMAT_FLOAT3); + targetBuffer->setSize(target_res, target_res); clearTarget(); // Material std::string ptx = OptixContextManager::getPtxString("laser_target_material.cu"); - optix::Program closeHitP = - context->createProgramFromPTXString(ptx, "closest_hit_radiance"); + optix::Program anyHitP = + context->createProgramFromPTXString(ptx, "any_hit_radiance"); optix::Program closeHitI = context->createProgramFromPTXString(ptx, "closest_hit_iterative"); targetMaterial = context->createMaterial(); - targetMaterial->setClosestHitProgram(0, closeHitP); + targetMaterial->setAnyHitProgram(0, anyHitP); targetMaterial->setClosestHitProgram(1, closeHitI); // Geometry @@ -290,11 +320,11 @@ void RayPass::createTarget() { targetAcc = context->createAcceleration("Trbvh"); targetGroup->setAcceleration(targetAcc); - targetGeometry["p1"]->setFloat(0, 0.0336f, 0.059f); - targetGeometry["p2"]->setFloat(0, 0.0869f, -0.059f); + targetGeometry["p1"]->setFloat(0, 0.0275f, 0.05f); + targetGeometry["p2"]->setFloat(0, 0.0825f, -0.05f); targetGeometry["stretchXY1"]->setFloat(0.05f, 0.05f); - targetGeometry["stretchXY2"]->setFloat(0.15f, 0.15f); + targetGeometry["stretchXY2"]->setFloat(0.155f, 0.155f); targetGeometry["targetBufferWrite"]->setInt(1); targetGeometry["targetBuffer"]->setBuffer(targetBuffer); @@ -306,13 +336,7 @@ void RayPass::createTarget() { optixContextManager_->getTopObject()->addChild(targetTransform); optixContextManager_->getTopObject()->getAcceleration()->markDirty(); - targetEntity = phx::SceneLoader::InsertModelIntoScene( - "models/opticalBench/laser/target.obj", engine_->GetScene().get()); - targetEntity->GetFirstComponent<phx::Transform>()->Translate( - glm::vec3(-0.2f, 1.20f, -0.6f)); - auto selector = targetEntity->AddComponent<phx::Selector>(targetEntity); - selector->SetMove([this](phx::Transform* t, glm::mat4 r) { targetEntity->GetFirstComponent<phx::Transform>()->SetGlobalMatrix( t->GetGlobalMatrix() * r); @@ -336,8 +360,10 @@ 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) { + for (unsigned int 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; } targetBuffer->unmap(); } diff --git a/demos/optical_bench/src/ray_pass.hpp b/demos/optical_bench/src/ray_pass.hpp index 0017fc216a254a3dcabe9e6dd753c53db15c7846..cd97c9ff3a580454afc9cdf6c841049f733d17dd 100644 --- a/demos/optical_bench/src/ray_pass.hpp +++ b/demos/optical_bench/src/ray_pass.hpp @@ -114,6 +114,9 @@ class RayPass : public RenderPass { unsigned int current_pattern_index_; const unsigned int target_res = 150u; + gl::texture_2d* target_texture; + GLuint targetBufferOpenGL = 0; + phx::MaterialHandle* target_screen_; void createLaser(); void createTarget(); optix::Buffer targetBuffer; diff --git a/library/phx/resources/types/material.cpp b/library/phx/resources/types/material.cpp index cf0b925a2b12089a464e9910b295ad9bf89fcf69..4f92de6fa3cdf5afc1a890f791f085eb88746d91 100644 --- a/library/phx/resources/types/material.cpp +++ b/library/phx/resources/types/material.cpp @@ -103,7 +103,7 @@ void Material::SetTexture(ResourcePointer<Image> image, auto dimensions = image->GetDimensions(); (*texture) = std::make_shared<gl::texture_2d>(); - (*texture)->set_min_filter(GL_LINEAR_MIPMAP_LINEAR); + (*texture)->set_min_filter(GL_LINEAR); (*texture)->set_mag_filter(GL_LINEAR); (*texture)->set_wrap_s(GL_REPEAT); (*texture)->set_wrap_t(GL_REPEAT); diff --git a/resources/models/opticalBench/laser/target.blend b/resources/models/opticalBench/laser/target.blend index c98913e275eb4f470fd400afd784af98786223eb..a42774a54fe96418818cd250a73bcd1f280df3a3 100644 Binary files a/resources/models/opticalBench/laser/target.blend and b/resources/models/opticalBench/laser/target.blend differ diff --git a/resources/models/opticalBench/laser/target.blend1 b/resources/models/opticalBench/laser/target.blend1 index 7e07c40f20cc658a6e31f47dfa32ca0873c0a289..6673a6ddebf48ba842954ea291ca7c77e69f5b67 100644 Binary files a/resources/models/opticalBench/laser/target.blend1 and b/resources/models/opticalBench/laser/target.blend1 differ diff --git a/resources/models/opticalBench/laser/target.mtl b/resources/models/opticalBench/laser/target.mtl index dd079d10b0aa14b03a7b2a451cb149a6e46ab4e9..87d942756a2986e111d9e3f89903b8eb34b336c3 100644 --- a/resources/models/opticalBench/laser/target.mtl +++ b/resources/models/opticalBench/laser/target.mtl @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:64bbe84dd51ab53c28e310fd697dbf1ebade3f89ebf1554b709fb292b8ba140b -size 232 +oid sha256:24a8c7dff8ece317a7b29cc3d2bd5f8d7d4000af1dd601828d1a9fff749541d4 +size 430 diff --git a/resources/models/opticalBench/laser/target.obj b/resources/models/opticalBench/laser/target.obj index 6086c840795aeccba4a968d80c68ee6d796b7c8c..3807a6d08e2dd799a393b4f7c1da08c294ff671c 100644 --- a/resources/models/opticalBench/laser/target.obj +++ b/resources/models/opticalBench/laser/target.obj @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d5d5315f4dd77607ce68ee765168a4a99beba692027658b32c1468e230910983 -size 27976 +oid sha256:ff71851ff44a0d9926bc546f58c7c7a9f7c8f04b690e4c7966c28191b73a540b +size 39217 diff --git a/resources/models/opticalBench/laser/texture.png b/resources/models/opticalBench/laser/texture.png new file mode 100644 index 0000000000000000000000000000000000000000..9b6f045781d34d31d8a201249b5c912870fb0ce2 --- /dev/null +++ b/resources/models/opticalBench/laser/texture.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:08a18a9d6063c07e85dbe0c7218bd4f8b52ff4390d0199b1a2338fbd6eec7d37 +size 1008 diff --git a/resources/models/opticalBench/menu/Tablet.obj b/resources/models/opticalBench/menu/Tablet.obj index afe96bbc9b4faea0f0102233ece2731c34660aca..a9e7b8e1dc02f3111e8d85a79ebbc4b9035ae23d 100644 --- a/resources/models/opticalBench/menu/Tablet.obj +++ b/resources/models/opticalBench/menu/Tablet.obj @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e2604637ddfde24b425297c13253001fadfb967d0cafa730f3424341dc66d8e6 -size 42491 +oid sha256:9dbc034301be02f94822cda8ace192771c20715b5112e0eea693b45404e93bc9 +size 49158 diff --git a/resources/models/opticalBench/room/lab.mtl b/resources/models/opticalBench/room/lab.mtl index 96a56ed914ed6182c8db69b4e19d7cf07ad2c100..f1131b59d05d6604c81548fb480e2e858a0e8c71 100644 --- a/resources/models/opticalBench/room/lab.mtl +++ b/resources/models/opticalBench/room/lab.mtl @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5c97aecee8a096fde3485cff449f98c4789d5c414720dd39dc037515b5198307 +oid sha256:4f7207bbb0193509aa4d47cab7db77ef895da7681a08dd2d87990615bdb3f14f size 4215 diff --git a/resources/models/opticalBench/room/lab.obj b/resources/models/opticalBench/room/lab.obj index b0ef555a9d90a928add229042b29d79820493c7d..e95b2ff6b115fea6fa018fc78ea748355263284f 100644 --- a/resources/models/opticalBench/room/lab.obj +++ b/resources/models/opticalBench/room/lab.obj @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:461ee16017f562aa30ed2a2fdcb2ac596c6b7b2425a14a59699fb3fd49f15c4e -size 467718 +oid sha256:f983f2e7131cca520b398f0a6fad159f4f533d27511368c128cc5b137f29cd7e +size 498266 diff --git a/resources/shader/phong.frag b/resources/shader/phong.frag index da9439dcce7fd9c651aba3982d8371b1a1578890..58f0eab21f73db2f8f2b5f2e9065b5ce9eb47c44 100644 --- a/resources/shader/phong.frag +++ b/resources/shader/phong.frag @@ -76,9 +76,9 @@ void main() { specularf = pow(specAngle, material.shininess); } - vec3 ambient = light[i].intensity * light[i].color.xyz * (material.texture_toggle.x == 0 ? material.ambient : texture(material.ambient_tex , in_tex_coord).xyz); + vec3 ambient = light[i].intensity * light[i].color.xyz * (material.texture_toggle.x == 0 ? material.ambient : texture(material.ambient_tex , in_tex_coord).xyz); vec3 diffuse = light[i].intensity * light[i].color.xyz * (lambertian * (material.texture_toggle.y == 0 ? material.diffuse : texture(material.diffuse_tex , in_tex_coord).xyz)); vec3 specular = light[i].intensity * light[i].color.xyz * (specularf * (material.texture_toggle.z == 0 ? material.specular : texture(material.specular_tex, in_tex_coord).xyz)); - frag_color = vec4(ambient + diffuse + specular , 1.0); + frag_color = vec4(ambient + diffuse + specular, 1.0); } }