diff options
author | clayjohn <claynjohn@gmail.com> | 2023-01-19 12:58:59 -0800 |
---|---|---|
committer | clayjohn <claynjohn@gmail.com> | 2023-01-19 12:58:59 -0800 |
commit | 2ccc69cd7dc57e8ca47601818be3450e00b81865 (patch) | |
tree | 5796afe25c8db5dba8b6cf21e0f030c8e3be29be /servers | |
parent | 14fdd28de9f1f9979cb6cffa4b715a16d406439d (diff) |
Use proper space for forward GI reflections
Diffstat (limited to 'servers')
-rw-r--r-- | servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl b/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl index d32e6d717f..92bf208ef1 100644 --- a/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl +++ b/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl @@ -1305,24 +1305,26 @@ void fragment_shader(in SceneData scene_data) { } if (sc_use_forward_gi && bool(instances.data[instance_index].flags & INSTANCE_FLAGS_USE_VOXEL_GI)) { // process voxel_gi_instances - uint index1 = instances.data[instance_index].gi_offset & 0xFFFF; - vec3 ref_vec = normalize(reflect(-view, normal)); - ref_vec = mix(ref_vec, normal, roughness * roughness); + // Make vertex orientation the world one, but still align to camera. + vec3 cam_pos = mat3(scene_data.inv_view_matrix) * vertex; + vec3 cam_normal = mat3(scene_data.inv_view_matrix) * normal; + vec3 ref_vec = mat3(scene_data.inv_view_matrix) * normalize(reflect(-view, normal)); + //find arbitrary tangent and bitangent, then build a matrix - vec3 v0 = abs(normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(0.0, 1.0, 0.0); - vec3 tangent = normalize(cross(v0, normal)); - vec3 bitangent = normalize(cross(tangent, normal)); - mat3 normal_mat = mat3(tangent, bitangent, normal); + vec3 v0 = abs(cam_normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(0.0, 1.0, 0.0); + vec3 tangent = normalize(cross(v0, cam_normal)); + vec3 bitangent = normalize(cross(tangent, cam_normal)); + mat3 normal_mat = mat3(tangent, bitangent, cam_normal); vec4 amb_accum = vec4(0.0); vec4 spec_accum = vec4(0.0); - voxel_gi_compute(index1, vertex, normal, ref_vec, normal_mat, roughness * roughness, ambient_light, specular_light, spec_accum, amb_accum); + voxel_gi_compute(index1, cam_pos, cam_normal, ref_vec, normal_mat, roughness * roughness, ambient_light, specular_light, spec_accum, amb_accum); uint index2 = instances.data[instance_index].gi_offset >> 16; if (index2 != 0xFFFF) { - voxel_gi_compute(index2, vertex, normal, ref_vec, normal_mat, roughness * roughness, ambient_light, specular_light, spec_accum, amb_accum); + voxel_gi_compute(index2, cam_pos, cam_normal, ref_vec, normal_mat, roughness * roughness, ambient_light, specular_light, spec_accum, amb_accum); } if (amb_accum.a > 0.0) { |