Skip to content
Snippets Groups Projects
Commit a2149549 authored by Alexander Gauggel's avatar Alexander Gauggel
Browse files

[#94] Raytracing compute shader bug fixes

Hardcoded sphere and light counts to avoid shader freeze and added missing out keywords to functions so variables changes are applied to outside of function
parent 0f9acb80
No related branches found
No related tags found
1 merge request!77Resolve "SAF-R Module"
......@@ -36,13 +36,14 @@ layout(std430, binding = 2) coherent buffer spheres{
layout(set=0, binding=3, rgba8) uniform image2D outImage;
const int sphereCount = 4;
const int lightCount = 3;
vec3 safr_reflect(const vec3 dir, const vec3 hit_center) {
return dir - hit_center * 2.f * (dot(dir, hit_center));
}
bool ray_intersect(const vec3 origin, const vec3 dir, float t0, int id){
bool ray_intersect(const vec3 origin, const vec3 dir, out float t0, const int id){
vec3 L = inSpheres[id].center - origin;
float tca = dot(L, dir);
float d2 = dot(L, L) - tca * tca;
......@@ -61,10 +62,10 @@ bool ray_intersect(const vec3 origin, const vec3 dir, float t0, int id){
return true;
}
int sceneIntersect(const vec3 orig, const vec3 dir, vec3 hit, vec3 hit_center, Material material) {
int sceneIntersect(const vec3 orig, const vec3 dir, out vec3 hit, out vec3 hit_center, out Material material) {
float spheres_dist = 1.0 / 0.0;
int index = -1;
for (int i = 0; i < inSpheres.length(); i++) {
for (int i = 0; i < sphereCount; i++) {
float dist_i;
if (ray_intersect(orig, dir, dist_i, i) && dist_i < spheres_dist) {
spheres_dist = dist_i;
......@@ -84,7 +85,6 @@ int sceneIntersect(const vec3 orig, const vec3 dir, vec3 hit, vec3 hit_center, M
vec3 castRay(const vec3 orig, const vec3 dir, int max_depth) {
// max depth is 5
int depth = 0;
vec3 point, hit_center;
Material material;
......@@ -94,7 +94,7 @@ vec3 castRay(const vec3 orig, const vec3 dir, int max_depth) {
vec3 reflect_dir = direction;
vec3 reflect_orig = orig;
for(int i = 0; i < depth;i++){
for(int i = 0; i < max_depth;i++){
depth++;
intersect = sceneIntersect(reflect_orig, reflect_dir, point, hit_center, material);
if(intersect != -1){
......@@ -113,7 +113,7 @@ vec3 castRay(const vec3 orig, const vec3 dir, int max_depth) {
//compute shadows and other light properties for the returned ray color
float diffuse_light_intensity = 0, specular_light_intensity = 0;
for (int i = 0; i < inLights.length(); i++) {
for (int i = 0; i < lightCount; i++) {
vec3 light_dir = normalize(inLights[i].position - point);
float light_distance = distance(inLights[i].position, point);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment