This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| srand(time(0)); | |
| for (size_t num_tries = 0; num_tries < 10000000; num_tries++) | |
| { | |
| float a0 = (rand() % RAND_MAX); | |
| if (rand() % 2) | |
| a0 = -a0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #version 460 | |
| #extension GL_EXT_ray_tracing : require | |
| #extension GL_EXT_nonuniform_qualifier : enable | |
| layout(location = 0) rayPayloadInEXT vec3 hitValue; | |
| layout(location = 2) rayPayloadEXT bool shadowed; | |
| hitAttributeEXT vec2 attribs; | |
| layout(binding = 0, set = 0) uniform accelerationStructureEXT topLevelAS; | |
| layout(binding = 2, set = 0) uniform UBO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void screenshot(uint32_t size_x, uint32_t size_y, const char* filename) | |
| { | |
| VkDeviceSize size = size_x * size_y * 4; | |
| // Create screenshot image | |
| createScreenshotStorageImage(VK_FORMAT_R8G8B8A8_UNORM, { size_x, size_y, 1 }); | |
| // Create screenshot descriptor set | |
| createScreenshotDescriptorSet(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| VkBufferImageCopy copyRegion{}; | |
| copyRegion.bufferOffset = 0; | |
| copyRegion.bufferRowLength = 0; | |
| copyRegion.bufferImageHeight = 0; | |
| copyRegion.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; | |
| copyRegion.imageSubresource.mipLevel = 0; | |
| copyRegion.imageSubresource.baseArrayLayer = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| virtual void render() | |
| { | |
| if (!prepared) | |
| return; | |
| VulkanExampleBase::prepareFrame(); | |
| submitInfo.commandBufferCount = 1; | |
| submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer]; | |
| VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, fence)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "VulkanRaytracingSample.h" | |
| #include "VulkanglTFModel.h" | |
| #include <vector> | |
| using std::vector; | |
| #include <fstream> | |
| using std::ofstream; | |
| #include <ios> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #version 460 | |
| #extension GL_EXT_ray_tracing : require | |
| #extension GL_EXT_nonuniform_qualifier : enable | |
| struct RayPayload { | |
| vec3 color; | |
| vec3 pure_color; | |
| float distance; | |
| vec3 normal; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void main() | |
| { | |
| const int steps = 10; | |
| float max_hue = rgb2hsv(vec3(1.0, 0.0, 1.0)).x; | |
| float min_hue = rgb2hsv(vec3(1.0, 0.0, 0.0)).x; | |
| const float max_eta = 0.9; | |
| const float min_eta = 0.6; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| vec3 o_reflect = hitPos + rayPayload.normal * 0.01; | |
| vec3 d_reflect = reflect(d, rayPayload.normal); | |
| vec3 temp_o = o_reflect; | |
| vec3 temp_d = d_reflect; | |
| if(rayPayload.reflector < 1.0) // if less than fully reflective, do scattering | |
| { | |
| vec3 o_scatter = hitPos + rayPayload.normal * 0.01; | |
| vec3 d_scatter = cosWeightedRandomHemisphereDirection(rayPayload.normal, prng_state); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| float trace_path2(out vec3 final_pos, const int steps, const vec3 origin, const vec3 direction, const float hue, float eta) | |
| { | |
| const RayPayload r = rayPayload; | |
| vec3 hitPos = vec3(0.0); | |
| float ret_colour = 0; | |
| vec3 o = origin; |