vk: add `rt_debug_display_only` cvar

Displays only the specified channel.

Fixes #631
This commit is contained in:
Ivan Avdeev 2023-11-03 10:58:13 -04:00
parent 2a3f48fd50
commit 0ba85e3f08
4 changed files with 78 additions and 78 deletions

View File

@ -1,12 +1,16 @@
# 2023-11-03 E324
- [x] add cvar for displaying only specified channel
- [ ] r_lightmap
- [ ] massage shaders: consolidate all bindings explicitly
- [ ] skip sorting-by-texture when loading brush models ~~(=> geometry count explosion; i.e. kusochki count will explode too)~~
- [ ] kusochki-vs-materials structures
- [ ] -vkverbose arg for turning all debug logs before detailed cvars are read
# 2023-11-02 E323
- [x] lol meta: read and sort issues
- [x] merge from upstream
- [x] hevsuit glitches
- [x] inverted normal map orientation
- [ ] massage shaders: consolidate all bindings explicitly
- [ ] skip sorting-by-texture when loading brush models (=> geometry count explosion; i.e. kusochki count will explode too)
- [ ] kusochki-vs-materials
- [ ] -vkverbose arg for turning all debug logs before detailed cvars are read
# 2023-10-31 E322
- [x] load png blue noise files

View File

@ -43,17 +43,11 @@ layout(set = 0, binding = 18) uniform sampler3D blue_noise_texture;
#endif
//layout(set = 0, binding = 19) uniform sampler2D textures[MAX_TEXTURES];
//layout(set = 0, binding = 18, rgba8) uniform readonly image2D material_rmxx;
const int INDIRECT_SCALE = 2;
//#define DEBUG_TEXTURE normals_gs
//#define DEBUG_TEXTURE emissive
//#define DEBUG_TEXTURE base_color_a
//#define DEBUG_TEXTURE light_point_diffuse
//#define DEBUG_NORMAL
//layout(set = 0, binding = 18, rgba8) uniform readonly image2D material_rmxx;
// Blatantly copypasted from https://www.shadertoy.com/view/XsGfWV
vec3 aces_tonemap(vec3 color){
mat3 m1 = mat3(
@ -121,10 +115,6 @@ Components blurSamples(const ivec2 res, const ivec2 pix) {
continue;
}
// const vec4 c = imageLoad(light_poly, p);
// if (c.a != material_index)
// continue;
vec3 sample_geometry_normal, sample_shading_normal;
readNormals(p, sample_geometry_normal, sample_shading_normal);
@ -194,69 +184,34 @@ void main() {
return;
}
if (ubo.ubo.debug_display_only == DEBUG_DISPLAY_DISABLED) {
// no-op, just continue
} else if (ubo.ubo.debug_display_only == DEBUG_DISPLAY_BASECOLOR) {
imageStore(out_dest, pix, vec4(LINEARtoSRGB(imageLoad(base_color_a, pix).rgb), 0.)); return;
return;
} else if (ubo.ubo.debug_display_only == DEBUG_DISPLAY_BASEALPHA) {
imageStore(out_dest, pix, imageLoad(base_color_a, pix).aaaa); return;
return;
} else if (ubo.ubo.debug_display_only == DEBUG_DISPLAY_EMISSIVE) {
imageStore(out_dest, pix, vec4(LINEARtoSRGB(imageLoad(emissive, pix).rgb), 0.)); return;
return;
} else if (ubo.ubo.debug_display_only == DEBUG_DISPLAY_NSHADE) {
vec3 geometry_normal, shading_normal;
readNormals(pix, geometry_normal, shading_normal);
imageStore(out_dest, pix, vec4(.5 + shading_normal * .5, 0.));
return;
} else if (ubo.ubo.debug_display_only == DEBUG_DISPLAY_NGEOM) {
vec3 geometry_normal, shading_normal;
readNormals(pix, geometry_normal, shading_normal);
imageStore(out_dest, pix, vec4(.5 + geometry_normal * .5, 0.));
return;
}
#ifdef DEBUG_NOISE
imageStore(out_dest, pix, blueNoise(ivec3(pix.xy, ubo.ubo.frame_counter))); return;
#endif
/* if (pix.y < res.y / 3) { */
/* imageStore(out_dest, pix, vec4(pow(float(pix.x) / res.x, 2.2))); return; */
/* } else if (pix.y < res.y * 2 / 3) { */
/* imageStore(out_dest, pix, vec4(float(pix.x) / res.x)); return; */
/* } else { */
/* imageStore(out_dest, pix, vec4(sqrt(float(pix.x) / res.x))); return; */
/* } */
#if defined(DEBUG_TEXTURE)
//if (pix.x < res.x / 2) {
//imageStore(out_dest, pix, vec4(LINEARtoSRGB(texture(textures[161], vec2(pix)/vec2(res)).rgb), 0.)); return;
//}
imageStore(out_dest, pix, vec4(LINEARtoSRGB(imageLoad(DEBUG_TEXTURE, pix).rgb), 0.)); return;
#endif
/*
if (pix.x < res.x / 4) {
imageStore(out_dest, pix, vec4(imageLoad(base_color_a, pix).rgb, 0.)); return;
} else if (pix.x < res.x / 2) {
imageStore(out_dest, pix, vec4(LINEARtoSRGB(imageLoad(emissive, pix).rgb), 0.)); return;
} else if (pix.x < res.x * 3 / 4) {
imageStore(out_dest, pix, vec4(LINEARtoSRGB(fract(
imageLoad(light_poly_diffuse, pix).rgb
+ imageLoad(light_poly_specular, pix).rgb
+ imageLoad(light_point_diffuse, pix).rgb
+ imageLoad(light_point_specular, pix).rgb
)), 0.)); return;
} else {
imageStore(out_dest, pix, vec4(LINEARtoSRGB(
imageLoad(indirect_diffuse, pix / INDIRECT_SCALE).rgb
+ imageLoad(indirect_specular, pix / INDIRECT_SCALE).rgb
), 0.)); return;
}*/
//imageStore(out_dest, pix, vec4(fract(imageLoad(position_t, pix).rgb/10.), 0.)); return;
//imageStore(out_dest, pix, vec4(fract(imageLoad(geometry_prev_position, pix).rgb/50.), 0.)); return;
#if defined(DEBUG_NORMAL)
vec3 geometry_normal, shading_normal;
readNormals(pix, geometry_normal, shading_normal);
//imageStore(out_dest, pix, vec4(.5 + geometry_normal * .5, 0.)); return;
//const vec4 mat_rmxx = imageLoad(material_rmxx, pix);
//imageStore(out_dest, pix, vec4((.5 + shading_normal * .5)*.8 + .2 * mat_rmxx.a , 0.)); return;
//imageStore(out_dest, pix, vec4(.5 + shading_normal * .5, 0.)); return;
//vec3 normal = pix.x < res.x / 2 ? shading_normal : geometry_normal;
vec3 normal = shading_normal;// : geometry_normal;
imageStore(out_dest, pix, vec4(.5 + normal * .5, 0.)); return;
#endif
/* const uint mi = uint(material_index); */
/* imageStore(out_dest, pix, vec4(rand3_f01(uvec3(mi,mi+1,mi+2)), 0.)); */
/* return; */
const Components c = blurSamples(res, pix);
//imageStore(out_dest, pix, vec4(aces_tonemap(c.direct_diffuse), 0.)); return;
//imageStore(out_dest, pix, vec4(aces_tonemap(c.direct_specular), 0.)); return;
//imageStore(out_dest, pix, vec4(aces_tonemap(c.indirect_diffuse), 0.)); return;
//imageStore(out_dest, pix, vec4(aces_tonemap(c.indirect_specular), 0.)); return;
vec3 colour = vec3(0.);
{
@ -304,10 +259,6 @@ void main() {
imageStore(out_temporal_diffuse, pix, vec4(diffuse, depth));
imageStore(out_temporal_specular, pix, vec4(specular, 0./*unused*/));
colour = diffuse + specular;
//imageStore(out_dest, pix, vec4(LINEARtoSRGB(diffuse), 0.)); return;
//imageStore(out_dest, pix, vec4(fract(abs(position - prev_position)), 0./*unused*/)); return;
//imageStore(out_dest, pix, vec4(fract(abs(prev_position)), 0./*unused*/)); return;
}
const vec4 base_color_a = SRGBtoLINEAR(imageLoad(base_color_a, pix));

View File

@ -168,13 +168,22 @@ struct PushConstants {
uint flags;
};
#define DEBUG_DISPLAY_DISABLED 0
#define DEBUG_DISPLAY_BASECOLOR 1
#define DEBUG_DISPLAY_BASEALPHA 2
#define DEBUG_DISPLAY_EMISSIVE 3
#define DEBUG_DISPLAY_NSHADE 4
#define DEBUG_DISPLAY_NGEOM 5
// add more when needed
struct UniformBuffer {
mat4 inv_proj, inv_view;
mat4 prev_inv_proj, prev_inv_view;
float ray_cone_width;
uint random_seed;
uint frame_counter;
PAD(1)
uint debug_display_only;
};
#undef PAD

View File

@ -89,6 +89,11 @@ static struct {
qboolean reload_pipeline;
matrix4x4 prev_inv_proj, prev_inv_view;
struct {
cvar_t *rt_debug_display_only;
uint32_t rt_debug_display_only_value;
} debug;
} g_rtx = {0};
static int findResource(const char *name) {
@ -145,6 +150,32 @@ void VK_RayFrameBegin( void ) {
RT_LightsFrameBegin();
}
static void parseDebugDisplayValue( void ) {
if (!(g_rtx.debug.rt_debug_display_only->flags & FCVAR_CHANGED))
return;
g_rtx.debug.rt_debug_display_only->flags &= ~FCVAR_CHANGED;
const char *cvalue = g_rtx.debug.rt_debug_display_only->string;
#define LIST_DISPLAYS(X) \
X(BASECOLOR) \
X(BASEALPHA) \
X(EMISSIVE) \
X(NSHADE) \
X(NGEOM) \
#define X(suffix) \
if (0 == Q_stricmp(cvalue, #suffix)) { \
WARN("setting debug display to %s", "DEBUG_DISPLAY_"#suffix); \
g_rtx.debug.rt_debug_display_only_value = DEBUG_DISPLAY_##suffix; \
return; \
}
LIST_DISPLAYS(X)
#undef X
g_rtx.debug.rt_debug_display_only_value = DEBUG_DISPLAY_DISABLED;
}
static void prepareUniformBuffer( const vk_ray_frame_render_args_t *args, int frame_index, uint32_t frame_counter, float fov_angle_y ) {
struct UniformBuffer *ubo = (struct UniformBuffer*)((char*)g_rtx.uniform_buffer.mapped + frame_index * g_rtx.uniform_unit_size);
@ -166,6 +197,9 @@ static void prepareUniformBuffer( const vk_ray_frame_render_args_t *args, int fr
ubo->ray_cone_width = atanf((2.0f*tanf(DEG2RAD(fov_angle_y) * 0.5f)) / (float)FRAME_HEIGHT);
ubo->random_seed = (uint32_t)gEngine.COM_RandomLong(0, INT32_MAX);
ubo->frame_counter = frame_counter;
parseDebugDisplayValue();
ubo->debug_display_only = g_rtx.debug.rt_debug_display_only_value;
}
typedef struct {
@ -657,6 +691,8 @@ qboolean VK_RayInit( void )
gEngine.Cmd_AddCommand("vk_rtx_reload", reloadPipeline, "Reload RTX shader");
g_rtx.debug.rt_debug_display_only = gEngine.Cvar_Get("rt_debug_display_only", "", FCVAR_GLCONFIG, "Display only the specified channel (nshade, ngeom, basecolor, basealpha, ...)");
return true;
}