diff --git a/ref_vk/shaders/ray.rgen b/ref_vk/shaders/ray.rgen index fb15f462..029b240c 100644 --- a/ref_vk/shaders/ray.rgen +++ b/ref_vk/shaders/ray.rgen @@ -298,7 +298,7 @@ void main() { const uint sbt_stride = 0; const uint miss_index = 0; const float L = 10000.; - traceRayEXT(tlas, flags, GEOMETRY_BIT_OPAQUE, + traceRayEXT(tlas, flags, GEOMETRY_BIT_OPAQUE | GEOMETRY_BIT_REFRACTIVE, sbt_offset, sbt_stride, miss_index, origin, 0., direction, L, PAYLOAD_LOCATION_OPAQUE); diff --git a/ref_vk/shaders/ray_interop.h b/ref_vk/shaders/ray_interop.h index 2737c402..1cd571c4 100644 --- a/ref_vk/shaders/ray_interop.h +++ b/ref_vk/shaders/ray_interop.h @@ -23,6 +23,7 @@ layout (constant_id = 3) const uint MAX_VISIBLE_SURFACE_LIGHTS = 255; #define GEOMETRY_BIT_OPAQUE 0x01 #define GEOMETRY_BIT_ADDITIVE 0x02 +#define GEOMETRY_BIT_REFRACTIVE 0x04 #define SHADER_OFFSET_MISS_REGULAR 0 #define SHADER_OFFSET_MISS_SHADOW 1 diff --git a/ref_vk/vk_ray_internal.h b/ref_vk/vk_ray_internal.h index 5413f513..c01a4648 100644 --- a/ref_vk/vk_ray_internal.h +++ b/ref_vk/vk_ray_internal.h @@ -34,6 +34,8 @@ typedef struct { enum { MaterialMode_Opaque, MaterialMode_Opaque_AlphaTest, + MaterialMode_Refractive, + // TODO MaterialMode_Subtractive, MaterialMode_Additive, } material_mode; } vk_ray_draw_model_t; diff --git a/ref_vk/vk_ray_model.c b/ref_vk/vk_ray_model.c index aa143b5b..ce106f1d 100644 --- a/ref_vk/vk_ray_model.c +++ b/ref_vk/vk_ray_model.c @@ -339,7 +339,7 @@ void VK_RayFrameAddModel( vk_ray_model_t *model, const vk_render_model_t *render case kRenderTransColor: case kRenderTransTexture: HACK_reflective = true; - draw_model->material_mode = MaterialMode_Opaque_AlphaTest; // FIXME add new translucency mode + draw_model->material_mode = MaterialMode_Refractive; break; // Additive blending: C = SRC * alpha + DST diff --git a/ref_vk/vk_rtx.c b/ref_vk/vk_rtx.c index 085f01a1..ce62d0e6 100644 --- a/ref_vk/vk_rtx.c +++ b/ref_vk/vk_rtx.c @@ -523,6 +523,10 @@ static void prepareTlas( VkCommandBuffer cmdbuf ) { inst[i].instanceShaderBindingTableRecordOffset = SHADER_OFFSET_HIT_ALPHA_TEST, inst[i].flags = VK_GEOMETRY_INSTANCE_FORCE_NO_OPAQUE_BIT_KHR; break; + case MaterialMode_Refractive: + inst[i].mask = GEOMETRY_BIT_REFRACTIVE; + inst[i].flags = VK_GEOMETRY_INSTANCE_FORCE_OPAQUE_BIT_KHR; + break; case MaterialMode_Additive: inst[i].mask = GEOMETRY_BIT_ADDITIVE; inst[i].instanceShaderBindingTableRecordOffset = SHADER_OFFSET_HIT_ADDITIVE,