1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-13 13:31:48 +00:00

ReflectionProbe priority

This commit is contained in:
landervr
2024-12-05 22:50:06 +01:00
parent 691d8bee2b
commit 1637736c20
7 changed files with 68 additions and 29 deletions

View File

@@ -1897,17 +1897,29 @@ void fragment_shader(in SceneData scene_data) {
continue; //not masked
}
if (reflection_accum.a >= 1.0 && ambient_accum.a >= 1.0) {
break;
}
reflection_process(reflection_index, vertex, ref_vec, normal, roughness, ambient_light, specular_light, ambient_accum, reflection_accum);
}
}
if (ambient_accum.a < 1.0) {
ambient_accum.rgb = mix(ambient_light, ambient_accum.rgb, ambient_accum.a);
}
if (reflection_accum.a < 1.0) {
reflection_accum.rgb = mix(specular_light, reflection_accum.rgb, reflection_accum.a);
}
if (reflection_accum.a > 0.0) {
specular_light = reflection_accum.rgb / reflection_accum.a;
specular_light = reflection_accum.rgb;
}
#if !defined(USE_LIGHTMAP)
if (ambient_accum.a > 0.0) {
ambient_light = ambient_accum.rgb / ambient_accum.a;
ambient_light = ambient_accum.rgb;
}
#endif
}

View File

@@ -1364,16 +1364,29 @@ void main() {
uvec2 reflection_indices = instances.data[draw_call.instance_index].reflection_probes;
for (uint i = 0; i < sc_reflection_probes(); i++) {
uint reflection_index = (i > 3) ? ((reflection_indices.y >> ((i - 4) * 8)) & 0xFF) : ((reflection_indices.x >> (i * 8)) & 0xFF);
reflection_process(reflection_index, vertex, ref_vec, bent_normal, roughness, ambient_light, specular_light, ambient_accum, reflection_accum);
if (reflection_accum.a >= 1.0 && ambient_accum.a >= 1.0) {
break;
}
reflection_process(reflection_index, vertex, ref_vec, normal, roughness, ambient_light, specular_light, ambient_accum, reflection_accum);
}
if (ambient_accum.a < 1.0) {
ambient_accum.rgb = mix(ambient_light, ambient_accum.rgb, ambient_accum.a);
}
if (reflection_accum.a < 1.0) {
reflection_accum.rgb = mix(specular_light, reflection_accum.rgb, reflection_accum.a);
}
if (reflection_accum.a > 0.0) {
specular_light = reflection_accum.rgb / reflection_accum.a;
specular_light = reflection_accum.rgb;
}
#if !defined(USE_LIGHTMAP)
if (ambient_accum.a > 0.0) {
ambient_light = ambient_accum.rgb / ambient_accum.a;
ambient_light = ambient_accum.rgb;
}
#endif
} //Reflection probes

View File

@@ -885,7 +885,7 @@ void reflection_process(uint ref_index, vec3 vertex, vec3 ref_vec, vec3 normal,
blend = pow(blend_axes.x * blend_axes.y * blend_axes.z, 2.0);
}
if (reflections.data[ref_index].intensity > 0.0) { // compute reflection
if (reflections.data[ref_index].intensity > 0.0 && reflection_accum.a < 1.0) { // compute reflection
vec3 local_ref_vec = (reflections.data[ref_index].local_matrix * vec4(ref_vec, 0.0)).xyz;
@@ -903,47 +903,43 @@ void reflection_process(uint ref_index, vec3 vertex, vec3 ref_vec, vec3 normal,
}
vec4 reflection;
float reflection_blend = max(0.0, blend - reflection_accum.a);
reflection.rgb = textureLod(samplerCubeArray(reflection_atlas, DEFAULT_SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP), vec4(local_ref_vec, reflections.data[ref_index].index), sqrt(roughness) * MAX_ROUGHNESS_LOD).rgb * sc_luminance_multiplier();
reflection.rgb *= reflections.data[ref_index].exposure_normalization;
if (reflections.data[ref_index].exterior) {
reflection.rgb = mix(specular_light, reflection.rgb, blend);
}
reflection.a = reflection_blend;
reflection.rgb *= reflections.data[ref_index].intensity; //intensity
reflection.a = blend;
reflection.rgb *= reflections.data[ref_index].intensity;
reflection.rgb *= reflection.a;
reflection_accum += reflection;
}
if (ambient_accum.a >= 1.0) {
return;
}
switch (reflections.data[ref_index].ambient_mode) {
case REFLECTION_AMBIENT_DISABLED: {
//do nothing
} break;
case REFLECTION_AMBIENT_ENVIRONMENT: {
//do nothing
vec3 local_amb_vec = (reflections.data[ref_index].local_matrix * vec4(normal, 0.0)).xyz;
vec4 ambient_out;
float ambient_blend = max(0.0, blend - ambient_accum.a);
ambient_out.rgb = textureLod(samplerCubeArray(reflection_atlas, DEFAULT_SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP), vec4(local_amb_vec, reflections.data[ref_index].index), MAX_ROUGHNESS_LOD).rgb;
ambient_out.rgb *= reflections.data[ref_index].exposure_normalization;
ambient_out.a = blend;
if (reflections.data[ref_index].exterior) {
ambient_out.rgb = mix(ambient_light, ambient_out.rgb, blend);
}
ambient_out.a = ambient_blend;
ambient_out.rgb *= ambient_out.a;
ambient_accum += ambient_out;
} break;
case REFLECTION_AMBIENT_COLOR: {
vec4 ambient_out;
ambient_out.a = blend;
float ambient_blend = max(0.0, blend - ambient_accum.a);
ambient_out.rgb = reflections.data[ref_index].ambient;
if (reflections.data[ref_index].exterior) {
ambient_out.rgb = mix(ambient_light, ambient_out.rgb, blend);
}
ambient_out.a = ambient_blend;
ambient_out.rgb *= ambient_out.a;
ambient_accum += ambient_out;
} break;