Skip to content

Commit

Permalink
vk: rt: add white furnace debug display mode
Browse files Browse the repository at this point in the history
Known issues:
- it doesn't really look how it's supposed to look
- using debug display mode for it was a mistake
  • Loading branch information
w23 committed Jan 26, 2024
1 parent 18269eb commit 6d58ad8
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 7 deletions.
11 changes: 8 additions & 3 deletions ref/vk/TODO.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
## Next
- [ ] white furnace test
- [ ] fix no-hit bounce absent legacy blending
- [ ] -vkdbgprintf or something
- [ ] performance profiling and comparison

## 2024-01-26 E369
- [ ] white furnace test
- [x] do it using display_only mode
- [ ] do it via separate flag

# Previously
## 2024-01-23 E368
- [ ] specular bounce
- [x] specular-vs-diffuse choice based on metalness+frensel
Expand All @@ -14,7 +21,6 @@
- [ ] BRDF material params attenuation
- [x] try improving, multiply specular by fresnel


## 2024-01-22 E367
- [ ] specular bounce
- [ ] specular-vs-diffuse choice based on metalness+frensel
Expand All @@ -25,7 +31,6 @@
- [ ] BRDF material params attenuation
- [ ] decide on the diffuse-vs-specular out channel based on the first bounce

# Previously
## 2024-01-19 E366
- [x] investigate more shading nans
- found zero normals in studio models, see #731
Expand Down
4 changes: 3 additions & 1 deletion ref/vk/shaders/bounce.comp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ layout(set = 0, binding = 33, std430) readonly buffer Vertices { Vertex a[]; } v
#include "light.glsl"

#include "trace_simple_blending.glsl"
#include "skybox.glsl"

void readNormals(ivec2 uv, out vec3 geometry_normal, out vec3 shading_normal) {
const vec4 n = imageLoad(normals_gs, uv);
Expand Down Expand Up @@ -189,7 +190,8 @@ void computeBounces(MaterialEx mat, vec3 pos, vec3 direction, inout vec3 diffuse

hit_skybox = payload.hit_t.w < 0.;
} else {
lighting = texture(skybox, bounce_direction).rgb * ubo.ubo.skybox_exposure;
// FIXME this no-hit path should still do traceLegacyBlending()
lighting = sampleSkybox(bounce_direction);
hit_skybox = true;
} // not hit

Expand Down
1 change: 1 addition & 0 deletions ref/vk/shaders/denoiser.comp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ void main() {
const Components c = blurSamples(res, pix);

if (ubo.ubo.debug_display_only == DEBUG_DISPLAY_DISABLED) {
// Skip
} else if (ubo.ubo.debug_display_only == DEBUG_DISPLAY_DIRECT) {
imageStore(out_dest, pix, vec4(LINEARtoSRGB(c.direct_diffuse + c.direct_specular), 0.)); return;
return;
Expand Down
5 changes: 5 additions & 0 deletions ref/vk/shaders/light.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ void computePointLights(vec3 P, vec3 N, uint cluster_index, vec3 view_dir, Mater
void computeLighting(vec3 P, vec3 N, vec3 view_dir, MaterialProperties material, out vec3 diffuse, out vec3 specular) {
diffuse = specular = vec3(0.);

// No direct lighting for white furnace mode. The only light sources is no-hit|SURF_SKY bounce indirect light.
if (ubo.ubo.debug_display_only == DEBUG_DISPLAY_WHITE_FURNACE) {
return;
}

#ifdef DEBUG_VALIDATE_EXTRA
if (IS_INVALIDV(P) || IS_INVALIDV(N) || IS_INVALIDV(view_dir)) {
debugPrintfEXT("INVALID computeLighting(P=(%f,%f,%f), N=(%f,%f,%f), view_dir=(%f,%f,%f))",
Expand Down
1 change: 1 addition & 0 deletions ref/vk/shaders/ray_interop.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ struct LightCluster {
#define DEBUG_DISPLAY_INDIRECT_SPEC 13
#define DEBUG_DISPLAY_TRIHASH 14
#define DEBUG_DISPLAY_MATERIAL 15
#define DEBUG_DISPLAY_WHITE_FURNACE 16
// add more when needed

struct UniformBuffer {
Expand Down
3 changes: 2 additions & 1 deletion ref/vk/shaders/ray_primary.comp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ layout(set = 0, binding = 33, std430) readonly buffer Vertices { Vertex a[]; } v
#include "ray_primary_hit.glsl"

#include "trace_simple_blending.glsl"
#include "skybox.glsl"

struct Ray {
vec3 origin, direction;
Expand Down Expand Up @@ -116,7 +117,7 @@ void main() {
L = rayQueryGetIntersectionTEXT(rq, true);
} else {
// Draw skybox when nothing is hit
payload.emissive.rgb = texture(skybox, ray.direction).rgb * ubo.ubo.skybox_exposure;
payload.emissive.rgb = sampleSkybox(ray.direction);
}

const vec4 blend = traceLegacyBlending(ray.origin, ray.direction, L);
Expand Down
3 changes: 2 additions & 1 deletion ref/vk/shaders/ray_primary.rchit
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ hitAttributeEXT vec2 bary;
#include "color_spaces.glsl"

#include "rt_geometry.glsl"
#include "skybox.glsl"

vec4 sampleTexture(uint tex_index, vec2 uv, vec4 uv_lods) {
return textureGrad(textures[nonuniformEXT(tex_index)], uv, uv_lods.xy, uv_lods.zw);
Expand All @@ -41,7 +42,7 @@ void main() {
const Kusok kusok = getKusok(geom.kusok_index);

if (kusok.material.tex_base_color == TEX_BASE_SKYBOX) {
payload.emissive.rgb = texture(skybox, gl_WorldRayDirectionEXT).rgb * ubo.ubo.skybox_exposure;
payload.emissive.rgb = sampleSkybox(gl_WorldRayDirectionEXT);
return;
} else {
const vec4 color = getModelHeader(gl_InstanceID).color * kusok.material.base_color;
Expand Down
8 changes: 7 additions & 1 deletion ref/vk/shaders/ray_primary_hit.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "ray_kusochki.glsl"
#include "rt_geometry.glsl"
#include "color_spaces.glsl"
#include "skybox.glsl"

#include "noise.glsl" // for DEBUG_DISPLAY_SURFHASH

Expand All @@ -32,7 +33,7 @@ void primaryRayHit(rayQueryEXT rq, inout RayPayloadPrimary payload) {
if (kusok.material.tex_base_color == TEX_BASE_SKYBOX) {
// Mark as non-geometry
payload.hit_t.w = -payload.hit_t.w;
payload.emissive.rgb = texture(skybox, rayDirection).rgb * ubo.ubo.skybox_exposure;
payload.emissive.rgb = sampleSkybox(rayDirection);
return;
} else {
payload.base_color_a = sampleTexture(material.tex_base_color, geom.uv, geom.uv_lods);
Expand Down Expand Up @@ -137,6 +138,11 @@ void primaryRayHit(rayQueryEXT rq, inout RayPayloadPrimary payload) {

if (ubo.ubo.debug_display_only == DEBUG_DISPLAY_DISABLED) {
// Nop
} else if (ubo.ubo.debug_display_only == DEBUG_DISPLAY_WHITE_FURNACE) {
// White furnace mode: everything is diffuse and white
payload.base_color_a.rgb = vec3(1.);
payload.emissive.rgb = vec3(0.);
payload.material_rmxx.rg = vec2(1., 0.);
} else if (ubo.ubo.debug_display_only == DEBUG_DISPLAY_SURFHASH) {
const uint hash = xxhash32(geom.kusok_index);
payload.emissive.rgb = vec3(0xff & (hash>>16), 0xff & (hash>>8), 0xff & hash) / 255.;
Expand Down
12 changes: 12 additions & 0 deletions ref/vk/shaders/skybox.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef SKYBOX_GLSL_INCLUDED
#define SKYBOX_GLSL_INCLUDED

vec3 sampleSkybox(vec3 direction) {
if (ubo.ubo.debug_display_only != DEBUG_DISPLAY_WHITE_FURNACE) {
return texture(skybox, direction).rgb * ubo.ubo.skybox_exposure;
} else {
return vec3(1.);
}
}

#endif // #ifndef SKYBOX_GLSL_INCLUDED
1 change: 1 addition & 0 deletions ref/vk/vk_rtx.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ static void parseDebugDisplayValue( void ) {
X(INDIRECT_SPEC, "indirect specular only") \
X(TRIHASH, "each triangle is drawn with random color") \
X(MATERIAL, "red = roughness, green = metalness") \
X(WHITE_FURNACE, "white furnace mode: diffuse white materials, diffuse sky light only") \

#define X(suffix, info) \
if (0 == Q_stricmp(cvalue, #suffix)) { \
Expand Down

0 comments on commit 6d58ad8

Please sign in to comment.