random offsets in raygen

This commit is contained in:
CDaut 2024-06-29 19:08:24 +02:00
parent 2bc40926b8
commit 74457d1a9c
Signed by: clara
GPG key ID: 223391B52FAD4463
5 changed files with 37 additions and 38 deletions

View file

@ -351,22 +351,21 @@ void HelloVulkan::createPointsetTexture(const VkCommandBuffer& cmdBuf)
// TODO: generate and parse pointset here // TODO: generate and parse pointset here
std::vector<float_t> points{}; std::vector<float_t> 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) for(int x = 0; x < swapchainExtent.width; ++x)
{ {
float rand_x = static_cast<float>(rand()) / static_cast<float_t>(RAND_MAX); float rand_x = static_cast<float>(rand()) / static_cast<float_t>(RAND_MAX);
float rand_y = static_cast<float>(rand()) / static_cast<float_t>(RAND_MAX); float rand_y = static_cast<float>(rand()) / static_cast<float_t>(RAND_MAX);
std::cout << "x: " << rand_x << "|y: " << rand_y << std::endl; points.push_back(rand_x);
points.emplace_back(rand_x); points.push_back(rand_y);
points.emplace_back(rand_y);
} }
} }
VkImageCreateInfo imageCreateInfo =
VkImageCreateInfo imageCreateInfo = nvvk::makeImage2DCreateInfo(swapchainExtent, VK_FORMAT_R32G32_SFLOAT, VK_IMAGE_USAGE_SAMPLED_BIT, false); 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); nvvk::Image image = m_alloc.createImage(cmdBuf, points.size(), points.data(), imageCreateInfo);
VkImageViewCreateInfo ivInfo = nvvk::makeImageViewCreateInfo(image.image, imageCreateInfo); VkImageViewCreateInfo ivInfo = nvvk::makeImageViewCreateInfo(image.image, imageCreateInfo);
m_pointset = m_alloc.createTexture(image, ivInfo, samplerCreateInfo); m_pointset = m_alloc.createTexture(image, ivInfo, samplerCreateInfo);

View file

@ -71,8 +71,8 @@ void renderUI(HelloVulkan& helloVk, bool useRaytracer)
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
static int const SAMPLE_WIDTH = 1280; static int const SAMPLE_WIDTH = 800;
static int const SAMPLE_HEIGHT = 720; static int const SAMPLE_HEIGHT = 800;
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View file

@ -35,13 +35,15 @@ layout(set = 0, binding = 1, rgba32f) uniform image2D image;
layout(set = 1, binding = 0) uniform _GlobalUniforms { GlobalUniforms uni; }; layout(set = 1, binding = 0) uniform _GlobalUniforms { GlobalUniforms uni; };
layout(push_constant) uniform _PushConstantRay { PushConstantRay pcRay; }; 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 // clang-format on
void main() void main()
{ {
const vec2 pixelCenter = vec2(gl_LaunchIDEXT.xy) + vec2(0.5); vec2 uv = vec2(float(gl_LaunchIDEXT.x) / float(gl_LaunchSizeEXT.x), float(gl_LaunchIDEXT.y) / float(gl_LaunchSizeEXT.y));
const vec2 inUV = pixelCenter / vec2(gl_LaunchSizeEXT.xy);
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; vec2 d = inUV * 2.0 - 1.0;
vec4 origin = uni.viewInverse * vec4(0, 0, 0, 1); vec4 origin = uni.viewInverse * vec4(0, 0, 0, 1);
@ -62,10 +64,8 @@ void main()
tMin, // ray min range tMin, // ray min range
direction.xyz, // ray direction direction.xyz, // ray direction
tMax, // ray max range tMax, // ray max range
0 // payload (location = 0) 0// payload (location = 0)
); );
//imageStore(image, ivec2(gl_LaunchIDEXT.xy), vec4(prd.hitValue, 1.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));
} }