Skip to content

Instantly share code, notes, and snippets.

View sjhalayka's full-sized avatar

Shawn Halayka sjhalayka

View GitHub Profile
custom_math::vector_3 grav_acceleration(const custom_math::vector_3 &pos, const custom_math::vector_3 &vel, const double G)
{
custom_math::vector_3 grav_dir = sun_pos - pos;
float distance = grav_dir.length();
grav_dir.normalize();
float alpha = (vel.length()*vel.length()) / (speed_of_light * speed_of_light);
alpha = pow(alpha, 0.01); // suit to taste
@sjhalayka
sjhalayka / gist:71bc4a87ce612af1876a57baf6129521
Created November 23, 2023 19:30
Programming Drill 1.3.2
#include <iostream>
#include <fstream>
#include <complex>
#include <vector>
using namespace std;
#include "Eigen/Dense"
using Eigen::VectorXcf;
using Eigen::VectorXf;
@sjhalayka
sjhalayka / blah.glsl
Created October 27, 2023 01:11
Clear line of sight
layout(location = 2) rayPayloadEXT bool shadowed;
bool is_clear_line_of_sight(vec3 pos_start, const vec3 pos_end)
{
shadowed = true; // Make sure to set this to the default before tracing the ray!
traceRayEXT(topLevelAS, gl_RayFlagsTerminateOnFirstHitEXT | gl_RayFlagsOpaqueEXT | gl_RayFlagsSkipClosestHitShaderEXT, 0xFF, 0, 0, 1, pos_start, 0.001, pos_end, 10000.0, 2);
return !shadowed;
}
@sjhalayka
sjhalayka / path_trace.glsl
Created September 19, 2023 16:04
Path tracer issue
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;
@sjhalayka
sjhalayka / raygen caustics
Created September 16, 2023 16:44
Reflection, scattering, and refraction
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);
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;
#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;
#include "VulkanRaytracingSample.h"
#include "VulkanglTFModel.h"
#include <vector>
using std::vector;
#include <fstream>
using std::ofstream;
#include <ios>
@sjhalayka
sjhalayka / render.cpp
Created May 16, 2023 16:51
render function
virtual void render()
{
if (!prepared)
return;
VulkanExampleBase::prepareFrame();
submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
VK_CHECK_RESULT(vkQueueSubmit(queue, 1, &submitInfo, fence));
@sjhalayka
sjhalayka / pipeline_barrier.cpp
Created May 16, 2023 16:49
pipeline_barrier
...
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;