Merge pull request #71694 from clayjohn/VoxelGI-reflection
Use proper space for forward GI reflections
This commit is contained in:
commit
260daf8a13
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue