vk: rt: allow disabling debug printfs in shaders
This commit is contained in:
parent
64520ef5a1
commit
20e9af6496
|
@ -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);
|
computeLighting(hit_pos, hit_shading_normal, -bounce_direction, hit_material, ldiffuse, lspecular);
|
||||||
|
|
||||||
if (IS_INVALID3(ldiffuse)) {
|
if (IS_INVALID3(ldiffuse)) {
|
||||||
|
#ifdef SHADER_DEBUG_ENABLE
|
||||||
debugPrintfEXT("pix=(%d,%d) pos=(%f,%f,%f) dir=(%f,%f,%f) ldiffuse=invalid",
|
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);
|
pix.x, pix.y, pos.x, pos.y, pos.z, direction.x, direction.y, direction.z);
|
||||||
|
#endif
|
||||||
ldiffuse = vec3(0.);
|
ldiffuse = vec3(0.);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_INVALID3(lspecular)) {
|
if (IS_INVALID3(lspecular)) {
|
||||||
|
#ifdef SHADER_DEBUG_ENABLE
|
||||||
debugPrintfEXT("pix=(%d,%d) pos=(%f,%f,%f) dir=(%f,%f,%f) lspecular=invalid",
|
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);
|
pix.x, pix.y, pos.x, pos.y, pos.z, direction.x, direction.y, direction.z);
|
||||||
|
#endif
|
||||||
lspecular = vec3(0.);
|
lspecular = vec3(0.);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,8 +189,10 @@ void computeBounces(MaterialEx mat, vec3 pos, vec3 direction, inout vec3 diffuse
|
||||||
specular += throughput * lighting;
|
specular += throughput * lighting;
|
||||||
|
|
||||||
if (IS_INVALID3(throughput)) {
|
if (IS_INVALID3(throughput)) {
|
||||||
|
#ifdef SHADER_DEBUG_ENABLE
|
||||||
debugPrintfEXT("pix=(%d,%d) pos=(%f,%f,%f) dir=(%f,%f,%f) throughput=invalid",
|
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);
|
pix.x, pix.y, pos.x, pos.y, pos.z, direction.x, direction.y, direction.z);
|
||||||
|
#endif
|
||||||
throughput = vec3(0.);
|
throughput = vec3(0.);
|
||||||
//diffuse = 10.*vec3(1., 0., 0.);
|
//diffuse = 10.*vec3(1., 0., 0.);
|
||||||
//specular = 10.*vec3(0., 0., 1.);
|
//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.)))) {
|
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)",
|
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,
|
pix.x, pix.y, pos.x, pos.y, pos.z, direction.x, direction.y, direction.z,
|
||||||
throughput.r, throughput.g, throughput.b
|
throughput.r, throughput.g, throughput.b
|
||||||
);
|
);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -255,12 +263,16 @@ void main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_INVALID3(specular)) {
|
if (IS_INVALID3(specular)) {
|
||||||
|
#ifdef SHADER_DEBUG_ENABLE
|
||||||
debugPrintfEXT("pix=(%d,%d) specular=inv", pix.x, pix.y);
|
debugPrintfEXT("pix=(%d,%d) specular=inv", pix.x, pix.y);
|
||||||
|
#endif
|
||||||
specular = vec3(0.);
|
specular = vec3(0.);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_INVALID3(diffuse)) {
|
if (IS_INVALID3(diffuse)) {
|
||||||
|
#ifdef SHADER_DEBUG_ENABLE
|
||||||
debugPrintfEXT("pix=(%d,%d) diffuse=inv", pix.x, pix.y);
|
debugPrintfEXT("pix=(%d,%d) diffuse=inv", pix.x, pix.y);
|
||||||
|
#endif
|
||||||
diffuse = vec3(0.);
|
diffuse = vec3(0.);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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.));
|
float fresnel_factor = max(0., pow(1. - abs(h_dot_v), 5.));
|
||||||
|
|
||||||
if (fresnel_factor < .0 || fresnel_factor > 1. || IS_INVALID(fresnel_factor)) {
|
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",
|
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);
|
PRIVEC3(N), PRIVEC3(L), PRIVEC3(V), PRIVEC3(H), h_dot_v, fresnel_factor);
|
||||||
|
#endif
|
||||||
fresnel_factor = clamp(fresnel_factor, 0., 1.);
|
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
|
// This is the correctly derived diffuse term that doesn't include the base_color twice
|
||||||
out_diffuse = diffuse_color * kOneOverPi * .96 * (1. - fresnel_factor);
|
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.*/) {
|
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",
|
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);
|
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.*/) {
|
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",
|
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);
|
PRIVEC3(N), PRIVEC3(L), PRIVEC3(V), a2, h_dot_n, ggxv);
|
||||||
|
#endif
|
||||||
|
ggxv = 0.;
|
||||||
}
|
}
|
||||||
|
|
||||||
out_specular = fresnel * ggxd * ggxv;
|
out_specular = fresnel * ggxd * ggxv;
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
#ifndef DEBUG_GLSL_INCLUDED
|
#ifndef DEBUG_GLSL_INCLUDED
|
||||||
#define 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
|
#define SHADER_DEBUG_ENABLE
|
||||||
#ifdef SHADER_DEBUG_ENABLE
|
#ifdef SHADER_DEBUG_ENABLE
|
||||||
|
|
||||||
#extension GL_EXT_debug_printf: 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__
|
// msg should begin with "%d" for __LINE__
|
||||||
// GLSL u y no string concatenation ;_;
|
// GLSL u y no string concatenation ;_;
|
||||||
#define VALIDATE_VEC3(v, msg) \
|
#define VALIDATE_VEC3(v, msg) \
|
||||||
|
@ -17,6 +17,14 @@
|
||||||
debugPrintfEXT(msg, __LINE__, PRIVEC3(v)); \
|
debugPrintfEXT(msg, __LINE__, PRIVEC3(v)); \
|
||||||
v = vec3(0.); \
|
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
|
#endif // SHADER_DEBUG_ENABLE
|
||||||
|
|
||||||
|
|
|
@ -188,12 +188,16 @@ Components blurSamples(const ivec2 res, const ivec2 pix) {
|
||||||
c.indirect_diffuse *= indirect_diffuse_total;
|
c.indirect_diffuse *= indirect_diffuse_total;
|
||||||
|
|
||||||
if (IS_INVALID3(c.direct_specular)) {
|
if (IS_INVALID3(c.direct_specular)) {
|
||||||
|
#ifdef SHADER_DEBUG_ENABLE
|
||||||
debugPrintfEXT("c.direct_specular=(%f,%f,%f)", PRIVEC3(c.direct_specular));
|
debugPrintfEXT("c.direct_specular=(%f,%f,%f)", PRIVEC3(c.direct_specular));
|
||||||
|
#endif
|
||||||
c.direct_specular = vec3(0.);
|
c.direct_specular = vec3(0.);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_INVALID(direct_specular_total)) {
|
if (IS_INVALID(direct_specular_total)) {
|
||||||
|
#ifdef SHADER_DEBUG_ENABLE
|
||||||
debugPrintfEXT("direct_specular_total=%f", direct_specular_total);
|
debugPrintfEXT("direct_specular_total=%f", direct_specular_total);
|
||||||
|
#endif
|
||||||
direct_specular_total = 0.;
|
direct_specular_total = 0.;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +208,9 @@ Components blurSamples(const ivec2 res, const ivec2 pix) {
|
||||||
c.indirect_specular *= indirect_specular_total;
|
c.indirect_specular *= indirect_specular_total;
|
||||||
|
|
||||||
if (IS_INVALID3(c.indirect_specular)) {
|
if (IS_INVALID3(c.indirect_specular)) {
|
||||||
|
#ifdef SHADER_DEBUG_ENABLE
|
||||||
debugPrintfEXT("c.indirect_specular=(%f,%f,%f)", PRIVEC3(c.indirect_specular));
|
debugPrintfEXT("c.indirect_specular=(%f,%f,%f)", PRIVEC3(c.indirect_specular));
|
||||||
|
#endif
|
||||||
c.indirect_specular = vec3(0.);
|
c.indirect_specular = vec3(0.);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,12 +320,16 @@ void main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_INVALID3(history_specular)) {
|
if (IS_INVALID3(history_specular)) {
|
||||||
|
#ifdef SHADER_DEBUG_ENABLE
|
||||||
debugPrintfEXT("PRE pix=(%d,%d) history_specular=inv", pix.x, pix.y);
|
debugPrintfEXT("PRE pix=(%d,%d) history_specular=inv", pix.x, pix.y);
|
||||||
|
#endif
|
||||||
history_specular = vec3(0.);
|
history_specular = vec3(0.);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_INVALID3(specular)) {
|
if (IS_INVALID3(specular)) {
|
||||||
|
#ifdef SHADER_DEBUG_ENABLE
|
||||||
debugPrintfEXT("PRE pix=(%d,%d) specular=(%f,%f,%f)", pix.x, pix.y, PRIVEC3(specular));
|
debugPrintfEXT("PRE pix=(%d,%d) specular=(%f,%f,%f)", pix.x, pix.y, PRIVEC3(specular));
|
||||||
|
#endif
|
||||||
specular = vec3(0.);
|
specular = vec3(0.);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,16 +340,20 @@ void main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_INVALID3(diffuse)) {
|
if (IS_INVALID3(diffuse)) {
|
||||||
|
#ifdef SHADER_DEBUG_ENABLE
|
||||||
debugPrintfEXT("pix=(%d,%d) diffuse=inv", pix.x, pix.y);
|
debugPrintfEXT("pix=(%d,%d) diffuse=inv", pix.x, pix.y);
|
||||||
|
#endif
|
||||||
diffuse = vec3(0.);
|
diffuse = vec3(0.);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_INVALID3(new_specular)) {
|
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)",
|
debugPrintfEXT("pix=(%d,%d) new_specular=inv, specular=(%f, %f, %f) history_specular=(%f, %f, %f)",
|
||||||
pix.x, pix.y,
|
pix.x, pix.y,
|
||||||
specular.r, specular.g, specular.b,
|
specular.r, specular.g, specular.b,
|
||||||
history_specular.r, history_specular.g, history_specular.b
|
history_specular.r, history_specular.g, history_specular.b
|
||||||
);
|
);
|
||||||
|
#endif
|
||||||
new_specular = vec3(0.);
|
new_specular = vec3(0.);
|
||||||
}
|
}
|
||||||
specular = new_specular;
|
specular = new_specular;
|
||||||
|
|
|
@ -157,14 +157,18 @@ void computeLighting(vec3 P, vec3 N, vec3 view_dir, MaterialProperties material,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (IS_INVALID3(diffuse) || any(lessThan(diffuse,vec3(0.)))) {
|
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)",
|
debugPrintfEXT("P=(%f,%f,%f) N=(%f,%f,%f) INVALID diffuse=(%f,%f,%f)",
|
||||||
PRIVEC3(P), PRIVEC3(N), PRIVEC3(diffuse));
|
PRIVEC3(P), PRIVEC3(N), PRIVEC3(diffuse));
|
||||||
|
#endif
|
||||||
diffuse = vec3(0.);
|
diffuse = vec3(0.);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_INVALID3(specular) || any(lessThan(specular,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)",
|
debugPrintfEXT("P=(%f,%f,%f) N=(%f,%f,%f) INVALID specular=(%f,%f,%f)",
|
||||||
PRIVEC3(P), PRIVEC3(N), PRIVEC3(specular));
|
PRIVEC3(P), PRIVEC3(N), PRIVEC3(specular));
|
||||||
|
#endif
|
||||||
specular = vec3(0.);
|
specular = vec3(0.);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -264,8 +264,10 @@ void sampleEmissiveSurfaces(vec3 P, vec3 N, vec3 view_dir, MaterialProperties ma
|
||||||
specular += emissive * estimate * poly_specular;
|
specular += emissive * estimate * poly_specular;
|
||||||
|
|
||||||
if (IS_INVALID3(specular) || any(lessThan(specular,vec3(0.)))) {
|
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)",
|
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));
|
__LINE__, PRIVEC3(specular), index, PRIVEC3(emissive), estimate, PRIVEC3(poly_specular));
|
||||||
|
#endif
|
||||||
specular = vec3(0.);
|
specular = vec3(0.);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue