libgarbage: fix depth AGAIN

This commit is contained in:
Crispy 2023-07-29 16:41:25 +02:00
parent 5cb5dcd785
commit bf23886a73

View file

@ -108,6 +108,7 @@ struct Material {
float3 col; float3 col;
float gloss; float gloss;
}; };
#define DEFAULT_MAT {float3(1, 1, 1), 0} #define DEFAULT_MAT {float3(1, 1, 1), 0}
Material mat(float3 col = float3(1, 1,1 ), float gloss = 0) { Material mat(float3 col = float3(1, 1,1 ), float gloss = 0) {
Material m; Material m;
@ -115,6 +116,9 @@ Material mat(float3 col = float3(1, 1,1 ), float gloss = 0) {
m.gloss = gloss; m.gloss = gloss;
return m; return m;
} }
Material mat(float r, float g, float b) {
return mat(float3(r, g, b));
}
struct SurfacePoint { struct SurfacePoint {
float dist; float dist;
@ -191,7 +195,7 @@ FragOut frag (V2F i) {
} }
prev_gloss = ray.mat.gloss; prev_gloss = ray.mat.gloss;
ray_dir = reflect(ray_dir, ray.normal); ray_dir = reflect(ray_dir, ray.normal);
ray_origin = ray.hit_pos + ray_dir * 0.01; ray_origin = ray.hit_pos + ray_dir * SURF_DIST * 2;
} }
#ifdef DISCARD_ON_MISS #ifdef DISCARD_ON_MISS
@ -199,7 +203,7 @@ FragOut frag (V2F i) {
#endif #endif
FragOut o; FragOut o;
o.col = col; o.col = clamp(col, 0, 1);
#ifndef DISABLE_DEPTH #ifndef DISABLE_DEPTH
float3 depth_point = first_hit * SCENE_SCALE; float3 depth_point = first_hit * SCENE_SCALE;
@ -207,7 +211,7 @@ FragOut frag (V2F i) {
depth_point = i.hit_pos; depth_point = i.hit_pos;
#ifdef LIMIT_DEPTH_TO_MESH #ifdef LIMIT_DEPTH_TO_MESH
if (length(ray.start - first_hit) > length(i.cam_pos - i.hit_pos)) if (length(i.cam_pos - first_hit) > length(i.cam_pos - i.hit_pos))
depth_point = i.hit_pos; depth_point = i.hit_pos;
#endif #endif