From 74457d1a9cc9c39a95f0a54b9a486d9cb3a2d2ef Mon Sep 17 00:00:00 2001 From: CDaut Date: Sat, 29 Jun 2024 19:08:24 +0200 Subject: [PATCH] random offsets in raygen --- raytracer/ray_tracing_gltf/hello_vulkan.cpp | 21 ++++---- raytracer/ray_tracing_gltf/main.cpp | 4 +- .../ray_tracing_gltf/shaders/raytrace.rgen | 50 +++++++++--------- .../animation_cutoffs_with_radspec.mp4 | Bin 0 -> 48 bytes .../anmimation_cutoffs_with_radspec.mp4 | Bin 0 -> 262 bytes 5 files changed, 37 insertions(+), 38 deletions(-) create mode 100644 utk_experiments/plotting/animation_cutoffs_with_radspec.mp4 create mode 100644 utk_experiments/plotting/anmimation_cutoffs_with_radspec.mp4 diff --git a/raytracer/ray_tracing_gltf/hello_vulkan.cpp b/raytracer/ray_tracing_gltf/hello_vulkan.cpp index e5558be..f8f02b3 100644 --- a/raytracer/ray_tracing_gltf/hello_vulkan.cpp +++ b/raytracer/ray_tracing_gltf/hello_vulkan.cpp @@ -339,10 +339,10 @@ void HelloVulkan::createTextureImages(const VkCommandBuffer& cmdBuf, tinygltf::M void HelloVulkan::createPointsetTexture(const VkCommandBuffer& cmdBuf) { VkSamplerCreateInfo samplerCreateInfo{VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO}; - samplerCreateInfo.minFilter = VK_FILTER_NEAREST; - samplerCreateInfo.magFilter = VK_FILTER_NEAREST; - samplerCreateInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; - samplerCreateInfo.maxLod = FLT_MAX; + samplerCreateInfo.minFilter = VK_FILTER_NEAREST; + samplerCreateInfo.magFilter = VK_FILTER_NEAREST; + samplerCreateInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR; + samplerCreateInfo.maxLod = FLT_MAX; samplerCreateInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT; samplerCreateInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT; samplerCreateInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT; @@ -351,22 +351,21 @@ void HelloVulkan::createPointsetTexture(const VkCommandBuffer& cmdBuf) // TODO: generate and parse pointset here std::vector points{}; - points.reserve(swapchainExtent.height * swapchainExtent.width * 2); + points.reserve(swapchainExtent.height * swapchainExtent.width * 2 * 4); - for(int y = 0; y < swapchainExtent.height; ++y) + for(int y = 0; y < swapchainExtent.height * 4; ++y) { for(int x = 0; x < swapchainExtent.width; ++x) { float rand_x = static_cast(rand()) / static_cast(RAND_MAX); float rand_y = static_cast(rand()) / static_cast(RAND_MAX); - std::cout << "x: " << rand_x << "|y: " << rand_y << std::endl; - points.emplace_back(rand_x); - points.emplace_back(rand_y); + points.push_back(rand_x); + points.push_back(rand_y); } } - - VkImageCreateInfo imageCreateInfo = nvvk::makeImage2DCreateInfo(swapchainExtent, VK_FORMAT_R32G32_SFLOAT, VK_IMAGE_USAGE_SAMPLED_BIT, false); + VkImageCreateInfo imageCreateInfo = + nvvk::makeImage2DCreateInfo(swapchainExtent, VK_FORMAT_R32G32_SFLOAT, VK_IMAGE_USAGE_SAMPLED_BIT, false); nvvk::Image image = m_alloc.createImage(cmdBuf, points.size(), points.data(), imageCreateInfo); VkImageViewCreateInfo ivInfo = nvvk::makeImageViewCreateInfo(image.image, imageCreateInfo); m_pointset = m_alloc.createTexture(image, ivInfo, samplerCreateInfo); diff --git a/raytracer/ray_tracing_gltf/main.cpp b/raytracer/ray_tracing_gltf/main.cpp index 6688170..1439e95 100644 --- a/raytracer/ray_tracing_gltf/main.cpp +++ b/raytracer/ray_tracing_gltf/main.cpp @@ -71,8 +71,8 @@ void renderUI(HelloVulkan& helloVk, bool useRaytracer) ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// -static int const SAMPLE_WIDTH = 1280; -static int const SAMPLE_HEIGHT = 720; +static int const SAMPLE_WIDTH = 800; +static int const SAMPLE_HEIGHT = 800; //-------------------------------------------------------------------------------------------------- diff --git a/raytracer/ray_tracing_gltf/shaders/raytrace.rgen b/raytracer/ray_tracing_gltf/shaders/raytrace.rgen index d7d0b30..0af3b42 100644 --- a/raytracer/ray_tracing_gltf/shaders/raytrace.rgen +++ b/raytracer/ray_tracing_gltf/shaders/raytrace.rgen @@ -35,37 +35,37 @@ layout(set = 0, binding = 1, rgba32f) uniform image2D image; layout(set = 1, binding = 0) uniform _GlobalUniforms { GlobalUniforms uni; }; layout(push_constant) uniform _PushConstantRay { PushConstantRay pcRay; }; -layout(set = 1, binding = ePointsetTexture) uniform sampler2D pointset; // bluenoise pointset +layout(set = 1, binding = ePointsetTexture) uniform sampler2D pointset;// bluenoise pointset // clang-format on void main() { - const vec2 pixelCenter = vec2(gl_LaunchIDEXT.xy) + vec2(0.5); - const vec2 inUV = pixelCenter / vec2(gl_LaunchSizeEXT.xy); - vec2 d = inUV * 2.0 - 1.0; + vec2 uv = vec2(float(gl_LaunchIDEXT.x) / float(gl_LaunchSizeEXT.x), float(gl_LaunchIDEXT.y) / float(gl_LaunchSizeEXT.y)); - vec4 origin = uni.viewInverse * vec4(0, 0, 0, 1); - vec4 target = uni.projInverse * vec4(d.x, d.y, 1, 1); - vec4 direction = uni.viewInverse * vec4(normalize(target.xyz), 0); + const vec2 rayOriginInPix = vec2(gl_LaunchIDEXT.xy) + texture(pointset, uv).xy; + const vec2 inUV = rayOriginInPix / vec2(gl_LaunchSizeEXT.xy); + vec2 d = inUV * 2.0 - 1.0; - uint rayFlags = gl_RayFlagsOpaqueEXT; - float tMin = 0.001; - float tMax = 10000.0; + vec4 origin = uni.viewInverse * vec4(0, 0, 0, 1); + vec4 target = uni.projInverse * vec4(d.x, d.y, 1, 1); + vec4 direction = uni.viewInverse * vec4(normalize(target.xyz), 0); - traceRayEXT(topLevelAS, // acceleration structure - rayFlags, // rayFlags - 0xFF, // cullMask - 0, // sbtRecordOffset - 0, // sbtRecordStride - 0, // missIndex - origin.xyz, // ray origin - tMin, // ray min range - direction.xyz, // ray direction - tMax, // ray max range - 0 // payload (location = 0) - ); + uint rayFlags = gl_RayFlagsOpaqueEXT; + float tMin = 0.001; + float tMax = 10000.0; - //imageStore(image, ivec2(gl_LaunchIDEXT.xy), vec4(prd.hitValue, 1.0)); - vec2 uv = vec2(float(gl_LaunchIDEXT.x) / float(gl_LaunchSizeEXT.x) - 0.5, float(gl_LaunchIDEXT.y) / float(gl_LaunchSizeEXT.y) - 0.5); - imageStore(image, ivec2(gl_LaunchIDEXT.xy), texture(pointset, uv)); + traceRayEXT(topLevelAS, // acceleration structure + rayFlags, // rayFlags + 0xFF, // cullMask + 0, // sbtRecordOffset + 0, // sbtRecordStride + 0, // missIndex + origin.xyz, // ray origin + tMin, // ray min range + direction.xyz, // ray direction + tMax, // ray max range + 0// payload (location = 0) + ); + + imageStore(image, ivec2(gl_LaunchIDEXT.xy), vec4(prd.hitValue, 1.0)); } diff --git a/utk_experiments/plotting/animation_cutoffs_with_radspec.mp4 b/utk_experiments/plotting/animation_cutoffs_with_radspec.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..17e5e5fbd204f4f1c8bf240b166ab0a318db4744 GIT binary patch literal 48 zcmZQzU{FXasVvAW&d+6FU}6B#nZ@}=iDk)#xdkSM3=9k$X+^223=9kmxhaVy06gam A&;S4c literal 0 HcmV?d00001 diff --git a/utk_experiments/plotting/anmimation_cutoffs_with_radspec.mp4 b/utk_experiments/plotting/anmimation_cutoffs_with_radspec.mp4 new file mode 100644 index 0000000000000000000000000000000000000000..9b8291ca5389aa23f1745d753ec158fc846877aa GIT binary patch literal 262 zcmZQzU{FXasVvAW&d+6FU}6B#nZ@}=iDk)#xdkSM3=9k$X+^22AUZcCv4nwv;aYBf zei;J;Lr!j4MhXK8V15DSGBPkQf*DW(g~Na*$-v+MRfdCNVqjoMDorU#WME*3%1s5+ zAf<{KDLF+T1_dKP*d