From 335be32cff172a4eb7b76e8c1a87e1863a53841b Mon Sep 17 00:00:00 2001 From: Ivan Avdeev Date: Fri, 19 Nov 2021 11:09:01 -0800 Subject: [PATCH] rtx: fix additive when hitting sky --- ref_vk/shaders/ray.rgen | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ref_vk/shaders/ray.rgen b/ref_vk/shaders/ray.rgen index 5bec8da1..2ec90d59 100644 --- a/ref_vk/shaders/ray.rgen +++ b/ref_vk/shaders/ray.rgen @@ -356,21 +356,24 @@ void main() { const uint flags = gl_RayFlagsCullFrontFacingTrianglesEXT; const uint sbt_offset = 0; const uint sbt_stride = 0; - const uint miss_index = 0; const float L = 10000.; // Why 10k? traceRayEXT(tlas, flags, GEOMETRY_BIT_OPAQUE | GEOMETRY_BIT_REFRACTIVE, - sbt_offset, sbt_stride, miss_index, + sbt_offset, sbt_stride, SHADER_OFFSET_MISS_REGULAR, origin, 0., direction, L, PAYLOAD_LOCATION_OPAQUE); + vec3 additive = traceAdditive(origin, direction, payload_opaque.hit_pos_t.w <= 0. ? L : payload_opaque.hit_pos_t.w); + // Sky/envmap if (payload_opaque.hit_pos_t.w <= 0.) { - out_accumulated += throughput * payload_opaque.base_color; + if (bounce == 0) { + out_additive += payload_opaque.emissive * color_factor + additive; + } else { + out_accumulated += throughput * (payload_opaque.emissive * color_factor + additive); + } break; } - vec3 additive = traceAdditive(origin, direction, payload_opaque.hit_pos_t.w); - #ifdef DEBUG_LIGHT_CULLING // light clusters debugging { @@ -423,7 +426,11 @@ void main() { imageStore(out_image_normals, ivec2(gl_LaunchIDEXT.xy), vec4(geometryNormal.xy, shadingNormal.xy)); payload_opaque.base_color = vec3(1.); + //out_material_index = float(kusochki[payload_opaque.kusok_index].tex_roughness); #if 0 + //imageStore(out_image_base_color, ivec2(gl_LaunchIDEXT.xy), vec4(fract(payload_opaque.debug.xy), 0., 0.)); + //imageStore(out_image_base_color, ivec2(gl_LaunchIDEXT.xy), vec4(payload_opaque.kusok_index)); + imageStore(out_image_base_color, ivec2(gl_LaunchIDEXT.xy), vec4(payload_opaque.roughness)); imageStore(out_image_diffuse_gi, ivec2(gl_LaunchIDEXT.xy), vec4(0)); imageStore(out_image_specular, ivec2(gl_LaunchIDEXT.xy), vec4(0.)); imageStore(out_image_additive, ivec2(gl_LaunchIDEXT.xy), vec4(clamp(payload_opaque.normal, vec3(0.), vec3(1.)), 0.));