From 593be43b58d0bff63340eb33cd23b36fa6767512 Mon Sep 17 00:00:00 2001 From: Anton Baskanov Date: Wed, 10 Nov 2021 01:42:34 +0700 Subject: [PATCH 1/2] Pass world positions to computeAnisotropicEllipseAxes(). Fixes #197. --- ref_vk/shaders/ray.rchit | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ref_vk/shaders/ray.rchit b/ref_vk/shaders/ray.rchit index 5ca89469..8628d990 100644 --- a/ref_vk/shaders/ray.rchit +++ b/ref_vk/shaders/ray.rchit @@ -87,19 +87,19 @@ void main() { }; const vec3 pos[3] = { - vertices[vi1].pos, - vertices[vi2].pos, - vertices[vi3].pos, + gl_ObjectToWorldEXT * vec4(vertices[vi1].pos, 1.), + gl_ObjectToWorldEXT * vec4(vertices[vi2].pos, 1.), + gl_ObjectToWorldEXT * vec4(vertices[vi3].pos, 1.), }; const vec2 texture_uv = vertices[vi1].gl_tc * (1. - bary.x - bary.y) + vertices[vi2].gl_tc * bary.x + vertices[vi3].gl_tc * bary.y + push_constants.time * kusochki[kusok_index].uv_speed; const uint tex_index = kusochki[kusok_index].texture; - const vec3 real_geom_normal = normalize(normalTransformMat * cross(pos[2]-pos[0], pos[1]-pos[0])); + const vec3 real_geom_normal = normalize(cross(pos[2]-pos[0], pos[1]-pos[0])); const float geom_normal_sign = sign(dot(real_geom_normal, -gl_WorldRayDirectionEXT)); const vec3 geom_normal = geom_normal_sign * real_geom_normal; // This one is supposed to be numerically better, but I can't see why - const vec3 hit_pos = (gl_ObjectToWorldEXT * vec4(pos[0] * (1. - bary.x - bary.y) + pos[1] * bary.x + pos[2] * bary.y, 1.)).xyz + geom_normal * normal_offset_fudge; + const vec3 hit_pos = pos[0] * (1. - bary.x - bary.y) + pos[1] * bary.x + pos[2] * bary.y + geom_normal * normal_offset_fudge; //const vec3 hit_pos = gl_WorldRayOriginEXT + gl_WorldRayDirectionEXT * gl_HitTEXT + geom_normal * normal_offset_fudge; const float ray_cone_width = payload.pixel_cone_spread_angle * payload.t_offset; From c17a53c78f138c335f416e42590cb39d1c9b1e49 Mon Sep 17 00:00:00 2001 From: Anton Baskanov Date: Wed, 10 Nov 2021 12:27:31 +0700 Subject: [PATCH 2/2] Pass stationary UV coordinates to computeAnisotropicEllipseAxes. The coordinates must match the ones in the uvs array. Fixes blur of func_conveyor textures. --- ref_vk/shaders/ray.rchit | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ref_vk/shaders/ray.rchit b/ref_vk/shaders/ray.rchit index 8628d990..50c8b644 100644 --- a/ref_vk/shaders/ray.rchit +++ b/ref_vk/shaders/ray.rchit @@ -91,7 +91,8 @@ void main() { gl_ObjectToWorldEXT * vec4(vertices[vi2].pos, 1.), gl_ObjectToWorldEXT * vec4(vertices[vi3].pos, 1.), }; - const vec2 texture_uv = vertices[vi1].gl_tc * (1. - bary.x - bary.y) + vertices[vi2].gl_tc * bary.x + vertices[vi3].gl_tc * bary.y + push_constants.time * kusochki[kusok_index].uv_speed; + const vec2 texture_uv_stationary = vertices[vi1].gl_tc * (1. - bary.x - bary.y) + vertices[vi2].gl_tc * bary.x + vertices[vi3].gl_tc * bary.y; + const vec2 texture_uv = texture_uv_stationary + push_constants.time * kusochki[kusok_index].uv_speed; const uint tex_index = kusochki[kusok_index].texture; const vec3 real_geom_normal = normalize(cross(pos[2]-pos[0], pos[1]-pos[0])); @@ -104,7 +105,7 @@ void main() { const float ray_cone_width = payload.pixel_cone_spread_angle * payload.t_offset; vec4 uv_lods; - computeAnisotropicEllipseAxes(hit_pos, normal, gl_WorldRayDirectionEXT, ray_cone_width, pos, uvs, texture_uv, uv_lods.xy, uv_lods.zw); + computeAnisotropicEllipseAxes(hit_pos, normal, gl_WorldRayDirectionEXT, ray_cone_width, pos, uvs, texture_uv_stationary, uv_lods.xy, uv_lods.zw); const vec4 tex_color = textureGrad(textures[nonuniformEXT(tex_index)], texture_uv, uv_lods.xy, uv_lods.zw); //const vec3 base_color = pow(tex_color.rgb, vec3(2.)); const vec3 base_color = ((push_constants.flags & PUSH_FLAG_LIGHTMAP_ONLY) != 0) ? vec3(1.) : tex_color.rgb;// pow(tex_color.rgb, vec3(2.));