Skip to content

Commit

Permalink
Small fixups for the new reflection probe blending
Browse files Browse the repository at this point in the history
  • Loading branch information
clayjohn committed Dec 13, 2024
1 parent ba2c5c1 commit 356fa37
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
22 changes: 8 additions & 14 deletions drivers/gles3/shaders/scene.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -1619,21 +1619,15 @@ void reflection_process(samplerCube reflection_map,
return;
}

vec3 inner_pos = abs(local_pos / box_extents);
vec3 blend_axes = vec3(0.0, 0.0, 0.0);
float blend = 0.0;
if (blend_distance != 0) {
for (int i = 0; i < 3; i++) {
float axis_blend_distance = min(blend_distance, box_extents[i]);
blend_axes[i] = (inner_pos[i] * box_extents[i]) - box_extents[i] + axis_blend_distance;
blend_axes[i] = blend_axes[i] / axis_blend_distance;
blend_axes[i] = clamp(blend_axes[i], 0.0, 1.0);
}
blend = pow((1.0 - blend_axes.x) * (1.0 - blend_axes.y) * (1.0 - blend_axes.z), 2);
blend = 1 - blend;
float blend = 1.0;
if (blend_distance != 0.0) {
vec3 axis_blend_distance = min(vec3(blend_distance), box_extents);
vec3 blend_axes = abs(local_pos) - box_extents + axis_blend_distance;
blend_axes /= axis_blend_distance;
blend_axes = clamp(1.0 - blend_axes, vec3(0.0), vec3(1.0));

blend = pow(blend_axes.x * blend_axes.y * blend_axes.z, 2.0);
}
blend = max(0.0, 1.0 - blend);
blend = clamp(blend, 0.0, 1.0);

//reflect and make local
vec3 ref_normal = normalize(reflect(vertex, normal));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -875,21 +875,15 @@ void reflection_process(uint ref_index, vec3 vertex, vec3 ref_vec, vec3 normal,
return;
}

vec3 inner_pos = abs(local_pos / box_extents);
vec3 blend_axes = vec3(0.0, 0.0, 0.0);
float blend = 0.0;
if (reflections.data[ref_index].blend_distance != 0) {
for (int i = 0; i < 3; i++) {
float axis_blend_distance = min(reflections.data[ref_index].blend_distance, box_extents[i]);
blend_axes[i] = (inner_pos[i] * box_extents[i]) - box_extents[i] + axis_blend_distance;
blend_axes[i] = blend_axes[i] / axis_blend_distance;
blend_axes[i] = clamp(blend_axes[i], 0.0, 1.0);
}
blend = pow((1.0 - blend_axes.x) * (1.0 - blend_axes.y) * (1.0 - blend_axes.z), 2);
blend = 1 - blend;
float blend = 1.0;
if (reflections.data[ref_index].blend_distance != 0.0) {
vec3 axis_blend_distance = min(vec3(reflections.data[ref_index].blend_distance), box_extents);
vec3 blend_axes = abs(local_pos) - box_extents + axis_blend_distance;
blend_axes /= axis_blend_distance;
blend_axes = clamp(1.0 - blend_axes, vec3(0.0), vec3(1.0));

blend = pow(blend_axes.x * blend_axes.y * blend_axes.z, 2.0);
}
blend = max(0.0, 1.0 - blend);
blend = clamp(blend, 0.0, 1.0);

if (reflections.data[ref_index].intensity > 0.0) { // compute reflection

Expand Down

0 comments on commit 356fa37

Please sign in to comment.