diff --git a/ref/vk/shaders/bounce.comp b/ref/vk/shaders/bounce.comp index 69bb232f..74e18201 100644 --- a/ref/vk/shaders/bounce.comp +++ b/ref/vk/shaders/bounce.comp @@ -143,14 +143,18 @@ void computeBounces(MaterialEx mat, vec3 pos, vec3 direction, inout vec3 diffuse computeLighting(hit_pos, hit_shading_normal, -bounce_direction, hit_material, ldiffuse, lspecular); if (IS_INVALID3(ldiffuse)) { +#ifdef SHADER_DEBUG_ENABLE debugPrintfEXT("pix=(%d,%d) pos=(%f,%f,%f) dir=(%f,%f,%f) ldiffuse=invalid", pix.x, pix.y, pos.x, pos.y, pos.z, direction.x, direction.y, direction.z); +#endif ldiffuse = vec3(0.); } if (IS_INVALID3(lspecular)) { +#ifdef SHADER_DEBUG_ENABLE debugPrintfEXT("pix=(%d,%d) pos=(%f,%f,%f) dir=(%f,%f,%f) lspecular=invalid", pix.x, pix.y, pos.x, pos.y, pos.z, direction.x, direction.y, direction.z); +#endif lspecular = vec3(0.); } @@ -185,8 +189,10 @@ void computeBounces(MaterialEx mat, vec3 pos, vec3 direction, inout vec3 diffuse specular += throughput * lighting; if (IS_INVALID3(throughput)) { +#ifdef SHADER_DEBUG_ENABLE debugPrintfEXT("pix=(%d,%d) pos=(%f,%f,%f) dir=(%f,%f,%f) throughput=invalid", pix.x, pix.y, pos.x, pos.y, pos.z, direction.x, direction.y, direction.z); +#endif throughput = vec3(0.); //diffuse = 10.*vec3(1., 0., 0.); //specular = 10.*vec3(0., 0., 1.); @@ -196,10 +202,12 @@ void computeBounces(MaterialEx mat, vec3 pos, vec3 direction, inout vec3 diffuse /* if (any(lessThan(throughput, vec3(0.)))) { +#ifdef SHADER_DEBUG_ENABLE debugPrintfEXT("pix=(%d,%d) pos=(%f,%f,%f) dir=(%f,%f,%f) throughput=(%f, %f, %f)", pix.x, pix.y, pos.x, pos.y, pos.z, direction.x, direction.y, direction.z, throughput.r, throughput.g, throughput.b ); +#endif } */ @@ -255,12 +263,16 @@ void main() { } if (IS_INVALID3(specular)) { +#ifdef SHADER_DEBUG_ENABLE debugPrintfEXT("pix=(%d,%d) specular=inv", pix.x, pix.y); +#endif specular = vec3(0.); } if (IS_INVALID3(diffuse)) { +#ifdef SHADER_DEBUG_ENABLE debugPrintfEXT("pix=(%d,%d) diffuse=inv", pix.x, pix.y); +#endif diffuse = vec3(0.); } diff --git a/ref/vk/shaders/brdf.glsl b/ref/vk/shaders/brdf.glsl index 7314e78f..f64280d8 100644 --- a/ref/vk/shaders/brdf.glsl +++ b/ref/vk/shaders/brdf.glsl @@ -102,8 +102,10 @@ void brdfComputeGltfModel(vec3 N, vec3 L, vec3 V, MaterialProperties material, o float fresnel_factor = max(0., pow(1. - abs(h_dot_v), 5.)); if (fresnel_factor < .0 || fresnel_factor > 1. || IS_INVALID(fresnel_factor)) { +#ifdef SHADER_DEBUG_ENABLE debugPrintfEXT("N=(%f,%f,%f) L=(%f,%f,%f) V=(%f,%f,%f) H=(%f,%f,%f) h_dot_v=%f INVALID fresnel_factor=%f", PRIVEC3(N), PRIVEC3(L), PRIVEC3(V), PRIVEC3(H), h_dot_v, fresnel_factor); +#endif fresnel_factor = clamp(fresnel_factor, 0., 1.); } @@ -118,16 +120,22 @@ void brdfComputeGltfModel(vec3 N, vec3 L, vec3 V, MaterialProperties material, o // This is the correctly derived diffuse term that doesn't include the base_color twice out_diffuse = diffuse_color * kOneOverPi * .96 * (1. - fresnel_factor); - const float ggxd = ggxD(a2, h_dot_n); + float ggxd = ggxD(a2, h_dot_n); if (IS_INVALID(ggxd) || ggxd < 0. /* || ggxd > 1.*/) { +#ifdef SHADER_DEBUG_ENABLE debugPrintfEXT("N=(%f,%f,%f) L=(%f,%f,%f) V=(%f,%f,%f) a2=%f h_dot_n=%f INVALID ggxd=%f", PRIVEC3(N), PRIVEC3(L), PRIVEC3(V), a2, h_dot_n, ggxd); +#endif + ggxd = 0.; } - const float ggxv = ggxV(a2, l_dot_n, h_dot_l, n_dot_v, h_dot_v); + float ggxv = ggxV(a2, l_dot_n, h_dot_l, n_dot_v, h_dot_v); if (IS_INVALID(ggxv) || ggxv < 0. /*|| ggxv > 1.*/) { +#ifdef SHADER_DEBUG_ENABLE debugPrintfEXT("N=(%f,%f,%f) L=(%f,%f,%f) V=(%f,%f,%f) a2=%f h_dot_n=%f INVALID ggxv=%f", PRIVEC3(N), PRIVEC3(L), PRIVEC3(V), a2, h_dot_n, ggxv); +#endif + ggxv = 0.; } out_specular = fresnel * ggxd * ggxv; diff --git a/ref/vk/shaders/debug.glsl b/ref/vk/shaders/debug.glsl index b6ac6579..599f6aa5 100644 --- a/ref/vk/shaders/debug.glsl +++ b/ref/vk/shaders/debug.glsl @@ -1,15 +1,15 @@ #ifndef DEBUG_GLSL_INCLUDED #define DEBUG_GLSL_INCLUDED +#define IS_INVALID(v) (isnan(v) || isinf(v)) +#define IS_INVALID3(v) (any(isnan(v)) || any(isinf(v))) +#define PRIVEC3(v) (v).r, (v).g, (v).b + #define SHADER_DEBUG_ENABLE #ifdef SHADER_DEBUG_ENABLE #extension GL_EXT_debug_printf: enable -#define IS_INVALID(v) (isnan(v) || isinf(v)) -#define IS_INVALID3(v) (any(isnan(v)) || any(isinf(v))) -#define PRIVEC3(v) (v).r, (v).g, (v).b - // msg should begin with "%d" for __LINE__ // GLSL u y no string concatenation ;_; #define VALIDATE_VEC3(v, msg) \ @@ -17,6 +17,14 @@ debugPrintfEXT(msg, __LINE__, PRIVEC3(v)); \ v = vec3(0.); \ } +#else // SHADER_DEBUG_ENABLE +#define VALIDATE_VEC3(v, msg) \ + if (IS_INVALID3(v)) { \ + v = vec3(0.); \ + } + +// GLSL u y no variadic macro +//#define debugPrintfEXT(...) #endif // SHADER_DEBUG_ENABLE diff --git a/ref/vk/shaders/denoiser.comp b/ref/vk/shaders/denoiser.comp index 798048f7..e4302fc6 100644 --- a/ref/vk/shaders/denoiser.comp +++ b/ref/vk/shaders/denoiser.comp @@ -188,12 +188,16 @@ Components blurSamples(const ivec2 res, const ivec2 pix) { c.indirect_diffuse *= indirect_diffuse_total; if (IS_INVALID3(c.direct_specular)) { +#ifdef SHADER_DEBUG_ENABLE debugPrintfEXT("c.direct_specular=(%f,%f,%f)", PRIVEC3(c.direct_specular)); +#endif c.direct_specular = vec3(0.); } if (IS_INVALID(direct_specular_total)) { +#ifdef SHADER_DEBUG_ENABLE debugPrintfEXT("direct_specular_total=%f", direct_specular_total); +#endif direct_specular_total = 0.; } @@ -204,7 +208,9 @@ Components blurSamples(const ivec2 res, const ivec2 pix) { c.indirect_specular *= indirect_specular_total; if (IS_INVALID3(c.indirect_specular)) { +#ifdef SHADER_DEBUG_ENABLE debugPrintfEXT("c.indirect_specular=(%f,%f,%f)", PRIVEC3(c.indirect_specular)); +#endif c.indirect_specular = vec3(0.); } @@ -314,12 +320,16 @@ void main() { } if (IS_INVALID3(history_specular)) { +#ifdef SHADER_DEBUG_ENABLE debugPrintfEXT("PRE pix=(%d,%d) history_specular=inv", pix.x, pix.y); +#endif history_specular = vec3(0.); } if (IS_INVALID3(specular)) { +#ifdef SHADER_DEBUG_ENABLE debugPrintfEXT("PRE pix=(%d,%d) specular=(%f,%f,%f)", pix.x, pix.y, PRIVEC3(specular)); +#endif specular = vec3(0.); } @@ -330,16 +340,20 @@ void main() { } if (IS_INVALID3(diffuse)) { +#ifdef SHADER_DEBUG_ENABLE debugPrintfEXT("pix=(%d,%d) diffuse=inv", pix.x, pix.y); +#endif diffuse = vec3(0.); } if (IS_INVALID3(new_specular)) { +#ifdef SHADER_DEBUG_ENABLE debugPrintfEXT("pix=(%d,%d) new_specular=inv, specular=(%f, %f, %f) history_specular=(%f, %f, %f)", pix.x, pix.y, specular.r, specular.g, specular.b, history_specular.r, history_specular.g, history_specular.b ); +#endif new_specular = vec3(0.); } specular = new_specular; diff --git a/ref/vk/shaders/light.glsl b/ref/vk/shaders/light.glsl index 7f7f1cba..1f2cc9db 100644 --- a/ref/vk/shaders/light.glsl +++ b/ref/vk/shaders/light.glsl @@ -157,14 +157,18 @@ void computeLighting(vec3 P, vec3 N, vec3 view_dir, MaterialProperties material, #endif if (IS_INVALID3(diffuse) || any(lessThan(diffuse,vec3(0.)))) { +#ifdef SHADER_DEBUG_ENABLE debugPrintfEXT("P=(%f,%f,%f) N=(%f,%f,%f) INVALID diffuse=(%f,%f,%f)", PRIVEC3(P), PRIVEC3(N), PRIVEC3(diffuse)); +#endif diffuse = vec3(0.); } if (IS_INVALID3(specular) || any(lessThan(specular,vec3(0.)))) { +#ifdef SHADER_DEBUG_ENABLE debugPrintfEXT("P=(%f,%f,%f) N=(%f,%f,%f) INVALID specular=(%f,%f,%f)", PRIVEC3(P), PRIVEC3(N), PRIVEC3(specular)); +#endif specular = vec3(0.); } } diff --git a/ref/vk/shaders/light_polygon.glsl b/ref/vk/shaders/light_polygon.glsl index b9f66802..5f3d42b7 100644 --- a/ref/vk/shaders/light_polygon.glsl +++ b/ref/vk/shaders/light_polygon.glsl @@ -264,8 +264,10 @@ void sampleEmissiveSurfaces(vec3 P, vec3 N, vec3 view_dir, MaterialProperties ma specular += emissive * estimate * poly_specular; if (IS_INVALID3(specular) || any(lessThan(specular,vec3(0.)))) { +#ifdef SHADER_DEBUG_ENABLE debugPrintfEXT("%d INVALID specular=(%f,%f,%f) light=%d emissive=(%f,%f,%f) estimate=%f poly_specular=(%f,%f,%f)", __LINE__, PRIVEC3(specular), index, PRIVEC3(emissive), estimate, PRIVEC3(poly_specular)); +#endif specular = vec3(0.); } }